class DHP_SmallButton_UI extends BasicButtonUI {
public final static int SCHLIESSEN = 0;
public final static int MAXIMIEREN = 1;
private int Zustand;
public DHP_SmallButton_UI(int zustand) { // 0 - schliesen, 1- maximieren
this.Zustand = zustand;
}
protected void installDefaults(AbstractButton b) {
super.installDefaults(b);
b.setOpaque(false);
b.setBorderPainted(true);
b.setRolloverEnabled(true);
b.setHorizontalAlignment(AbstractButton.LEFT);
}
protected void installListeners(AbstractButton b) {
super.installListeners(b);
}
protected void uninstallListeners(AbstractButton b) {
super.uninstallListeners(b);
}
public void paint(Graphics g, JComponent c) {
AbstractButton abstractButton = (AbstractButton) c;
ButtonModel model = abstractButton.getModel();
GradientPaint paint;
int x = 0, y = 0, w = 25, h = 15;
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setClip(new RoundRectangle2D.Double(x, y, w, h, 3, 3));
// Button Hintegrund
switch (this.Zustand) {
case SCHLIESSEN:
// Hintegrund oben
if (model.isRollover())
paint = new GradientPaint(x,y,new Color(252,200,191),x,h/2,new Color(250,164,149));
else
paint = new GradientPaint(x,y,new Color(233,169,156),x,h/2,new Color(222,146,132));
g2d.setPaint(paint);
g2d.fillRect(x, y, w, h/2);
// Hintegrund unten
if (model.isRollover())
paint = new GradientPaint(x,h/2,new Color(210,35,2),x,h/2,new Color(232,160,86));
else
paint = new GradientPaint(x,h/2,new Color(184,67,44),x,h/2,new Color(213,133,118));
g2d.setPaint(paint);
g2d.fillRect(x, h/2, w, h - h/2);
break;
default:
// Hintegrund oben
if (model.isRollover())
paint = new GradientPaint(x,y,new Color(170,213,243),x,h/2,new Color(125,190,233));
else
paint = new GradientPaint(x,y,new Color(195,212,231),x,h/2,new Color(190,211,232));
g2d.setPaint(paint);
g2d.fillRect(x, y, w, h/2);
// Hintegrund unten
if (model.isRollover())
paint = new GradientPaint(x,h/2,new Color(45,115,163),x,h/2,new Color(41,169,223));
else
paint = new GradientPaint(x,h/2,new Color(152,177,204),x,h/2,new Color(183,208,233));
g2d.setPaint(paint);
g2d.fillRect(x, h/2, w, h - h/2);
break;
}
// Innerer Umriss
g2d.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2d.setColor(new Color(240,240,240,127));
g2d.drawRoundRect(x, y, w-1, h-1, 3, 3);
// Äußerer Umriss
g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
switch (this.Zustand) {
case SCHLIESSEN:
g2d.setColor(new Color(68,22,36));
break;
default:
g2d.setColor(new Color(132,142,172));
break;
}
g2d.drawRoundRect(x, y, w-1, h-1, 3, 3);
// Figur Fühlung
g2d.setColor(new Color(233,233,233));
g2d.fill(getFigur());
// Figur Umriss
g2d.setColor(new Color(83,86,102));
g2d.draw(getFigur());
}
private Area getFigur(){
Area result = null, temp;
switch (this.Zustand) {
case SCHLIESSEN:
result = new Area(new RoundRectangle2D.Double(7,3,10,8,2,2));
Polygon pol = new Polygon();
pol.addPoint(7, 3);
pol.addPoint(10, 3);
pol.addPoint(17, 10);
pol.addPoint(17, 11);
pol.addPoint(14, 11);
pol.addPoint(7, 4);
pol.addPoint(7, 3);
temp = new Area(pol);
pol.reset();
pol.addPoint(7, 11);
pol.addPoint(7, 10);
pol.addPoint(14, 3);
pol.addPoint(17, 3);
pol.addPoint(17, 4);
pol.addPoint(10, 11);
pol.addPoint(7, 11);
temp.add(new Area(pol));
result.intersect(temp);
break;
case MAXIMIEREN:
result = new Area(new RoundRectangle2D.Double(7,3,10,8,2,2));
temp = new Area(new Rectangle2D.Double(10,6,4,2));
result.subtract(temp);
break;
}
return result;
}
}