2 * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
\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
13 package com.ibm.richtext.textpanel;
\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
21 class ScrollBarLayout implements LayoutManager {
\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
29 public ScrollBarLayout() {
\r
32 public void addLayoutComponent(String name, Component comp) {
\r
34 if ("Center".equals(name))
\r
36 else if ("South".equals(name))
\r
37 fHorizScrollBar = comp;
\r
38 else if ("East".equals(name))
\r
39 fVertScrollBar = comp;
\r
42 public void layoutContainer(Container target) {
\r
44 Insets insets = target.getInsets();
\r
45 Dimension targetSize = target.getSize();
\r
46 int hsbHeight = (fHorizScrollBar != null) ? fHorizScrollBar.getPreferredSize().
\r
48 int vsbWidth = (fVertScrollBar != null) ? fVertScrollBar.getPreferredSize().
\r
51 if (fHorizScrollBar != null)
\r
52 fHorizScrollBar.setBounds(insets.left, targetSize.height - insets.bottom -
\r
53 hsbHeight, targetSize.width - vsbWidth, hsbHeight);
\r
55 if (fVertScrollBar != null)
\r
56 fVertScrollBar.setBounds(targetSize.width - insets.right - vsbWidth,
\r
57 insets.top, vsbWidth, targetSize.height - hsbHeight);
\r
60 fChild.setBounds(insets.left, insets.top, targetSize.width - insets.right - vsbWidth,
\r
61 targetSize.height - insets.bottom - hsbHeight);
\r
64 public Dimension minimumLayoutSize(Container target) {
\r
66 Dimension returnVal = new Dimension(0, 0);
\r
69 Dimension childSize;
\r
71 if (fHorizScrollBar != null && fHorizScrollBar.isVisible()) {
\r
72 hsbSize = fHorizScrollBar.getMinimumSize();
\r
75 hsbSize = new Dimension(0, 0);
\r
78 if (fVertScrollBar != null && fVertScrollBar.isVisible()) {
\r
79 vsbSize = fVertScrollBar.getMinimumSize();
\r
82 vsbSize = new Dimension(0, 0);
\r
85 if (fChild != null && fChild.isVisible()) {
\r
86 childSize = fChild.getMinimumSize();
\r
89 childSize = new Dimension(0, 0);
\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
95 Insets insets = target.getInsets();
\r
97 returnVal.width += insets.left + insets.right;
\r
98 returnVal.height += insets.top + insets.bottom;
\r
103 public Dimension preferredLayoutSize(Container target) {
\r
105 Dimension returnVal = new Dimension(0, 0);
\r
108 Dimension childSize;
\r
110 if (fHorizScrollBar != null && fHorizScrollBar.isVisible()) {
\r
111 hsbSize = fHorizScrollBar.getPreferredSize();
\r
114 hsbSize = new Dimension(0, 0);
\r
117 if (fVertScrollBar != null && fVertScrollBar.isVisible()) {
\r
118 vsbSize = fVertScrollBar.getPreferredSize();
\r
121 vsbSize = new Dimension(0, 0);
\r
124 if (fChild != null && fChild.isVisible()) {
\r
125 childSize = fChild.getPreferredSize();
\r
128 childSize = new Dimension(0, 0);
\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
134 Insets insets = target.getInsets();
\r
136 returnVal.width += insets.left + insets.right;
\r
137 returnVal.height += insets.top + insets.bottom;
\r
142 public void removeLayoutComponent(Component comp) {
\r
144 if (comp == fChild)
\r
146 else if (comp == fHorizScrollBar)
\r
147 fHorizScrollBar = null;
\r
148 else if (comp == fVertScrollBar)
\r
149 fVertScrollBar = null;
\r