Ignore:
Timestamp:
2009-12-13T12:28:18+01:00 (12 years ago)
Author:
bastiK
Message:

geoimage: new button 'delelet image from disk' (shortcut: Ctrl+Shift+Del)

  • geoimage: shortcut for 'remove from layer' (Shift+Del)
  • ExtendedDialog: • option to choose the default button (reacts to ENTER)
    • option to better handle 'don't show again'
Location:
trunk/src/org/openstreetmap/josm/gui/layer/geoimage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r2621 r2627  
    1010
    1111import java.awt.AlphaComposite;
     12import java.awt.BorderLayout;
    1213import java.awt.Color;
    1314import java.awt.Component;
     
    3637
    3738import javax.swing.Icon;
     39import javax.swing.JLabel;
    3840import javax.swing.JMenuItem;
    3941import javax.swing.JOptionPane;
     42import javax.swing.JPanel;
    4043import javax.swing.JSeparator;
     44import javax.swing.SwingConstants;
    4145
    4246import org.openstreetmap.josm.Main;
     
    4650import org.openstreetmap.josm.data.coor.LatLon;
    4751import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     52import org.openstreetmap.josm.gui.ExtendedDialog;
    4853import org.openstreetmap.josm.gui.MapView;
    4954import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    587592                ImageViewerDialog.showImage(this, null);
    588593            }
    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        }
    592645    }
    593646
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r2617 r2627  
    3939    private static final String COMMAND_NEXT = "next";
    4040    private static final String COMMAND_REMOVE = "remove";
     41    private static final String COMMAND_REMOVE_FROM_DISK = "removefromdisk";
    4142    private static final String COMMAND_PREVIOUS = "previous";
    4243    private static final String COMMAND_COLLAPSE = "collapse";
     
    9394        btnPrevious.getActionMap().put(APREVIOUS, prevAction);
    9495
    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);
    9699        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);
    97117
    98118        ImageAction nextAction = new ImageAction(COMMAND_NEXT, ImageProvider.get("dialogs", "next"), tr("Next"));
     
    125145        buttons.add(Box.createRigidArea(new Dimension(14, 0)));
    126146        buttons.add(btnDelete);
     147        buttons.add(btnDeleteFromDisk);
    127148
    128149        JPanel bottomPane = new JPanel();
     
    176197                if (currentLayer != null) {
    177198                   currentLayer.removeCurrentPhoto();
     199                }
     200            } else if (COMMAND_REMOVE_FROM_DISK.equals(action)) {
     201                if (currentLayer != null) {
     202                    currentLayer.removeCurrentPhotoFromDisk();
    178203                }
    179204            } else if (COMMAND_COLLAPSE.equals(action)) {
Note: See TracChangeset for help on using the changeset viewer.