1 | package UtilsPlugin;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import UtilsPlugin.*;
|
---|
6 | //import UtilsPlugin.JosmLint.JosmLint;
|
---|
7 | import org.openstreetmap.josm.gui.IconToggleButton;
|
---|
8 |
|
---|
9 | import java.awt.event.ActionEvent;
|
---|
10 | import javax.swing.AbstractAction;
|
---|
11 | import javax.swing.JMenu;
|
---|
12 | import javax.swing.JMenuBar;
|
---|
13 | import javax.swing.JMenuItem;
|
---|
14 | import javax.swing.JOptionPane;
|
---|
15 |
|
---|
16 | import javax.swing.JPanel;
|
---|
17 | import javax.swing.BoxLayout;
|
---|
18 |
|
---|
19 | import org.openstreetmap.josm.Main;
|
---|
20 | import org.openstreetmap.josm.plugins.Plugin;
|
---|
21 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
22 |
|
---|
23 | public class UtilsPlugin extends Plugin {
|
---|
24 |
|
---|
25 | private JMenu toolsMenu;
|
---|
26 | private JMenuItem mergePointsMenu = new JMenuItem(new MergePointsAction());
|
---|
27 | private JMenuItem mergePointLineMenu = new JMenuItem(new MergePointLineAction());
|
---|
28 | private JMenuItem mergeWaysMenu = new JMenuItem(new MergeWaysAction());
|
---|
29 | private JMenuItem deduplicateWayMenu = new JMenuItem(new DeduplicateWayAction());
|
---|
30 | private JMenuItem simplifyWayMenu = new JMenuItem(new SimplifyWayAction());
|
---|
31 |
|
---|
32 | public UtilsPlugin() {
|
---|
33 | JMenuBar menu = Main.main.menu;
|
---|
34 | toolsMenu = menu.getMenu(4);
|
---|
35 | /*
|
---|
36 | This code doesn't work, because getName returns null always, so we get two menus
|
---|
37 |
|
---|
38 | for (int i = 0; i < menu.getMenuCount(); ++i) {
|
---|
39 | javax.swing.JOptionPane.showMessageDialog(Main.parent, tr("Menu ["+menu.getMenu(i).getName()+","+tr("Edit")+"]"));
|
---|
40 | if (menu.getMenu(i) != null && tr("Edit").equals(menu.getMenu(i).getName())) {
|
---|
41 | editMenu = menu.getMenu(i);
|
---|
42 | break;
|
---|
43 | }
|
---|
44 | }
|
---|
45 | */
|
---|
46 | if (toolsMenu == null) {
|
---|
47 | toolsMenu = new JMenu(tr("Tools"));
|
---|
48 | menu.add(toolsMenu, 5);
|
---|
49 | toolsMenu.setVisible(false);
|
---|
50 | }
|
---|
51 | toolsMenu.add(mergePointsMenu);
|
---|
52 | toolsMenu.add(mergePointLineMenu);
|
---|
53 | toolsMenu.add(mergeWaysMenu);
|
---|
54 | toolsMenu.add(deduplicateWayMenu);
|
---|
55 | toolsMenu.add(simplifyWayMenu);
|
---|
56 | mergePointsMenu.setVisible(false);
|
---|
57 | mergePointLineMenu.setVisible(false);
|
---|
58 | mergeWaysMenu.setVisible(false);
|
---|
59 | deduplicateWayMenu.setVisible(false);
|
---|
60 | simplifyWayMenu.setVisible(false);
|
---|
61 | }
|
---|
62 | @Override
|
---|
63 | public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
|
---|
64 | if (oldFrame != null && newFrame == null) {
|
---|
65 | // disable
|
---|
66 | mergePointsMenu.setVisible(false);
|
---|
67 | mergePointLineMenu.setVisible(false);
|
---|
68 | mergeWaysMenu.setVisible(false);
|
---|
69 | deduplicateWayMenu.setVisible(false);
|
---|
70 | simplifyWayMenu.setVisible(false);
|
---|
71 | // JosmLint.stopPlugin();
|
---|
72 | if (toolsMenu.getMenuComponentCount() == 4)
|
---|
73 | toolsMenu.setVisible(false);
|
---|
74 | } else if (oldFrame == null && newFrame != null) {
|
---|
75 | // enable
|
---|
76 | mergePointsMenu.setVisible(true);
|
---|
77 | mergePointLineMenu.setVisible(true);
|
---|
78 | mergeWaysMenu.setVisible(true);
|
---|
79 | deduplicateWayMenu.setVisible(true);
|
---|
80 | simplifyWayMenu.setVisible(true);
|
---|
81 |
|
---|
82 | // JosmLint.setupPlugin();
|
---|
83 |
|
---|
84 | if (toolsMenu.getMenuComponentCount() == 4)
|
---|
85 | toolsMenu.setVisible(true);
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | }
|
---|