source: osm/applications/editors/josm/plugins/smed1/src/oseam/OSeaMAction.java@ 29036

Last change on this file since 29036 was 29036, checked in by malcolmh, 14 years ago

initial

File size: 3.2 KB
Line 
1package oseam;
2
3import java.awt.Color;
4import java.awt.Dimension;
5import java.awt.event.ActionEvent;
6import java.util.Collection;
7
8import javax.swing.JFrame;
9import javax.swing.JTextField;
10import javax.swing.SwingUtilities;
11import javax.swing.WindowConstants;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.actions.JosmAction;
15import org.openstreetmap.josm.data.SelectionChangedListener;
16import org.openstreetmap.josm.data.osm.DataSet;
17import org.openstreetmap.josm.data.osm.Node;
18import org.openstreetmap.josm.data.osm.OsmPrimitive;
19
20import static org.openstreetmap.josm.tools.I18n.tr;
21
22import panels.PanelMain;
23
24public class OSeaMAction extends JosmAction {
25
26 private static final long serialVersionUID = 1L;
27 private static String editor = tr("SeaMap Editor");
28 public static JFrame frame = null;
29 private boolean isOpen = false;
30 public JTextField messageBar = null;
31
32 private OSeaMAction dlg = this;
33 public PanelMain panelMain = null;
34
35 public Node node = null;
36 private Collection<? extends OsmPrimitive> Selection = null;
37
38 public SelectionChangedListener SmpListener = new SelectionChangedListener() {
39 public void selectionChanged(
40 Collection<? extends OsmPrimitive> newSelection) {
41 Node nextNode = null;
42 Selection = newSelection;
43
44 for (OsmPrimitive osm : Selection) {
45 if (osm instanceof Node) {
46 nextNode = (Node) osm;
47 if (Selection.size() == 1) {
48 if (nextNode.compareTo(node) != 0) {
49 node = nextNode;
50 panelMain.mark.parseMark(node);
51 }
52 } else {
53 node = null;
54 panelMain.mark.clrMark();
55 messageBar.setText(Messages.getString("OneNode"));
56 }
57 }
58 }
59 if (nextNode == null) {
60 node = null;
61 panelMain.mark.clrMark();
62 messageBar.setText(Messages.getString("SelectNode"));
63 }
64 }
65 };
66
67 public OSeaMAction() {
68 super(editor, "Smed", editor, null, true);
69 DataSet.addSelectionListener(SmpListener);
70 String str = Main.pref.get("mappaint.style.sources");
71 if (!str.contains("dev.openseamap.org")) {
72 if (!str.isEmpty())
73 str += new String(new char[] { 0x1e });
74 Main.pref.put("mappaint.style.sources", str
75 + "http://dev.openseamap.org/josm/seamark_styles.xml");
76 }
77 }
78
79 @Override
80 public void actionPerformed(ActionEvent arg0) {
81 SwingUtilities.invokeLater(new Runnable() {
82 public void run() {
83 if (!isOpen)
84 createFrame();
85 else
86 frame.toFront();
87 isOpen = true;
88 }
89 });
90 }
91
92 protected void createFrame() {
93 frame = new JFrame(editor);
94 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
95 frame.setResizable(true);
96 frame.setAlwaysOnTop(false);
97
98 frame.addWindowListener(new java.awt.event.WindowAdapter() {
99 public void windowClosing(java.awt.event.WindowEvent e) {
100 closeDialog();
101 }
102 });
103 frame.setSize(new Dimension(400, 400));
104 frame.setLocation(100, 200);
105 frame.setAlwaysOnTop(true);
106 frame.setVisible(true);
107 messageBar = new JTextField();
108 messageBar.setBounds(10, 355, 380, 20);
109 messageBar.setEditable(false);
110 messageBar.setBackground(Color.WHITE);
111 frame.add(messageBar);
112 panelMain = new PanelMain(dlg);
113 frame.add(panelMain);
114 panelMain.syncPanel();
115 // System.out.println("hello");
116 }
117
118 public void closeDialog() {
119 if (isOpen) {
120 frame.setVisible(false);
121 frame.dispose();
122 }
123 isOpen = false;
124 }
125
126}
Note: See TracBrowser for help on using the repository browser.