|
1 |
| -// License: GPL. For details, see LICENSE file. |
2 |
| -package org.openstreetmap.josm.plugins.pt_assistant; |
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; |
8 |
| -import java.awt.KeyboardFocusManager; |
9 |
| -import java.awt.event.KeyEvent; |
10 |
| -import java.util.ArrayList; |
11 |
| -import java.util.List; |
12 |
| - |
13 |
| -import javax.swing.JMenu; |
14 |
| -import javax.swing.JMenuItem; |
15 |
| -import javax.swing.JPopupMenu; |
16 |
| -import javax.swing.SwingUtilities; |
17 |
| - |
18 |
| -import org.openstreetmap.josm.data.osm.DataSet; |
19 |
| -import org.openstreetmap.josm.data.osm.Relation; |
20 |
| -import org.openstreetmap.josm.data.validation.OsmValidator; |
21 |
| -import org.openstreetmap.josm.gui.IconToggleButton; |
22 |
| -import org.openstreetmap.josm.gui.MainApplication; |
23 |
| -import org.openstreetmap.josm.gui.MainMenu; |
24 |
| -import org.openstreetmap.josm.gui.MapFrame; |
25 |
| -import org.openstreetmap.josm.gui.preferences.PreferenceSetting; |
26 |
| -import org.openstreetmap.josm.plugins.Plugin; |
27 |
| -import org.openstreetmap.josm.plugins.PluginInformation; |
28 |
| -import org.openstreetmap.josm.plugins.pt_assistant.actions.AddStopPositionAction; |
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; |
32 |
| -import org.openstreetmap.josm.plugins.pt_assistant.actions.DoubleSplitAction; |
33 |
| -import org.openstreetmap.josm.plugins.pt_assistant.actions.EdgeSelectionAction; |
34 |
| -import org.openstreetmap.josm.plugins.pt_assistant.actions.EditHighlightedRelationsAction; |
35 |
| -import org.openstreetmap.josm.plugins.pt_assistant.actions.ExtractPlatformNodeAction; |
36 |
| -import org.openstreetmap.josm.plugins.pt_assistant.actions.PTWizardAction; |
37 |
| -import org.openstreetmap.josm.plugins.pt_assistant.actions.RepeatLastFixAction; |
38 |
| -import org.openstreetmap.josm.plugins.pt_assistant.actions.SortPTRouteMembersAction; |
39 |
| -import org.openstreetmap.josm.plugins.pt_assistant.actions.SplitRoundaboutAction; |
40 |
| -import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment; |
41 |
| -import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayerManager; |
42 |
| -import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantPreferenceSetting; |
43 |
| -import org.openstreetmap.josm.plugins.pt_assistant.validation.BicycleFootRouteValidatorTest; |
44 |
| -import org.openstreetmap.josm.plugins.pt_assistant.validation.PTAssistantValidatorTest; |
45 |
| - |
46 |
| -/** |
47 |
| - * This is the main class of the PTAssistant plugin. |
48 |
| - * |
49 |
| - * @author darya / Darya Golovko |
50 |
| - * |
51 |
| - */ |
52 |
| -public class PTAssistantPlugin extends Plugin { |
53 |
| - |
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; |
59 |
| - |
60 |
| - /* list of relation currently highlighted by the layer */ |
61 |
| - private static List<Relation> highlightedRelations = new ArrayList<>(); |
62 |
| - |
63 |
| - /* item of the Tools menu for repeating the last fix */ |
64 |
| - private static JMenuItem repeatLastFixMenu; |
65 |
| - |
66 |
| - /* edit the currently highlighted relations */ |
67 |
| - private static JMenuItem editHighlightedRelationsMenu; |
68 |
| - |
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); |
79 |
| - |
80 |
| - MainMenu menu = MainApplication.getMenu(); |
81 |
| - JMenu PublicTransportMenu = menu.addMenu("File", trc("menu", "Public Transport"), KeyEvent.VK_P, 5, ht("/Menu/Public Transport")); |
82 |
| - |
83 |
| - DataSet.addSelectionListener(PTAssistantLayerManager.PTLM); |
84 |
| - KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(PTAssistantLayerManager.PTLM); |
85 |
| - addToPTAssistantmenu(PublicTransportMenu); |
86 |
| - initialiseWizard(); |
87 |
| - initialiseShorcutsForCreatePlatformNode(); |
88 |
| - } |
89 |
| - |
90 |
| - /** |
91 |
| - * Called when the JOSM map frame is created or destroyed. |
92 |
| - */ |
93 |
| - @Override |
94 |
| - public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { |
95 |
| - if (oldFrame == null && newFrame != null) { |
96 |
| - repeatLastFixMenu.setEnabled(false); |
97 |
| - editHighlightedRelationsMenu.setEnabled(false); |
98 |
| - MainApplication.getMap().addMapMode(new IconToggleButton(new AddStopPositionAction())); |
99 |
| - MainApplication.getMap().addMapMode(new IconToggleButton(new EdgeSelectionAction())); |
100 |
| - MainApplication.getMap().addMapMode(new IconToggleButton(new DoubleSplitAction())); |
101 |
| - } else if (oldFrame != null && newFrame == null) { |
102 |
| - repeatLastFixMenu.setEnabled(false); |
103 |
| - editHighlightedRelationsMenu.setEnabled(false); |
104 |
| - } |
105 |
| - } |
106 |
| - |
107 |
| - /** |
108 |
| - * Sets up the pt_assistant tab in JOSM Preferences |
109 |
| - */ |
110 |
| - @Override |
111 |
| - public PreferenceSetting getPreferenceSetting() { |
112 |
| - return new PTAssistantPreferenceSetting(); |
113 |
| - } |
114 |
| - |
115 |
| - public static PTRouteSegment getLastFix() { |
116 |
| - return lastFix; |
117 |
| - } |
118 |
| - |
119 |
| - /** |
120 |
| - * Remembers the last fix and enables/disables the Repeat last fix menu |
121 |
| - * |
122 |
| - * @param segment |
123 |
| - * The last fix, call be null to disable the Repeat last fix menu |
124 |
| - */ |
125 |
| - public static void setLastFix(PTRouteSegment segment) { |
126 |
| - lastFix = segment; |
127 |
| - SwingUtilities.invokeLater(() -> repeatLastFixMenu.setEnabled(segment != null)); |
128 |
| - } |
129 |
| - |
130 |
| - /** |
131 |
| - * Used in unit tests |
132 |
| - * |
133 |
| - * @param segment |
134 |
| - * route segment |
135 |
| - */ |
136 |
| - public static void setLastFixNoGui(PTRouteSegment segment) { |
137 |
| - lastFix = segment; |
138 |
| - } |
139 |
| - |
140 |
| - public static List<Relation> getHighlightedRelations() { |
141 |
| - return new ArrayList<>(highlightedRelations); |
142 |
| - } |
143 |
| - |
144 |
| - public static void addHighlightedRelation(Relation highlightedRelation) { |
145 |
| - highlightedRelations.add(highlightedRelation); |
146 |
| - if (!editHighlightedRelationsMenu.isEnabled()) { |
147 |
| - SwingUtilities.invokeLater(() -> editHighlightedRelationsMenu.setEnabled(true)); |
148 |
| - } |
149 |
| - } |
150 |
| - |
151 |
| - public static void clearHighlightedRelations() { |
152 |
| - highlightedRelations.clear(); |
153 |
| - SwingUtilities.invokeLater(() -> editHighlightedRelationsMenu.setEnabled(false)); |
154 |
| - } |
155 |
| - |
156 |
| - private void addToPTAssistantmenu(JMenu PublicTransportMenu) { |
157 |
| - RepeatLastFixAction repeatLastFixAction = new RepeatLastFixAction(); |
158 |
| - EditHighlightedRelationsAction editHighlightedRelationsAction = new EditHighlightedRelationsAction(); |
159 |
| - repeatLastFixMenu = MainMenu.add(PublicTransportMenu, repeatLastFixAction); |
160 |
| - editHighlightedRelationsMenu = MainMenu.add(PublicTransportMenu, editHighlightedRelationsAction); |
161 |
| - MainMenu.add(PublicTransportMenu, new SplitRoundaboutAction()); |
162 |
| - MainMenu.add(PublicTransportMenu, new CreatePlatformNodeAction()); |
163 |
| - MainMenu.add(PublicTransportMenu, new SortPTRouteMembersAction()); |
164 |
| - Component sep = new JPopupMenu.Separator(); |
165 |
| - PublicTransportMenu.add(sep); |
166 |
| - MainMenu.add(PublicTransportMenu, new PTWizardAction()); |
167 |
| - } |
168 |
| - |
169 |
| - private static void initialiseWizard() { |
170 |
| - PTWizardAction wizard = new PTWizardAction(); |
171 |
| - wizard.noDialogBox = true; |
172 |
| - wizard.actionPerformed(null); |
173 |
| - } |
174 |
| - |
175 |
| - private static void initialiseShorcutsForCreatePlatformNode() { |
176 |
| - CreatePlatformShortcutAction shortcut1 = new CreatePlatformShortcutAction(); |
177 |
| - CreatePlatformNodeThroughReplaceAction shortcut2 = new CreatePlatformNodeThroughReplaceAction(); |
178 |
| - ExtractPlatformNodeAction shortcut3 = new ExtractPlatformNodeAction(); |
179 |
| - } |
180 |
| -} |
| 1 | +// License: GPL. For details, see LICENSE file. |
| 2 | +package org.openstreetmap.josm.plugins.pt_assistant; |
| 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; |
| 8 | +import java.awt.KeyboardFocusManager; |
| 9 | +import java.awt.event.KeyEvent; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +import javax.swing.JMenu; |
| 14 | +import javax.swing.JMenuItem; |
| 15 | +import javax.swing.JPopupMenu; |
| 16 | +import javax.swing.SwingUtilities; |
| 17 | + |
| 18 | +import org.openstreetmap.josm.data.osm.Relation; |
| 19 | +import org.openstreetmap.josm.data.osm.event.SelectionEventManager; |
| 20 | +import org.openstreetmap.josm.data.validation.OsmValidator; |
| 21 | +import org.openstreetmap.josm.gui.IconToggleButton; |
| 22 | +import org.openstreetmap.josm.gui.MainApplication; |
| 23 | +import org.openstreetmap.josm.gui.MainMenu; |
| 24 | +import org.openstreetmap.josm.gui.MapFrame; |
| 25 | +import org.openstreetmap.josm.gui.preferences.PreferenceSetting; |
| 26 | +import org.openstreetmap.josm.plugins.Plugin; |
| 27 | +import org.openstreetmap.josm.plugins.PluginInformation; |
| 28 | +import org.openstreetmap.josm.plugins.pt_assistant.actions.AddStopPositionAction; |
| 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; |
| 32 | +import org.openstreetmap.josm.plugins.pt_assistant.actions.DoubleSplitAction; |
| 33 | +import org.openstreetmap.josm.plugins.pt_assistant.actions.EdgeSelectionAction; |
| 34 | +import org.openstreetmap.josm.plugins.pt_assistant.actions.EditHighlightedRelationsAction; |
| 35 | +import org.openstreetmap.josm.plugins.pt_assistant.actions.ExtractPlatformNodeAction; |
| 36 | +import org.openstreetmap.josm.plugins.pt_assistant.actions.PTWizardAction; |
| 37 | +import org.openstreetmap.josm.plugins.pt_assistant.actions.RepeatLastFixAction; |
| 38 | +import org.openstreetmap.josm.plugins.pt_assistant.actions.SortPTRouteMembersAction; |
| 39 | +import org.openstreetmap.josm.plugins.pt_assistant.actions.SplitRoundaboutAction; |
| 40 | +import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment; |
| 41 | +import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayerManager; |
| 42 | +import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantPreferenceSetting; |
| 43 | +import org.openstreetmap.josm.plugins.pt_assistant.validation.BicycleFootRouteValidatorTest; |
| 44 | +import org.openstreetmap.josm.plugins.pt_assistant.validation.PTAssistantValidatorTest; |
| 45 | + |
| 46 | +/** |
| 47 | + * This is the main class of the PTAssistant plugin. |
| 48 | + * |
| 49 | + * @author darya / Darya Golovko |
| 50 | + * |
| 51 | + */ |
| 52 | +public class PTAssistantPlugin extends Plugin { |
| 53 | + |
| 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; |
| 59 | + |
| 60 | + /* list of relation currently highlighted by the layer */ |
| 61 | + private static List<Relation> highlightedRelations = new ArrayList<>(); |
| 62 | + |
| 63 | + /* item of the Tools menu for repeating the last fix */ |
| 64 | + private static JMenuItem repeatLastFixMenu; |
| 65 | + |
| 66 | + /* edit the currently highlighted relations */ |
| 67 | + private static JMenuItem editHighlightedRelationsMenu; |
| 68 | + |
| 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); |
| 79 | + |
| 80 | + MainMenu menu = MainApplication.getMenu(); |
| 81 | + JMenu PublicTransportMenu = menu.addMenu("File", trc("menu", "Public Transport"), KeyEvent.VK_P, 5, ht("/Menu/Public Transport")); |
| 82 | + |
| 83 | + SelectionEventManager.getInstance().addSelectionListener(PTAssistantLayerManager.PTLM); |
| 84 | + KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(PTAssistantLayerManager.PTLM); |
| 85 | + addToPTAssistantmenu(PublicTransportMenu); |
| 86 | + initialiseWizard(); |
| 87 | + initialiseShorcutsForCreatePlatformNode(); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Called when the JOSM map frame is created or destroyed. |
| 92 | + */ |
| 93 | + @Override |
| 94 | + public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { |
| 95 | + if (oldFrame == null && newFrame != null) { |
| 96 | + repeatLastFixMenu.setEnabled(false); |
| 97 | + editHighlightedRelationsMenu.setEnabled(false); |
| 98 | + MainApplication.getMap().addMapMode(new IconToggleButton(new AddStopPositionAction())); |
| 99 | + MainApplication.getMap().addMapMode(new IconToggleButton(new EdgeSelectionAction())); |
| 100 | + MainApplication.getMap().addMapMode(new IconToggleButton(new DoubleSplitAction())); |
| 101 | + } else if (oldFrame != null && newFrame == null) { |
| 102 | + repeatLastFixMenu.setEnabled(false); |
| 103 | + editHighlightedRelationsMenu.setEnabled(false); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Sets up the pt_assistant tab in JOSM Preferences |
| 109 | + */ |
| 110 | + @Override |
| 111 | + public PreferenceSetting getPreferenceSetting() { |
| 112 | + return new PTAssistantPreferenceSetting(); |
| 113 | + } |
| 114 | + |
| 115 | + public static PTRouteSegment getLastFix() { |
| 116 | + return lastFix; |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Remembers the last fix and enables/disables the Repeat last fix menu |
| 121 | + * |
| 122 | + * @param segment |
| 123 | + * The last fix, call be null to disable the Repeat last fix menu |
| 124 | + */ |
| 125 | + public static void setLastFix(PTRouteSegment segment) { |
| 126 | + lastFix = segment; |
| 127 | + SwingUtilities.invokeLater(() -> repeatLastFixMenu.setEnabled(segment != null)); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Used in unit tests |
| 132 | + * |
| 133 | + * @param segment |
| 134 | + * route segment |
| 135 | + */ |
| 136 | + public static void setLastFixNoGui(PTRouteSegment segment) { |
| 137 | + lastFix = segment; |
| 138 | + } |
| 139 | + |
| 140 | + public static List<Relation> getHighlightedRelations() { |
| 141 | + return new ArrayList<>(highlightedRelations); |
| 142 | + } |
| 143 | + |
| 144 | + public static void addHighlightedRelation(Relation highlightedRelation) { |
| 145 | + highlightedRelations.add(highlightedRelation); |
| 146 | + if (!editHighlightedRelationsMenu.isEnabled()) { |
| 147 | + SwingUtilities.invokeLater(() -> editHighlightedRelationsMenu.setEnabled(true)); |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + public static void clearHighlightedRelations() { |
| 152 | + highlightedRelations.clear(); |
| 153 | + SwingUtilities.invokeLater(() -> editHighlightedRelationsMenu.setEnabled(false)); |
| 154 | + } |
| 155 | + |
| 156 | + private void addToPTAssistantmenu(JMenu PublicTransportMenu) { |
| 157 | + RepeatLastFixAction repeatLastFixAction = new RepeatLastFixAction(); |
| 158 | + EditHighlightedRelationsAction editHighlightedRelationsAction = new EditHighlightedRelationsAction(); |
| 159 | + repeatLastFixMenu = MainMenu.add(PublicTransportMenu, repeatLastFixAction); |
| 160 | + editHighlightedRelationsMenu = MainMenu.add(PublicTransportMenu, editHighlightedRelationsAction); |
| 161 | + MainMenu.add(PublicTransportMenu, new SplitRoundaboutAction()); |
| 162 | + MainMenu.add(PublicTransportMenu, new CreatePlatformNodeAction()); |
| 163 | + MainMenu.add(PublicTransportMenu, new SortPTRouteMembersAction()); |
| 164 | + Component sep = new JPopupMenu.Separator(); |
| 165 | + PublicTransportMenu.add(sep); |
| 166 | + MainMenu.add(PublicTransportMenu, new PTWizardAction()); |
| 167 | + } |
| 168 | + |
| 169 | + private static void initialiseWizard() { |
| 170 | + PTWizardAction wizard = new PTWizardAction(); |
| 171 | + wizard.noDialogBox = true; |
| 172 | + wizard.actionPerformed(null); |
| 173 | + } |
| 174 | + |
| 175 | + private static void initialiseShorcutsForCreatePlatformNode() { |
| 176 | + CreatePlatformShortcutAction shortcut1 = new CreatePlatformShortcutAction(); |
| 177 | + CreatePlatformNodeThroughReplaceAction shortcut2 = new CreatePlatformNodeThroughReplaceAction(); |
| 178 | + ExtractPlatformNodeAction shortcut3 = new ExtractPlatformNodeAction(); |
| 179 | + } |
| 180 | +} |
0 commit comments