1 19 20 package com.sshtools.ui.awt; 21 22 import java.awt.Color ; 23 import java.awt.Dimension ; 24 import java.awt.Graphics ; 25 import java.awt.Insets ; 26 import java.awt.LayoutManager ; 27 import java.awt.Panel ; 28 29 44 public class BevelPanel 45 extends java.awt.Panel { 46 48 51 public static final int NONE = 0; 52 53 56 public static final int LOWERED = 1; 57 58 61 public static final int RAISED = 2; 62 63 65 private int type; 66 67 72 public BevelPanel(int bevel) { 73 this(bevel, null); 74 } 75 76 82 public BevelPanel(int type, LayoutManager layout) { 83 super(); 84 if (layout != null) { 85 setLayout(layout); 86 } 87 setType(type); 88 } 89 90 101 public void setType(int type) { 102 this.type = type; 103 repaint(); 104 } 105 106 109 public Insets getInsets() { 110 return new Insets (2, 2, 2, 2); 111 } 112 113 118 public void paint(Graphics g) { 119 super.paint(g); 120 Dimension d = getSize(); 121 Color si = getBackground().darker(); 122 Color so = si.darker(); 123 Color hi = getBackground().brighter(); 124 Color ho = hi.brighter(); 125 if (type == LOWERED) { 126 g.setColor(si); 127 g.drawLine(0, 0, 0, d.height - 1); 128 g.drawLine(1, 0, d.width - 1, 0); 129 g.setColor(so); 130 g.drawLine(1, 1, 1, d.height - 2); 131 g.drawLine(2, 1, d.width - 2, 1); 132 g.setColor(ho); 133 g.drawLine(1, d.height - 1, d.width - 1, d.height - 1); 134 g.drawLine(d.width - 1, 1, d.width - 1, d.height - 2); 135 g.setColor(hi); 136 g.drawLine(2, d.height - 2, d.width - 2, d.height - 2); 137 g.drawLine(d.width - 2, 2, d.width - 2, d.height - 3); 138 } 139 else { 140 if (type == RAISED) { 141 g.setColor(ho); 142 g.drawLine(0, 0, 0, d.height - 2); 143 g.drawLine(1, 0, d.width - 2, 0); 144 g.setColor(hi); 145 g.drawLine(1, 1, 1, d.height - 3); 146 g.drawLine(2, 1, d.width - 3, 1); 147 g.setColor(so); 148 g.drawLine(0, d.height - 1, d.width - 1, d.height - 1); 149 g.drawLine(d.width - 1, 0, d.width - 1, d.height - 2); 150 g.setColor(si); 151 g.drawLine(1, d.height - 2, d.width - 2, d.height - 2); 152 g.drawLine(d.width - 2, 1, d.width - 2, d.height - 3); 153 } 154 } 155 } 156 } 157 | Popular Tags |