1 19 20 package org.apache.excalibur.instrument.client; 21 22 import java.awt.Component ; 23 import java.awt.Dimension ; 24 import java.awt.GridBagConstraints ; 25 import java.awt.GridBagLayout ; 26 27 import javax.swing.Box ; 28 import javax.swing.JFrame ; 29 import javax.swing.JLabel ; 30 import javax.swing.JPanel ; 31 32 39 public abstract class AbstractTabularOptionDialog 40 extends AbstractOptionDialog 41 { 42 45 52 protected AbstractTabularOptionDialog( JFrame frame, String title, int buttons ) 53 { 54 super( frame, title, buttons ); 55 } 56 57 60 67 protected JPanel getMainPanel() 68 { 69 String [] labels = getMainPanelLabels(); 70 Component [] components = getMainPanelComponents(); 71 72 JPanel panel = new JPanel (); 73 74 GridBagLayout gbl = new GridBagLayout (); 75 GridBagConstraints gbc = new GridBagConstraints (); 76 panel.setLayout( gbl ); 77 78 for ( int i = 0; i < labels.length; i++ ) 79 { 80 addRow( panel, labels[i], components[i], gbl, gbc ); 81 } 82 83 return panel; 84 } 85 86 89 95 protected abstract String [] getMainPanelLabels(); 96 97 102 protected abstract Component [] getMainPanelComponents(); 103 104 116 private void addRow( JPanel panel, 117 String label, 118 Component component, 119 GridBagLayout gbl, 120 GridBagConstraints gbc ) 121 { 122 JLabel jLabel = new JLabel ( label ); 123 gbc.gridwidth = 1; 124 gbc.anchor = GridBagConstraints.EAST; 125 gbl.setConstraints( jLabel, gbc ); 126 panel.add( jLabel ); 127 128 Component spacer = Box.createRigidArea( new Dimension ( 5, 5 ) ); 130 gbc.gridwidth = GridBagConstraints.RELATIVE; 131 gbc.anchor = GridBagConstraints.WEST; 132 gbl.setConstraints( spacer, gbc ); 133 panel.add( spacer ); 134 135 gbc.gridwidth = GridBagConstraints.REMAINDER; 136 gbc.anchor = GridBagConstraints.WEST; 137 gbl.setConstraints( component, gbc ); 138 panel.add( component ); 139 140 spacer = Box.createRigidArea( new Dimension ( 5, 5 ) ); 142 gbc.gridwidth = GridBagConstraints.REMAINDER; 143 gbc.anchor = GridBagConstraints.WEST; 144 gbl.setConstraints( spacer, gbc ); 145 panel.add( spacer ); 146 } 147 } 148 149 | Popular Tags |