1 19 20 package org.netbeans.modules.options.ui; 21 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Graphics ; 25 import java.awt.Graphics2D ; 26 import java.awt.Insets ; 27 import java.awt.Shape ; 28 import java.awt.geom.Line2D ; 29 import javax.swing.JToggleButton ; 30 import javax.swing.JToolBar ; 31 import javax.swing.border.Border ; 32 33 38 public class VariableBorder implements Border { 39 private Color topColor; 40 private Color leftColor; 41 private Color bottomColor; 42 private Color rightColor; 43 44 45 public VariableBorder(final Color topColor, 46 final Color leftColor, 47 final Color bottomColor, 48 final Color rightColor) { 49 this.topColor = topColor; 50 this.leftColor = leftColor; 51 this.bottomColor = bottomColor; 52 this.rightColor = rightColor; 53 } 54 55 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 56 Graphics2D g2d = (Graphics2D )g; 57 Shape s; 58 59 if(topColor != null) { 60 s = new Line2D.Double (x,y,x+width, y); 61 g2d.setColor(topColor); 62 g2d.fill(s); 63 } 64 65 if(leftColor != null) { 66 s = new Line2D.Double (x,y,x, y+height); 67 g2d.setColor(leftColor); 68 g2d.fill(s); 69 } 70 71 if(bottomColor != null) { 72 s = new Line2D.Double (x,y+height-1,x+width, y+height-1); 73 g2d.setColor(bottomColor); 74 g2d.fill(s); 75 } 76 77 if(rightColor != null) { 78 s = new Line2D.Double (x+width-1,y,x+width-1, y+height); 79 g2d.setColor(rightColor); 80 g2d.fill(s); 81 } 82 83 84 } 85 86 public Insets getBorderInsets(Component c) { 87 Insets i = new Insets (0, 0, 0, 0); 88 89 if(topColor != null) 90 i.top = 1; 91 92 if(leftColor != null) 93 i.left = 1; 94 95 if(bottomColor != null) 96 i.bottom = 1; 97 98 if(rightColor != null) 99 i.right = 1; 100 101 if (c instanceof JToolBar ) { 102 Insets toolBarInsets = ((JToolBar )c).getMargin(); 103 i.top += toolBarInsets.top; 104 i.left += toolBarInsets.left; 105 i.right += toolBarInsets.right; 106 i.bottom += toolBarInsets.bottom; 107 } 108 109 if (c instanceof JToggleButton ) { 110 Insets buttonInsets = ((JToggleButton )c).getMargin(); 111 i.top += buttonInsets.top; 112 i.left += buttonInsets.left; 113 i.right += buttonInsets.right; 114 i.bottom += buttonInsets.bottom; 115 } 116 117 return i; 118 } 119 120 public boolean isBorderOpaque() { 121 return false; 122 } 123 } 124 | Popular Tags |