Ignore:
Timestamp:
2009-12-10T16:34:13+01:00 (12 years ago)
Author:
bastiK
Message:

some minor things:

  • layerlist dialog: right click on an entry selects it
  • geoimage dialog: add button on the lower right, that moves the window to the side pane
  • geoimage dialog: show image file name in the title
  • chained calling for ExtendedDialog
Location:
trunk/src/org/openstreetmap/josm/gui/layer/geoimage
Files:
2 edited

Legend:

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

    r2592 r2602  
    133133            // To avoid issues when the user tries to zoom in on the image borders, this point is not calculated
    134134            // again if there was less than 1.5seconds since the last event.
    135             System.out.println(e);
    136135            if (e.getWhen() - lastTimeForMousePoint > 1500 || mousePointInImg == null) {
    137136                lastTimeForMousePoint = e.getWhen();
     
    535534
    536535    private Rectangle calculateDrawImageRectangle(Rectangle visibleRect) {
    537         Dimension size = getSize();
     536        return calculateDrawImageRectangle(visibleRect, new Rectangle(0, 0, getSize().width, getSize().height));
     537    }
     538   
     539    /**
     540     * calculateDrawImageRectangle
     541     *
     542     * @param imgRect the part of the image that should be drawn (in image coordinates)
     543     * @param compRect the part of the component where the image should be drawn (in component coordinates)
     544     * @return the part of compRect with the same width/height ratio as the image
     545     */
     546    static Rectangle calculateDrawImageRectangle(Rectangle imgRect, Rectangle compRect) {
    538547        int x, y, w, h;
    539548        x = 0;
    540549        y = 0;
    541         w = size.width;
    542         h = size.height;
    543 
    544         int wFact = w * visibleRect.height;
    545         int hFact = h * visibleRect.width;
     550        w = compRect.width;
     551        h = compRect.height;
     552
     553        int wFact = w * imgRect.height;
     554        int hFact = h * imgRect.width;
    546555        if (wFact != hFact) {
    547556            if (wFact > hFact) {
    548                 w = hFact / visibleRect.height;
    549                 x = (size.width - w) / 2;
     557                w = hFact / imgRect.height;
     558                x = (compRect.width - w) / 2;
    550559            } else {
    551                 h = wFact / visibleRect.width;
    552                 y = (size.height - h) / 2;
    553             }
    554         }
    555         return new Rectangle(x, y, w, h);
     560                h = wFact / imgRect.width;
     561                y = (compRect.height - h) / 2;
     562            }
     563        }
     564        return new Rectangle(x + compRect.x, y + compRect.y, w, h);
    556565    }
    557566
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r2601 r2602  
    99
    1010import java.awt.BorderLayout;
     11import java.awt.Component;
    1112import java.awt.Dimension;
    12 import java.awt.FlowLayout;
     13import java.awt.GridBagConstraints;
     14import java.awt.GridBagLayout;
    1315import java.awt.event.ActionEvent;
    1416import java.awt.event.ActionListener;
    1517import java.awt.event.KeyEvent;
    16 
     18import java.awt.event.WindowEvent;
     19
     20import javax.swing.Box;
    1721import javax.swing.AbstractAction;
    1822import javax.swing.ImageIcon;
     
    2327
    2428import org.openstreetmap.josm.Main;
    25 import org.openstreetmap.josm.gui.SideButton;
    2629import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    2730import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
     
    3740    private static final String COMMAND_REMOVE = "remove";
    3841    private static final String COMMAND_PREVIOUS = "previous";
     42    private static final String COMMAND_COLLAPSE = "collapse";
    3943
    4044    private ImageDisplay imgDisplay = new ImageDisplay();
     
    4347    // Only one instance of that class
    4448    static private ImageViewerDialog INSTANCE = null;
     49
     50    private boolean collapseButtonClicked = false;
    4551
    4652    public static ImageViewerDialog getInstance() {
     
    5359    private JButton btnNext;
    5460    private JButton btnPrevious;
     61    private JButton btnCollapse;
    5562
    5663    private ImageViewerDialog() {
     
    7380        content.add(imgDisplay, BorderLayout.CENTER);
    7481
    75         JPanel buttons = new JPanel();
    76         buttons.setLayout(new FlowLayout());
    77 
    7882        Dimension buttonDim = new Dimension(26,26);
    79        
     83
    8084        ImageAction prevAction = new ImageAction(COMMAND_PREVIOUS, ImageProvider.get("dialogs", "previous"), tr("Previous"));
    8185        btnPrevious = new JButton(prevAction);
    8286        btnPrevious.setPreferredSize(buttonDim);
    83         buttons.add(btnPrevious);
    8487        Shortcut scPrev = Shortcut.registerShortcut(
    8588            "geoimage:previous", tr("Geoimage: {0}", tr("Show previous Image")), KeyEvent.VK_PAGE_UP, Shortcut.GROUP_DIRECT);
     
    9295        JButton btnDelete = new JButton(new ImageAction(COMMAND_REMOVE, ImageProvider.get("dialogs", "delete"), tr("Remove photo from layer")));
    9396        btnDelete.setPreferredSize(buttonDim);
    94         buttons.add(btnDelete);
    95      
     97
    9698        ImageAction nextAction = new ImageAction(COMMAND_NEXT, ImageProvider.get("dialogs", "next"), tr("Next"));
    9799        btnNext = new JButton(nextAction);
    98100        btnNext.setPreferredSize(buttonDim);
    99         buttons.add(btnNext);
    100101        Shortcut scNext = Shortcut.registerShortcut(
    101102            "geoimage:next", tr("Geoimage: {0}", tr("Show next Image")), KeyEvent.VK_PAGE_DOWN, Shortcut.GROUP_DIRECT);
     
    108109        JToggleButton tbCentre = new JToggleButton(new ImageAction(COMMAND_CENTERVIEW, ImageProvider.get("dialogs", "centreview"), tr("Center view")));
    109110        tbCentre.setPreferredSize(buttonDim);
    110         buttons.add(tbCentre);
    111        
     111
    112112        JButton btnZoomBestFit = new JButton(new ImageAction(COMMAND_ZOOM, ImageProvider.get("dialogs", "zoom-best-fit"), tr("Zoom best fit and 1:1")));
    113113        btnZoomBestFit.setPreferredSize(buttonDim);
     114
     115        btnCollapse = new JButton(new ImageAction(COMMAND_COLLAPSE, ImageProvider.get("dialogs", "collapse"), tr("Move dialog to the side pane")));
     116        btnCollapse.setPreferredSize(new Dimension(20,20));
     117        btnCollapse.setAlignmentY(Component.TOP_ALIGNMENT);
     118
     119        JPanel buttons = new JPanel();
     120        buttons.add(btnPrevious);
     121        buttons.add(btnNext);
     122        buttons.add(Box.createRigidArea(new Dimension(14, 0)));
     123        buttons.add(tbCentre);
    114124        buttons.add(btnZoomBestFit);
    115 
    116         content.add(buttons, BorderLayout.SOUTH);
     125        buttons.add(Box.createRigidArea(new Dimension(14, 0)));
     126        buttons.add(btnDelete);
     127
     128        JPanel bottomPane = new JPanel();
     129        bottomPane.setLayout(new GridBagLayout());
     130        GridBagConstraints gc = new GridBagConstraints();
     131        gc.gridx = 0;
     132        gc.gridy = 0;
     133        gc.anchor = GridBagConstraints.CENTER;
     134        gc.weightx = 1;
     135        bottomPane.add(buttons, gc);
     136
     137        gc.gridx = 1;
     138        gc.gridy = 0;
     139        gc.anchor = GridBagConstraints.PAGE_END;
     140        gc.weightx = 0;
     141        bottomPane.add(btnCollapse, gc);
     142
     143        content.add(bottomPane, BorderLayout.SOUTH);
    117144
    118145        add(content, BorderLayout.CENTER);
     
    150177                   currentLayer.removeCurrentPhoto();
    151178                }
     179            } else if (COMMAND_COLLAPSE.equals(action)) {
     180                collapseButtonClicked = true;
     181                detachedDialog.getToolkit().getSystemEventQueue().postEvent(new WindowEvent(detachedDialog, WindowEvent.WINDOW_CLOSING));
    152182            }
    153183        }
     
    186216        if (entry != null) {
    187217            imgDisplay.setImage(entry.file);
     218            titleBar.setTitle("Geotagged Images" + (entry.file != null ? " - " + entry.file.getName() : ""));
    188219            StringBuffer osd = new StringBuffer(entry.file != null ? entry.file.getName() : "");
    189220            if (entry.elevation != null) {
     
    227258    @Override
    228259    protected boolean dockWhenClosingDetachedDlg() {
     260        if (collapseButtonClicked) {
     261            collapseButtonClicked = false;
     262            return true;
     263        }
    229264        return false;
     265    }
     266
     267    @Override
     268    protected void stateChanged() {
     269        super.stateChanged();
     270        if (btnCollapse != null) {
     271            btnCollapse.setVisible(!isDocked);
     272        }
    230273    }
    231274
Note: See TracChangeset for help on using the changeset viewer.