Changeset 33030 in osm for applications/editors/josm/plugins/seachartedit/src/scedit/SCeditAction.java
- Timestamp:
- 2016-10-09T04:25:33+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachartedit/src/scedit/SCeditAction.java
r32370 r33030 54 54 55 55 public class SCeditAction extends JosmAction implements ActiveLayerChangeListener, SelectionChangedListener { 56 private static String title = tr("SeaChart Editor"); 57 public static JFrame editFrame = null; 58 public static ShowFrame showFrame = null; 59 private boolean isOpen = false; 60 public static PanelMain panelMain = null; 61 public static PanelS57 panelS57 = null; 62 public static S57map map = null; 63 public DataSet data = null; 64 65 private final DataSetListener dataSetListener = new DataSetListener() { 66 67 @Override 68 public void dataChanged(DataChangedEvent e) { 69 makeMap(); 70 } 71 72 @Override 73 public void nodeMoved(NodeMovedEvent e) { 74 makeMap(); 75 } 76 77 @Override 78 public void otherDatasetChange(AbstractDatasetChangedEvent e) { 79 makeMap(); 80 } 81 82 @Override 83 public void primitivesAdded(PrimitivesAddedEvent e) { 84 makeMap(); 85 } 86 87 @Override 88 public void primitivesRemoved(PrimitivesRemovedEvent e) { 89 makeMap(); 90 } 91 92 @Override 93 public void relationMembersChanged(RelationMembersChangedEvent e) { 94 makeMap(); 95 } 96 97 @Override 98 public void tagsChanged(TagsChangedEvent e) { 99 makeMap(); 100 } 101 102 @Override 103 public void wayNodesChanged(WayNodesChangedEvent e) { 104 makeMap(); 105 } 106 }; 107 108 public SCeditAction() { 109 super(title, "SC", title, null, true); 110 } 111 112 @Override 113 public void actionPerformed(ActionEvent arg0) { 114 SwingUtilities.invokeLater(new Runnable() { 115 public void run() { 116 if (!isOpen) 117 createFrame(); 118 else 119 editFrame.toFront(); 120 isOpen = true; 121 } 122 }); 123 } 124 125 protected void createFrame() { 126 editFrame = new JFrame(title); 127 editFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 128 editFrame.addWindowListener(new java.awt.event.WindowAdapter() { 129 public void windowClosing(java.awt.event.WindowEvent e) { 130 closeDialog(); 131 } 132 }); 133 editFrame.setSize(new Dimension(480, 480)); 134 editFrame.setLocation(100, 200); 135 editFrame.setResizable(true); 136 editFrame.setAlwaysOnTop(true); 137 editFrame.setVisible(true); 138 panelMain = new PanelMain(); 139 editFrame.add(panelMain); 140 141 panelS57 = new PanelS57(); 142 editFrame.add(panelS57); 143 144 showFrame = new ShowFrame(tr("Seamark Inspector")); 145 showFrame.setSize(new Dimension(300, 300)); 146 showFrame.setLocation(50, 400); 147 showFrame.setResizable(false); 148 showFrame.setAlwaysOnTop(true); 149 showFrame.setEnabled(true); 150 showFrame.setVisible(false); 151 152 Main.getLayerManager().addAndFireActiveLayerChangeListener(this); 153 DataSet.addSelectionListener(this); 154 } 155 156 public void closeDialog() { 157 if (isOpen) { 158 Main.getLayerManager().removeActiveLayerChangeListener(this); 159 editFrame.setVisible(false); 160 editFrame.dispose(); 161 data = null; 162 map = null; 163 } 164 isOpen = false; 165 } 166 167 @Override 168 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 169 if (e.getPreviousEditLayer() != null) { 170 e.getPreviousEditLayer().data.removeDataSetListener(dataSetListener); 171 } 172 OsmDataLayer newLayer = Main.getLayerManager().getEditLayer(); 173 if (newLayer != null) { 174 newLayer.data.addDataSetListener(dataSetListener); 175 data = newLayer.data; 176 makeMap(); 177 } else { 178 data = null; 179 map = null; 180 } 181 } 182 183 @Override 184 public void selectionChanged(Collection<? extends OsmPrimitive> selection) { 185 OsmPrimitive nextFeature = null; 186 OsmPrimitive feature = null; 187 188 showFrame.setVisible(false); 189 panelMain.clearMark(); 190 if (map != null) { 191 for (OsmPrimitive osm : selection) { 192 nextFeature = osm; 193 if (selection.size() == 1) { 194 if (nextFeature.compareTo(feature) != 0) { 195 feature = nextFeature; 196 Feature id = map.index.get(feature.getUniqueId()); 197 if (id != null) { 198 panelMain.parseMark(id); 199 showFrame.setVisible(true); 200 showFrame.showFeature(feature, map); 201 } 202 } 203 } else { 204 showFrame.setVisible(false); 205 PanelMain.setStatus(tr("Select only one object"), Color.orange); 206 } 207 } 208 if (nextFeature == null) { 209 feature = null; 210 panelMain.clearMark(); 211 showFrame.setVisible(false); 212 PanelMain.setStatus(tr("Select a map object"), Color.yellow); 213 } 214 } 215 } 216 217 void makeMap() { 218 map = new S57map(true); 219 if (data != null) { 220 double minlat = 90; 221 double maxlat = -90; 222 double minlon = 180; 223 double maxlon = -180; 224 for (Bounds bounds : data.getDataSourceBounds()) { 225 if (bounds.getMinLat() < minlat) { 226 minlat = bounds.getMinLat(); 227 } 228 if (bounds.getMaxLat() > maxlat) { 229 maxlat = bounds.getMaxLat(); 230 } 231 if (bounds.getMinLon() < minlon) { 232 minlon = bounds.getMinLon(); 233 } 234 if (bounds.getMaxLon() > maxlon) { 235 maxlon = bounds.getMaxLon(); 236 } 237 } 238 map.addNode(1, maxlat, minlon); 239 map.addNode(2, minlat, minlon); 240 map.addNode(3, minlat, maxlon); 241 map.addNode(4, maxlat, maxlon); 242 map.bounds.minlat = Math.toRadians(minlat); 243 map.bounds.maxlat = Math.toRadians(maxlat); 244 map.bounds.minlon = Math.toRadians(minlon); 245 map.bounds.maxlon = Math.toRadians(maxlon); 246 for (Node node : data.getNodes()) { 247 LatLon coor = node.getCoor(); 248 if (coor != null) { 249 map.addNode(node.getUniqueId(), coor.lat(), coor.lon()); 250 for (Entry<String, String> entry : node.getKeys().entrySet()) { 251 map.addTag(entry.getKey(), entry.getValue()); 252 } 253 map.tagsDone(node.getUniqueId()); 254 } 255 } 256 for (Way way : data.getWays()) { 257 if (way.getNodesCount() > 0) { 258 map.addEdge(way.getUniqueId()); 259 for (Node node : way.getNodes()) { 260 map.addToEdge((node.getUniqueId())); 261 } 262 for (Entry<String, String> entry : way.getKeys().entrySet()) { 263 map.addTag(entry.getKey(), entry.getValue()); 264 } 265 map.tagsDone(way.getUniqueId()); 266 } 267 } 268 for (Relation rel : data.getRelations()) { 269 if (rel.isMultipolygon() && (rel.getMembersCount() > 0)) { 270 map.addArea(rel.getUniqueId()); 271 for (RelationMember mem : rel.getMembers()) { 272 if (mem.getType() == OsmPrimitiveType.WAY) 273 map.addToArea(mem.getUniqueId(), (mem.getRole().equals("outer"))); 274 } 275 for (Entry<String, String> entry : rel.getKeys().entrySet()) { 276 map.addTag(entry.getKey(), entry.getValue()); 277 } 278 map.tagsDone(rel.getUniqueId()); 279 } 280 } 281 map.mapDone(); 282 } 283 } 56 private static String title = tr("SeaChart Editor"); 57 public static JFrame editFrame = null; 58 public static ShowFrame showFrame = null; 59 private boolean isOpen = false; 60 public static PanelMain panelMain = null; 61 public static PanelS57 panelS57 = null; 62 public static S57map map = null; 63 public DataSet data = null; 64 65 private final DataSetListener dataSetListener = new DataSetListener() { 66 67 @Override 68 public void dataChanged(DataChangedEvent e) { 69 makeMap(); 70 } 71 72 @Override 73 public void nodeMoved(NodeMovedEvent e) { 74 makeMap(); 75 } 76 77 @Override 78 public void otherDatasetChange(AbstractDatasetChangedEvent e) { 79 makeMap(); 80 } 81 82 @Override 83 public void primitivesAdded(PrimitivesAddedEvent e) { 84 makeMap(); 85 } 86 87 @Override 88 public void primitivesRemoved(PrimitivesRemovedEvent e) { 89 makeMap(); 90 } 91 92 @Override 93 public void relationMembersChanged(RelationMembersChangedEvent e) { 94 makeMap(); 95 } 96 97 @Override 98 public void tagsChanged(TagsChangedEvent e) { 99 makeMap(); 100 } 101 102 @Override 103 public void wayNodesChanged(WayNodesChangedEvent e) { 104 makeMap(); 105 } 106 }; 107 108 public SCeditAction() { 109 super(title, "SC", title, null, true); 110 } 111 112 @Override 113 public void actionPerformed(ActionEvent arg0) { 114 SwingUtilities.invokeLater(new Runnable() { 115 @Override 116 public void run() { 117 if (!isOpen) 118 createFrame(); 119 else 120 editFrame.toFront(); 121 isOpen = true; 122 } 123 }); 124 } 125 126 protected void createFrame() { 127 editFrame = new JFrame(title); 128 editFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 129 editFrame.addWindowListener(new java.awt.event.WindowAdapter() { 130 @Override 131 public void windowClosing(java.awt.event.WindowEvent e) { 132 closeDialog(); 133 } 134 }); 135 editFrame.setSize(new Dimension(480, 480)); 136 editFrame.setLocation(100, 200); 137 editFrame.setResizable(true); 138 editFrame.setAlwaysOnTop(true); 139 editFrame.setVisible(true); 140 panelMain = new PanelMain(); 141 editFrame.add(panelMain); 142 143 panelS57 = new PanelS57(); 144 editFrame.add(panelS57); 145 146 showFrame = new ShowFrame(tr("Seamark Inspector")); 147 showFrame.setSize(new Dimension(300, 300)); 148 showFrame.setLocation(50, 400); 149 showFrame.setResizable(false); 150 showFrame.setAlwaysOnTop(true); 151 showFrame.setEnabled(true); 152 showFrame.setVisible(false); 153 154 Main.getLayerManager().addAndFireActiveLayerChangeListener(this); 155 DataSet.addSelectionListener(this); 156 } 157 158 public void closeDialog() { 159 if (isOpen) { 160 Main.getLayerManager().removeActiveLayerChangeListener(this); 161 editFrame.setVisible(false); 162 editFrame.dispose(); 163 data = null; 164 map = null; 165 } 166 isOpen = false; 167 } 168 169 @Override 170 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 171 if (e.getPreviousEditLayer() != null) { 172 e.getPreviousEditLayer().data.removeDataSetListener(dataSetListener); 173 } 174 OsmDataLayer newLayer = Main.getLayerManager().getEditLayer(); 175 if (newLayer != null) { 176 newLayer.data.addDataSetListener(dataSetListener); 177 data = newLayer.data; 178 makeMap(); 179 } else { 180 data = null; 181 map = null; 182 } 183 } 184 185 @Override 186 public void selectionChanged(Collection<? extends OsmPrimitive> selection) { 187 OsmPrimitive nextFeature = null; 188 OsmPrimitive feature = null; 189 190 showFrame.setVisible(false); 191 panelMain.clearMark(); 192 if (map != null) { 193 for (OsmPrimitive osm : selection) { 194 nextFeature = osm; 195 if (selection.size() == 1) { 196 if (nextFeature.compareTo(feature) != 0) { 197 feature = nextFeature; 198 Feature id = map.index.get(feature.getUniqueId()); 199 if (id != null) { 200 panelMain.parseMark(id); 201 showFrame.setVisible(true); 202 showFrame.showFeature(feature, map); 203 } 204 } 205 } else { 206 showFrame.setVisible(false); 207 PanelMain.setStatus(tr("Select only one object"), Color.orange); 208 } 209 } 210 if (nextFeature == null) { 211 feature = null; 212 panelMain.clearMark(); 213 showFrame.setVisible(false); 214 PanelMain.setStatus(tr("Select a map object"), Color.yellow); 215 } 216 } 217 } 218 219 void makeMap() { 220 map = new S57map(true); 221 if (data != null) { 222 double minlat = 90; 223 double maxlat = -90; 224 double minlon = 180; 225 double maxlon = -180; 226 for (Bounds bounds : data.getDataSourceBounds()) { 227 if (bounds.getMinLat() < minlat) { 228 minlat = bounds.getMinLat(); 229 } 230 if (bounds.getMaxLat() > maxlat) { 231 maxlat = bounds.getMaxLat(); 232 } 233 if (bounds.getMinLon() < minlon) { 234 minlon = bounds.getMinLon(); 235 } 236 if (bounds.getMaxLon() > maxlon) { 237 maxlon = bounds.getMaxLon(); 238 } 239 } 240 map.addNode(1, maxlat, minlon); 241 map.addNode(2, minlat, minlon); 242 map.addNode(3, minlat, maxlon); 243 map.addNode(4, maxlat, maxlon); 244 map.bounds.minlat = Math.toRadians(minlat); 245 map.bounds.maxlat = Math.toRadians(maxlat); 246 map.bounds.minlon = Math.toRadians(minlon); 247 map.bounds.maxlon = Math.toRadians(maxlon); 248 for (Node node : data.getNodes()) { 249 LatLon coor = node.getCoor(); 250 if (coor != null) { 251 map.addNode(node.getUniqueId(), coor.lat(), coor.lon()); 252 for (Entry<String, String> entry : node.getKeys().entrySet()) { 253 map.addTag(entry.getKey(), entry.getValue()); 254 } 255 map.tagsDone(node.getUniqueId()); 256 } 257 } 258 for (Way way : data.getWays()) { 259 if (way.getNodesCount() > 0) { 260 map.addEdge(way.getUniqueId()); 261 for (Node node : way.getNodes()) { 262 map.addToEdge((node.getUniqueId())); 263 } 264 for (Entry<String, String> entry : way.getKeys().entrySet()) { 265 map.addTag(entry.getKey(), entry.getValue()); 266 } 267 map.tagsDone(way.getUniqueId()); 268 } 269 } 270 for (Relation rel : data.getRelations()) { 271 if (rel.isMultipolygon() && (rel.getMembersCount() > 0)) { 272 map.addArea(rel.getUniqueId()); 273 for (RelationMember mem : rel.getMembers()) { 274 if (mem.getType() == OsmPrimitiveType.WAY) 275 map.addToArea(mem.getUniqueId(), (mem.getRole().equals("outer"))); 276 } 277 for (Entry<String, String> entry : rel.getKeys().entrySet()) { 278 map.addTag(entry.getKey(), entry.getValue()); 279 } 280 map.tagsDone(rel.getUniqueId()); 281 } 282 } 283 map.mapDone(); 284 } 285 } 284 286 }
Note:
See TracChangeset
for help on using the changeset viewer.