- Timestamp:
- 2009-12-13T12:28:18+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r2626 r2627 44 44 private String[] bToolTipTexts; 45 45 private String[] bIcons; 46 private int cancelButtonIdx = -1; 47 private int defaultButtonIdx = -1; 48 private JButton defaultButton = null; 46 49 47 50 /** true, if the dialog should include a help button */ … … 171 174 172 175 setupDialog(); 176 if (defaultButton != null) { 177 getRootPane().setDefaultButton(defaultButton); 178 } 173 179 setVisible(true); 174 180 toggleSaveState(); … … 200 206 201 207 button = new JButton(action); 208 if (i == defaultButtonIdx-1) { 209 defaultButton = button; 210 } 202 211 if(bIcons != null && bIcons[i] != null) { 203 212 button.setIcon(ImageProvider.get(bIcons[i])); … … 385 394 386 395 /** 396 * Sets the button that will react to ENTER. 397 */ 398 public ExtendedDialog setDefaultButton(int defaultButtonIdx) { 399 this.defaultButtonIdx = defaultButtonIdx; 400 return this; 401 } 402 403 /** 404 * Used in combination with toggle: 405 * If the user presses 'cancel' the toggle settings are ignored and not saved to the pref 406 * @param cancelButton index of the button that stands for cancel 407 */ 408 public ExtendedDialog setCancelButton(int cancelButtonIdx) { 409 this.cancelButtonIdx = cancelButtonIdx; 410 return this; 411 } 412 413 /** 387 414 * This function returns true if the dialog has been set to "do not show again" 388 415 * @return true if dialog should not be shown again … … 394 421 if(!toggleable) 395 422 return false; 396 397 423 this.togglePref = togglePref; 398 424 // The pref is true, if the dialog should be shown. … … 405 431 */ 406 432 private void toggleSaveState() { 407 if(!toggleable || toggleCheckbox == null )433 if(!toggleable || toggleCheckbox == null || result == cancelButtonIdx || result == ExtendedDialog.DialogClosedOtherwise) 408 434 return; 409 435 Main.pref.put("message."+ togglePref, !toggleCheckbox.isSelected()); -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r2621 r2627 10 10 11 11 import java.awt.AlphaComposite; 12 import java.awt.BorderLayout; 12 13 import java.awt.Color; 13 14 import java.awt.Component; … … 36 37 37 38 import javax.swing.Icon; 39 import javax.swing.JLabel; 38 40 import javax.swing.JMenuItem; 39 41 import javax.swing.JOptionPane; 42 import javax.swing.JPanel; 40 43 import javax.swing.JSeparator; 44 import javax.swing.SwingConstants; 41 45 42 46 import org.openstreetmap.josm.Main; … … 46 50 import org.openstreetmap.josm.data.coor.LatLon; 47 51 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 52 import org.openstreetmap.josm.gui.ExtendedDialog; 48 53 import org.openstreetmap.josm.gui.MapView; 49 54 import org.openstreetmap.josm.gui.PleaseWaitRunnable; … … 587 592 ImageViewerDialog.showImage(this, null); 588 593 } 589 } 590 updateOffscreenBuffer = true; 591 Main.main.map.repaint(); 594 updateOffscreenBuffer = true; 595 Main.main.map.repaint(); 596 } 597 } 598 599 public void removeCurrentPhotoFromDisk() { 600 ImageEntry toDelete = null; 601 if (data != null && data.size() > 0 && currentPhoto >= 0 && currentPhoto < data.size()) { 602 toDelete = data.get(currentPhoto); 603 604 int result = new ExtendedDialog( 605 Main.parent, 606 tr("Delete image file from disk"), 607 new String[] {tr("Cancel"), tr("Delete")}) 608 .setButtonIcons(new String[] {"cancel.png", "dialogs/delete.png"}) 609 .setContent(new JLabel(tr("<html><h3>Delete the file {0} from the disk?<p>The image file will be permanently lost!" 610 ,toDelete.file.getName()), ImageProvider.get("dialogs/geoimage/deletefromdisk"),SwingConstants.LEFT)) 611 .toggleEnable("geoimage.deleteimagefromdisk") 612 .setToggleCheckboxText(tr("Always delete and don't show this dialog again")) 613 .setCancelButton(1) 614 .setDefaultButton(2) 615 .showDialog() 616 .getValue(); 617 618 if(result == 2 || result == ExtendedDialog.DialogNotShown) 619 { 620 data.remove(currentPhoto); 621 if (currentPhoto >= data.size()) { 622 currentPhoto = data.size() - 1; 623 } 624 if (currentPhoto >= 0) { 625 ImageViewerDialog.showImage(this, data.get(currentPhoto)); 626 } else { 627 ImageViewerDialog.showImage(this, null); 628 } 629 630 if (toDelete.file.delete()) { 631 System.out.println("File "+toDelete.file.toString()+" deleted. "); 632 } else { 633 JOptionPane.showMessageDialog( 634 Main.parent, 635 tr("Image file could not be deleted."), 636 tr("Error"), 637 JOptionPane.ERROR_MESSAGE 638 ); 639 } 640 641 updateOffscreenBuffer = true; 642 Main.main.map.repaint(); 643 } 644 } 592 645 } 593 646 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r2617 r2627 39 39 private static final String COMMAND_NEXT = "next"; 40 40 private static final String COMMAND_REMOVE = "remove"; 41 private static final String COMMAND_REMOVE_FROM_DISK = "removefromdisk"; 41 42 private static final String COMMAND_PREVIOUS = "previous"; 42 43 private static final String COMMAND_COLLAPSE = "collapse"; … … 93 94 btnPrevious.getActionMap().put(APREVIOUS, prevAction); 94 95 95 JButton btnDelete = new JButton(new ImageAction(COMMAND_REMOVE, ImageProvider.get("dialogs", "delete"), tr("Remove photo from layer"))); 96 final String DELETE_TEXT = tr("Remove photo from layer"); 97 ImageAction delAction = new ImageAction(COMMAND_REMOVE, ImageProvider.get("dialogs", "delete"), DELETE_TEXT); 98 JButton btnDelete = new JButton(delAction); 96 99 btnDelete.setPreferredSize(buttonDim); 100 Shortcut scDelete = Shortcut.registerShortcut( 101 "geoimage:deleteimagefromlayer", tr("Geoimage: {0}", DELETE_TEXT), KeyEvent.VK_DELETE, Shortcut.GROUP_DIRECT, Shortcut.SHIFT_DEFAULT); 102 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scDelete.getKeyStroke(), DELETE_TEXT); 103 Main.contentPane.getActionMap().put(DELETE_TEXT, delAction); 104 btnDelete.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scDelete.getKeyStroke(), DELETE_TEXT); 105 btnDelete.getActionMap().put(DELETE_TEXT, delAction); 106 107 ImageAction delFromDiskAction = new ImageAction(COMMAND_REMOVE_FROM_DISK, ImageProvider.get("dialogs", "geoimage/deletefromdisk"), tr("Delete image file from disk")); 108 JButton btnDeleteFromDisk = new JButton(delFromDiskAction); 109 btnDeleteFromDisk.setPreferredSize(buttonDim); 110 Shortcut scDeleteFromDisk = Shortcut.registerShortcut( 111 "geoimage:deletefilefromdisk", tr("Geoimage: {0}", tr("Delete File from disk")), KeyEvent.VK_DELETE, Shortcut.GROUP_DIRECT, Shortcut.GROUP_MENU + Shortcut.SHIFT_DEFAULT); 112 final String ADELFROMDISK = "Delete image file from disk"; 113 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scDeleteFromDisk.getKeyStroke(), ADELFROMDISK); 114 Main.contentPane.getActionMap().put(ADELFROMDISK, delFromDiskAction); 115 btnDeleteFromDisk.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scDeleteFromDisk.getKeyStroke(), ADELFROMDISK); 116 btnDeleteFromDisk.getActionMap().put(ADELFROMDISK, delFromDiskAction); 97 117 98 118 ImageAction nextAction = new ImageAction(COMMAND_NEXT, ImageProvider.get("dialogs", "next"), tr("Next")); … … 125 145 buttons.add(Box.createRigidArea(new Dimension(14, 0))); 126 146 buttons.add(btnDelete); 147 buttons.add(btnDeleteFromDisk); 127 148 128 149 JPanel bottomPane = new JPanel(); … … 176 197 if (currentLayer != null) { 177 198 currentLayer.removeCurrentPhoto(); 199 } 200 } else if (COMMAND_REMOVE_FROM_DISK.equals(action)) { 201 if (currentLayer != null) { 202 currentLayer.removeCurrentPhotoFromDisk(); 178 203 } 179 204 } else if (COMMAND_COLLAPSE.equals(action)) {
Note:
See TracChangeset
for help on using the changeset viewer.