38 |
package javax.swing.plaf.metal; |
package javax.swing.plaf.metal; |
39 |
|
|
40 |
import java.awt.Color; |
import java.awt.Color; |
41 |
|
import java.awt.Component; |
42 |
|
import java.awt.Container; |
43 |
import java.awt.Dimension; |
import java.awt.Dimension; |
44 |
import java.awt.Graphics; |
import java.awt.Graphics; |
45 |
|
import java.awt.LayoutManager; |
46 |
|
import java.awt.Point; |
47 |
|
|
48 |
|
import javax.swing.JSplitPane; |
49 |
|
import javax.swing.SwingConstants; |
50 |
|
import javax.swing.plaf.basic.BasicArrowButton; |
51 |
import javax.swing.plaf.basic.BasicSplitPaneDivider; |
import javax.swing.plaf.basic.BasicSplitPaneDivider; |
52 |
|
|
53 |
/** |
/** |
63 |
|
|
64 |
/** The light color in the pattern. */ |
/** The light color in the pattern. */ |
65 |
Color light; |
Color light; |
66 |
|
|
67 |
|
/** The JSplitPane the divider is on. */ |
68 |
|
JSplitPane splitPane; |
69 |
|
|
70 |
|
/** The split pane orientation. */ |
71 |
|
int orientation; |
72 |
|
|
73 |
/** |
/** |
74 |
* Creates a new instance of MetalSplitPaneDivider. |
* Creates a new instance of MetalSplitPaneDivider. |
75 |
* |
* |
78 |
public MetalSplitPaneDivider(MetalSplitPaneUI ui, Color light, Color dark) |
public MetalSplitPaneDivider(MetalSplitPaneUI ui, Color light, Color dark) |
79 |
{ |
{ |
80 |
super(ui); |
super(ui); |
81 |
|
setLayout(new MetalDividerLayout()); |
82 |
|
this.splitPane = super.splitPane; |
83 |
|
this.orientation = super.orientation; |
84 |
this.light = light; |
this.light = light; |
85 |
this.dark = dark; |
this.dark = dark; |
86 |
} |
} |
92 |
*/ |
*/ |
93 |
public void paint(Graphics g) |
public void paint(Graphics g) |
94 |
{ |
{ |
|
//super.paint(g); |
|
95 |
Dimension s = getSize(); |
Dimension s = getSize(); |
96 |
MetalUtils.fillMetalPattern(splitPane, g, 2, 2, s.width - 4, s.height - 4, |
MetalUtils.fillMetalPattern(splitPane, g, 2, 2, s.width - 4, s.height - 4, |
97 |
light, dark); |
light, dark); |
98 |
|
if (splitPane.isOneTouchExpandable()) |
99 |
|
{ |
100 |
|
((BasicArrowButton) rightButton).paint(g); |
101 |
|
((BasicArrowButton) leftButton).paint(g); |
102 |
|
} |
103 |
|
} |
104 |
|
|
105 |
|
/** |
106 |
|
* This helper class acts as the Layout Manager for the divider. |
107 |
|
*/ |
108 |
|
protected class MetalDividerLayout implements LayoutManager |
109 |
|
{ |
110 |
|
/** The right button. */ |
111 |
|
BasicArrowButton rb; |
112 |
|
|
113 |
|
/** The left button. */ |
114 |
|
BasicArrowButton lb; |
115 |
|
|
116 |
|
/** |
117 |
|
* Creates a new DividerLayout object. |
118 |
|
*/ |
119 |
|
protected MetalDividerLayout() |
120 |
|
{ |
121 |
|
// Nothing to do here |
122 |
|
} |
123 |
|
|
124 |
|
/** |
125 |
|
* This method is called when a Component is added. |
126 |
|
* |
127 |
|
* @param string The constraints string. |
128 |
|
* @param c The Component to add. |
129 |
|
*/ |
130 |
|
public void addLayoutComponent(String string, Component c) |
131 |
|
{ |
132 |
|
// Nothing to do here, constraints are set depending on |
133 |
|
// orientation in layoutContainer |
134 |
|
} |
135 |
|
|
136 |
|
/** |
137 |
|
* This method is called to lay out the container. |
138 |
|
* |
139 |
|
* @param c The container to lay out. |
140 |
|
*/ |
141 |
|
public void layoutContainer(Container c) |
142 |
|
{ |
143 |
|
// The only components we care about setting up are the |
144 |
|
// one touch buttons. |
145 |
|
if (splitPane.isOneTouchExpandable()) |
146 |
|
{ |
147 |
|
if (c.getComponentCount() == 2) |
148 |
|
{ |
149 |
|
Component c1 = c.getComponent(0); |
150 |
|
Component c2 = c.getComponent(1); |
151 |
|
if ((c1 instanceof BasicArrowButton) |
152 |
|
&& (c2 instanceof BasicArrowButton)) |
153 |
|
{ |
154 |
|
lb = ((BasicArrowButton) c1); |
155 |
|
rb = ((BasicArrowButton) c2); |
156 |
|
} |
157 |
|
} |
158 |
|
if (rb != null && lb != null) |
159 |
|
{ |
160 |
|
Point p = getLocation(); |
161 |
|
lb.setSize(lb.getPreferredSize()); |
162 |
|
rb.setSize(rb.getPreferredSize()); |
163 |
|
lb.setLocation(p.x, p.y); |
164 |
|
|
165 |
|
if (orientation == JSplitPane.HORIZONTAL_SPLIT) |
166 |
|
{ |
167 |
|
rb.setDirection(SwingConstants.EAST); |
168 |
|
lb.setDirection(SwingConstants.WEST); |
169 |
|
rb.setLocation(p.x, p.y + lb.getHeight()); |
170 |
|
} |
171 |
|
else |
172 |
|
{ |
173 |
|
rb.setDirection(SwingConstants.SOUTH); |
174 |
|
lb.setDirection(SwingConstants.NORTH); |
175 |
|
rb.setLocation(p.x + lb.getWidth(), p.y); |
176 |
|
} |
177 |
|
} |
178 |
|
} |
179 |
|
} |
180 |
|
|
181 |
|
/** |
182 |
|
* This method returns the minimum layout size. |
183 |
|
* |
184 |
|
* @param c The container to calculate for. |
185 |
|
* |
186 |
|
* @return The minimum layout size. |
187 |
|
*/ |
188 |
|
public Dimension minimumLayoutSize(Container c) |
189 |
|
{ |
190 |
|
return preferredLayoutSize(c); |
191 |
|
} |
192 |
|
|
193 |
|
/** |
194 |
|
* This method returns the preferred layout size. |
195 |
|
* |
196 |
|
* @param c The container to calculate for. |
197 |
|
* |
198 |
|
* @return The preferred layout size. |
199 |
|
*/ |
200 |
|
public Dimension preferredLayoutSize(Container c) |
201 |
|
{ |
202 |
|
int dividerSize = getDividerSize(); |
203 |
|
return new Dimension(dividerSize, dividerSize); |
204 |
|
} |
205 |
|
|
206 |
|
/** |
207 |
|
* This method is called when a component is removed. |
208 |
|
* |
209 |
|
* @param c The component to remove. |
210 |
|
*/ |
211 |
|
public void removeLayoutComponent(Component c) |
212 |
|
{ |
213 |
|
// Nothing to do here. If buttons are removed |
214 |
|
// they will not be layed out when layoutContainer is |
215 |
|
// called. |
216 |
|
} |
217 |
} |
} |
218 |
} |
} |