1 23 package org.enhydra.kelp.common.xmlc; 24 25 import org.enhydra.tool.common.PathHandle; 27 import org.enhydra.tool.common.SwingUtil; 28 29 import org.enhydra.kelp.common.node.OtterProject; 31 32 import javax.swing.*; 34 import java.awt.*; 35 import java.awt.event.*; 36 import java.io.*; 37 import java.beans.*; 38 import java.util.ResourceBundle ; 39 40 46 public class MapEditorDialog extends JDialog { 47 static ResourceBundle res = 48 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); public static final int ACTION_OK = 0; 50 public static final int ACTION_CANCEL = 1; 51 private static File startFolder = null; 52 private int option = ACTION_CANCEL; 53 private LocalButtonListener buttonListener = null; 54 private JPanel panelMain = new JPanel(); 55 private GridBagLayout layoutMain; 56 private JPanel panelEntry; 57 private GridBagLayout layoutEntry; 58 private JPanel panelButtons; 59 private GridBagLayout layoutButton; 60 private JLabel labelFolder; 61 private JTextField textFolder; 62 private JButton buttonBrowse; 63 private JLabel labelPackage; 64 private JTextField textPackage; 65 private JButton buttonCancel; 66 private JButton buttonOK; 67 private OtterProject project; 68 69 77 public MapEditorDialog(Frame owner, String title, boolean modal) { 78 super(owner, title, modal); 79 construct(); 80 } 81 82 public MapEditorDialog(JDialog owner, String title, boolean modal) { 83 super(owner, title, modal); 84 construct(); 85 } 86 87 private void construct() { 88 try { 89 jbInit(); 90 pmInit(); 91 pack(); 92 } catch (Exception ex) { 93 ex.printStackTrace(); 94 } 95 } 96 97 101 public MapEditorDialog() { 102 this(new Frame(), new String (), false); 103 } 104 105 109 public void show() { 110 setResizable(false); 111 Point cPoint; 112 113 invalidate(); 114 doLayout(); 115 pack(); 116 cPoint = SwingUtil.getCenteringPoint(getSize()); 117 setLocation(cPoint); 118 super.show(); 119 } 120 121 125 private void pmInit() { 126 buttonListener = new LocalButtonListener(); 127 buttonBrowse.addActionListener(buttonListener); 128 buttonOK.addActionListener(buttonListener); 129 buttonCancel.addActionListener(buttonListener); 130 textFolder.setText(new String ()); 131 textPackage.setText(new String ()); 132 } 133 134 140 private void jbInit() throws Exception { 141 layoutMain = 142 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 143 GridBagLayout.class.getName()); 144 panelEntry = (JPanel) Beans.instantiate(getClass().getClassLoader(), 145 JPanel.class.getName()); 146 layoutEntry = 147 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 148 GridBagLayout.class.getName()); 149 panelButtons = (JPanel) Beans.instantiate(getClass().getClassLoader(), 150 JPanel.class.getName()); 151 layoutButton = 152 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 153 GridBagLayout.class.getName()); 154 labelFolder = (JLabel) Beans.instantiate(getClass().getClassLoader(), 155 JLabel.class.getName()); 156 textFolder = 157 (JTextField) Beans.instantiate(getClass().getClassLoader(), 158 JTextField.class.getName()); 159 buttonBrowse = 160 (JButton) Beans.instantiate(getClass().getClassLoader(), 161 JButton.class.getName()); 162 labelPackage = (JLabel) Beans.instantiate(getClass().getClassLoader(), 163 JLabel.class.getName()); 164 textPackage = 165 (JTextField) Beans.instantiate(getClass().getClassLoader(), 166 JTextField.class.getName()); 167 buttonCancel = 168 (JButton) Beans.instantiate(getClass().getClassLoader(), 169 JButton.class.getName()); 170 buttonOK = (JButton) Beans.instantiate(getClass().getClassLoader(), 171 JButton.class.getName()); 172 panelMain.setLayout(layoutMain); 173 panelEntry.setLayout(layoutEntry); 174 panelButtons.setLayout(layoutButton); 175 labelFolder.setText(res.getString("labelFolder_Text")); 176 textFolder.setPreferredSize(new Dimension(250, 21)); 177 buttonBrowse.setText(res.getString("Browse")); 178 labelPackage.setText(res.getString("labelPackage_Text")); 179 textPackage.setPreferredSize(new Dimension(250, 21)); 180 buttonCancel.setText(res.getString("Cancel")); 181 buttonOK.setText(res.getString("OK")); 182 getContentPane().add(panelMain); 183 panelMain.add(panelEntry, 184 new GridBagConstraints(0, 0, 1, 1, 0.2, 0.2, 185 GridBagConstraints.CENTER, 186 GridBagConstraints.BOTH, 187 new Insets(0, 0, 0, 0), 0, 0)); 188 panelEntry.add(labelFolder, 189 new GridBagConstraints(0, 0, 1, 1, 0.2, 0.2, 190 GridBagConstraints.WEST, 191 GridBagConstraints.HORIZONTAL, 192 new Insets(5, 5, 5, 5), 0, 0)); 193 panelEntry.add(textFolder, 194 new GridBagConstraints(0, 1, 1, 1, 0.4, 0.4, 195 GridBagConstraints.WEST, 196 GridBagConstraints.HORIZONTAL, 197 new Insets(5, 5, 5, 5), 200, 198 0)); 199 panelEntry.add(buttonBrowse, 200 new GridBagConstraints(1, 1, 1, 1, 0.2, 0.2, 201 GridBagConstraints.CENTER, 202 GridBagConstraints.NONE, 203 new Insets(5, 5, 5, 5), 0, 0)); 204 panelEntry.add(labelPackage, 205 new GridBagConstraints(0, 2, 1, 1, 0.2, 0.2, 206 GridBagConstraints.WEST, 207 GridBagConstraints.HORIZONTAL, 208 new Insets(5, 5, 5, 5), 0, 0)); 209 panelEntry.add(textPackage, 210 new GridBagConstraints(0, 3, 1, 1, 0.4, 0.4, 211 GridBagConstraints.WEST, 212 GridBagConstraints.HORIZONTAL, 213 new Insets(5, 5, 5, 5), 200, 214 0)); 215 panelMain.add(panelButtons, 216 new GridBagConstraints(0, 1, 1, 1, 0.2, 0.2, 217 GridBagConstraints.CENTER, 218 GridBagConstraints.BOTH, 219 new Insets(5, 5, 5, 0), 0, 0)); 220 panelButtons.add(buttonOK, 221 new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 222 GridBagConstraints.CENTER, 223 GridBagConstraints.NONE, 224 new Insets(5, 5, 5, 5), 0, 225 0)); 226 panelButtons.add(buttonCancel, 227 new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 228 GridBagConstraints.CENTER, 229 GridBagConstraints.NONE, 230 new Insets(5, 5, 5, 5), 0, 231 0)); 232 } 233 234 238 protected void closeDialog() { 239 setVisible(false); 240 removeAll(); 241 dispose(); 242 } 243 244 250 protected int getOption() { 251 return option; 252 } 253 254 260 protected String getFolder() { 261 return textFolder.getText(); 262 } 263 264 protected void setFolder(String folder) { 265 textFolder.setText(folder); 266 } 267 268 protected void setProject(OtterProject p) { 269 project = p; 270 } 271 272 protected OtterProject getProject() { 273 return project; 274 } 275 276 282 protected String getPackageName() { 283 return textPackage.getText(); 284 } 285 286 protected void setPackageName(String pack) { 287 textPackage.setText(pack); 288 } 289 290 296 private void setOption(int o) { 297 option = o; 298 } 299 300 304 private void browseAction() { 305 File choice; 306 307 if (startFolder == null ||!startFolder.exists()) { 308 if (textFolder.getText().trim().length() == 0) { 309 startFolder = new File(getProject().getRootPath()); 310 } else { 312 startFolder = new File(textFolder.getText()); 313 } 314 } 315 choice = 316 SwingUtil.getDirectoryChoice(this, startFolder, 317 res.getString("Select_directory_to")); 318 buttonBrowse.requestFocus(); 319 if (choice != null) { 320 textFolder.setText(PathHandle.createPathString(choice)); 321 startFolder = choice; } 323 } 324 325 332 class LocalButtonListener implements ActionListener { 333 334 340 public void actionPerformed(ActionEvent event) { 341 Object source = event.getSource(); 342 343 if (source == buttonBrowse) { 344 browseAction(); 345 } else if (source == buttonOK) { 346 setOption(ACTION_OK); 347 closeDialog(); 348 } else if (source == buttonCancel) { 349 setOption(ACTION_CANCEL); 350 closeDialog(); 351 } 352 } 353 354 } 355 } 356 | Popular Tags |