Changeset 34226 in osm for applications/editors
- Timestamp:
- 2018-05-30T09:56:21+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/PTAssistantPlugin.java
r34203 r34226 2 2 package org.openstreetmap.josm.plugins.pt_assistant; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 import static org.openstreetmap.josm.tools.I18n.trc; 6 7 import java.awt.Component; 4 8 import java.awt.KeyboardFocusManager; 9 import java.awt.event.KeyEvent; 5 10 import java.util.ArrayList; 6 11 import java.util.List; 7 12 13 import javax.swing.JMenu; 8 14 import javax.swing.JMenuItem; 15 import javax.swing.JPopupMenu; 9 16 import javax.swing.SwingUtilities; 10 17 … … 21 28 import org.openstreetmap.josm.plugins.pt_assistant.actions.AddStopPositionAction; 22 29 import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformNodeAction; 30 import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformNodeThroughReplaceAction; 31 import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformShortcutAction; 23 32 import org.openstreetmap.josm.plugins.pt_assistant.actions.DoubleSplitAction; 24 33 import org.openstreetmap.josm.plugins.pt_assistant.actions.EdgeSelectionAction; 25 34 import org.openstreetmap.josm.plugins.pt_assistant.actions.EditHighlightedRelationsAction; 35 import org.openstreetmap.josm.plugins.pt_assistant.actions.ExtractPlatformNodeAction; 26 36 import org.openstreetmap.josm.plugins.pt_assistant.actions.PTWizardAction; 27 37 import org.openstreetmap.josm.plugins.pt_assistant.actions.RepeatLastFixAction; … … 42 52 public class PTAssistantPlugin extends Plugin { 43 53 44 45 46 47 48 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; 49 59 50 51 60 /* list of relation currently highlighted by the layer */ 61 private static List<Relation> highlightedRelations = new ArrayList<>(); 52 62 53 54 63 /* item of the Tools menu for repeating the last fix */ 64 private static JMenuItem repeatLastFixMenu; 55 65 56 57 66 /* edit the currently highlighted relations */ 67 private static JMenuItem editHighlightedRelationsMenu; 58 68 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); 70 79 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")); 83 83 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 } 100 90 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 } 108 107 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 } 112 115 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 } 124 119 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 } 133 130 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 } 137 140 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 } 145 144 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 } 151 151 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 } 157 181 }
Note:
See TracChangeset
for help on using the changeset viewer.