1 7 package org.enhydra.base.tool; 8 9 import java.awt.event.ActionEvent ; 10 import java.awt.event.ActionListener ; 11 12 import javax.swing.JPanel ; 13 14 import javax.swing.AbstractAction ; 15 import javax.swing.JCheckBox ; 16 import javax.swing.JFileChooser ; 17 import javax.swing.JLabel ; 18 import javax.swing.JOptionPane ; 19 import javax.swing.JTextField ; 20 import javax.swing.JButton ; 21 22 28 public class EnhydraBasePanel extends JPanel { 29 30 private JCheckBox createNew = null; 31 32 private JLabel jLabel = null; 33 34 private JLabel serviceLabel = null; 35 36 private JTextField serviceText = null; 37 38 private JLabel pathLabel = null; 39 40 private JTextField pathText = null; 41 42 private JButton browseButton = null; 43 44 private JLabel jLabel2 = null; 45 46 private JLabel jLabel1 = null; 47 48 51 public EnhydraBasePanel() { 52 super(); 53 initialize(); 54 } 55 56 61 private void initialize() { 62 jLabel1 = new JLabel (); 63 serviceLabel = new JLabel (); 64 jLabel2 = new JLabel (); 65 pathLabel = new JLabel (); 66 jLabel = new JLabel (); 67 this.setPreferredSize(new java.awt.Dimension (300, 150)); 68 this.setSize(300, 150); 69 jLabel.setText(""); 70 jLabel.setPreferredSize(new java.awt.Dimension (300, 16)); 71 serviceLabel.setText("Service Name:"); 72 serviceLabel.setName("serviceLabel"); 73 serviceLabel.setEnabled(false); 74 pathLabel.setText("Path to Enhydra Base Directory:"); 75 pathLabel.setEnabled(false); 76 pathLabel.setName("pathLabel"); 77 pathLabel.setPreferredSize(new java.awt.Dimension (281, 16)); 78 jLabel2.setText(""); 79 jLabel2.setPreferredSize(new java.awt.Dimension (80, 10)); 80 jLabel1.setText(""); 81 jLabel1.setPreferredSize(new java.awt.Dimension (300, 5)); 82 this.add(getCreateNew(), null); 83 this.add(jLabel, null); 84 this.add(serviceLabel, null); 85 this.add(getServiceText(), null); 86 this.add(jLabel2, null); 87 this.add(jLabel1, null); 88 this.add(pathLabel, null); 89 this.add(getPathText(), null); 90 this.add(getBrowseButton(), null); 91 } 92 93 98 private JCheckBox getCreateNew() { 99 if (createNew == null) { 100 createNew = new JCheckBox (); 101 createNew.setSelected(false); 102 createNew.setName("createNew"); 103 createNew.setText("Create New Enhydra Base Directory"); 104 createNew.setPreferredSize(new java.awt.Dimension (300, 24)); 105 createNew.addActionListener(new CustomActionListener()); 106 } 107 return createNew; 108 } 109 110 115 private JTextField getServiceText() { 116 if (serviceText == null) { 117 serviceText = new JTextField (); 118 serviceText.setName("serviceText"); 119 serviceText.setPreferredSize(new java.awt.Dimension (110, 20)); 120 serviceText.setEnabled(false); 121 } 122 return serviceText; 123 } 124 125 130 private JTextField getPathText() { 131 if (pathText == null) { 132 pathText = new JTextField (); 133 pathText.setPreferredSize(new java.awt.Dimension (196, 20)); 134 pathText.setEnabled(false); 135 pathText.setName("pathText"); 136 } 137 return pathText; 138 } 139 140 145 private JButton getBrowseButton() { 146 if (browseButton == null) { 147 browseButton = new JButton (); 148 browseButton.setText("Browse"); 149 browseButton.setEnabled(false); 150 browseButton.setName("browseButton"); 151 browseButton.setPreferredSize(new java.awt.Dimension (80, 26)); 152 browseButton.addActionListener(new CustomActionListener()); 153 } 154 return browseButton; 155 } 156 157 public void setServiceName (String name){ 158 getServiceText().setText(name); 159 } 160 161 public String getServiceName (){ 162 return getServiceText().getText(); 163 } 164 165 public void setBasePath (String path){ 166 getPathText().setText(path); 167 } 168 169 public String getBasePath (){ 170 return getPathText().getText(); 171 } 172 173 public void setBaseChecked (boolean selected){ 174 getCreateNew().setSelected(selected); 175 176 serviceLabel.setEnabled(getCreateNew().isSelected()); 177 serviceText.setEnabled(getCreateNew().isSelected()); 178 pathLabel.setEnabled(getCreateNew().isSelected()); 179 pathText.setEnabled(getCreateNew().isSelected()); 180 browseButton.setEnabled(getCreateNew().isSelected()); 181 } 182 183 public boolean getBaseChecked (){ 184 return getCreateNew().isSelected(); 185 } 186 187 private class CustomAction extends AbstractAction { 188 public void actionPerformed(ActionEvent ae) { 189 String command = ae.getActionCommand(); 190 if ("Create New Enhydra Base Directory".equals(command)) { 191 serviceLabel.setEnabled(getCreateNew().isSelected()); 192 serviceText.setEnabled(getCreateNew().isSelected()); 193 pathLabel.setEnabled(getCreateNew().isSelected()); 194 pathText.setEnabled(getCreateNew().isSelected()); 195 browseButton.setEnabled(getCreateNew().isSelected()); 196 } else if ("Browse".equals(command)) { 197 JFileChooser chooser = new JFileChooser (); 198 chooser.setDialogTitle("Choose Enhydra Base Path!!!"); 199 chooser.setFileSelectionMode(chooser.DIRECTORIES_ONLY); 200 int returnVal = chooser.showOpenDialog(null); 201 if (returnVal == JFileChooser.APPROVE_OPTION) { 202 pathText.setText(chooser.getSelectedFile() 203 .getAbsolutePath()); 204 } 205 } 206 } 207 } 208 209 private class CustomActionListener implements ActionListener { 210 211 protected AbstractAction action; 212 213 public CustomActionListener() { 214 action = new CustomAction(); 215 } 216 217 public void actionPerformed(ActionEvent e) { 218 action.actionPerformed(e); 219 } 220 } 221 222 public boolean checkEntries() { 223 boolean valid = true; 224 if (createNew.isSelected()) { 225 if ("".equals(serviceText.getText()) 226 || serviceText.getText() == null) { 227 displayErrorMessage("Service Name"); 228 valid = false; 229 } else { 230 serviceText.setText(serviceText.getText().replace(' ', '_')); 231 } 232 233 if ("".equals(pathText.getText()) || pathText.getText() == null) { 234 displayErrorMessage("Path to Enhydra Base Directory"); 235 valid = false; 236 } 237 } 238 return valid; 239 } 240 241 private void displayErrorMessage(String field) { 242 JOptionPane.showMessageDialog(null, "Check '" + field 243 + "' Field Setting!", 244 "Enhydra Configuration Tool - Houston, we have a problem!", 245 JOptionPane.ERROR_MESSAGE); 246 } 247 248 } | Popular Tags |