1 7 8 package com.sun.java.swing.plaf.windows; 9 10 import javax.swing.*; 11 import javax.swing.border.*; 12 import javax.swing.plaf.*; 13 import javax.swing.plaf.basic.*; 14 15 import java.awt.Component ; 16 import java.awt.Insets ; 17 import java.awt.Dimension ; 18 import java.awt.Image ; 19 import java.awt.Rectangle ; 20 import java.awt.Color ; 21 import java.awt.Graphics ; 22 import java.io.Serializable ; 23 24 import com.sun.java.swing.plaf.windows.TMSchema.*; 25 import com.sun.java.swing.plaf.windows.XPStyle.Skin; 26 27 32 33 public class WindowsBorders { 34 35 39 public static Border getProgressBarBorder() { 40 UIDefaults table = UIManager.getLookAndFeelDefaults(); 41 Border progressBarBorder = new BorderUIResource.CompoundBorderUIResource( 42 new WindowsBorders.ProgressBarBorder( 43 table.getColor("ProgressBar.shadow"), 44 table.getColor("ProgressBar.highlight")), 45 new EmptyBorder(1,1,1,1) 46 ); 47 return progressBarBorder; 48 } 49 50 56 public static Border getToolBarBorder() { 57 UIDefaults table = UIManager.getLookAndFeelDefaults(); 58 Border toolBarBorder = new WindowsBorders.ToolBarBorder( 59 table.getColor("ToolBar.shadow"), 60 table.getColor("ToolBar.highlight")); 61 return toolBarBorder; 62 } 63 64 71 public static Border getFocusCellHighlightBorder() { 72 return new ComplementDashedBorder(); 73 } 74 75 public static Border getTableHeaderBorder() { 76 UIDefaults table = UIManager.getLookAndFeelDefaults(); 77 Border tableHeaderBorder = new BorderUIResource.CompoundBorderUIResource( 78 new BasicBorders.ButtonBorder( 79 table.getColor("Table.shadow"), 80 table.getColor("Table.darkShadow"), 81 table.getColor("Table.light"), 82 table.getColor("Table.highlight")), 83 new BasicBorders.MarginBorder()); 84 return tableHeaderBorder; 85 } 86 87 public static Border getInternalFrameBorder() { 88 UIDefaults table = UIManager.getLookAndFeelDefaults(); 89 Border internalFrameBorder = new 90 BorderUIResource.CompoundBorderUIResource( 91 BorderFactory.createBevelBorder(BevelBorder.RAISED, 92 table.getColor("InternalFrame.borderColor"), 93 table.getColor("InternalFrame.borderHighlight"), 94 table.getColor("InternalFrame.borderDarkShadow"), 95 table.getColor("InternalFrame.borderShadow")), 96 new WindowsBorders.InternalFrameLineBorder( 97 table.getColor("InternalFrame.activeBorderColor"), 98 table.getColor("InternalFrame.inactiveBorderColor"), 99 table.getInt("InternalFrame.borderWidth"))); 100 101 return internalFrameBorder; 102 } 103 104 public static class ProgressBarBorder extends AbstractBorder implements UIResource { 105 protected Color shadow; 106 protected Color highlight; 107 108 public ProgressBarBorder(Color shadow, Color highlight) { 109 this.highlight = highlight; 110 this.shadow = shadow; 111 } 112 113 public void paintBorder(Component c, Graphics g, int x, int y, 114 int width, int height) { 115 g.setColor(shadow); 116 g.drawLine(x,y, width-1,y); g.drawLine(x,y, x,height-1); g.setColor(highlight); 119 g.drawLine(x,height-1, width-1,height-1); g.drawLine(width-1,y, width-1,height-1); } 122 123 public Insets getBorderInsets(Component c) { 124 return new Insets (1,1,1,1); 125 } 126 127 public Insets getBorderInsets(Component c, Insets insets) { 128 insets.top = insets.left = insets.bottom = insets.right = 1; 129 return insets; 130 } 131 } 132 133 138 public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants { 139 protected Color shadow; 140 protected Color highlight; 141 142 public ToolBarBorder(Color shadow, Color highlight) { 143 this.highlight = highlight; 144 this.shadow = shadow; 145 } 146 147 public void paintBorder(Component c, Graphics g, int x, int y, 148 int width, int height) { 149 g.translate(x, y); 150 151 XPStyle xp = XPStyle.getXP(); 152 if (xp != null) { 153 Border xpBorder = xp.getBorder(c, Part.TP_TOOLBAR); 154 if (xpBorder != null) { 155 xpBorder.paintBorder(c, g, 0, 0, width, height); 156 } 157 } 158 if (((JToolBar)c).isFloatable()) { 159 boolean vertical = ((JToolBar)c).getOrientation() == VERTICAL; 160 161 if (xp != null) { 162 Part part = vertical ? Part.RP_GRIPPERVERT : Part.RP_GRIPPER; 163 Skin skin = xp.getSkin(c, part); 164 int dx, dy, dw, dh; 165 if (vertical) { 166 dx = 0; 167 dy = 2; 168 dw = width - 1; 169 dh = skin.getHeight(); 170 } else { 171 dw = skin.getWidth(); 172 dh = height - 1; 173 dx = c.getComponentOrientation().isLeftToRight() ? 2 : (width-dw-2); 174 dy = 0; 175 } 176 skin.paintSkin(g, dx, dy, dw, dh, State.NORMAL); 177 178 } else { 179 180 if (!vertical) { 181 if (c.getComponentOrientation().isLeftToRight()) { 182 g.setColor(shadow); 183 g.drawLine(4, 3, 4, height - 4); 184 g.drawLine(4, height - 4, 2, height - 4); 185 186 g.setColor(highlight); 187 g.drawLine(2, 3, 3, 3); 188 g.drawLine(2, 3, 2, height - 5); 189 } else { 190 g.setColor(shadow); 191 g.drawLine(width - 3, 3, width - 3, height - 4); 192 g.drawLine(width - 4, height - 4, width - 4, height - 4); 193 194 g.setColor(highlight); 195 g.drawLine(width - 5, 3, width - 4, 3); 196 g.drawLine(width - 5, 3, width - 5, height - 5); 197 } 198 } else { g.setColor(shadow); 200 g.drawLine(3, 4, width - 4, 4); 201 g.drawLine(width - 4, 2, width - 4, 4); 202 203 g.setColor(highlight); 204 g.drawLine(3, 2, width - 4, 2); 205 g.drawLine(3, 2, 3, 3); 206 } 207 } 208 } 209 210 g.translate(-x, -y); 211 } 212 213 public Insets getBorderInsets(Component c) { 214 return getBorderInsets(c, new Insets (1,1,1,1)); 215 } 216 217 public Insets getBorderInsets(Component c, Insets insets) { 218 insets.top = insets.left = insets.bottom = insets.right = 1; 219 if (((JToolBar)c).isFloatable()) { 220 int gripInset = (XPStyle.getXP() != null) ? 12 : 9; 221 if (((JToolBar)c).getOrientation() == HORIZONTAL) { 222 if (c.getComponentOrientation().isLeftToRight()) { 223 insets.left = gripInset; 224 } else { 225 insets.right = gripInset; 226 } 227 } else { 228 insets.top = gripInset; 229 } 230 } 231 return insets; 232 } 233 } 234 235 239 public static class DashedBorder extends LineBorder implements UIResource { 240 public DashedBorder(Color color) { 241 super(color); 242 } 243 244 public DashedBorder(Color color, int thickness) { 245 super(color, thickness); 246 } 247 248 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 249 Color oldColor = g.getColor(); 250 int i; 251 252 g.setColor(lineColor); 253 for(i = 0; i < thickness; i++) { 254 BasicGraphicsUtils.drawDashedRect(g, x+i, y+i, width-i-i, height-i-i); 255 } 256 g.setColor(oldColor); 257 } 258 } 259 260 264 static class ComplementDashedBorder extends LineBorder implements UIResource { 265 private Color origColor; 266 private Color paintColor; 267 268 public ComplementDashedBorder() { 269 super(null); 270 } 271 272 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 273 Color color = c.getBackground(); 274 275 if (origColor != color) { 276 origColor = color; 277 paintColor = new Color (~origColor.getRGB()); 278 } 279 280 g.setColor(paintColor); 281 BasicGraphicsUtils.drawDashedRect(g, x, y, width, height); 282 } 283 } 284 285 289 public static class InternalFrameLineBorder extends LineBorder implements 290 UIResource { 291 protected Color activeColor; 292 protected Color inactiveColor; 293 294 public InternalFrameLineBorder(Color activeBorderColor, 295 Color inactiveBorderColor, 296 int thickness) { 297 super(activeBorderColor, thickness); 298 activeColor = activeBorderColor; 299 inactiveColor = inactiveBorderColor; 300 } 301 302 public void paintBorder(Component c, Graphics g, int x, int y, 303 int width, int height) { 304 305 JInternalFrame jif = null; 306 if (c instanceof JInternalFrame) { 307 jif = (JInternalFrame)c; 308 } else if (c instanceof JInternalFrame.JDesktopIcon) { 309 jif = ((JInternalFrame.JDesktopIcon)c).getInternalFrame(); 310 } else { 311 return; 312 } 313 314 if (jif.isSelected()) { 315 lineColor = activeColor; 318 super.paintBorder(c, g, x, y, width, height); 319 } else { 320 lineColor = inactiveColor; 321 super.paintBorder(c, g, x, y, width, height); 322 } 323 } 324 } 325 } 326 | Popular Tags |