1 | package smed2;
|
---|
2 |
|
---|
3 | import java.awt.Dimension;
|
---|
4 | import java.awt.event.ActionEvent;
|
---|
5 | import java.util.Collection;
|
---|
6 |
|
---|
7 | import javax.swing.JFrame;
|
---|
8 | import javax.swing.SwingUtilities;
|
---|
9 | import javax.swing.WindowConstants;
|
---|
10 |
|
---|
11 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
12 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
13 | import org.openstreetmap.josm.gui.MapView;
|
---|
14 | import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
|
---|
15 | import org.openstreetmap.josm.gui.layer.ImageryLayer;
|
---|
16 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
17 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
---|
18 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
19 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
20 | import org.openstreetmap.josm.data.osm.Node;
|
---|
21 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
22 | import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
|
---|
23 | import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
|
---|
24 | import org.openstreetmap.josm.data.osm.event.DataSetListener;
|
---|
25 | import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;
|
---|
26 | import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
|
---|
27 | import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
|
---|
28 | import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;
|
---|
29 | import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent;
|
---|
30 | import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;
|
---|
31 | import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
|
---|
32 | import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
|
---|
33 | import org.openstreetmap.josm.Main;
|
---|
34 |
|
---|
35 | import s57.S57dat;
|
---|
36 |
|
---|
37 | import panels.PanelMain;
|
---|
38 |
|
---|
39 | public class Smed2Action extends JosmAction implements EditLayerChangeListener, SelectionChangedListener {
|
---|
40 |
|
---|
41 | private static final long serialVersionUID = 1L;
|
---|
42 | private static String editor = tr("SeaMap Editor");
|
---|
43 | public static JFrame frame = null;
|
---|
44 | public static S57dat panelS57;
|
---|
45 | private boolean isOpen = false;
|
---|
46 | public static PanelMain panelMain = null;
|
---|
47 | public ImageryLayer rendering;
|
---|
48 |
|
---|
49 | private final DataSetListener dataSetListener = new DataSetListener() {
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public void dataChanged(DataChangedEvent e) {
|
---|
53 | System.out.println(e);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public void nodeMoved(NodeMovedEvent e) {
|
---|
58 | System.out.println(e);
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public void otherDatasetChange(AbstractDatasetChangedEvent e) {
|
---|
63 | System.out.println(e);
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | public void primitivesAdded(PrimitivesAddedEvent e) {
|
---|
68 | System.out.println(e);
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public void primitivesRemoved(PrimitivesRemovedEvent e) {
|
---|
73 | System.out.println(e);
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public void relationMembersChanged(RelationMembersChangedEvent e) {
|
---|
78 | System.out.println(e);
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Override
|
---|
82 | public void tagsChanged(TagsChangedEvent e) {
|
---|
83 | System.out.println(e);
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Override
|
---|
87 | public void wayNodesChanged(WayNodesChangedEvent e) {
|
---|
88 | System.out.println(e);
|
---|
89 | }
|
---|
90 | };
|
---|
91 |
|
---|
92 | public Smed2Action() {
|
---|
93 | super(editor, "Smed2", editor, null, true);
|
---|
94 | MapView.addEditLayerChangeListener(this); // DataSet.addDataSetListener(DataListener);
|
---|
95 | DataSet.addSelectionListener(this);
|
---|
96 | }
|
---|
97 |
|
---|
98 | @Override
|
---|
99 | public void actionPerformed(ActionEvent arg0) {
|
---|
100 | SwingUtilities.invokeLater(new Runnable() {
|
---|
101 | public void run() {
|
---|
102 | if (!isOpen)
|
---|
103 | createFrame();
|
---|
104 | else
|
---|
105 | frame.toFront();
|
---|
106 | isOpen = true;
|
---|
107 | }
|
---|
108 | });
|
---|
109 | }
|
---|
110 |
|
---|
111 | protected void createFrame() {
|
---|
112 | frame = new JFrame(editor);
|
---|
113 | frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
---|
114 | frame.setResizable(true);
|
---|
115 | frame.setAlwaysOnTop(false);
|
---|
116 |
|
---|
117 | frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
---|
118 | public void windowClosing(java.awt.event.WindowEvent e) {
|
---|
119 | closeDialog();
|
---|
120 | }
|
---|
121 | });
|
---|
122 | frame.setSize(new Dimension(480, 480));
|
---|
123 | frame.setLocation(100, 200);
|
---|
124 | frame.setAlwaysOnTop(true);
|
---|
125 | frame.setVisible(true);
|
---|
126 | panelMain = new PanelMain();
|
---|
127 | frame.add(panelMain);
|
---|
128 | panelS57 = new S57dat();
|
---|
129 | panelS57.setVisible(false);
|
---|
130 | frame.add(panelS57);
|
---|
131 | System.out.println("hello");
|
---|
132 | rendering = ImageryLayer.create(new ImageryInfo("OpenSeaMap"));
|
---|
133 | Main.main.addLayer(rendering);
|
---|
134 | }
|
---|
135 |
|
---|
136 | public void closeDialog() {
|
---|
137 | if (isOpen) {
|
---|
138 | Main.main.removeLayer(rendering);
|
---|
139 | frame.setVisible(false);
|
---|
140 | frame.dispose();
|
---|
141 | }
|
---|
142 | isOpen = false;
|
---|
143 | }
|
---|
144 |
|
---|
145 | @Override
|
---|
146 | public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
|
---|
147 | if (oldLayer != null) {
|
---|
148 | oldLayer.data.removeDataSetListener(dataSetListener);
|
---|
149 | }
|
---|
150 |
|
---|
151 | if (newLayer != null) {
|
---|
152 | newLayer.data.addDataSetListener(dataSetListener);
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | @Override
|
---|
157 | public void selectionChanged(Collection<? extends OsmPrimitive> arg0) {
|
---|
158 | // TODO Auto-generated method stub
|
---|
159 |
|
---|
160 | }
|
---|
161 |
|
---|
162 | }
|
---|