]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/textpanel/ScrollBarLayout.java
go
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / textpanel / ScrollBarLayout.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.\r
3  *\r
4  * The program is provided "as is" without any warranty express or\r
5  * implied, including the warranty of non-infringement and the implied\r
6  * warranties of merchantibility and fitness for a particular purpose.\r
7  * IBM will not be liable for any damages suffered by you as a result\r
8  * of using the Program. In no event will IBM be liable for any\r
9  * special, indirect or consequential damages or lost profits even if\r
10  * IBM has been advised of the possibility of their occurrence. IBM\r
11  * will not be liable for any third party claims against you.\r
12  */\r
13 package com.ibm.richtext.textpanel;\r
14 \r
15 import java.awt.Component;\r
16 import java.awt.Container;\r
17 import java.awt.Dimension;\r
18 import java.awt.Insets;\r
19 import java.awt.LayoutManager;\r
20 \r
21 class ScrollBarLayout implements LayoutManager {\r
22 \r
23     static final String COPYRIGHT =\r
24                 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
25     Component   fHorizScrollBar = null;\r
26     Component   fVertScrollBar = null;\r
27     Component   fChild = null;\r
28 \r
29     public ScrollBarLayout() {\r
30     }\r
31 \r
32     public void addLayoutComponent(String name, Component comp) {\r
33 \r
34         if ("Center".equals(name))\r
35             fChild = comp;\r
36         else if ("South".equals(name))\r
37             fHorizScrollBar = comp;\r
38         else if ("East".equals(name))\r
39             fVertScrollBar = comp;\r
40     }\r
41 \r
42     public void layoutContainer(Container target) {\r
43 \r
44         Insets      insets = target.getInsets();\r
45         Dimension   targetSize = target.getSize();\r
46         int         hsbHeight = (fHorizScrollBar != null) ? fHorizScrollBar.getPreferredSize().\r
47                             height : 0;\r
48         int         vsbWidth = (fVertScrollBar != null) ? fVertScrollBar.getPreferredSize().\r
49                             width : 0;\r
50 \r
51         if (fHorizScrollBar != null)\r
52             fHorizScrollBar.setBounds(insets.left, targetSize.height - insets.bottom -\r
53                                 hsbHeight, targetSize.width - vsbWidth, hsbHeight);\r
54 \r
55         if (fVertScrollBar != null)\r
56             fVertScrollBar.setBounds(targetSize.width - insets.right - vsbWidth,\r
57                                 insets.top, vsbWidth, targetSize.height - hsbHeight);\r
58 \r
59         if (fChild != null)\r
60             fChild.setBounds(insets.left, insets.top, targetSize.width - insets.right - vsbWidth,\r
61                                 targetSize.height - insets.bottom - hsbHeight);\r
62     }\r
63 \r
64     public Dimension minimumLayoutSize(Container target) {\r
65 \r
66         Dimension   returnVal = new Dimension(0, 0);\r
67         Dimension   hsbSize;\r
68         Dimension   vsbSize;\r
69         Dimension   childSize;\r
70 \r
71         if (fHorizScrollBar != null && fHorizScrollBar.isVisible()) {\r
72             hsbSize = fHorizScrollBar.getMinimumSize();\r
73         }\r
74         else {\r
75             hsbSize = new Dimension(0, 0);\r
76         }\r
77 \r
78         if (fVertScrollBar != null && fVertScrollBar.isVisible()) {\r
79             vsbSize = fVertScrollBar.getMinimumSize();\r
80         }\r
81         else {\r
82             vsbSize = new Dimension(0, 0);\r
83         }\r
84 \r
85         if (fChild != null && fChild.isVisible()) {\r
86             childSize = fChild.getMinimumSize();\r
87         }\r
88         else {\r
89             childSize = new Dimension(0, 0);\r
90         }\r
91 \r
92         returnVal.width = Math.max(childSize.width, hsbSize.width) + vsbSize.width;\r
93         returnVal.height = Math.max(childSize.height, vsbSize.height) + hsbSize.height;\r
94 \r
95         Insets  insets = target.getInsets();\r
96 \r
97         returnVal.width += insets.left + insets.right;\r
98         returnVal.height += insets.top + insets.bottom;\r
99 \r
100         return returnVal;\r
101     }\r
102 \r
103     public Dimension preferredLayoutSize(Container target) {\r
104 \r
105         Dimension   returnVal = new Dimension(0, 0);\r
106         Dimension   hsbSize;\r
107         Dimension   vsbSize;\r
108         Dimension   childSize;\r
109 \r
110         if (fHorizScrollBar != null && fHorizScrollBar.isVisible()) {\r
111             hsbSize = fHorizScrollBar.getPreferredSize();\r
112         }\r
113         else {\r
114             hsbSize = new Dimension(0, 0);\r
115         }\r
116 \r
117         if (fVertScrollBar != null && fVertScrollBar.isVisible()) {\r
118             vsbSize = fVertScrollBar.getPreferredSize();\r
119         }\r
120         else {\r
121             vsbSize = new Dimension(0, 0);\r
122         }\r
123 \r
124         if (fChild != null && fChild.isVisible()) {\r
125             childSize = fChild.getPreferredSize();\r
126         }\r
127         else {\r
128             childSize = new Dimension(0, 0);\r
129         }\r
130 \r
131         returnVal.width = Math.max(childSize.width, hsbSize.width) + vsbSize.width;\r
132         returnVal.height = Math.max(childSize.height, vsbSize.height) + hsbSize.height;\r
133 \r
134         Insets  insets = target.getInsets();\r
135 \r
136         returnVal.width += insets.left + insets.right;\r
137         returnVal.height += insets.top + insets.bottom;\r
138 \r
139         return returnVal;\r
140     }\r
141 \r
142     public void removeLayoutComponent(Component comp) {\r
143 \r
144         if (comp == fChild)\r
145             fChild = null;\r
146         else if (comp == fHorizScrollBar)\r
147             fHorizScrollBar = null;\r
148         else if (comp == fVertScrollBar)\r
149             fVertScrollBar = null;\r
150     }\r
151 }\r