001: /*
002: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
003: *
004: * The program is provided "as is" without any warranty express or
005: * implied, including the warranty of non-infringement and the implied
006: * warranties of merchantibility and fitness for a particular purpose.
007: * IBM will not be liable for any damages suffered by you as a result
008: * of using the Program. In no event will IBM be liable for any
009: * special, indirect or consequential damages or lost profits even if
010: * IBM has been advised of the possibility of their occurrence. IBM
011: * will not be liable for any third party claims against you.
012: */
013: package com.ibm.richtext.textpanel;
014:
015: import java.awt.Component;
016: import java.awt.Container;
017: import java.awt.Dimension;
018: import java.awt.Insets;
019: import java.awt.LayoutManager;
020:
021: class ScrollBarLayout implements LayoutManager {
022:
023: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
024: Component fHorizScrollBar = null;
025: Component fVertScrollBar = null;
026: Component fChild = null;
027:
028: public ScrollBarLayout() {
029: }
030:
031: public void addLayoutComponent(String name, Component comp) {
032:
033: if ("Center".equals(name))
034: fChild = comp;
035: else if ("South".equals(name))
036: fHorizScrollBar = comp;
037: else if ("East".equals(name))
038: fVertScrollBar = comp;
039: }
040:
041: public void layoutContainer(Container target) {
042:
043: Insets insets = target.getInsets();
044: Dimension targetSize = target.getSize();
045: int hsbHeight = (fHorizScrollBar != null) ? fHorizScrollBar
046: .getPreferredSize().height : 0;
047: int vsbWidth = (fVertScrollBar != null) ? fVertScrollBar
048: .getPreferredSize().width : 0;
049:
050: if (fHorizScrollBar != null)
051: fHorizScrollBar.setBounds(insets.left, targetSize.height
052: - insets.bottom - hsbHeight, targetSize.width
053: - vsbWidth, hsbHeight);
054:
055: if (fVertScrollBar != null)
056: fVertScrollBar.setBounds(targetSize.width - insets.right
057: - vsbWidth, insets.top, vsbWidth, targetSize.height
058: - hsbHeight);
059:
060: if (fChild != null)
061: fChild.setBounds(insets.left, insets.top, targetSize.width
062: - insets.right - vsbWidth, targetSize.height
063: - insets.bottom - hsbHeight);
064: }
065:
066: public Dimension minimumLayoutSize(Container target) {
067:
068: Dimension returnVal = new Dimension(0, 0);
069: Dimension hsbSize;
070: Dimension vsbSize;
071: Dimension childSize;
072:
073: if (fHorizScrollBar != null && fHorizScrollBar.isVisible()) {
074: hsbSize = fHorizScrollBar.getMinimumSize();
075: } else {
076: hsbSize = new Dimension(0, 0);
077: }
078:
079: if (fVertScrollBar != null && fVertScrollBar.isVisible()) {
080: vsbSize = fVertScrollBar.getMinimumSize();
081: } else {
082: vsbSize = new Dimension(0, 0);
083: }
084:
085: if (fChild != null && fChild.isVisible()) {
086: childSize = fChild.getMinimumSize();
087: } else {
088: childSize = new Dimension(0, 0);
089: }
090:
091: returnVal.width = Math.max(childSize.width, hsbSize.width)
092: + vsbSize.width;
093: returnVal.height = Math.max(childSize.height, vsbSize.height)
094: + hsbSize.height;
095:
096: Insets insets = target.getInsets();
097:
098: returnVal.width += insets.left + insets.right;
099: returnVal.height += insets.top + insets.bottom;
100:
101: return returnVal;
102: }
103:
104: public Dimension preferredLayoutSize(Container target) {
105:
106: Dimension returnVal = new Dimension(0, 0);
107: Dimension hsbSize;
108: Dimension vsbSize;
109: Dimension childSize;
110:
111: if (fHorizScrollBar != null && fHorizScrollBar.isVisible()) {
112: hsbSize = fHorizScrollBar.getPreferredSize();
113: } else {
114: hsbSize = new Dimension(0, 0);
115: }
116:
117: if (fVertScrollBar != null && fVertScrollBar.isVisible()) {
118: vsbSize = fVertScrollBar.getPreferredSize();
119: } else {
120: vsbSize = new Dimension(0, 0);
121: }
122:
123: if (fChild != null && fChild.isVisible()) {
124: childSize = fChild.getPreferredSize();
125: } else {
126: childSize = new Dimension(0, 0);
127: }
128:
129: returnVal.width = Math.max(childSize.width, hsbSize.width)
130: + vsbSize.width;
131: returnVal.height = Math.max(childSize.height, vsbSize.height)
132: + hsbSize.height;
133:
134: Insets insets = target.getInsets();
135:
136: returnVal.width += insets.left + insets.right;
137: returnVal.height += insets.top + insets.bottom;
138:
139: return returnVal;
140: }
141:
142: public void removeLayoutComponent(Component comp) {
143:
144: if (comp == fChild)
145: fChild = null;
146: else if (comp == fHorizScrollBar)
147: fHorizScrollBar = null;
148: else if (comp == fVertScrollBar)
149: fVertScrollBar = null;
150: }
151: }
|