1 30 31 package com.jgoodies.forms.debug; 32 33 import java.awt.Color ; 34 import java.awt.Graphics ; 35 36 import javax.swing.JPanel ; 37 38 import com.jgoodies.forms.layout.FormLayout; 39 40 41 59 public class FormDebugPanel extends JPanel { 60 61 64 private static final Color DEFAULT_GRID_COLOR = Color.red; 65 66 67 71 private boolean paintInBackground; 72 73 74 77 private boolean paintDiagonals; 78 79 80 83 private Color gridColor = DEFAULT_GRID_COLOR; 84 85 86 88 91 public FormDebugPanel() { 92 this(null); 93 } 94 95 96 102 public FormDebugPanel(FormLayout layout) { 103 this(layout, false, false); 104 } 105 106 107 115 public FormDebugPanel(boolean paintInBackground, 116 boolean paintDiagonals) { 117 this(null, paintInBackground, paintDiagonals); 118 } 119 120 121 130 public FormDebugPanel(FormLayout layout, 131 boolean paintInBackground, 132 boolean paintDiagonals) { 133 super(layout); 134 setPaintInBackground(paintInBackground); 135 setPaintDiagonals(paintDiagonals); 136 setGridColor(DEFAULT_GRID_COLOR); 137 } 138 139 140 142 147 public void setPaintInBackground(boolean b) { 148 paintInBackground = b; 149 } 150 151 156 public void setPaintDiagonals(boolean b) { 157 paintDiagonals = b; 158 } 159 160 165 public void setGridColor(Color color) { 166 gridColor = color; 167 } 168 169 170 172 176 protected void paintComponent(Graphics g) { 177 super.paintComponent(g); 178 if (paintInBackground) { 179 paintGrid(g); 180 } 181 } 182 183 184 188 public void paint(Graphics g) { 189 super.paint(g); 190 if (!paintInBackground) { 191 paintGrid(g); 192 } 193 } 194 195 196 199 private void paintGrid(Graphics g) { 200 if (!(getLayout() instanceof FormLayout)) { 201 return; 202 } 203 FormLayout.LayoutInfo layoutInfo = FormDebugUtils.getLayoutInfo(this); 204 int left = layoutInfo.getX(); 205 int top = layoutInfo.getY(); 206 int width = layoutInfo.getWidth(); 207 int height = layoutInfo.getHeight(); 208 209 g.setColor(gridColor); 210 for (int col = 0; col < layoutInfo.columnOrigins.length; col++) { 212 g.fillRect(layoutInfo.columnOrigins[col], top, 1, height); 213 } 214 215 for (int row = 0; row < layoutInfo.rowOrigins.length; row++) { 217 g.fillRect(left, layoutInfo.rowOrigins[row], width, 1); 218 } 219 220 if (paintDiagonals) { 221 g.drawLine(left, top, left + width, top + height); 222 g.drawLine(left, top + height, left + width, top); 223 } 224 } 225 226 227 } | Popular Tags |