Changeset 2602 in josm for trunk/src


Ignore:
Timestamp:
2009-12-10T16:34:13+01:00 (15 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
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java

    r2512 r2602  
    102102     * @param buttonIcons
    103103     */
    104     public void setButtonIcons(String[] buttonIcons) {
     104    public ExtendedDialog setButtonIcons(String[] buttonIcons) {
    105105        this.bIcons = buttonIcons;
     106        return this;
    106107    }
    107108
     
    112113     * @param toolTipTexts the tool tip texts. Ignored, if null.
    113114     */
    114     public void setToolTipTexts(String[] toolTipTexts) {
     115    public ExtendedDialog setToolTipTexts(String[] toolTipTexts) {
    115116        this.bToolTipTexts = toolTipTexts;
     117        return this;
    116118    }
    117119
     
    124126     * @param content Any element that can be displayed in the message dialog
    125127     */
    126     public void setContent(Component content) {
    127         setContent(content, true);
     128    public ExtendedDialog setContent(Component content) {
     129        return setContent(content, true);
    128130    }
    129131
     
    138140     *
    139141     */
    140     public void setContent(Component content, boolean placeContentInScrollPane) {
     142    public ExtendedDialog setContent(Component content, boolean placeContentInScrollPane) {
    141143        this.content = content;
    142144        this.placeContentInScrollPane = placeContentInScrollPane;
     145        return this;
    143146    }
    144147
     
    152155     * @param message The text that should be shown to the user
    153156     */
    154     public void setContent(String message) {
    155         setContent(string2label(message), false);
     157    public ExtendedDialog setContent(String message) {
     158        return setContent(string2label(message), false);
    156159    }
    157160
     
    160163     * for the dialog. You can retrieve the result using <code>getValue</code>
    161164     */
    162     public void showDialog() {
     165    public ExtendedDialog showDialog() {
    163166        // Check if the user has set the dialog to not be shown again
    164167        if(toggleCheckState(togglePref)) {
    165168            result = ExtendedDialog.DialogNotShown;
    166             return;
     169            return this;
    167170        }
    168171
     
    170173        setVisible(true);
    171174        toggleSaveState();
     175        return this;
    172176    }
    173177
     
    342346     *
    343347     */
    344     public void setRememberWindowGeometry(String pref, WindowGeometry wg) {
     348    public ExtendedDialog setRememberWindowGeometry(String pref, WindowGeometry wg) {
    345349        rememberSizePref = pref == null ? "" : pref;
    346350        defaultWindowGeometry = wg;
     351        return this;
    347352    }
    348353
     
    354359     * @param togglePref  The preference to save the checkbox state to
    355360     */
    356     public void toggleEnable(String togglePref) {
     361    public ExtendedDialog toggleEnable(String togglePref) {
    357362        this.toggleable = true;
    358363        this.togglePref = togglePref;
     364        return this;
    359365    }
    360366
     
    363369     * to be called for every dialog, as it's the default anyway.
    364370     */
    365     public void toggleDisable() {
     371    public ExtendedDialog toggleDisable() {
    366372        this.toggleable = false;
     373        return this;
    367374    }
    368375
     
    373380     * @param text
    374381     */
    375     public void setToggleCheckboxText(String text) {
     382    public ExtendedDialog setToggleCheckboxText(String text) {
    376383        this.toggleCheckboxText = text;
     384        return this;
    377385    }
    378386
     
    429437     * @param showHelpButton true, if the dialog displays a help button
    430438     */
    431     public void configureContextsensitiveHelp(String helpTopic, boolean showHelpButton) {
     439    public ExtendedDialog configureContextsensitiveHelp(String helpTopic, boolean showHelpButton) {
    432440        this.helpTopic = helpTopic;
    433441        this.showHelpButton = showHelpButton;
     442        return this;
    434443    }
    435444
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r2512 r2602  
    542542            if (!layerList.getCellBounds(index, index).contains(e.getPoint()))
    543543                return;
     544            if (!layerList.isSelectedIndex(index)) {
     545                layerList.setSelectedIndex(index);
     546            }
    544547            Layer layer = model.getLayer(index);
    545548            LayerListPopup menu = new LayerListPopup(layerList, layer);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r2577 r2602  
    6868     */
    6969    protected boolean isCollapsed;
    70 
     70   
    7171    /** the preferred height if the toggle dialog is expanded */
    7272    private int preferredHeight;
     
    7676
    7777    /** the JDialog displaying the toggle dialog as undocked dialog */
    78     private JDialog detachedDialog;
     78    protected JDialog detachedDialog;
    7979
    8080    /**
     
    295295     *
    296296     */
    297     private class TitleBar extends JPanel {
     297    protected class TitleBar extends JPanel {
    298298        final private JLabel lblTitle;
    299299        final private JComponent lblTitle_weak;
     
    478478        isShowing = val;
    479479        Main.pref.put(preferencePrefix+".visible", val);
     480        stateChanged();
    480481    }
    481482
     
    483484        isDocked = val;
    484485        Main.pref.put(preferencePrefix+".docked", val);
     486        stateChanged();
    485487    }
    486488
     
    488490        isCollapsed = val;
    489491        Main.pref.put(preferencePrefix+".minimized", val);
     492        stateChanged();
    490493    }
    491494
     
    549552        return true;
    550553    }
     554   
     555    /**
     556     * primitive stateChangedListener for subclasses
     557     */
     558    protected void stateChanged() {
     559    }
    551560
    552561    /***
  • 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.