BorderPanelpublic class BorderPanel extends Panel
Fields Summary |
---|
protected int | shadowPanel shadow border width | protected boolean | raisedPanel raised vs depressed look |
Constructors Summary |
---|
public BorderPanel()
this.raised=true;
| public BorderPanel(boolean raised)
this.raised=raised;
|
Methods Summary |
---|
public static java.awt.Color | avgColor(java.awt.Color c1, java.awt.Color c2)
return new Color(
(c1.getRed()+c2.getRed())/2,
(c1.getGreen()+c2.getGreen())/2,
(c1.getBlue()+c2.getBlue())/2
);
| public void | draw3DRect(java.awt.Graphics g, int x, int y, int width, int height, boolean raised)Draw a 3D Rectangle.
Color c = g.getColor();
Color brighter = avgColor(c,Color.white);
Color darker = avgColor(c,Color.black);
// upper left corner
g.setColor(raised ? brighter : darker);
for (int i=0; i<shadow; i++) {
g.drawLine(x+i, y+i, x+width-1-i, y+i);
g.drawLine(x+i, y+i, x+i, y+height-1-i);
}
// lower right corner
g.setColor(raised ? darker : brighter);
for (int i=0; i<shadow; i++) {
g.drawLine(x+i, y+height-1-i, x+width-1-i, y+height-1-i);
g.drawLine(x+width-1-i, y+height-1-i, x+width-1-i, y+i);
}
g.setColor(c);
// added by rip.
g.setColor(Color.black);
g.drawRect(x,y,width+2,height+2);
| protected void | layoutParent()Re-layout parent. Called when a panel changes
size etc.
Container parent = getParent();
if (parent != null) {
parent.doLayout();
}
| public void | paint(java.awt.Graphics g)
super.paint(g);
Dimension size = getSize();
paintBorder(g, size);
| protected void | paintBorder(java.awt.Graphics g, java.awt.Dimension size)
Color c = getBackground();
g.setColor(c);
g.fillRect(0, 0, size.width, size.height);
draw3DRect(g, 0, 0, size.width, size.height, raised);
|
|