1 22 23 package org.gjt.sp.jedit; 24 25 import javax.swing.border.EmptyBorder ; 27 import javax.swing.*; 28 import java.awt.*; 29 31 60 public class AbstractOptionPane extends JPanel implements OptionPane 64 { 65 71 public AbstractOptionPane(String internalName) 72 { 73 this.name = internalName; 74 setLayout(gridBag = new GridBagLayout()); 75 } 77 83 public String getName() 84 { 85 return name; 86 } 88 93 public Component getComponent() 94 { 95 return this; 96 } 98 102 public void init() 104 { 105 if(!initialized) 106 { 107 initialized = true; 108 _init(); 109 } 110 } 112 116 public void save() 118 { 119 if(initialized) 120 _save(); 121 } 123 130 public JLabel newLabel(String label, Component comp) 131 { 132 JLabel retval = new JLabel(label); 133 try 134 { 135 JComponent jc = (JComponent) comp; 136 String tttext = jc.getToolTipText(); 137 retval.setToolTipText(tttext); 138 } 139 catch (Exception e) 140 { 141 144 } 145 return retval; 146 } 148 156 public void addComponent(String label, Component comp) 157 { 158 JLabel l = newLabel(label, comp); 159 l.setBorder(new EmptyBorder (0,0,0,12)); 160 addComponent(l,comp,GridBagConstraints.BOTH); 161 } 163 173 public void addComponent(String label, Component comp, int fill) 174 { 175 JLabel l = newLabel(label, comp); 176 l.setBorder(new EmptyBorder (0,0,0,12)); 177 addComponent(l,comp,fill); 178 } 180 190 public void addComponent(Component comp1, Component comp2) 191 { 192 addComponent(comp1,comp2,GridBagConstraints.BOTH); 193 } 195 207 public void addComponent(Component comp1, Component comp2, int fill) 208 { 209 copyToolTips(comp1, comp2); 210 GridBagConstraints cons = new GridBagConstraints(); 211 cons.gridy = y++; 212 cons.gridheight = 1; 213 cons.gridwidth = 1; 214 cons.weightx = 0.0f; 215 cons.insets = new Insets(1,0,1,0); 216 cons.fill = GridBagConstraints.BOTH; 217 218 gridBag.setConstraints(comp1,cons); 219 add(comp1); 220 221 cons.fill = fill; 222 cons.gridx = 1; 223 cons.weightx = 1.0f; 224 gridBag.setConstraints(comp2,cons); 225 add(comp2); 226 } 228 234 public void addComponent(Component comp) 235 { 236 GridBagConstraints cons = new GridBagConstraints(); 237 cons.gridy = y++; 238 cons.gridheight = 1; 239 cons.gridwidth = cons.REMAINDER; 240 cons.fill = GridBagConstraints.NONE; 241 cons.anchor = GridBagConstraints.WEST; 242 cons.weightx = 1.0f; 243 cons.insets = new Insets(1,0,1,0); 244 245 gridBag.setConstraints(comp,cons); 246 add(comp); 247 } 249 257 public void addComponent(Component comp, int fill) 258 { 259 GridBagConstraints cons = new GridBagConstraints(); 260 cons.gridy = y++; 261 cons.gridheight = 1; 262 cons.gridwidth = cons.REMAINDER; 263 cons.fill = fill; 264 cons.anchor = GridBagConstraints.WEST; 265 cons.weightx = 1.0f; 266 cons.insets = new Insets(1,0,1,0); 267 268 gridBag.setConstraints(comp,cons); 269 add(comp); 270 } 272 private void copyToolTips (Component c1, Component c2) { 273 int tooltips = 0; 274 int jc=0; 275 String text = null; 276 JComponent jc1 = null, jc2 = null; 277 try { 278 jc1 = (JComponent) c1; 279 text = jc1.getToolTipText(); 280 ++jc; 281 if (text != null && text.length() > 0) tooltips++; 282 } 283 catch (Exception e) {} 284 try { 285 jc2 = (JComponent) c2; 286 String text2 = jc2.getToolTipText(); 287 ++jc; 288 if (text2 != null && text2.length() > 0) { 289 text = text2; 290 tooltips++; 291 } 292 } 293 catch (Exception e) {} 294 if (tooltips == 1 && jc == 2) { 295 jc1.setToolTipText(text); 296 jc2.setToolTipText(text); 297 } 298 299 } 300 305 public void addSeparator() 306 { 307 addComponent(Box.createVerticalStrut(6)); 308 309 JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); 310 311 GridBagConstraints cons = new GridBagConstraints(); 312 cons.gridy = y++; 313 cons.gridheight = 1; 314 cons.gridwidth = cons.REMAINDER; 315 cons.fill = GridBagConstraints.BOTH; 316 cons.anchor = GridBagConstraints.WEST; 317 cons.weightx = 1.0f; 318 320 gridBag.setConstraints(sep,cons); 321 add(sep); 322 323 addComponent(Box.createVerticalStrut(6)); 324 } 326 332 public void addSeparator(String label) 333 { 334 if(y != 0) 335 addComponent(Box.createVerticalStrut(6)); 336 337 Box box = new Box(BoxLayout.X_AXIS); 338 Box box2 = new Box(BoxLayout.Y_AXIS); 339 box2.add(Box.createGlue()); 340 box2.add(new JSeparator(JSeparator.HORIZONTAL)); 341 box2.add(Box.createGlue()); 342 box.add(box2); 343 JLabel l = new JLabel(jEdit.getProperty(label)); 344 l.setMaximumSize(l.getPreferredSize()); 345 box.add(l); 346 Box box3 = new Box(BoxLayout.Y_AXIS); 347 box3.add(Box.createGlue()); 348 box3.add(new JSeparator(JSeparator.HORIZONTAL)); 349 box3.add(Box.createGlue()); 350 box.add(box3); 351 352 GridBagConstraints cons = new GridBagConstraints(); 353 cons.gridy = y++; 354 cons.gridheight = 1; 355 cons.gridwidth = cons.REMAINDER; 356 cons.fill = GridBagConstraints.BOTH; 357 cons.anchor = GridBagConstraints.WEST; 358 cons.weightx = 1.0f; 359 cons.insets = new Insets(1,0,1,0); 360 361 gridBag.setConstraints(box,cons); 362 add(box); 363 } 365 369 protected boolean initialized; 370 371 374 protected GridBagLayout gridBag; 375 376 379 protected int y; 380 381 387 protected void _init() {} 388 389 394 protected void _save() {} 395 397 private String name; 399 } 401 | Popular Tags |