Changeset 1868 in josm


Ignore:
Timestamp:
2009-07-28T21:43:34+02:00 (16 years ago)
Author:
Gubaer
Message:

fixed #3041: Relation Editor: Provide action for zooming to a particular member

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r1854 r1868  
    5959    }
    6060
    61     public void actionPerformed(ActionEvent e) {
     61    public void autoScale() {
    6262        if (Main.map != null) {
    6363            BoundingXYVisitor bbox = getBoundingBox();
     
    6767        }
    6868        putValue("active", true);
     69    }
     70
     71    public void actionPerformed(ActionEvent e) {
     72        autoScale();
    6973    }
    7074
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r1866 r1868  
    11package org.openstreetmap.josm.gui.dialogs;
    22
    3 import static org.openstreetmap.josm.tools.I18n.marktr;
    43import static org.openstreetmap.josm.tools.I18n.tr;
    54
     
    76import java.awt.GridLayout;
    87import java.awt.event.ActionEvent;
    9 import java.awt.event.ActionListener;
    108import java.awt.event.KeyEvent;
    119import java.awt.event.MouseAdapter;
    1210import java.awt.event.MouseEvent;
    13 import java.util.ArrayList;
    14 import java.util.Collections;
    15 import java.util.List;
    1611
    1712import javax.swing.AbstractAction;
    1813import javax.swing.DefaultListModel;
    1914import javax.swing.JList;
    20 import javax.swing.JOptionPane;
    2115import javax.swing.JPanel;
    2216import javax.swing.JScrollPane;
     
    2620
    2721import org.openstreetmap.josm.Main;
    28 import org.openstreetmap.josm.command.ChangeCommand;
    29 import org.openstreetmap.josm.command.Command;
    30 import org.openstreetmap.josm.command.DeleteCommand;
    31 import org.openstreetmap.josm.command.SequenceCommand;
    3222import org.openstreetmap.josm.data.osm.DataSet;
    3323import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3424import org.openstreetmap.josm.data.osm.Relation;
    35 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    36 import org.openstreetmap.josm.gui.OptionPaneUtil;
    3725import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    3826import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
    3927import org.openstreetmap.josm.gui.SideButton;
    40 import org.openstreetmap.josm.gui.dialogs.relation.ParentRelationLoadingTask;
    41 import org.openstreetmap.josm.gui.dialogs.relation.RelationDialogManager;
    4228import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    4329import org.openstreetmap.josm.gui.layer.DataChangeListener;
     
    4531import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4632import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    47 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
    4833import org.openstreetmap.josm.tools.GBC;
    4934import org.openstreetmap.josm.tools.ImageProvider;
    5035import org.openstreetmap.josm.tools.Shortcut;
    51 
    52 import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;
    5336
    5437/**
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r1857 r1868  
    327327        pnl.setLayout(new GridBagLayout());
    328328        // setting up the member table
    329         memberTable = new MemberTable(memberTableModel);
     329        memberTable = new MemberTable(getLayer(),memberTableModel);
    330330
    331331        memberTable.getSelectionModel().addListSelectionListener(new SelectionSynchronizer());
     
    666666            );
    667667            switch(ret) {
    668             case ConditionalOptionPaneUtil.DIALOG_DISABLED_OPTION: return;
    669             case JOptionPane.CLOSED_OPTION: return;
    670             case JOptionPane.NO_OPTION: return;
    671             case JOptionPane.YES_OPTION:
    672                 memberTableModel.removeMembersReferringTo(toCheck);
    673                 break;
     668                case ConditionalOptionPaneUtil.DIALOG_DISABLED_OPTION: return;
     669                case JOptionPane.CLOSED_OPTION: return;
     670                case JOptionPane.NO_OPTION: return;
     671                case JOptionPane.YES_OPTION:
     672                    memberTableModel.removeMembersReferringTo(toCheck);
     673                    break;
    674674            }
    675675        }
     
    704704            );
    705705            switch(ret) {
    706             case ConditionalOptionPaneUtil.DIALOG_DISABLED_OPTION : return true;
    707             case JOptionPane.YES_OPTION: return true;
    708             case JOptionPane.NO_OPTION: return false;
    709             case JOptionPane.CLOSED_OPTION: return false;
    710             case JOptionPane.CANCEL_OPTION: throw new AddAbortException();
     706                case ConditionalOptionPaneUtil.DIALOG_DISABLED_OPTION : return true;
     707                case JOptionPane.YES_OPTION: return true;
     708                case JOptionPane.NO_OPTION: return false;
     709                case JOptionPane.CLOSED_OPTION: return false;
     710                case JOptionPane.CANCEL_OPTION: throw new AddAbortException();
    711711            }
    712712            // should not happen
     
    10791079            );
    10801080            switch(ret) {
    1081             case JOptionPane.CANCEL_OPTION: return false;
    1082             case JOptionPane.YES_OPTION: return true;
    1083             case JOptionPane.NO_OPTION: return false;
     1081                case JOptionPane.CANCEL_OPTION: return false;
     1082                case JOptionPane.YES_OPTION: return true;
     1083                case JOptionPane.NO_OPTION: return false;
    10841084            }
    10851085            return false;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

    r1804 r1868  
    22package org.openstreetmap.josm.gui.dialogs.relation;
    33
    4 import java.awt.Dimension;
    5 import java.awt.Rectangle;
    64import java.awt.event.ActionEvent;
    75import java.awt.event.KeyEvent;
     6import java.awt.event.MouseAdapter;
     7import java.awt.event.MouseEvent;
    88
    99import javax.swing.AbstractAction;
    1010import javax.swing.JComponent;
     11import javax.swing.JPopupMenu;
    1112import javax.swing.JTable;
    1213import javax.swing.KeyStroke;
    1314import javax.swing.ListSelectionModel;
     15import javax.swing.event.ListSelectionEvent;
     16import javax.swing.event.ListSelectionListener;
    1417import javax.swing.table.TableColumnModel;
    1518
     19import org.openstreetmap.josm.Main;
     20import org.openstreetmap.josm.actions.AutoScaleAction;
     21import org.openstreetmap.josm.data.osm.DataSet;
     22import org.openstreetmap.josm.data.osm.OsmPrimitive;
     23import org.openstreetmap.josm.gui.layer.Layer;
     24import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     25import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
     26
     27import static org.openstreetmap.josm.tools.I18n.tr;
     28
    1629public class MemberTable extends JTable implements IMemberModelListener {
     30
     31    /**
     32     * the data layer in whose context relation members are edited in this table
     33     */
     34    protected OsmDataLayer layer;
     35
     36    /** the popup menu */
     37    protected JPopupMenu popupMenu;
    1738
    1839    /**
     
    2243     * @param columnModel
    2344     */
    24     public MemberTable(MemberTableModel model) {
     45    public MemberTable(OsmDataLayer layer, MemberTableModel model) {
    2546        super(model, new MemberTableColumnModel(), model.getSelectionModel());
     47        this.layer = layer;
    2648        model.addMemberModelListener(this);
    2749        init();
     50
    2851    }
    2952
     
    3861        // make ENTER behave like TAB
    3962        //
    40         getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
    41         .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), "selectNextColumnCell");
     63        getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
     64                KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), "selectNextColumnCell");
    4265
    4366        // install custom navigation actions
     
    4568        getActionMap().put("selectNextColumnCell", new SelectNextColumnCellAction());
    4669        getActionMap().put("selectPreviousColumnCell", new SelectPreviousColumnCellAction());
    47     }
    48 
    49     /**
    50      * adjusts the width of the columns for the tag name and the tag value
    51      * to the width of the scroll panes viewport.
     70
     71        addMouseListener(new PopupListener());
     72    }
     73
     74    /**
     75     * adjusts the width of the columns for the tag name and the tag value to the width of the
     76     * scroll panes viewport.
    5277     *
    5378     * Note: {@see #getPreferredScrollableViewportSize()} did not work as expected
     
    7196
    7297    public void makeMemberVisible(int index) {
    73         scrollRectToVisible(
    74                 getCellRect(index, 0, true)
    75         );
    76     }
    77 
    78     /**
    79      * Action to be run when the user navigates to the next cell in the table,
    80      * for instance by pressing TAB or ENTER. The action alters the standard
    81      * navigation path from cell to cell:
    82      * <ul>
    83      *   <li>it jumps over cells in the first column</li>
    84      *   <li>it automatically add a new empty row when the user leaves the
    85      *   last cell in the table</li>
    86      * <ul>
    87      *
    88      *
    89      */
    90     class SelectNextColumnCellAction extends AbstractAction  {
     98        scrollRectToVisible(getCellRect(index, 0, true));
     99    }
     100
     101    /**
     102     * Action to be run when the user navigates to the next cell in the table, for instance by
     103     * pressing TAB or ENTER. The action alters the standard navigation path from cell to cell: <ul>
     104     * <li>it jumps over cells in the first column</li> <li>it automatically add a new empty row
     105     * when the user leaves the last cell in the table</li> <ul>
     106     *
     107     *
     108     */
     109    class SelectNextColumnCellAction extends AbstractAction {
    91110        public void actionPerformed(ActionEvent e) {
    92111            run();
     
    102121            if (col == 0 && row < getRowCount() - 1) {
    103122                row++;
    104             } else if (row < getRowCount()-1) {
    105                 col=0;
     123            } else if (row < getRowCount() - 1) {
     124                col = 0;
    106125                row++;
    107126            }
     
    110129    }
    111130
    112 
    113     /**
    114      * Action to be run when the user navigates to the previous cell in the table,
    115      * for instance by pressing Shift-TAB
    116      *
    117      */
    118     class SelectPreviousColumnCellAction extends AbstractAction  {
     131    /**
     132     * Action to be run when the user navigates to the previous cell in the table, for instance by
     133     * pressing Shift-TAB
     134     *
     135     */
     136    class SelectPreviousColumnCellAction extends AbstractAction {
    119137
    120138        public void actionPerformed(ActionEvent e) {
     
    125143            }
    126144
    127 
    128145            if (col == 0 && row == 0) {
    129146                // change nothing
     
    135152        }
    136153    }
     154
     155    /**
     156     * creates the popup men
     157     */
     158    protected void createPopupMenu() {
     159        popupMenu = new JPopupMenu();
     160        ZoomToAction zoomToAction = new ZoomToAction();
     161        Layer.listeners.add(zoomToAction);
     162        getSelectionModel().addListSelectionListener(zoomToAction);
     163        popupMenu.add(zoomToAction);
     164    }
     165
     166    /**
     167     * Replies the popup menu for this table
     168     *
     169     * @return the popup menu
     170     */
     171    protected JPopupMenu getPopUpMenu() {
     172        if (popupMenu == null) {
     173            createPopupMenu();
     174        }
     175        return popupMenu;
     176    }
     177
     178    class PopupListener extends MouseAdapter {
     179        @Override
     180        public void mousePressed(MouseEvent e) {
     181            showPopup(e);
     182        }
     183
     184        @Override
     185        public void mouseReleased(MouseEvent e) {
     186            showPopup(e);
     187        }
     188
     189        private void showPopup(MouseEvent e) {
     190            if (e.isPopupTrigger()) {
     191                getPopUpMenu().show(e.getComponent(), e.getX(), e.getY());
     192            }
     193        }
     194    }
     195
     196    class ZoomToAction extends AbstractAction implements LayerChangeListener, ListSelectionListener {
     197        public ZoomToAction() {
     198            putValue(NAME, tr("Zoom to"));
     199            putValue(SHORT_DESCRIPTION, tr("Zoom to primitive the first selected member refers to"));
     200            updateEnabledState();
     201        }
     202
     203        public void actionPerformed(ActionEvent e) {
     204            if (! isEnabled())
     205                return;
     206            int rows[] = getSelectedRows();
     207            if (rows == null || rows.length == 0)
     208                return;
     209            int row = rows[0];
     210            OsmPrimitive primitive = getMemberTableModel().getReferredPrimitive(row);
     211            layer.data.setSelected(primitive);
     212            DataSet.fireSelectionChanged(layer.data.getSelected());
     213            AutoScaleAction action = new AutoScaleAction("selection");
     214            action.autoScale();
     215        }
     216
     217        protected void updateEnabledState() {
     218            if (Main.main == null || Main.main.getEditLayer() != layer) {
     219                setEnabled(false);
     220                putValue(SHORT_DESCRIPTION, tr("Zooming disabled because layer of this relation is not active"));
     221                return;
     222            }
     223            if (getSelectedRowCount() == 0) {
     224                setEnabled(false);
     225                putValue(SHORT_DESCRIPTION, tr("Zooming disabled because there is no selected member"));
     226                return;
     227            }
     228            setEnabled(true);
     229            putValue(SHORT_DESCRIPTION, tr("Zoom to primitive the first selected member refers to"));
     230        }
     231
     232        public void valueChanged(ListSelectionEvent e) {
     233            updateEnabledState();
     234        }
     235
     236        public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     237            updateEnabledState();
     238        }
     239
     240        public void layerAdded(Layer newLayer) {
     241            updateEnabledState();
     242        }
     243
     244        public void layerRemoved(Layer oldLayer) {
     245            updateEnabledState();
     246        }
     247    }
     248
     249    protected MemberTableModel getMemberTableModel() {
     250        return (MemberTableModel) getModel();
     251    }
    137252}
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r1867 r1868  
    2424import java.util.Properties;
    2525
     26import javax.swing.JPopupMenu;
    2627import javax.xml.parsers.SAXParserFactory;
    2728
     
    502503        return capabilities;
    503504    }
     505
    504506}
Note: See TracChangeset for help on using the changeset viewer.