1 7 package javax.swing.border; 8 9 import java.awt.Graphics ; 10 import java.awt.Insets ; 11 import java.awt.Component ; 12 13 39 public class CompoundBorder extends AbstractBorder { 40 protected Border outsideBorder; 41 protected Border insideBorder; 42 43 46 public CompoundBorder() { 47 this.outsideBorder = null; 48 this.insideBorder = null; 49 } 50 51 57 public CompoundBorder(Border outsideBorder, Border insideBorder) { 58 this.outsideBorder = outsideBorder; 59 this.insideBorder = insideBorder; 60 } 61 62 67 public boolean isBorderOpaque() { 68 return (outsideBorder == null || outsideBorder.isBorderOpaque()) && 69 (insideBorder == null || insideBorder.isBorderOpaque()); 70 } 71 72 84 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 85 Insets nextInsets; 86 int px, py, pw, ph; 87 88 px = x; 89 py = y; 90 pw = width; 91 ph = height; 92 93 if(outsideBorder != null) { 94 outsideBorder.paintBorder(c, g, px, py, pw, ph); 95 96 nextInsets = outsideBorder.getBorderInsets(c); 97 px += nextInsets.left; 98 py += nextInsets.top; 99 pw = pw - nextInsets.right - nextInsets.left; 100 ph = ph - nextInsets.bottom - nextInsets.top; 101 } 102 if(insideBorder != null) 103 insideBorder.paintBorder(c, g, px, py, pw, ph); 104 105 } 106 107 112 public Insets getBorderInsets(Component c, Insets insets) { 113 Insets nextInsets; 114 115 insets.top = insets.left = insets.right = insets.bottom = 0; 116 if(outsideBorder != null) { 117 nextInsets = outsideBorder.getBorderInsets(c); 118 insets.top += nextInsets.top; 119 insets.left += nextInsets.left; 120 insets.right += nextInsets.right; 121 insets.bottom += nextInsets.bottom; 122 } 123 if(insideBorder != null) { 124 nextInsets = insideBorder.getBorderInsets(c); 125 insets.top += nextInsets.top; 126 insets.left += nextInsets.left; 127 insets.right += nextInsets.right; 128 insets.bottom += nextInsets.bottom; 129 } 130 return insets; 131 } 132 133 139 public Insets getBorderInsets(Component c) { 140 return getBorderInsets(c, new Insets (0,0,0,0)); 141 } 142 143 146 public Border getOutsideBorder() { 147 return outsideBorder; 148 } 149 150 153 public Border getInsideBorder() { 154 return insideBorder; 155 } 156 } 157 158 | Popular Tags |