1 23 package org.enhydra.kelp.common.importer; 24 25 import org.enhydra.tool.common.SwingUtil; 27 import org.enhydra.tool.common.PathHandle; 28 29 import org.enhydra.kelp.common.ValidationUtil; 31 import org.enhydra.kelp.common.ValidationException; 32 33 import javax.swing.*; 35 import javax.swing.border.*; 36 import java.awt.*; 37 import java.awt.event.ActionEvent ; 38 import java.awt.event.ActionListener ; 39 import java.beans.*; 40 import java.io.File ; 41 import java.util.ResourceBundle ; 42 43 49 public class RootPanel extends ImporterPanel { 50 static ResourceBundle res = 51 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); transient private JPanel panelRoot; 53 transient private JTextField textRoot; 54 transient private JButton buttonRoot; 55 56 transient private JPanel panelFiller; 58 transient private GridBagLayout layoutMain; 59 transient private GridBagLayout layoutRoot; 60 transient private LocalButtonListener buttonListener; 61 transient private TitledBorder borderRoot; 62 63 68 public RootPanel() { 69 try { 70 jbInit(); 71 pmInit(); 72 } catch (Exception ex) { 73 ex.printStackTrace(); 74 } 75 } 76 77 84 public void readOptions() { 85 String path; 86 87 path = getPaths().getRootPath(); 89 if (path == null) { 90 textRoot.setText(new String ()); 91 } else { 92 textRoot.setText(path); 93 } 94 } 95 96 103 public void writeOptions() throws ValidationException { 104 String path = null; 105 106 if (getPaths() == null) { 107 throw new ValidationException(res.getString("Import_paths_not_set1")); 108 } 109 110 path = textRoot.getText(); 112 getPaths().setRootPath(path); 113 } 114 115 123 public void validateOptions() throws ValidationException { 124 String value = new String (); 125 126 value = textRoot.getText().trim(); 128 if (!ValidationUtil.isDirectory(value)) { 129 throw new ValidationException(res.getString("Project_directory_is") 130 + res.getString("Directory_not_found_")); 131 } 132 } 133 134 140 public String getPageTitle() { 141 return res.getString("Project_Directory"); 142 } 143 144 151 public String getInstructions() { 152 StringBuffer buf = new StringBuffer (); 153 154 buf.append(res.getString("RootInstruct1")); 155 buf.append(res.getString("RootInstruct2")); 156 buf.append(res.getString("RootInstruct3")); 157 return buf.toString(); 158 } 159 160 164 170 private void jbInit() throws Exception { 171 textRoot = (JTextField) Beans.instantiate(getClass().getClassLoader(), 172 JTextField.class.getName()); 173 panelRoot = (JPanel) Beans.instantiate(getClass().getClassLoader(), 174 JPanel.class.getName()); 175 layoutRoot = 176 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 177 GridBagLayout.class.getName()); 178 buttonRoot = (JButton) Beans.instantiate(getClass().getClassLoader(), 179 JButton.class.getName()); 180 layoutMain = 181 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 182 GridBagLayout.class.getName()); 183 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 184 JPanel.class.getName()); 185 buttonRoot.setText("..."); panelRoot.setLayout(layoutRoot); 187 panelRoot.add(textRoot, 188 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1, 189 GridBagConstraints.WEST, 190 GridBagConstraints.HORIZONTAL, 191 new Insets(5, 5, 5, 5), 0, 0)); 192 panelRoot.add(buttonRoot, 193 new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, 194 GridBagConstraints.CENTER, 195 GridBagConstraints.NONE, 196 new Insets(5, 5, 5, 20), 0, 0)); 197 this.setLayout(layoutMain); 198 this.add(panelRoot, 199 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1, 200 GridBagConstraints.CENTER, 201 GridBagConstraints.BOTH, 202 new Insets(5, 5, 5, 5), 0, 0)); 203 } 204 205 207 private void pmInit() { 208 Border border = BorderFactory.createEtchedBorder(); 209 210 borderRoot = BorderFactory.createTitledBorder(border); 211 borderRoot.setTitle(res.getString("borderRoot_Title")); 212 panelRoot.setBorder(borderRoot); 213 buttonListener = new LocalButtonListener(); 214 buttonRoot.addActionListener(buttonListener); 215 textRoot.setText(new String ()); 216 } 217 218 220 private void browseForDirectory() { 221 File dir = null; 222 223 dir = 224 SwingUtil.getDirectoryChoice(this, textRoot.getText(), 225 res.getString("Choose_the_project")); 226 if (dir != null) { 227 textRoot.setText(PathHandle.createPathString(dir)); 228 } 229 } 230 231 233 private class LocalButtonListener implements ActionListener { 234 public void actionPerformed(ActionEvent event) { 235 browseForDirectory(); 236 } 237 238 } 239 } 240 | Popular Tags |