Ignore:
Timestamp:
2010-03-27T16:51:44+01:00 (15 years ago)
Author:
guggis
Message:

Added configuration of global shortcut in the preference settings
Fixed a couple of minor issues

Location:
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
Files:
1 added
9 edited

Legend:

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

    r20556 r20701  
    44
    55import java.awt.event.ActionEvent;
    6 import java.awt.event.KeyEvent;
    76import java.util.Collection;
    87import java.util.logging.Logger;
     8
     9import javax.swing.ActionMap;
     10import javax.swing.InputMap;
     11import javax.swing.JComponent;
     12import javax.swing.KeyStroke;
    913
    1014import org.openstreetmap.josm.Main;
     
    1519import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionEditorManager;
    1620import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionSelectionPopupPanel;
    17 import org.openstreetmap.josm.tools.Shortcut;
     21import org.openstreetmap.josm.plugins.turnrestrictions.preferences.PreferenceKeys;
    1822
    1923/**
     
    2630public class CreateOrEditTurnRestrictionAction extends JosmAction {
    2731        static private final Logger logger = Logger.getLogger(CreateOrEditTurnRestrictionAction.class.getName());
    28         public CreateOrEditTurnRestrictionAction() {
     32       
     33        /**
     34         * Installs the global key stroke with which creating/editing a turn restriction
     35         * is triggered.
     36         *
     37         * @param keyStroke the key stroke
     38         */
     39        static public void install(KeyStroke keyStroke){
     40                InputMap im = Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
     41                Object actionMapKey = im.get(keyStroke);
     42                if (actionMapKey != null && !actionMapKey.toString().equals("turnrestrictions:create-or-edit")) {
     43                        System.out.println(tr("Warning: turnrestrictions plugin replaces already existing action ''{0}'' behind shortcut ''{1}'' by action ''{2}''", actionMapKey.toString(), keyStroke.toString(), "turnrestrictions:create-or-edit"));                       
     44                }
     45                KeyStroke[] keys = im.keys();
     46                if (keys != null){
     47                        for(KeyStroke ks: im.keys()){
     48                                if (im.get(ks).equals("turnrestrictions:create-or-edit")) {
     49                                        im.remove(ks);
     50                                }
     51                        }
     52                }
     53                im.put(keyStroke, "turnrestrictions:create-or-edit");
     54                ActionMap am = Main.contentPane.getActionMap();
     55                am.put("turnrestrictions:create-or-edit", getInstance());
     56        }
     57       
     58        /**
     59         * Installs  global key stroke configured in the preferences.
     60         *
     61         * @param keyStroke the key stroke
     62         */
     63        static public void install(){
     64                String value = Main.pref.get(PreferenceKeys.EDIT_SHORTCUT, "shift ctrl T");
     65                KeyStroke key = KeyStroke.getKeyStroke(value);
     66                if (key == null){
     67                        System.out.println(tr("Warning: illegal value ''{0}'' for preference key ''{1}''. Falling back to default value ''shift ctrl T''.", value, PreferenceKeys.EDIT_SHORTCUT));
     68                        key = KeyStroke.getKeyStroke("shift ctrl T");
     69                }
     70                install(key);
     71        }
     72       
     73        /** the singleton instance of this action */
     74        private static CreateOrEditTurnRestrictionAction instance;
     75       
     76        /**
     77         * Replies the unique instance of this action
     78         *
     79         * @return
     80         */
     81        public static CreateOrEditTurnRestrictionAction getInstance() {
     82                if (instance == null){
     83                        instance = new CreateOrEditTurnRestrictionAction();
     84                }
     85                return instance;
     86        }
     87       
     88        protected CreateOrEditTurnRestrictionAction() {
    2989                super(
    3090                    tr("Create/Edit turn restriction..."),
    3191                    null,
    3292                    tr("Create or edit a turn restriction."),
    33                     Shortcut.registerShortcut(
    34                                         "turnrestrictions:create-or-edit",
    35                                         tr("Turnrestrictions: Create or Edit"),
    36                                         // results in Shift-Ctrl-T on windows
    37                                         KeyEvent.VK_T,
    38                                         Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY,
    39                                         Shortcut.SHIFT_DEFAULT
    40                         ),
    41                         true /* register action */
     93                    null, // shortcut is going to be registered later
     94                        false
    4295            );
    4396        }       
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionsPlugin.java

    r20556 r20701  
    99
    1010/**
    11  * This is the main class for the turnrestriction plugin.
     11 * This is the main class for the turnrestrictions plugin.
    1212 *
    1313 */
    1414public class TurnRestrictionsPlugin extends Plugin{
    1515       
    16         private CreateOrEditTurnRestrictionAction actCreateOrEditTurnRestriction;
    17        
    1816        public TurnRestrictionsPlugin(PluginInformation info) {
    19                 super(info);
    20                 actCreateOrEditTurnRestriction = new CreateOrEditTurnRestrictionAction();
     17                super(info);           
    2118        }
    2219       
     
    3027                        // add the dialog
    3128                        newFrame.addToggleDialog(dialog);
     29                        CreateOrEditTurnRestrictionAction.install();
    3230                }
    3331        }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java

    r20586 r20701  
    156156                        lblOsmObject.setFont(UIManager.getFont("Label.font").deriveFont(Font.ITALIC));
    157157                        lblOsmObject.setIcon(null);
    158                         lblOsmObject.setText(tr("multiple objects with role ''{0}''",this.role.toString()));
     158                        lblOsmObject.setText(tr("multiple objects with role ''{0}''",this.role.getOsmRole()));
    159159                        lblOsmObject.setToolTipText(null);                     
    160160                }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionCellRenderer.java

    r20666 r20701  
    9696         */
    9797        protected ImageIcon getIcon(String restrictionType) {
    98                 if (!isValidRestrictionType(restrictionType)) return null;
     98                if (!isValidRestrictionType(restrictionType)) {
     99                        return ImageProvider.get("types", "non-standard-type");
     100                }
    99101                return ImageProvider.get(buildImageName(restrictionType));
    100102        }
     
    146148        protected void renderIcon(Relation tr) {
    147149                String restrictionType = tr.get("restriction");
    148                 if (!isValidRestrictionType(restrictionType)) {
    149                         icon.setIcon(null);
    150                         return;
    151                 }
    152150                icon.setIcon(getIcon(restrictionType));
    153151        }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferenceKeys.java

    r20675 r20701  
    11package org.openstreetmap.josm.plugins.turnrestrictions.preferences;
     2
     3import javax.swing.KeyStroke;
    24
    35/**
     
    2931         */
    3032        String SHOW_VIAS_IN_BASIC_EDITOR = "turnrestrictions.show-vias-in-basic-editor";
     33       
     34        /**
     35         * The shortcut which triggers creating a new or editing and existing turn
     36         * restriction. The value must be parseable by {@see KeyStroke#getKeyStroke(String)}.
     37         * If missing, the default value "ctrl shift T" is assumed.
     38         */
     39        String EDIT_SHORTCUT= "turnrestrictions.edit-shortcut";
    3140}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferencesPanel.java

    r20675 r20701  
    1616import javax.swing.JPanel;
    1717import javax.swing.JRadioButton;
     18import javax.swing.JSeparator;
    1819
    1920import org.openstreetmap.josm.data.Preferences;
     
    3435        private ButtonGroup bgIconSet;
    3536        private JCheckBox cbShowViaListInBasicEditor;
     37        private ShortcutPreferencePanel pnlShortcutPreference;
    3638       
    3739        protected JPanel buildShowViaListInBasicEditorPanel() {
     
    4749                msg.setText("<html><body>"
    4850                                + tr("The Basic Editor can optionally display the list of via-objects "
    49                                          + "of a turn restrictions. If enabled, one can also edit them "
    50                                          + "in the Basic editor. If disabled, editing of via-objects is only "
    51                                          + "possible in the Advanced Editor."
     51                                         + "of a turn restriction. If enabled, one can edit them "
     52                                         + "in the Basic editor too. If disabled, editing of via-objects is "
     53                                         + "possible in the Advanced Editor only."
    5254                                  )
    5355                                + "</body></html>"
     
    153155                add(buildSetBPanel(), gc);
    154156                gc.gridy++;
     157                add(new JSeparator(), gc);             
     158                gc.gridy++;
    155159                add(buildShowViaListInBasicEditorPanel(), gc);
     160                gc.gridy++;
     161                add(new JSeparator(), gc);
     162                gc.gridy++;
     163                add(pnlShortcutPreference = new ShortcutPreferencePanel(), gc);
    156164               
    157165                // filler - just grab remaining space
     
    189197                boolean b = prefs.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false);
    190198                cbShowViaListInBasicEditor.setSelected(b);
     199               
     200                pnlShortcutPreference.initFromPreferences(prefs);
    191201        }
    192202       
     
    213223                        prefs.put(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, newValue);
    214224                }               
     225               
     226                pnlShortcutPreference.saveToPreferences(prefs);
    215227        }
    216228       
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IdenticalTurnRestrictionLegsError.java

    r20622 r20701  
    2727        @Override
    2828        public String getText() {               
    29                 return tr("This turn restriction uses the OSM way <span class=\"object-name\">{0}</span> with role ''from'' <strong>and</strong> with role ''to''. "
    30                                 + "In a turn restriction, the way with role ''from'' should be different from the way with role ''to'', though.",
     29                return tr("This turn restriction uses the OSM way <span class=\"object-name\">{0}</span> with role <tt>from</tt> <strong>and</strong> with role <tt>to</tt>. "
     30                                + "In a turn restriction, the way with role <tt>from</tt> should be different from the way with role <tt>to</tt>, though.",
    3131                                leg.getDisplayName(DefaultNameFormatter.getInstance())
    3232                                );                             
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IntersectionMissingAsViaError.java

    r20622 r20701  
    3737                String msg = tr("The <strong>from</strong>-way <span class=\"object-name\">{0}</span> and the <strong>to</strong>-way <span class=\"object-name\">{1}</span> "
    3838                       + "interesect at node <span class=\"object-name\">{2}</span> but <span class=\"object-name\">{2}</span> isn''t a <strong>via</strong>-object.<br> "
    39                        + "It is recommended to set <span class=\"object-name\">{2}</span> as only <strong>via</strong>-object.",
     39                       + "It is recommended to set <span class=\"object-name\">{2}</span> as unique <strong>via</strong>-object.",
    4040                       this.from.getDisplayName(DefaultNameFormatter.getInstance()),
    4141                       this.to.getDisplayName(DefaultNameFormatter.getInstance()),
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MultipleTurnRestrictionLegError.java

    r20622 r20701  
    2020         * Create the issue
    2121         *
    22          * @param parent the parant model
     22         * @param parent the parent model
    2323         * @param role the role of the turn restriction leg with multiple entries
    2424         * @param numLegs the number of legs
     
    3434        public String getText() {
    3535                switch(role){
    36                 case FROM: return
    37                         tr("A turn restriction requires exactly one way with role <tt>from</tt>. "
     36                case FROM:
     37                        return tr("A turn restriction requires exactly one way with role <tt>from</tt>. "
    3838                                + "This turn restriction has {0} ways in this role. Please remove "
    3939                                + "{1} of them.",
     
    4242                        );
    4343                case TO:
    44                         tr("A turn restriction requires exactly one way with role <tt>from</tt>. "
     44                        return tr("A turn restriction requires exactly one way with role <tt>to</tt>. "
    4545                                        + "This turn restriction has {0} ways in this role. Please remove "
    4646                                        + "{1} of them.",
Note: See TracChangeset for help on using the changeset viewer.