Changeset 34226 in osm for applications


Ignore:
Timestamp:
2018-05-30T09:56:21+02:00 (6 years ago)
Author:
biswesh
Message:

Add public Transport in Menu Bar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/PTAssistantPlugin.java

    r34203 r34226  
    22package org.openstreetmap.josm.plugins.pt_assistant;
    33
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.trc;
     6
     7import java.awt.Component;
    48import java.awt.KeyboardFocusManager;
     9import java.awt.event.KeyEvent;
    510import java.util.ArrayList;
    611import java.util.List;
    712
     13import javax.swing.JMenu;
    814import javax.swing.JMenuItem;
     15import javax.swing.JPopupMenu;
    916import javax.swing.SwingUtilities;
    1017
     
    2128import org.openstreetmap.josm.plugins.pt_assistant.actions.AddStopPositionAction;
    2229import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformNodeAction;
     30import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformNodeThroughReplaceAction;
     31import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformShortcutAction;
    2332import org.openstreetmap.josm.plugins.pt_assistant.actions.DoubleSplitAction;
    2433import org.openstreetmap.josm.plugins.pt_assistant.actions.EdgeSelectionAction;
    2534import org.openstreetmap.josm.plugins.pt_assistant.actions.EditHighlightedRelationsAction;
     35import org.openstreetmap.josm.plugins.pt_assistant.actions.ExtractPlatformNodeAction;
    2636import org.openstreetmap.josm.plugins.pt_assistant.actions.PTWizardAction;
    2737import org.openstreetmap.josm.plugins.pt_assistant.actions.RepeatLastFixAction;
     
    4252public class PTAssistantPlugin extends Plugin {
    4353
    44     /*
    45     * last fix that was can be re-applied to all similar route segments, can be
    46     * null if unavailable
    47     */
    48     private static PTRouteSegment lastFix;
     54        /*
     55        * last fix that was can be re-applied to all similar route segments, can be
     56        * null if unavailable
     57        */
     58        private static PTRouteSegment lastFix;
    4959
    50     /* list of relation currently highlighted by the layer */
    51     private static List<Relation> highlightedRelations = new ArrayList<>();
     60        /* list of relation currently highlighted by the layer */
     61        private static List<Relation> highlightedRelations = new ArrayList<>();
    5262
    53     /* item of the Tools menu for repeating the last fix */
    54     private static JMenuItem repeatLastFixMenu;
     63        /* item of the Tools menu for repeating the last fix */
     64        private static JMenuItem repeatLastFixMenu;
    5565
    56     /* edit the currently highlighted relations */
    57     private static JMenuItem editHighlightedRelationsMenu;
     66        /* edit the currently highlighted relations */
     67        private static JMenuItem editHighlightedRelationsMenu;
    5868
    59     /**
    60      * Main constructor.
    61      *
    62      * @param info
    63      *            Required information of the plugin. Obtained from the jar
    64      *            file.
    65      */
    66     public PTAssistantPlugin(PluginInformation info) {
    67         super(info);
    68         OsmValidator.addTest(PTAssistantValidatorTest.class);
    69         OsmValidator.addTest(BicycleFootRouteValidatorTest.class);
     69        /**
     70         * Main constructor.
     71         *
     72         * @param info
     73         *            Required information of the plugin. Obtained from the jar file.
     74         */
     75        public PTAssistantPlugin(PluginInformation info) {
     76                super(info);
     77                OsmValidator.addTest(PTAssistantValidatorTest.class);
     78                OsmValidator.addTest(BicycleFootRouteValidatorTest.class);
    7079
    71         DataSet.addSelectionListener(PTAssistantLayerManager.PTLM);
    72         KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(PTAssistantLayerManager.PTLM);
    73         RepeatLastFixAction repeatLastFixAction = new RepeatLastFixAction();
    74         EditHighlightedRelationsAction editHighlightedRelationsAction = new EditHighlightedRelationsAction();
    75         repeatLastFixMenu = MainMenu.add(MainApplication.getMenu().toolsMenu, repeatLastFixAction);
    76         editHighlightedRelationsMenu = MainMenu.add(MainApplication.getMenu().toolsMenu, editHighlightedRelationsAction);
    77         MainMenu.add(MainApplication.getMenu().toolsMenu, new SplitRoundaboutAction());
    78         MainMenu.add(MainApplication.getMenu().toolsMenu, new CreatePlatformNodeAction());
    79         MainMenu.add(MainApplication.getMenu().toolsMenu, new SortPTRouteMembersAction());
    80         MainMenu.add(MainApplication.getMenu().helpMenu, new PTWizardAction());
    81         initialiseWizard();
    82     }
     80                MainMenu menu = MainApplication.getMenu();
     81                JMenu PublicTransportMenu = menu.addMenu("File", /* I18N: mnemonic: F */ trc("menu", "Public Transport"),
     82                                KeyEvent.VK_P, 5, ht("/Menu/Public Transport"));
    8383
    84     /**
    85      * Called when the JOSM map frame is created or destroyed.
    86      */
    87     @Override
    88     public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    89         if (oldFrame == null && newFrame != null) {
    90             repeatLastFixMenu.setEnabled(false);
    91             editHighlightedRelationsMenu.setEnabled(false);
    92             MainApplication.getMap().addMapMode(new IconToggleButton(new AddStopPositionAction()));
    93             MainApplication.getMap().addMapMode(new IconToggleButton(new EdgeSelectionAction()));
    94             MainApplication.getMap().addMapMode(new IconToggleButton(new DoubleSplitAction()));
    95         } else if (oldFrame != null && newFrame == null) {
    96             repeatLastFixMenu.setEnabled(false);
    97             editHighlightedRelationsMenu.setEnabled(false);
    98         }
    99     }
     84                DataSet.addSelectionListener(PTAssistantLayerManager.PTLM);
     85                KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(PTAssistantLayerManager.PTLM);
     86                addToPTAssistantmenu(PublicTransportMenu);
     87                initialiseWizard();
     88                initialiseShorcutsForCreatePlatformNode();
     89        }
    10090
    101     /**
    102      * Sets up the pt_assistant tab in JOSM Preferences
    103      */
    104     @Override
    105     public PreferenceSetting getPreferenceSetting() {
    106         return new PTAssistantPreferenceSetting();
    107     }
     91        /**
     92         * Called when the JOSM map frame is created or destroyed.
     93         */
     94        @Override
     95        public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
     96                if (oldFrame == null && newFrame != null) {
     97                        repeatLastFixMenu.setEnabled(false);
     98                        editHighlightedRelationsMenu.setEnabled(false);
     99                        MainApplication.getMap().addMapMode(new IconToggleButton(new AddStopPositionAction()));
     100                        MainApplication.getMap().addMapMode(new IconToggleButton(new EdgeSelectionAction()));
     101                        MainApplication.getMap().addMapMode(new IconToggleButton(new DoubleSplitAction()));
     102                } else if (oldFrame != null && newFrame == null) {
     103                        repeatLastFixMenu.setEnabled(false);
     104                        editHighlightedRelationsMenu.setEnabled(false);
     105                }
     106        }
    108107
    109     public static PTRouteSegment getLastFix() {
    110         return lastFix;
    111     }
     108        /**
     109         * Sets up the pt_assistant tab in JOSM Preferences
     110         */
     111        @Override
     112        public PreferenceSetting getPreferenceSetting() {
     113                return new PTAssistantPreferenceSetting();
     114        }
    112115
    113     /**
    114      * Remembers the last fix and enables/disables the Repeat last fix menu
    115      *
    116      * @param segment
    117      *            The last fix, call be null to disable the Repeat last fix menu
    118      */
    119     public static void setLastFix(PTRouteSegment segment) {
    120         lastFix = segment;
    121         SwingUtilities.invokeLater(() ->
    122         repeatLastFixMenu.setEnabled(segment != null));
    123     }
     116        public static PTRouteSegment getLastFix() {
     117                return lastFix;
     118        }
    124119
    125     /**
    126      * Used in unit tests
    127      *
    128      * @param segment route segment
    129      */
    130     public static void setLastFixNoGui(PTRouteSegment segment) {
    131         lastFix = segment;
    132     }
     120        /**
     121         * Remembers the last fix and enables/disables the Repeat last fix menu
     122         *
     123         * @param segment
     124         *            The last fix, call be null to disable the Repeat last fix menu
     125         */
     126        public static void setLastFix(PTRouteSegment segment) {
     127                lastFix = segment;
     128                SwingUtilities.invokeLater(() -> repeatLastFixMenu.setEnabled(segment != null));
     129        }
    133130
    134     public static List<Relation> getHighlightedRelations() {
    135         return new ArrayList<>(highlightedRelations);
    136     }
     131        /**
     132         * Used in unit tests
     133         *
     134         * @param segment
     135         *            route segment
     136         */
     137        public static void setLastFixNoGui(PTRouteSegment segment) {
     138                lastFix = segment;
     139        }
    137140
    138     public static void addHighlightedRelation(Relation highlightedRelation) {
    139         highlightedRelations.add(highlightedRelation);
    140         if (!editHighlightedRelationsMenu.isEnabled()) {
    141             SwingUtilities.invokeLater(() ->
    142             editHighlightedRelationsMenu.setEnabled(true));
    143         }
    144     }
     141        public static List<Relation> getHighlightedRelations() {
     142                return new ArrayList<>(highlightedRelations);
     143        }
    145144
    146     public static void clearHighlightedRelations() {
    147         highlightedRelations.clear();
    148         SwingUtilities.invokeLater(() ->
    149         editHighlightedRelationsMenu.setEnabled(false));
    150     }
     145        public static void addHighlightedRelation(Relation highlightedRelation) {
     146                highlightedRelations.add(highlightedRelation);
     147                if (!editHighlightedRelationsMenu.isEnabled()) {
     148                        SwingUtilities.invokeLater(() -> editHighlightedRelationsMenu.setEnabled(true));
     149                }
     150        }
    151151
    152     private static void initialiseWizard() {
    153             PTWizardAction wizard = new PTWizardAction();
    154             wizard.noDialogBox = true;
    155         wizard.actionPerformed(null);
    156     }
     152        public static void clearHighlightedRelations() {
     153                highlightedRelations.clear();
     154                SwingUtilities.invokeLater(() -> editHighlightedRelationsMenu.setEnabled(false));
     155        }
     156
     157        private void addToPTAssistantmenu(JMenu PublicTransportMenu) {
     158                RepeatLastFixAction repeatLastFixAction = new RepeatLastFixAction();
     159                EditHighlightedRelationsAction editHighlightedRelationsAction = new EditHighlightedRelationsAction();
     160                repeatLastFixMenu = MainMenu.add(PublicTransportMenu, repeatLastFixAction);
     161                editHighlightedRelationsMenu = MainMenu.add(PublicTransportMenu, editHighlightedRelationsAction);
     162                MainMenu.add(PublicTransportMenu, new SplitRoundaboutAction());
     163                MainMenu.add(PublicTransportMenu, new CreatePlatformNodeAction());
     164                MainMenu.add(PublicTransportMenu, new SortPTRouteMembersAction());
     165                Component sep = new JPopupMenu.Separator();
     166                PublicTransportMenu.add(sep);
     167                MainMenu.add(PublicTransportMenu, new PTWizardAction());
     168        }
     169
     170        private static void initialiseWizard() {
     171                PTWizardAction wizard = new PTWizardAction();
     172                wizard.noDialogBox = true;
     173                wizard.actionPerformed(null);
     174        }
     175
     176        private static void initialiseShorcutsForCreatePlatformNode() {
     177                CreatePlatformShortcutAction shortcut1 = new CreatePlatformShortcutAction();
     178                CreatePlatformNodeThroughReplaceAction shortcut2 = new CreatePlatformNodeThroughReplaceAction();
     179                ExtractPlatformNodeAction shortcut3 = new ExtractPlatformNodeAction();
     180        }
    157181}
Note: See TracChangeset for help on using the changeset viewer.