38 |
|
|
39 |
package javax.swing.plaf.basic; |
package javax.swing.plaf.basic; |
40 |
|
|
41 |
|
import java.awt.Font; |
42 |
|
import java.awt.Graphics; |
43 |
|
import java.awt.Rectangle; |
44 |
|
|
45 |
|
import javax.swing.AbstractButton; |
46 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
47 |
|
import javax.swing.SwingUtilities; |
48 |
import javax.swing.plaf.ComponentUI; |
import javax.swing.plaf.ComponentUI; |
49 |
|
|
50 |
public class BasicToggleButtonUI extends BasicButtonUI |
public class BasicToggleButtonUI extends BasicButtonUI |
64 |
{ |
{ |
65 |
return "ToggleButton."; |
return "ToggleButton."; |
66 |
} |
} |
|
} |
|
67 |
|
|
68 |
|
/** |
69 |
|
* Paint the component, which is an {@link AbstractButton}, according to |
70 |
|
* its current state. |
71 |
|
* |
72 |
|
* @param g The graphics context to paint with |
73 |
|
* @param c The component to paint the state of |
74 |
|
*/ |
75 |
|
public void paint(Graphics g, JComponent c) |
76 |
|
{ |
77 |
|
AbstractButton b = (AbstractButton) c; |
78 |
|
|
79 |
|
Rectangle tr = new Rectangle(); |
80 |
|
Rectangle ir = new Rectangle(); |
81 |
|
Rectangle vr = new Rectangle(); |
82 |
|
|
83 |
|
Font f = c.getFont(); |
84 |
|
|
85 |
|
g.setFont(f); |
86 |
|
|
87 |
|
if (b.isBorderPainted()) |
88 |
|
SwingUtilities.calculateInnerArea(b, vr); |
89 |
|
else |
90 |
|
vr = SwingUtilities.getLocalBounds(b); |
91 |
|
String text = SwingUtilities.layoutCompoundLabel(c, g.getFontMetrics(f), |
92 |
|
b.getText(), |
93 |
|
currentIcon(b), |
94 |
|
b.getVerticalAlignment(), |
95 |
|
b.getHorizontalAlignment(), |
96 |
|
b.getVerticalTextPosition(), |
97 |
|
b.getHorizontalTextPosition(), |
98 |
|
vr, ir, tr, |
99 |
|
b.getIconTextGap() |
100 |
|
+ defaultTextShiftOffset); |
101 |
|
|
102 |
|
if ((b.getModel().isArmed() && b.getModel().isPressed()) |
103 |
|
|| b.isSelected()) |
104 |
|
paintButtonPressed(g, b); |
105 |
|
|
106 |
|
paintIcon(g, b, ir); |
107 |
|
if (text != null) |
108 |
|
paintText(g, b, tr, text); |
109 |
|
if (b.isFocusOwner()) |
110 |
|
paintFocus(g, b, vr, tr, ir); |
111 |
|
} |
112 |
|
|
113 |
|
/** |
114 |
|
* Paints the icon for the toggle button. This delegates to |
115 |
|
* {@link BasicButtonUI#paintIcon(Graphics, JComponent, Rectangle)}. |
116 |
|
* |
117 |
|
* @param g the graphics context |
118 |
|
* @param b the button to paint the icon for |
119 |
|
* @param iconRect the area allocated for the icon |
120 |
|
*/ |
121 |
|
protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) |
122 |
|
{ |
123 |
|
super.paintIcon(g, b, iconRect); |
124 |
|
} |
125 |
|
} |