38
38
package javax.swing.plaf.metal;
40
40
import java.awt.Color;
41
import java.awt.Component;
42
import java.awt.Container;
41
43
import java.awt.Dimension;
42
44
import java.awt.Graphics;
45
import java.awt.Insets;
46
import java.awt.LayoutManager;
47
import java.awt.Point;
49
import javax.swing.JSplitPane;
50
import javax.swing.SwingConstants;
51
import javax.swing.border.Border;
52
import javax.swing.plaf.basic.BasicArrowButton;
44
53
import javax.swing.plaf.basic.BasicSplitPaneDivider;
77
95
public void paint(Graphics g)
80
97
Dimension s = getSize();
99
// Paint border if one exists.
100
Border border = getBorder();
102
border.paintBorder(this, g, 0, 0, s.width, s.height);
81
104
MetalUtils.fillMetalPattern(splitPane, g, 2, 2, s.width - 4, s.height - 4,
106
if (splitPane.isOneTouchExpandable())
108
((BasicArrowButton) rightButton).paint(g);
109
((BasicArrowButton) leftButton).paint(g);
114
* This helper class acts as the Layout Manager for the divider.
116
public class MetalDividerLayout implements LayoutManager
118
/** The right button. */
121
/** The left button. */
125
* Creates a new DividerLayout object.
127
public MetalDividerLayout()
129
// Nothing to do here
133
* This method is called when a Component is added.
135
* @param string The constraints string.
136
* @param c The Component to add.
138
public void addLayoutComponent(String string, Component c)
140
// Nothing to do here, constraints are set depending on
141
// orientation in layoutContainer
145
* This method is called to lay out the container.
147
* @param c The container to lay out.
149
public void layoutContainer(Container c)
151
// The only components we care about setting up are the
152
// one touch buttons.
153
if (splitPane.isOneTouchExpandable())
155
if (c.getComponentCount() == 2)
157
Component c1 = c.getComponent(0);
158
Component c2 = c.getComponent(1);
159
if ((c1 instanceof BasicArrowButton)
160
&& (c2 instanceof BasicArrowButton))
162
lb = ((BasicArrowButton) c1);
163
rb = ((BasicArrowButton) c2);
166
if (rb != null && lb != null)
168
Point p = getLocation();
169
lb.setSize(lb.getPreferredSize());
170
rb.setSize(rb.getPreferredSize());
171
lb.setLocation(p.x, p.y);
173
if (orientation == JSplitPane.HORIZONTAL_SPLIT)
175
rb.setDirection(SwingConstants.EAST);
176
lb.setDirection(SwingConstants.WEST);
177
rb.setLocation(p.x, p.y + lb.getHeight());
181
rb.setDirection(SwingConstants.SOUTH);
182
lb.setDirection(SwingConstants.NORTH);
183
rb.setLocation(p.x + lb.getWidth(), p.y);
190
* This method returns the minimum layout size.
192
* @param c The container to calculate for.
194
* @return The minimum layout size.
196
public Dimension minimumLayoutSize(Container c)
198
return preferredLayoutSize(c);
202
* This method returns the preferred layout size.
204
* @param c The container to calculate for.
206
* @return The preferred layout size.
208
public Dimension preferredLayoutSize(Container c)
210
int dividerSize = getDividerSize();
211
return new Dimension(dividerSize, dividerSize);
215
* This method is called when a component is removed.
217
* @param c The component to remove.
219
public void removeLayoutComponent(Component c)
221
// Nothing to do here. If buttons are removed
222
// they will not be layed out when layoutContainer is