KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > xui > XuiButtonBorder


1
2 package com.memoire.vainstall.xui;
3
4 import com.memoire.vainstall.xui.*;
5 import javax.swing.*;
6 import javax.swing.border.*;
7 import java.awt.*;
8 import java.awt.event.*;
9
10 public class XuiButtonBorder extends AbstractBorder
11 {
12   public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
13   {
14     AbstractButton button=(AbstractButton)c;
15     ButtonModel model =button.getModel();
16
17     Color color=Color.magenta;
18
19     if(model.isEnabled())
20     {
21       if(model.isPressed()&&model.isArmed())
22     color=Color.red;
23       else
24       if(model.isSelected())
25     color=Color.green;
26       else
27     color=c.getForeground();
28     }
29     else color=Color.gray;
30
31     int r=h/2;
32
33     g.setColor(color);
34     g.drawArc(x,y,2*r,h-2,90,180);
35     g.drawArc(x+w-1-2*r,y,2*r,h-2,270,180);
36     g.drawArc(x+1,y,2*r,h-1,90,180);
37     g.drawArc(x+w-1-2*r-1,y,2*r,h-2,270,180);
38     g.drawArc(x,y+1,2*r,h-2,90,180);
39     g.drawArc(x+w-1-2*r-1,y+1,2*r,h-2,270,180);
40
41     g.drawLine(x+r,y,x+w-1-r,y);
42     g.drawLine(x+r,y+h-1,x+w-1-r,y+h-1);
43     g.drawLine(x+r,y+1,x+w-1-r,y+1);
44     g.drawLine(x+r,y+h-2,x+w-1-r,y+h-2);
45   }
46
47   public Insets getBorderInsets(Component c)
48   {
49     return new Insets(5,5,5,5);
50   }
51
52   public boolean isBorderOpaque()
53   {
54     return false;
55   }
56 }
57
Popular Tags