1 56 57 package org.objectstyle.cayenne.dataview.dvmodeler; 58 59 import java.awt.*; 60 import javax.swing.border.*; 61 import javax.swing.plaf.UIResource ; 62 import javax.swing.UIManager ; 63 64 69 70 public class CustomBorderFactory { 71 public static final Border THIN_RAISED_BORDER = new ThinRaisedBorder(); 72 public static final Border THIN_LOWERED_BORDER = new ThinLoweredBorder(); 73 public static final Border TILE_BORDER = new TileBorder(); 74 75 public static class ThinRaisedBorder extends AbstractBorder { 76 private static final Insets INSETS = new Insets(2, 2, 2, 2); 77 78 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { 79 g.translate(x, y); 80 g.setColor(c.getBackground().brighter()); 81 g.drawLine(0, 0, w - 2, 0); 82 g.drawLine(0, 0, 0, h - 2); 83 g.setColor(c.getBackground().darker()); 84 g.drawLine(w - 1, 0, w - 1, h - 1); 85 g.drawLine(0, h - 1, w - 1, h - 1); 86 g.translate(-x, -y); 87 } 88 89 public Insets getBorderInsets(Component c) { return INSETS; } 90 } 91 92 93 public static class ThinLoweredBorder extends AbstractBorder { 94 private static final Insets INSETS = new Insets(2, 2, 2, 2); 95 96 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { 97 g.translate(x, y); 98 g.setColor(c.getBackground().darker()); 99 g.drawLine(0, 0, w - 2, 0); 100 g.drawLine(0, 0, 0, h - 2); 101 g.setColor(c.getBackground().brighter()); 102 g.drawLine(w - 1, 0, w - 1, h - 1); 103 g.drawLine(0, h - 1, w - 1, h - 1); 104 g.translate(-x, -y); 105 } 106 107 public Insets getBorderInsets(Component c) { return INSETS; } 108 } 109 110 public static class TileBorder extends AbstractBorder implements UIResource { 111 112 public static final Insets INSETS = new Insets(1, 1, 3, 3); 113 114 static final int ALPHA1 = 173; 115 static final int ALPHA2 = 66; 116 117 118 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { 119 paintShadowedBorder(c, g, x, y, w, h); 120 } 121 122 private void paintShadowedBorder(Component c, Graphics g, int x, int y, int w, int h) { 123 Color background = c.getParent().getBackground(); 124 Color shadow = UIManager.getColor("controlShadow"); 125 Color lightShadow = new Color(shadow.getRed(), 126 shadow.getGreen(), 127 shadow.getBlue(), 128 ALPHA1); 129 Color lighterShadow = new Color(shadow.getRed(), 130 shadow.getGreen(), 131 shadow.getBlue(), 132 ALPHA2); 133 g.translate(x, y); 134 g.setColor(shadow); 136 g.drawRect(0, 0, w-3, h-3); 137 g.setColor(background); 139 g.fillRect(w - 2, 0, 2, h); 140 g.fillRect(0, h-2, w, 2); 141 g.setColor(lightShadow); 143 g.drawLine(w - 2, 1, w - 2, h - 2); 144 g.drawLine(1, h - 2, w - 3, h - 2); 145 g.setColor(lighterShadow); 147 g.drawLine(w - 1, 2, w - 1, h - 2); 148 g.drawLine(2, h - 1, w - 2, h - 1); 149 g.translate(-x, -y); 150 } 151 152 public Insets getBorderInsets(Component c) { 153 return INSETS; 154 } 155 } 156 } | Popular Tags |