Changeset 20556 in osm for applications/editors/josm


Ignore:
Timestamp:
2010-03-19T15:35:57+01:00 (14 years ago)
Author:
guggis
Message:

added global shortcut for creating/editing turn restrictions
added delete, select, and zoom to actions
added turn restriction builds. Proposes an initial configuration of turn restriction from a collection of OSM objects (i.e. the current selection)

Location:
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
Files:
3 added
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionsPlugin.java

    r20489 r20556  
    1414public class TurnRestrictionsPlugin extends Plugin{
    1515       
     16        private CreateOrEditTurnRestrictionAction actCreateOrEditTurnRestriction;
     17       
    1618        public TurnRestrictionsPlugin(PluginInformation info) {
    1719                super(info);
     20                actCreateOrEditTurnRestriction = new CreateOrEditTurnRestrictionAction();
    1821        }
    1922       
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java

    r20527 r20556  
    1212import java.awt.event.WindowAdapter;
    1313import java.awt.event.WindowEvent;
     14import java.beans.PropertyChangeEvent;
    1415import java.beans.PropertyChangeListener;
    1516import java.beans.PropertyChangeSupport;
     
    3132
    3233import org.openstreetmap.josm.Main;
     34import org.openstreetmap.josm.actions.AutoScaleAction;
    3335import org.openstreetmap.josm.command.AddCommand;
    3436import org.openstreetmap.josm.command.ChangeCommand;
     
    4749import org.openstreetmap.josm.tools.ImageProvider;
    4850
     51
    4952public class TurnRestrictionEditor extends JDialog {
    5053        final private static Logger logger = Logger.getLogger(TurnRestrictionEditor.class.getName());
     
    160163        tb.setFloatable(false);
    161164        tb.add(new ApplyAction());
     165        tb.addSeparator();
     166        DeleteAction actDelete = new DeleteAction();
     167        tb.add(actDelete);
     168        addPropertyChangeListener(actDelete);
     169        tb.addSeparator();
     170        SelectAction actSelect = new SelectAction();
     171        tb.add(actSelect);
     172        addPropertyChangeListener(actSelect);
     173
     174        ZoomToAction actZoomTo = new ZoomToAction();
     175        tb.add(actZoomTo);
     176        addPropertyChangeListener(actZoomTo);
    162177        return tb;
    163178    }
     
    225240     * that owned by the layer {@see #getLayer()}
    226241     */
    227     protected void setTurnRestriction(Relation turnRestriction) {
    228      
     242    protected void setTurnRestriction(Relation turnRestriction) {     
    229243        if (turnRestriction == null) {
    230244                editorModel.populate(new Relation());
     
    237251        Relation oldValue = this.turnRestriction;
    238252        this.turnRestriction = turnRestriction;
    239         if (this.turnRestriction != oldValue) {
    240             support.firePropertyChange(TURN_RESTRICION_PROP, oldValue, this.turnRestriction);
    241         }
     253        support.firePropertyChange(TURN_RESTRICION_PROP, null, this.turnRestriction);
    242254        updateTitle();
    243255    }
     
    247259     */
    248260    protected void updateTitle() {
    249         if (getTurnRestriction() == null) {
    250             setTitle(tr("Create new turn restriction in layer ''{0}''", layer.getName()));
     261        if (getTurnRestriction() == null || getTurnRestriction().getDataSet() == null) {
     262            setTitle(tr("Create a new turn restriction in layer ''{0}''", layer.getName()));
    251263        } else if (getTurnRestriction().isNew()) {
    252             setTitle(tr("Edit new turn restriction in layer ''{0}''", layer.getName()));
     264            setTitle(tr("Edit a new turn restriction in layer ''{0}''", layer.getName()));
    253265        } else {
    254             setTitle(tr("Edit turn restriction #{0} in layer ''{1}''", Long.toString(turnRestriction.getId()), layer.getName()));
     266            setTitle(tr("Edit turn restriction ''{0}'' in layer ''{1}''", Long.toString(turnRestriction.getId()), layer.getName()));
    255267        }
    256268    }
     
    281293     * @param snapshot the snapshot
    282294     */
    283     protected void setTurnRestrictionSnapshot(Relation snapshot) {
    284         Relation oldValue = turnRestrictionSnapshot;
     295    protected void setTurnRestrictionSnapshot(Relation snapshot) {       
    285296        turnRestrictionSnapshot = snapshot;
    286         if (turnRestrictionSnapshot != oldValue) {
    287             support.firePropertyChange(TURN_RESTRICION_SNAPSHOT_PROP, oldValue, turnRestrictionSnapshot);
    288         }
     297        support.firePropertyChange(TURN_RESTRICION_SNAPSHOT_PROP, null, turnRestrictionSnapshot);
    289298    }
    290299   
     
    486495         * outside of the turn restriction editor.
    487496         */
    488         protected void applyExistingNonConflictingTurnRestriction() {
    489                 Relation toUpdate = new Relation(getTurnRestriction());
    490             editorModel.apply(toUpdate);
    491             Main.main.undoRedo.add(new ChangeCommand(getTurnRestriction(), toUpdate));
     497        protected void applyExistingNonConflictingTurnRestriction() {           
     498            if (getTurnRestriction().getDataSet() == null) {
     499                editorModel.apply(getTurnRestriction());
     500                Main.main.undoRedo.add(new AddCommand(getTurnRestriction()));
     501            } else {
     502                Relation toUpdate = new Relation(getTurnRestriction());
     503                editorModel.apply(toUpdate);           
     504                Main.main.undoRedo.add(new ChangeCommand(getTurnRestriction(), toUpdate));
     505            }
    492506            // this will refresh the snapshot and update the dialog title
    493507            //
     
    645659        }
    646660    }
     661   
     662    class DeleteAction extends AbstractAction implements PropertyChangeListener{
     663        public DeleteAction() {
     664                putValue(NAME, tr("Delete"));
     665                putValue(SHORT_DESCRIPTION, tr(("Delete this turn restriction")));
     666                putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
     667                updateEnabledState();
     668        }
     669       
     670        protected void updateEnabledState() {                   
     671                Relation tr = getTurnRestriction();
     672                setEnabled(tr != null && tr.getDataSet() != null);
     673        }
     674
     675        public void actionPerformed(ActionEvent e) {
     676                Relation tr = getTurnRestriction();
     677                if (tr == null || tr.getDataSet() == null) return;
     678                org.openstreetmap.josm.actions.mapmode.DeleteAction.deleteRelation(
     679                    getLayer(),
     680                    tr
     681            );
     682                setVisible(false);
     683                }
     684
     685                public void propertyChange(PropertyChangeEvent evt) {
     686                        if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){
     687                                updateEnabledState();
     688                        }
     689                }
     690    }
     691   
     692    class SelectAction extends AbstractAction implements PropertyChangeListener{
     693        public SelectAction() {
     694                putValue(NAME, tr("Select"));
     695                putValue(SHORT_DESCRIPTION, tr(("Select this turn restriction")));
     696                putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
     697                updateEnabledState();
     698        }
     699       
     700        protected void updateEnabledState() {
     701                Relation tr = getTurnRestriction();
     702                setEnabled(tr != null && tr.getDataSet() != null);
     703        }
     704
     705        public void actionPerformed(ActionEvent e) {
     706                Relation tr = getTurnRestriction();
     707                if (tr == null || tr.getDataSet() == null) return;
     708                getLayer().data.setSelected(tr);
     709                }
     710
     711                public void propertyChange(PropertyChangeEvent evt) {
     712                        if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){
     713                                updateEnabledState();
     714                        }
     715                }
     716    }
     717   
     718    class ZoomToAction extends AbstractAction implements PropertyChangeListener{
     719        public ZoomToAction() {
     720                putValue(NAME, tr("Zoom to"));
     721                putValue(SHORT_DESCRIPTION, tr(("Activate the layer this turn restriction belongs to and zoom to it")));
     722                putValue(SMALL_ICON, ImageProvider.get("dialogs/autoscale", "data"));
     723                updateEnabledState();
     724        }
     725       
     726        protected void updateEnabledState() {
     727                Relation tr = getTurnRestriction();
     728                setEnabled(tr != null && tr.getDataSet() != null);
     729        }
     730
     731        public void actionPerformed(ActionEvent e) {
     732                if (Main.main.getActiveLayer() != getLayer()){
     733                        Main.map.mapView.setActiveLayer(getLayer());
     734                }
     735                Relation tr = getTurnRestriction();
     736                if (tr == null || tr.getDataSet() == null) return;
     737                getLayer().data.setSelected(tr);               
     738                AutoScaleAction.zoomToSelection();
     739                }
     740
     741                public void propertyChange(PropertyChangeEvent evt) {
     742                        if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){
     743                                updateEnabledState();
     744                        }
     745                }
     746    }
    647747}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionCellRenderer.java

    r20526 r20556  
    1111import java.util.HashSet;
    1212import java.util.Set;
     13import java.util.logging.Logger;
    1314
    1415import javax.swing.ImageIcon;
     
    1617import javax.swing.JList;
    1718import javax.swing.JPanel;
     19import javax.swing.JTable;
    1820import javax.swing.ListCellRenderer;
    1921import javax.swing.UIManager;
    20 
    21 import org.openstreetmap.josm.Main;
     22import javax.swing.table.TableCellRenderer;
     23
    2224import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    2325import org.openstreetmap.josm.data.osm.Relation;
     
    2729import org.openstreetmap.josm.gui.JMultilineLabel;
    2830import org.openstreetmap.josm.tools.ImageProvider;
     31import static org.openstreetmap.josm.tools.I18n.trc;
    2932
    3033/**
    31  * This the cell renderer for turn restrictions in the turn restriction list
    32  * dialog.
    33  *
     34 * This is a cell renderer for turn restrictions.
     35 *
     36 * It can be used a cell renderer in lists of turn restrictions and as cell renderer in
     37 * {@see JTable}s displaying turn restrictions.
     38 *
    3439 */
    35 public class TurnRestrictionListCellRenderer extends JPanel implements ListCellRenderer{
    36 
     40public class TurnRestrictionCellRenderer extends JPanel implements ListCellRenderer, TableCellRenderer{
     41        static private final Logger logger = Logger.getLogger(TurnRestrictionCellRenderer.class.getName());
     42       
    3743        /** the names of restriction types */
    3844        static private Set<String> RESTRICTION_TYPES = new HashSet<String>(
     
    5359        private JLabel to;
    5460       
    55         public TurnRestrictionListCellRenderer() {
     61        public TurnRestrictionCellRenderer() {
    5662                build();
    5763        }
     
    103109                gc.gridheight = 2;
    104110                gc.anchor = GridBagConstraints.CENTER;
    105                 gc.insets = new Insets(0,2,0,2);
     111                gc.insets = new Insets(0,0,2,2);
    106112                add(icon = new JLabel(), gc);
    107113               
     
    112118                gc.gridheight = 1;
    113119                gc.weightx = 0.0;
    114                 gc.insets = new Insets(0,0,0,0);
    115                 add(new JMultilineLabel("<html><strong>From:</strong></html>"), gc);
     120                add(new JMultilineLabel("<html><strong>" + trc("turnrestrictions","From:") + "</strong></html>"), gc);
    116121               
    117122                gc.gridx = 2;
     
    124129                gc.gridy = 1;
    125130                gc.weightx = 0.0;
    126                 add(new JMultilineLabel("<html><strong>To:</strong></html>"), gc);
     131                add(new JMultilineLabel("<html><strong>" + trc("turnrestriction", "To:")  + "</strong></html>"), gc);
    127132               
    128133                gc.gridx = 2;
     
    208213                this.to.setForeground(fg);
    209214        }
    210                
     215
     216        /* ---------------------------------------------------------------------------------- */
     217        /* interface ListCellRenderer                                                         */
     218        /* ---------------------------------------------------------------------------------- */
    211219        public Component getListCellRendererComponent(JList list, Object value,
    212220                        int index, boolean isSelected, boolean cellHasFocus) {
    213221
    214222                renderColor(isSelected);
     223                Relation tr = (Relation)value;
     224                renderIcon(tr);
     225                renderFrom(tr);
     226                renderTo(tr);           
     227                return this;
     228        }
     229
     230        /* ---------------------------------------------------------------------------------- */
     231        /* interface TableCellRenderer                                                        */
     232        /* ---------------------------------------------------------------------------------- */
     233        public Component getTableCellRendererComponent(JTable table, Object value,
     234                        boolean isSelected, boolean hasFocus, int row, int column) {
     235                renderColor(isSelected);               
    215236                Relation tr = (Relation)value;
    216237                renderIcon(tr);
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInDatasetView.java

    r20489 r20556  
    2525                lstTurnRestrictions.setSelectionModel(selectionModel);
    2626                lstTurnRestrictions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    27                 lstTurnRestrictions.setCellRenderer(new TurnRestrictionListCellRenderer());
     27                lstTurnRestrictions.setCellRenderer(new TurnRestrictionCellRenderer());
    2828               
    2929                setLayout(new BorderLayout());
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionView.java

    r20489 r20556  
    2828                lstTurnRestrictions.setSelectionModel(selectionModel);
    2929                lstTurnRestrictions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    30                 lstTurnRestrictions.setCellRenderer(new TurnRestrictionListCellRenderer());
     30                lstTurnRestrictions.setCellRenderer(new TurnRestrictionCellRenderer());
    3131               
    3232                setLayout(new BorderLayout());
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsListDialog.java

    r20489 r20556  
    3333import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3434import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     35import org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionBuilder;
    3536import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionEditor;
    3637import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionEditorManager;
     
    304305
    305306        public void run() {
    306                  Relation tr = new Relation();
    307307                 OsmDataLayer layer =  Main.main.getEditLayer();
    308308                 if (layer == null) return;
    309                  TurnRestrictionEditor editor = new TurnRestrictionEditor(TurnRestrictionsListDialog.this, layer);
     309                 Relation tr = new TurnRestrictionBuilder().buildFromSelection(layer);
     310                 TurnRestrictionEditor editor = new TurnRestrictionEditor(TurnRestrictionsListDialog.this, layer, tr);
    310311             TurnRestrictionEditorManager.getInstance().positionOnScreen(editor);             
    311312             TurnRestrictionEditorManager.getInstance().register(layer, tr, editor);
Note: See TracChangeset for help on using the changeset viewer.