1 22 package org.enhydra.kelp.common.xmlc; 23 24 import org.enhydra.tool.common.SwingUtil; 26 27 import org.enhydra.kelp.common.event.SwingTableSelectionEvent; 29 import org.enhydra.kelp.common.event.SwingTableSelectionListener; 30 import org.enhydra.kelp.common.node.OtterProject; 31 32 import javax.swing.*; 34 import java.beans.*; 35 import java.awt.*; 36 import java.awt.event.*; 37 import java.util.ResourceBundle ; 38 39 45 public class MapDialog extends JDialog 46 implements SwingTableSelectionListener { 47 static ResourceBundle res = 48 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); private boolean standalone = false; 50 private OtterProject project = null; 51 private LocalButtonListener buttonListener = null; 52 private JPanel panelMain; 53 private MapPanel mapPanel; 54 private GridBagLayout layoutMain; 55 private JPanel panelButton; 56 private GridBagLayout layoutButton; 57 private JButton buttonAdd; 58 private JButton buttonRemove; 59 private JButton buttonClose; 60 private JPanel jPanel1; 61 private JPanel panelFiller; 62 private JButton buttonEdit; 63 64 72 public MapDialog(Frame owner, String title, boolean modal) { 73 super(owner, title, modal); 74 construct(); 75 } 76 77 85 public MapDialog(Dialog owner, String title, boolean modal) { 86 super(owner, title, modal); 87 construct(); 88 } 89 90 92 96 public void show() { 97 98 Point cPoint; 100 101 invalidate(); 102 doLayout(); 103 pack(); 104 cPoint = SwingUtil.getCenteringPoint(getSize()); 105 setLocation(cPoint); 106 super.show(); 107 } 108 109 public void onSwingTableSelection(SwingTableSelectionEvent event) { 112 boolean en = (!event.isSelectionNull()); 113 114 buttonEdit.setEnabled(en); 115 buttonRemove.setEnabled(en); 116 } 117 118 122 protected void clearAll() { 123 layoutMain.removeLayoutComponent(mapPanel); 124 panelMain.removeAll(); 125 layoutMain = null; 126 panelMain = null; 127 setTitle(null); 128 } 129 130 136 public OtterProject getProject() { 137 return project; 138 } 139 140 146 public void setProject(OtterProject p) { 147 project = p; 148 mapPanel.setMap(project.getPackageMap()); 149 } 150 151 155 protected void closeDialog() { 156 project.setPackageMap(mapPanel.getMap()); 157 setVisible(false); 158 removeAll(); 159 dispose(); 160 if (standalone) { 161 System.exit(0); 162 } 163 } 164 165 168 172 private void construct() { 173 try { 174 jbInit(); 175 pmInit(); 176 pack(); 177 } catch (Exception ex) { 178 ex.printStackTrace(); 179 } 180 } 181 182 186 private void pmInit() { 187 buttonListener = new LocalButtonListener(); 188 buttonAdd.addActionListener(buttonListener); 189 buttonEdit.addActionListener(buttonListener); 190 buttonRemove.addActionListener(buttonListener); 191 buttonClose.addActionListener(buttonListener); 192 buttonEdit.setEnabled(false); 193 buttonRemove.setEnabled(false); 194 mapPanel.addSwingTableSelectionListener(this); 195 } 196 197 203 private void jbInit() throws Exception { 204 panelMain = (JPanel) Beans.instantiate(getClass().getClassLoader(), 205 JPanel.class.getName()); 206 mapPanel = (MapPanel) Beans.instantiate(getClass().getClassLoader(), 207 MapPanel.class.getName()); 208 layoutMain = 209 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 210 GridBagLayout.class.getName()); 211 panelButton = (JPanel) Beans.instantiate(getClass().getClassLoader(), 212 JPanel.class.getName()); 213 layoutButton = 214 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 215 GridBagLayout.class.getName()); 216 buttonAdd = (JButton) Beans.instantiate(getClass().getClassLoader(), 217 JButton.class.getName()); 218 buttonRemove = 219 (JButton) Beans.instantiate(getClass().getClassLoader(), 220 JButton.class.getName()); 221 buttonClose = (JButton) Beans.instantiate(getClass().getClassLoader(), 222 JButton.class.getName()); 223 jPanel1 = (JPanel) Beans.instantiate(getClass().getClassLoader(), 224 JPanel.class.getName()); 225 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 226 JPanel.class.getName()); 227 buttonEdit = (JButton) Beans.instantiate(getClass().getClassLoader(), 228 JButton.class.getName()); 229 panelMain.setLayout(layoutMain); 230 panelButton.setLayout(layoutButton); 231 buttonAdd.setText(res.getString("buttonAdd_Text")); 232 buttonRemove.setText(res.getString("Remove_")); 233 buttonClose.setText(res.getString("Close")); 234 buttonEdit.setText(res.getString("Edit")); 235 panelMain.add(mapPanel, 236 new GridBagConstraints(0, 0, 1, 1, 0.7, 0.7, 237 GridBagConstraints.CENTER, 238 GridBagConstraints.BOTH, 239 new Insets(0, 0, 0, 0), 0, 0)); 240 panelMain.add(panelButton, 241 new GridBagConstraints(0, 1, 1, 1, 0.3, 0.3, 242 GridBagConstraints.CENTER, 243 GridBagConstraints.BOTH, 244 new Insets(0, 0, 0, 0), 20, 20)); 245 panelButton.add(buttonAdd, 246 new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, 247 GridBagConstraints.CENTER, 248 GridBagConstraints.NONE, 249 new Insets(5, 5, 5, 5), 0, 0)); 250 panelButton.add(buttonRemove, 251 new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, 252 GridBagConstraints.CENTER, 253 GridBagConstraints.NONE, 254 new Insets(5, 5, 5, 5), 0, 0)); 255 panelButton.add(buttonClose, 256 new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0, 257 GridBagConstraints.CENTER, 258 GridBagConstraints.NONE, 259 new Insets(5, 5, 5, 5), 0, 0)); 260 panelButton.add(panelFiller, 261 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1, 262 GridBagConstraints.CENTER, 263 GridBagConstraints.BOTH, 264 new Insets(0, 0, 0, 0), 0, 0)); 265 panelButton.add(buttonEdit, 266 new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, 267 GridBagConstraints.CENTER, 268 GridBagConstraints.NONE, 269 new Insets(5, 5, 5, 5), 0, 0)); 270 this.getContentPane().add(panelMain); 271 } 272 273 277 private void actionAdd() { 278 MapEditorDialog d = 279 new MapEditorDialog(this, res.getString("Add_a_new_directory"), 280 true); 281 282 d.setProject(getProject()); 283 d.show(); 284 if (d.getOption() == MapEditorDialog.ACTION_OK) { 285 if (d.getFolder().trim().length() > 0) { 286 mapPanel.addRow(d.getFolder(), d.getPackageName()); 287 } 288 } 289 } 290 291 private void actionEdit() { 292 MapEditorDialog d = 293 new MapEditorDialog(this, res.getString("Edit_directory_to"), 294 true); 295 296 d.setFolder(mapPanel.getSelectedFolder()); 297 d.setPackageName(mapPanel.getSelectedPackageName()); 298 d.setProject(project); 299 d.show(); 300 if (d.getOption() == MapEditorDialog.ACTION_OK) { 301 if (d.getFolder().trim().length() > 0) { 302 mapPanel.updateSelectedRow(d.getFolder(), d.getPackageName()); 303 } 304 } 305 } 306 307 311 private void actionRemove() { 312 if (mapPanel.getCurrentSelectionIndex() == MapPanel.NO_SELECTION) { 313 314 } else { 317 int result = 318 JOptionPane.showConfirmDialog(this, 319 res.getString("Remove_the_current"), 320 res.getString("Remove_Mapping"), 321 JOptionPane.YES_NO_OPTION); 322 323 if (result == JOptionPane.YES_OPTION) { 324 mapPanel.removeRow(mapPanel.getCurrentSelectionIndex()); 325 } 326 } 327 } 328 329 336 class LocalButtonListener implements ActionListener { 337 338 344 public void actionPerformed(ActionEvent event) { 345 Object source = event.getSource(); 346 347 if (source == buttonAdd) { 348 actionAdd(); 349 } else if (source == buttonEdit) { 350 actionEdit(); 351 } else if (source == buttonRemove) { 352 actionRemove(); 353 } else if (source == buttonClose) { 354 closeDialog(); 355 } 356 } 357 358 } 359 } 360 | Popular Tags |