1 | /* |
---|
2 | * $Id: StackedLayout.java,v 1.5 2003/08/22 23:02:32 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt; |
---|
14 | |
---|
15 | import gov.noaa.pmel.sgt.beans.Panel; |
---|
16 | import java.awt.LayoutManager; |
---|
17 | import java.awt.Container; |
---|
18 | import java.awt.Dimension; |
---|
19 | import java.awt.Rectangle; |
---|
20 | import java.awt.Component; |
---|
21 | import java.awt.Insets; |
---|
22 | |
---|
23 | /** |
---|
24 | * <code>StackedLayout</code> works with <code>Pane</code> to |
---|
25 | * position multiple <code>Layer</code>s directly over each other. |
---|
26 | * |
---|
27 | * @author Donald Denbo |
---|
28 | * @version $Revision: 1.5 $, $Date: 2003/08/22 23:02:32 $ |
---|
29 | * @since 1.0 |
---|
30 | * @see Pane#setLayout |
---|
31 | * @see Layer |
---|
32 | */ |
---|
33 | public class StackedLayout implements LayoutManager { |
---|
34 | public Dimension preferredLayoutSize(Container parent) { |
---|
35 | synchronized (parent.getTreeLock()) { |
---|
36 | return parent.getSize(); |
---|
37 | } |
---|
38 | } |
---|
39 | public Dimension minimumLayoutSize(Container parent) { |
---|
40 | synchronized (parent.getTreeLock()) { |
---|
41 | return parent.getSize(); |
---|
42 | } |
---|
43 | } |
---|
44 | public void layoutContainer(Container parent) { |
---|
45 | synchronized (parent.getTreeLock()) { |
---|
46 | JPane pane = null; |
---|
47 | boolean batch = false; |
---|
48 | if(parent instanceof JPane) { |
---|
49 | pane = (JPane)parent; |
---|
50 | batch = pane.isBatch(); |
---|
51 | pane.setBatch(true, "StackedLayout"); |
---|
52 | } else if(parent instanceof Panel) { |
---|
53 | pane = ((Panel)parent).getPane(); |
---|
54 | batch = pane.isBatch(); |
---|
55 | pane.setBatch(true, "StackedLayout"); |
---|
56 | } |
---|
57 | Insets insets = parent.getInsets(); |
---|
58 | Rectangle rect = parent.getBounds(); |
---|
59 | int ncomponents = parent.getComponentCount(); |
---|
60 | int x, y, w, h; |
---|
61 | x = rect.x + insets.left; |
---|
62 | y = rect.y + insets.top; |
---|
63 | w = rect.width - (insets.left + insets.right); |
---|
64 | h = rect.height - (insets.top + insets.bottom); |
---|
65 | for(int i=0; i < ncomponents; i++) { |
---|
66 | parent.getComponent(i).setBounds(x, y, w, h); |
---|
67 | } |
---|
68 | if(!batch) pane.setBatch(false, "StackedLayout"); |
---|
69 | } |
---|
70 | } |
---|
71 | public void removeLayoutComponent(Component comp) { |
---|
72 | } |
---|
73 | public void addLayoutComponent(String name, Component comp) { |
---|
74 | } |
---|
75 | } |
---|