1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| private static class OceanHorizontalSliderThumbIcon extends CachedPainter
implements Icon, Serializable, UIResource {
// Used for clipping
private static Polygon THUMB_SHAPE;
static {
THUMB_SHAPE = new Polygon(new int[] { 0, 14, 14, 7, 0 },
new int[] { 0, 0, 8, 15, 8 }, 5);
}
OceanHorizontalSliderThumbIcon() {
super(3);
}
public void paintIcon(Component c, Graphics g, int x, int y) {
if (!(g instanceof Graphics2D)) {
return;
}
paint(c, g, x, y, getIconWidth(), getIconHeight(),
c.hasFocus(), c.isEnabled(),
MetalLookAndFeel.getCurrentTheme());
}
protected Image createImage(Component c, int w, int h,
GraphicsConfiguration config,
Object[] args) {
if (config == null) {
return new BufferedImage(w, h,BufferedImage.TYPE_INT_ARGB);
}
return config.createCompatibleImage(
w, h, Transparency.BITMASK);
}
protected void paintToImage(Component c, Image image, Graphics g2,
int w, int h, Object[] args) {
Graphics2D g = (Graphics2D)g2;
boolean hasFocus = ((Boolean)args[0]).booleanValue();
boolean enabled = ((Boolean)args[1]).booleanValue();
// Fill in the background
Rectangle clip = g.getClipBounds();
g.clip(THUMB_SHAPE);
if (!enabled) {
g.setColor(MetalLookAndFeel.getControl());
g.fillRect(1, 1, 13, 14);
}
else if (hasFocus) {
MetalUtils.drawGradient(c, g, "Slider.focusGradient",
1, 1, 13, 14, true);
}
else {
MetalUtils.drawGradient(c, g, "Slider.gradient",
1, 1, 13, 14, true);
}
g.setClip(clip);
// Draw the frame
if (hasFocus) {
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
}
else {
g.setColor(enabled ? MetalLookAndFeel.getPrimaryControlInfo() :
MetalLookAndFeel.getControlDarkShadow());
}
g.drawLine( 1,0 , 13,0 ); // top
g.drawLine( 0,1 , 0,8 ); // left
g.drawLine( 14,1 , 14,8 ); // right
g.drawLine( 1,9 , 7,15 ); // left slant
g.drawLine( 7,15 , 14,8 ); // right slant
if (hasFocus && enabled) {
// Inner line.
g.setColor(MetalLookAndFeel.getPrimaryControl());
g.fillRect(1, 1, 13, 1);
g.fillRect(1, 2, 1, 7);
g.fillRect(13, 2, 1, 7);
g.drawLine(2, 9, 7, 14);
g.drawLine(8, 13, 12, 9);
}
}
public int getIconWidth() {
return 15;
}
public int getIconHeight() {
return 16;
}
} |
Partager