1 package com.ca.commons.cbutil; 2 3 import javax.swing.*; 4 import java.awt.*; 5 6 52 53 public class CBPanel extends JPanel 54 { 55 GridBagLayout gridbag; 56 protected GridBagConstraints c; 57 58 protected int xpos = 0; 59 protected int ypos = 0; 60 61 66 public CBPanel() 67 { 68 super(true); gridbag = new GridBagLayout(); 70 setLayout(gridbag); 71 c = new GridBagConstraints(); 72 c.fill = GridBagConstraints.BOTH; 73 c.insets = new Insets(1, 1, 1, 1); 74 c.weightx = 0; 75 c.weighty = 0; 76 } 77 78 82 public void makeHeavy() 83 { 84 c.weightx = 1; 85 c.weighty = 1; 86 } 87 88 92 public void makeWide() 93 { 94 c.weightx = 1; 95 c.weighty = 0; 96 } 97 98 99 103 public void makeLight() 104 { 105 c.weightx = 0; 106 c.weighty = 0; 107 } 108 109 110 114 115 116 public void makeHigh() 117 { 118 c.weightx = 0; 119 c.weighty = 1; 120 } 121 122 123 132 private void setXYWH(int X, int Y, int width, int height) 133 { 134 c.gridx = X; 135 c.gridy = Y; 136 c.gridwidth = width; 137 c.gridheight = height; 138 } 139 140 146 public Component add(Component comp) 147 { 148 return add(comp, xpos, ypos, 1, 1); 149 155 } 156 157 164 public Component add(Component comp, int x, int y) 165 { 166 return add(comp, x, y, 1, 1); 167 175 } 176 177 185 186 public Component add(Component comp, int x, int y, int width, int height) 187 { 188 xpos = x; 190 ypos = y; 191 setXYWH(xpos, ypos, width, height); 192 add(comp, c); 193 ypos = y + height - 1; 194 xpos = x + width; 195 return comp; 196 } 197 198 203 204 205 public void newLine() 206 { 207 xpos = 0; 208 ypos++; 209 } 210 211 218 219 220 public void addLine(Component comp) 221 { 222 setXYWH(xpos, ypos, GridBagConstraints.REMAINDER, 1); 223 add(comp, c); 224 newLine(); 225 } 226 227 234 235 236 public void addln(Component comp) 237 { 238 addLine(comp); 239 } 240 241 249 250 251 public void addLines(Component comp, int height) 252 { 253 setXYWH(xpos, ypos, GridBagConstraints.REMAINDER, height); 254 add(comp, c); 255 xpos = 0; 256 ypos += height; 257 } 258 259 263 264 public void addWide(Component comp, int width) 265 { 266 setXYWH(xpos, ypos, width, 1); 268 add(comp, c); 269 xpos += width; 270 } 271 272 public void addGreedyWide(Component comp) 273 { 274 addGreedyWide(comp, 1); 275 } 276 277 public void addGreedyWide(Component comp, int width) 278 { 279 double oldx = c.weightx; 280 c.weightx = 1; 281 addWide(comp, width); 282 c.weightx = oldx; 283 } 284 285 288 289 public String toString() 290 { 291 return ("CBPanel x,y pos: " + xpos + "," + ypos + " constraint weight x,y " + c.weightx + "," + c.weighty); 292 } 293 } | Popular Tags |