1 19 20 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.border; 21 22 import java.awt.Color ; 23 import java.awt.Graphics2D ; 24 import java.awt.Insets ; 25 import java.awt.Paint ; 26 import java.awt.Rectangle ; 27 import org.netbeans.api.visual.border.Border; 28 import org.netbeans.api.visual.widget.Widget; 29 30 34 public class FilledBorder implements Border { 35 36 private Insets borderWidth; 37 private Insets padding; 38 39 private Color borderColor; 40 private Color fillColor; 41 42 public FilledBorder(int vBorderWidth, int hBorderWidth, 43 int vPadding, int hPadding, Color borderColor, Color fillColor) 44 { 45 this.borderWidth = new Insets (vBorderWidth, hBorderWidth, 46 vBorderWidth, hBorderWidth); 47 this.padding = new Insets (vPadding, hPadding, vPadding, hPadding); 48 49 this.borderColor = borderColor; 50 this.fillColor = fillColor; 51 } 52 53 54 public FilledBorder(Insets borderWidth, Insets padding, 55 Color borderColor, Color fillColor) 56 { 57 this.borderWidth = (Insets ) borderWidth.clone(); 58 this.padding = (Insets ) padding.clone(); 59 60 this.borderColor = borderColor; 61 this.fillColor = fillColor; 62 } 63 64 65 public Insets getInsets() { 66 return new Insets ( 67 borderWidth.top + padding.top, 68 borderWidth.left + padding.left, 69 borderWidth.bottom + padding.bottom, 70 borderWidth.right + padding.right); 71 } 72 73 public void paint(Graphics2D g2, Rectangle rect) { 74 Paint oldPaint = g2.getPaint(); 75 76 if (borderColor != null) { 77 g2.setPaint(borderColor); 78 g2.fill(rect); 79 } 80 81 if (fillColor != null) { 82 g2.setPaint(fillColor); 83 g2.fillRect(rect.x + borderWidth.left, rect.y + borderWidth.top, 84 rect.width - borderWidth.left - borderWidth.right, 85 rect.height - borderWidth.top - borderWidth.bottom); 86 } 87 88 g2.setPaint(oldPaint); 89 } 90 91 public boolean isOpaque() { 92 return true; 93 } 94 } 95 | Popular Tags |