41 |
import java.awt.Color; |
import java.awt.Color; |
42 |
import java.awt.Dimension; |
import java.awt.Dimension; |
43 |
import java.awt.Graphics; |
import java.awt.Graphics; |
|
import java.awt.Insets; |
|
44 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
45 |
|
|
46 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
47 |
import javax.swing.JSeparator; |
import javax.swing.JSeparator; |
48 |
import javax.swing.SwingUtilities; |
import javax.swing.SwingUtilities; |
|
import javax.swing.UIDefaults; |
|
49 |
import javax.swing.UIManager; |
import javax.swing.UIManager; |
50 |
import javax.swing.plaf.ComponentUI; |
import javax.swing.plaf.ComponentUI; |
51 |
import javax.swing.plaf.SeparatorUI; |
import javax.swing.plaf.SeparatorUI; |
119 |
*/ |
*/ |
120 |
protected void installDefaults(JSeparator s) |
protected void installDefaults(JSeparator s) |
121 |
{ |
{ |
122 |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
shadow = UIManager.getColor("Separator.shadow"); |
123 |
|
highlight = UIManager.getColor("Separator.highlight"); |
|
shadow = defaults.getColor("Separator.shadow"); |
|
|
highlight = defaults.getColor("Separator.highlight"); |
|
124 |
s.setOpaque(false); |
s.setOpaque(false); |
125 |
} |
} |
126 |
|
|
161 |
|
|
162 |
/** |
/** |
163 |
* The separator is made of two lines. The top line will be |
* The separator is made of two lines. The top line will be |
164 |
* the highlight color (or left line if it's vertical). The bottom |
* the shadow color (or left line if it's vertical). The bottom |
165 |
* or right line will be the shadow color. The two lines will |
* or right line will be the highlight color. The two lines will |
166 |
* be centered inside the bounds box. If the separator is horizontal, |
* be centered inside the bounds box. If the separator is horizontal, |
167 |
* then it will be vertically centered, or if it's vertical, it will |
* then it will be vertically centered, or if it's vertical, it will |
168 |
* be horizontally centered. |
* be horizontally centered. |
176 |
SwingUtilities.calculateInnerArea(c, r); |
SwingUtilities.calculateInnerArea(c, r); |
177 |
Color saved = g.getColor(); |
Color saved = g.getColor(); |
178 |
|
|
|
int midAB = r.width / 2 + r.x; |
|
|
int midAD = r.height / 2 + r.y; |
|
|
|
|
179 |
JSeparator s; |
JSeparator s; |
180 |
if (c instanceof JSeparator) |
if (c instanceof JSeparator) |
181 |
s = (JSeparator) c; |
s = (JSeparator) c; |
183 |
return; |
return; |
184 |
|
|
185 |
if (s.getOrientation() == JSeparator.HORIZONTAL) |
if (s.getOrientation() == JSeparator.HORIZONTAL) |
186 |
{ |
{ |
187 |
g.setColor(highlight); |
int midAB = r.height / 2; |
188 |
g.drawLine(r.x, midAD, r.x + r.width, midAD); |
g.setColor(shadow); |
189 |
|
g.drawLine(r.x, r.y + midAB - 1, r.x + r.width, r.y + midAB - 1); |
190 |
g.setColor(shadow); |
|
191 |
g.drawLine(r.x, midAD + 1, r.x + r.width, midAD + 1); |
g.setColor(highlight); |
192 |
} |
g.fillRect(r.x, r.y + midAB, r.x + r.width, r.y + midAB); |
193 |
else |
} |
194 |
{ |
else |
195 |
g.setColor(highlight); |
{ |
196 |
g.drawLine(midAB, r.y, midAB, r.y + r.height); |
int midAD = r.height / 2 + r.y; |
197 |
|
g.setColor(shadow); |
198 |
g.setColor(shadow); |
g.drawLine(r.x, r.y, r.x, r.y + r.height); |
199 |
g.drawLine(midAB + 1, r.y, midAB + 1, r.y + r.height); |
|
200 |
} |
g.setColor(highlight); |
201 |
|
g.fillRect(r.x + midAD, r.y + r.height, r.x + midAD, r.y + r.height); |
202 |
|
} |
203 |
|
g.setColor(saved); |
204 |
} |
} |
205 |
|
|
206 |
/** |
/** |
213 |
*/ |
*/ |
214 |
public Dimension getPreferredSize(JComponent c) |
public Dimension getPreferredSize(JComponent c) |
215 |
{ |
{ |
216 |
Dimension dims = new Dimension(0, 0); |
Dimension pref = new Dimension(2, 0); |
|
Insets insets = c.getInsets(); |
|
|
|
|
217 |
if (c instanceof JSeparator) |
if (c instanceof JSeparator) |
218 |
{ |
{ |
219 |
JSeparator s = (JSeparator) c; |
JSeparator s = (JSeparator) c; |
|
|
|
220 |
if (s.getOrientation() == JSeparator.HORIZONTAL) |
if (s.getOrientation() == JSeparator.HORIZONTAL) |
221 |
{ |
pref = new Dimension(0, 2); |
|
dims.height = 2; |
|
|
dims.width = 40; |
|
|
} |
|
|
else |
|
|
{ |
|
|
dims.width = 2; |
|
|
dims.height = 40; |
|
|
} |
|
222 |
} |
} |
223 |
dims.width += insets.left + insets.right; |
return pref; |
|
dims.height += insets.top + insets.bottom; |
|
|
|
|
|
return dims; |
|
224 |
} |
} |
225 |
|
|
226 |
/** |
/** |
233 |
*/ |
*/ |
234 |
public Dimension getMinimumSize(JComponent c) |
public Dimension getMinimumSize(JComponent c) |
235 |
{ |
{ |
236 |
return getPreferredSize(c); |
return new Dimension(0, 0); |
237 |
} |
} |
238 |
|
|
239 |
/** |
/** |
246 |
*/ |
*/ |
247 |
public Dimension getMaximumSize(JComponent c) |
public Dimension getMaximumSize(JComponent c) |
248 |
{ |
{ |
249 |
return getPreferredSize(c); |
return new Dimension(Short.MAX_VALUE, |
250 |
|
Short.MAX_VALUE); |
251 |
} |
} |
252 |
} |
} |