Changeset 30669 in osm for applications/editors/josm/plugins/CommandLine
- Timestamp:
- 2014-09-23T11:27:10+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/CommandLine/src/CommandLine
- Files:
-
- 8 edited
-
AnyAction.java (modified) (7 diffs)
-
Command.java (modified) (5 diffs)
-
CommandLine.java (modified) (3 diffs)
-
GpxFilter.java (modified) (2 diffs)
-
Loader.java (modified) (3 diffs)
-
OsmToCmd.java (modified) (9 diffs)
-
PointAction.java (modified) (2 diffs)
-
WayAction.java (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java
r29769 r30669 1 1 /* 2 2 * AnyAction.java 3 * 3 * 4 4 * Copyright 2010 Hind <foxhind@gmail.com> 5 * 5 * 6 6 */ 7 7 … … 24 24 25 25 public class AnyAction extends MapMode implements AWTEventListener { 26 privateCommandLine parentPlugin;26 private final CommandLine parentPlugin; 27 27 final private Cursor cursorNormal, cursorActive; 28 28 private Cursor currentCursor; … … 31 31 private boolean isCtrlDown; 32 32 33 public AnyAction(MapFrame mapFrame, CommandLine parentPlugin) {34 super(null, "addsegment.png", null, mapFrame, ImageProvider.getCursor("normal", "selection"));35 this.parentPlugin = parentPlugin;36 cursorNormal = ImageProvider.getCursor("normal", "selection");37 cursorActive = ImageProvider.getCursor("normal", "joinnode");33 public AnyAction(MapFrame mapFrame, CommandLine parentPlugin) { 34 super(null, "addsegment.png", null, mapFrame, ImageProvider.getCursor("normal", "selection")); 35 this.parentPlugin = parentPlugin; 36 cursorNormal = ImageProvider.getCursor("normal", "selection"); 37 cursorActive = ImageProvider.getCursor("normal", "joinnode"); 38 38 currentCursor = cursorNormal; 39 39 nearestPrimitive = null; 40 }40 } 41 41 42 @Override public void enterMode() {43 super.enterMode();42 @Override public void enterMode() { 43 super.enterMode(); 44 44 currentCursor = cursorNormal; 45 45 Main.map.mapView.addMouseListener(this); … … 49 49 } catch (SecurityException ex) { 50 50 } 51 }51 } 52 52 53 @Override public void exitMode() {54 super.exitMode();55 Main.map.mapView.removeMouseListener(this);53 @Override public void exitMode() { 54 super.exitMode(); 55 Main.map.mapView.removeMouseListener(this); 56 56 Main.map.mapView.removeMouseMotionListener(this); 57 57 try { … … 59 59 } catch (SecurityException ex) { 60 60 } 61 }61 } 62 62 63 63 @Override … … 77 77 processMouseEvent(e); 78 78 if (nearestPrimitive != null) { 79 if (isCtrlDown) {80 Main.main.getCurrentDataSet().clearSelection(nearestPrimitive);81 Main.map.mapView.repaint();82 }83 else {84 int maxInstances = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum).maxInstances;85 switch (maxInstances) {86 case 0:87 Main.main.getCurrentDataSet().addSelected(nearestPrimitive);88 Main.map.mapView.repaint();89 break;90 case 1:91 Main.main.getCurrentDataSet().addSelected(nearestPrimitive);92 Main.map.mapView.repaint();93 parentPlugin.loadParameter(nearestPrimitive, true);94 exitMode();95 break;96 default:97 if (Main.main.getCurrentDataSet().getSelected().size() < maxInstances) {98 Main.main.getCurrentDataSet().addSelected(nearestPrimitive);99 Main.map.mapView.repaint();100 }101 else102 System.out.println("Maximum instances!");103 }104 }105 }79 if (isCtrlDown) { 80 Main.main.getCurrentDataSet().clearSelection(nearestPrimitive); 81 Main.map.mapView.repaint(); 82 } 83 else { 84 int maxInstances = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum).maxInstances; 85 switch (maxInstances) { 86 case 0: 87 Main.main.getCurrentDataSet().addSelected(nearestPrimitive); 88 Main.map.mapView.repaint(); 89 break; 90 case 1: 91 Main.main.getCurrentDataSet().addSelected(nearestPrimitive); 92 Main.map.mapView.repaint(); 93 parentPlugin.loadParameter(nearestPrimitive, true); 94 exitMode(); 95 break; 96 default: 97 if (Main.main.getCurrentDataSet().getSelected().size() < maxInstances) { 98 Main.main.getCurrentDataSet().addSelected(nearestPrimitive); 99 Main.map.mapView.repaint(); 100 } 101 else 102 Main.info("Maximum instances!"); 103 } 104 } 105 } 106 106 super.mousePressed(e); 107 107 } 108 108 109 @Override110 public void eventDispatched(AWTEvent arg0) {109 @Override 110 public void eventDispatched(AWTEvent arg0) { 111 111 if (!(arg0 instanceof KeyEvent)) 112 return;112 return; 113 113 KeyEvent ev = (KeyEvent) arg0; 114 114 isCtrlDown = (ev.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0; … … 121 121 private void updCursor() { 122 122 if (mousePos != null) { 123 if (!Main.isDisplayingMapView())124 return;125 nearestPrimitive = Main.map.mapView.getNearestNodeOrWay(mousePos, OsmPrimitive.isUsablePredicate, false);126 if (nearestPrimitive != null) {127 setCursor(cursorActive);128 }129 else {130 setCursor(cursorNormal);131 }132 }123 if (!Main.isDisplayingMapView()) 124 return; 125 nearestPrimitive = Main.map.mapView.getNearestNodeOrWay(mousePos, OsmPrimitive.isUsablePredicate, false); 126 if (nearestPrimitive != null) { 127 setCursor(cursorActive); 128 } 129 else { 130 setCursor(cursorNormal); 131 } 132 } 133 133 } 134 134 135 private void processMouseEvent(MouseEvent e) {136 if (e != null) { mousePos = e.getPoint(); }137 }135 private void processMouseEvent(MouseEvent e) { 136 if (e != null) { mousePos = e.getPoint(); } 137 } 138 138 139 139 private void setCursor(final Cursor c) { -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Command.java
r29854 r30669 1 1 /* 2 2 * Command.java 3 * 3 * 4 4 * Copyright 2011 Hind <foxhind@gmail.com> 5 * 5 * 6 6 */ 7 7 … … 33 33 public boolean loadObject(Object obj) { 34 34 Parameter currentParameter = parameters.get(currentParameterNum); 35 //System.out.println("Parameter " + String.valueOf(currentParameterNum) + " (" + currentParameter.name + ")");36 35 if (currentParameter.maxInstances == 1) { 37 //System.out.println("mI = 1");38 //System.out.println("Candidate: " + String.valueOf(obj));39 36 if (isPair(obj, currentParameter)) { 40 37 currentParameter.setValue(obj); 41 //System.out.println("Accepted");42 38 return true; 43 39 } 44 40 } 45 41 else { 46 //System.out.println("mI = " + String.valueOf(currentParameter.maxInstances));47 42 ArrayList<OsmPrimitive> multiValue = currentParameter.getValueList(); 48 43 if (obj instanceof Collection) { 49 44 if ( ((Collection<?>)obj).size() > currentParameter.maxInstances && currentParameter.maxInstances != 0) 50 45 return false; 51 //System.out.println("Candidate (selected) accepted");52 46 multiValue.clear(); 53 47 multiValue.addAll((Collection<OsmPrimitive>)obj); … … 56 50 else if (obj instanceof OsmPrimitive) { 57 51 if (multiValue.size() < currentParameter.maxInstances || currentParameter.maxInstances == 0) { 58 //System.out.println("Candidate: " + String.valueOf(obj));59 52 if (isPair(obj, currentParameter)) { 60 53 multiValue.add((OsmPrimitive)obj); 61 //System.out.println("Accepted, added to list");62 54 return true; 63 55 } 64 56 else { 65 57 if (nextParameter() && multiValue.size() > 0) { 66 //System.out.println("Not accepted but considering for next Parameter");67 58 return loadObject(obj); 68 59 } … … 71 62 else { 72 63 if (nextParameter()) { 73 //System.out.println("Not accepted but considering for next Parameter");74 64 return loadObject(obj); 75 65 } … … 77 67 } 78 68 else if (obj instanceof String) { 79 //System.out.println("Candidate: " + (String)obj);80 69 if (isPair(obj, currentParameter)) { 81 70 currentParameter.setValue(obj); 82 //System.out.println("Accepted");83 71 return true; 84 72 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
r30668 r30669 223 223 224 224 @Override 225 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) 226 { 225 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 227 226 currentMapFrame = newFrame; 228 227 if (oldFrame == null && newFrame != null) { … … 411 410 } 412 411 else { 413 System.out.println("Invalid argument");412 Main.info("Invalid argument"); 414 413 endInput(); 415 414 } … … 429 428 currentCommand.resetLoading(); 430 429 } 431 //System.out.println("Selected before " + String.valueOf(currentCommand.currentParameterNum) + "\n");432 430 } 433 431 -
applications/editors/josm/plugins/CommandLine/src/CommandLine/GpxFilter.java
r29505 r30669 1 1 /* 2 2 * GpxFilter.java 3 * 3 * 4 4 * Copyright 2011 Hind <foxhind@gmail.com> 5 * 5 * 6 6 */ 7 7 … … 20 20 21 21 public class GpxFilter { 22 private BBox bbox;23 privateGpxData data;22 private BBox bbox; 23 private final GpxData data; 24 24 25 public GpxFilter() {26 bbox = new BBox(0.0, 0.0, 0.0, 0.0);27 data = new GpxData();28 }25 public GpxFilter() { 26 bbox = new BBox(0.0, 0.0, 0.0, 0.0); 27 data = new GpxData(); 28 } 29 29 30 public void initBboxFilter(BBox bbox) {31 this.bbox = bbox;32 }30 public void initBboxFilter(BBox bbox) { 31 this.bbox = bbox; 32 } 33 33 34 public void addGpxData(GpxData data) { 35 Collection<Collection<WayPoint>> currentTrack; 36 Collection<WayPoint> currentSegment; 37 for (GpxTrack track : data.tracks) { 38 //System.out.println("New track"); 39 currentTrack = new ArrayList<Collection<WayPoint>>(); 40 for (GpxTrackSegment segment : track.getSegments()) { 41 //System.out.println("New segment"); 42 currentSegment = new ArrayList<WayPoint>(); 43 for (WayPoint wp : segment.getWayPoints()) { 44 //System.out.println("Point " + String.valueOf(wp.getCoor().getX()) + ", " + String.valueOf(wp.getCoor().getY()) + " situaded in bbox? " + String.valueOf(bbox.bounds(wp.getCoor())) ); 45 if ( bbox.bounds(wp.getCoor()) ) { 46 currentSegment.add(wp); 47 } else { 48 if (currentSegment.size() > 1) { 49 currentTrack.add(currentSegment); 50 currentSegment = new ArrayList<WayPoint>(); 51 } 52 } 53 } 54 if (currentSegment.size() > 1) { 55 currentTrack.add(currentSegment); 56 currentSegment = new ArrayList<WayPoint>(); 57 } 58 } 59 this.data.tracks.add( new ImmutableGpxTrack( currentTrack, Collections.<String, Object>emptyMap()) ); 60 } 61 } 34 public void addGpxData(GpxData data) { 35 Collection<Collection<WayPoint>> currentTrack; 36 Collection<WayPoint> currentSegment; 37 for (GpxTrack track : data.tracks) { 38 currentTrack = new ArrayList<Collection<WayPoint>>(); 39 for (GpxTrackSegment segment : track.getSegments()) { 40 currentSegment = new ArrayList<WayPoint>(); 41 for (WayPoint wp : segment.getWayPoints()) { 42 if ( bbox.bounds(wp.getCoor()) ) { 43 currentSegment.add(wp); 44 } else { 45 if (currentSegment.size() > 1) { 46 currentTrack.add(currentSegment); 47 currentSegment = new ArrayList<WayPoint>(); 48 } 49 } 50 } 51 if (currentSegment.size() > 1) { 52 currentTrack.add(currentSegment); 53 currentSegment = new ArrayList<WayPoint>(); 54 } 55 } 56 this.data.tracks.add( new ImmutableGpxTrack( currentTrack, Collections.<String, Object>emptyMap()) ); 57 } 58 } 62 59 63 public GpxData getGpxData() {64 return data;65 }60 public GpxData getGpxData() { 61 return data; 62 } 66 63 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java
r29819 r30669 1 1 /* 2 2 * Loader.java 3 * 3 * 4 4 * Copyright 2011 Hind <foxhind@gmail.com> 5 * 5 * 6 6 */ 7 7 8 8 package CommandLine; 9 9 … … 14 14 import javax.xml.parsers.SAXParserFactory; 15 15 16 import org.openstreetmap.josm.Main; 16 17 import org.xml.sax.Attributes; 17 18 import org.xml.sax.SAXException; … … 20 21 21 22 public class Loader extends DefaultHandler { 22 privateString dirToScan;23 private String currentFile; // For debug XML-files24 private String currentTag;25 private Command currentCommand;26 private Parameter currentParameter;27 privateArrayList<Command> loadingCommands;23 private final String dirToScan; 24 private String currentFile; // For debug XML-files 25 private String currentTag; 26 private Command currentCommand; 27 private Parameter currentParameter; 28 private final ArrayList<Command> loadingCommands; 28 29 29 public Loader (String dir) {30 dirToScan = dir;31 currentTag = "";32 loadingCommands = new ArrayList<Command>();33 }30 public Loader (String dir) { 31 dirToScan = dir; 32 currentTag = ""; 33 loadingCommands = new ArrayList<Command>(); 34 } 34 35 35 public ArrayList<Command> load() { 36 try { 37 // Creating parser 38 SAXParserFactory spf = SAXParserFactory.newInstance(); 39 SAXParser sp = spf.newSAXParser(); 40 41 // Files loading 42 File path = new File(dirToScan + "/"); 43 String[] list; 44 list = path.list(); 45 for(int i = 0; i < list.length; i++) 46 if (list[i].endsWith(".xml")) { 47 currentFile = dirToScan + "/" + list[i]; 48 loadFile(sp, currentFile); 49 } 50 } 51 catch (Exception e) { 52 System.err.println(e); 53 } 54 return loadingCommands; 55 } 36 public ArrayList<Command> load() { 37 try { 38 // Creating parser 39 SAXParserFactory spf = SAXParserFactory.newInstance(); 40 SAXParser sp = spf.newSAXParser(); 56 41 57 private void loadFile(SAXParser parser, String fileName) { 58 try { 59 String a = new File(fileName).toURI().toString().replace("file:/", "file:///"); 60 System.out.println(a); 61 parser.parse(a, this); 62 } 63 catch (Exception e) { 64 System.err.println(e); 65 } 66 // TODO: Create links for each argument 67 } 42 // Files loading 43 File path = new File(dirToScan + "/"); 44 String[] list; 45 list = path.list(); 46 for(int i = 0; i < list.length; i++) 47 if (list[i].endsWith(".xml")) { 48 currentFile = dirToScan + "/" + list[i]; 49 loadFile(sp, currentFile); 50 } 51 } 52 catch (Exception e) { 53 System.err.println(e); 54 } 55 return loadingCommands; 56 } 68 57 69 @Override 70 public void startElement(String namespaceURI, String localName, String rawName, Attributes attrs) { 71 int len = attrs.getLength(); 72 String Name, Value; 73 currentTag = rawName; 58 private void loadFile(SAXParser parser, String fileName) { 59 try { 60 String a = new File(fileName).toURI().toString().replace("file:/", "file:///"); 61 Main.info(a); 62 parser.parse(a, this); 63 } 64 catch (Exception e) { 65 Main.error(e); 66 } 67 // TODO: Create links for each argument 68 } 74 69 75 if (rawName.equals("command")) { 76 currentCommand = new Command(); 77 for (int i = 0; i < len; i++) { 78 Name = attrs.getQName(i); 79 Value = attrs.getValue(i); 80 if (Name.equals("name")) 81 currentCommand.name = Value; 82 else if (Name.equals("run")) 83 currentCommand.run = Value; 84 else if (Name.equals("tracks")) { 85 if (Value.equals("bbox")) 86 currentCommand.tracks = true; 87 } else if (Name.equals("icon")) { 88 currentCommand.icon = Value; 89 } else if (Name.equals("asynchronous")) { 90 currentCommand.asynchronous = Value.equals("true") ? true : false; 91 } 92 } 93 } 94 else if (rawName.equals("parameter")) { 95 currentParameter = new Parameter(); 96 for (int i = 0; i < len; i++) { 97 Name = attrs.getQName(i); 98 Value = attrs.getValue(i); 99 if (Name.equals("required")) { 100 currentParameter.required = Value.equals("true") ? true : false; 101 } 102 else if (Name.equals("type")) { 103 if (Value.equals("node")) currentParameter.type = Type.NODE; 104 else if (Value.equals("way")) currentParameter.type = Type.WAY; 105 else if (Value.equals("relation")) currentParameter.type = Type.RELATION; 106 else if (Value.equals("point")) currentParameter.type = Type.POINT; 107 else if (Value.equals("length")) currentParameter.type = Type.LENGTH; 108 else if (Value.equals("natural")) currentParameter.type = Type.NATURAL; 109 else if (Value.equals("any")) currentParameter.type = Type.ANY; 110 else if (Value.equals("string")) currentParameter.type = Type.STRING; 111 else if (Value.equals("relay")) currentParameter.type = Type.RELAY; 112 else if (Value.equals("username")) currentParameter.type = Type.USERNAME; 113 else if (Value.equals("imageryurl")) currentParameter.type = Type.IMAGERYURL; 114 else if (Value.equals("imageryoffset")) currentParameter.type = Type.IMAGERYOFFSET; 115 } 116 else if (Name.equals("maxinstances")) { 117 currentParameter.maxInstances = Integer.parseInt(Value); 118 } 119 else if (Name.equals("maxvalue")) { 120 currentParameter.maxVal = Float.parseFloat(Value); 121 } 122 else if (Name.equals("minvalue")) { 123 currentParameter.minVal = Float.parseFloat(Value); 124 } 125 } 126 } 127 } 70 @Override 71 public void startElement(String namespaceURI, String localName, String rawName, Attributes attrs) { 72 int len = attrs.getLength(); 73 String Name, Value; 74 currentTag = rawName; 128 75 129 @Override 130 public void characters(char ch[], int start, int length) 131 { 132 String text = (new String(ch, start, length)).trim(); 133 if (currentParameter != null) { 134 if (currentTag.equals("name")) { 135 currentParameter.name = text; 136 } 137 else if (currentTag.equals("description")) { 138 currentParameter.description = text; 139 } 140 else if (currentTag.equals("value")) { 141 if (currentParameter.type == Type.RELAY) { 142 if (!(currentParameter.getRawValue() instanceof Relay)) 143 currentParameter.setValue(new Relay()); 144 ((Relay)(currentParameter.getRawValue())).addValue(text); 145 } 146 else { 147 currentParameter.setValue(text); 148 } 149 } 150 } 151 } 76 if (rawName.equals("command")) { 77 currentCommand = new Command(); 78 for (int i = 0; i < len; i++) { 79 Name = attrs.getQName(i); 80 Value = attrs.getValue(i); 81 if (Name.equals("name")) 82 currentCommand.name = Value; 83 else if (Name.equals("run")) 84 currentCommand.run = Value; 85 else if (Name.equals("tracks")) { 86 if (Value.equals("bbox")) 87 currentCommand.tracks = true; 88 } else if (Name.equals("icon")) { 89 currentCommand.icon = Value; 90 } else if (Name.equals("asynchronous")) { 91 currentCommand.asynchronous = Value.equals("true") ? true : false; 92 } 93 } 94 } 95 else if (rawName.equals("parameter")) { 96 currentParameter = new Parameter(); 97 for (int i = 0; i < len; i++) { 98 Name = attrs.getQName(i); 99 Value = attrs.getValue(i); 100 if (Name.equals("required")) { 101 currentParameter.required = Value.equals("true") ? true : false; 102 } 103 else if (Name.equals("type")) { 104 if (Value.equals("node")) currentParameter.type = Type.NODE; 105 else if (Value.equals("way")) currentParameter.type = Type.WAY; 106 else if (Value.equals("relation")) currentParameter.type = Type.RELATION; 107 else if (Value.equals("point")) currentParameter.type = Type.POINT; 108 else if (Value.equals("length")) currentParameter.type = Type.LENGTH; 109 else if (Value.equals("natural")) currentParameter.type = Type.NATURAL; 110 else if (Value.equals("any")) currentParameter.type = Type.ANY; 111 else if (Value.equals("string")) currentParameter.type = Type.STRING; 112 else if (Value.equals("relay")) currentParameter.type = Type.RELAY; 113 else if (Value.equals("username")) currentParameter.type = Type.USERNAME; 114 else if (Value.equals("imageryurl")) currentParameter.type = Type.IMAGERYURL; 115 else if (Value.equals("imageryoffset")) currentParameter.type = Type.IMAGERYOFFSET; 116 } 117 else if (Name.equals("maxinstances")) { 118 currentParameter.maxInstances = Integer.parseInt(Value); 119 } 120 else if (Name.equals("maxvalue")) { 121 currentParameter.maxVal = Float.parseFloat(Value); 122 } 123 else if (Name.equals("minvalue")) { 124 currentParameter.minVal = Float.parseFloat(Value); 125 } 126 } 127 } 128 } 152 129 153 public void endElement(String namespaceURI, String localName, String rawName) { 154 if (rawName.equals("command")) { 155 loadingCommands.add(currentCommand); 156 currentCommand = null; 157 } 158 else if (rawName.equals("parameter")) { 159 if(currentParameter.required) 160 currentCommand.parameters.add(currentParameter); 161 else 162 currentCommand.optParameters.add(currentParameter); 163 currentParameter = null; 164 } 165 else { 166 currentTag = ""; 167 } 168 } 130 @Override 131 public void characters(char ch[], int start, int length) 132 { 133 String text = (new String(ch, start, length)).trim(); 134 if (currentParameter != null) { 135 if (currentTag.equals("name")) { 136 currentParameter.name = text; 137 } 138 else if (currentTag.equals("description")) { 139 currentParameter.description = text; 140 } 141 else if (currentTag.equals("value")) { 142 if (currentParameter.type == Type.RELAY) { 143 if (!(currentParameter.getRawValue() instanceof Relay)) 144 currentParameter.setValue(new Relay()); 145 ((Relay)(currentParameter.getRawValue())).addValue(text); 146 } 147 else { 148 currentParameter.setValue(text); 149 } 150 } 151 } 152 } 169 153 170 @Override 171 public void warning(SAXParseException ex) { 172 System.err.println("Warning in command xml file " + currentFile + ": " + ex.getMessage()); 173 } 154 @Override 155 public void endElement(String namespaceURI, String localName, String rawName) { 156 if (rawName.equals("command")) { 157 loadingCommands.add(currentCommand); 158 currentCommand = null; 159 } 160 else if (rawName.equals("parameter")) { 161 if(currentParameter.required) 162 currentCommand.parameters.add(currentParameter); 163 else 164 currentCommand.optParameters.add(currentParameter); 165 currentParameter = null; 166 } 167 else { 168 currentTag = ""; 169 } 170 } 174 171 175 @Override176 public voiderror(SAXParseException ex) {177 System.err.println("Errorin command xml file " + currentFile + ": " + ex.getMessage());178 }172 @Override 173 public void warning(SAXParseException ex) { 174 System.err.println("Warning in command xml file " + currentFile + ": " + ex.getMessage()); 175 } 179 176 180 @Override 181 public void fatalError(SAXParseException ex) throws SAXException { 182 System.err.println("Error in command xml file " + currentFile + ": " + ex.getMessage()); 183 throw ex; 184 } 177 @Override 178 public void error(SAXParseException ex) { 179 System.err.println("Error in command xml file " + currentFile + ": " + ex.getMessage()); 180 } 181 182 @Override 183 public void fatalError(SAXParseException ex) throws SAXException { 184 System.err.println("Error in command xml file " + currentFile + ": " + ex.getMessage()); 185 throw ex; 186 } 185 187 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java
r30523 r30669 135 135 currentPrimitive = n; 136 136 externalIdMap.put(source.getPrimitiveId(), n); 137 //System.out.println("NODE " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(n.getUniqueId()) );138 137 } 139 138 else if (qName.equals("way")) { … … 153 152 currentWayNodes.clear(); 154 153 externalIdMap.put(source.getPrimitiveId(), w); 155 //System.out.println("WAY " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(w.getUniqueId()) );156 154 } 157 155 else if (qName.equals("nd")) { … … 161 159 if (id == 0) 162 160 throwException(tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", id) ); 163 //System.out.println("NODE " + String.valueOf(id) + " HAS ADDED TO WAY " + String.valueOf(currentPrimitive.getUniqueId()));164 161 Node node = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE)); 165 162 if (node == null || node.isModified()) { … … 188 185 currentRelationMembers.clear(); 189 186 externalIdMap.put(source.getPrimitiveId(), r); 190 //System.out.println("RELATION " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(r.getUniqueId()) );191 187 } 192 188 else if (qName.equals("member")) { … … 211 207 String role = atts.getValue("role"); 212 208 213 //System.out.println("MEMBER " + value.toUpperCase() + " " +String.valueOf(id) + " HAS ADDED TO RELATION " + String.valueOf(currentPrimitive.getUniqueId()));214 209 OsmPrimitive member = externalIdMap.get(new SimplePrimitiveId(id, type)); 215 210 if (member == null) { … … 233 228 } 234 229 else { 235 System.out.println(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName));230 Main.warn(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName)); 236 231 } 237 232 } … … 248 243 } 249 244 else if (currentPrimitive.isModified()) { 250 //System.out.println(String.valueOf(currentPrimitive.getUniqueId()) + " IS MODIFIED BY SCRIPT");251 245 cmds.add(new ChangeCommand(Main.main.getEditLayer(), targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 252 246 } … … 393 387 } catch(NumberFormatException e) { 394 388 if (current.getUniqueId() <= 0) { 395 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId()));389 Main.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId())); 396 390 current.setChangesetId(0); 397 391 } else { … … 401 395 if (current.getChangesetId() <=0) { 402 396 if (current.getUniqueId() <= 0) { 403 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId()));397 Main.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId())); 404 398 current.setChangesetId(0); 405 399 } else { -
applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java
r29769 r30669 1 1 /* 2 2 * PointAction.java 3 * 3 * 4 4 * Copyright 2011 Hind <foxhind@gmail.com> 5 * 5 * 6 6 */ 7 7 … … 31 31 32 32 public class PointAction extends MapMode implements AWTEventListener { 33 privateCommandLine parentPlugin;34 final private Cursor cursorCrosshair;35 final private Cursor cursorJoinNode;36 private Cursor currentCursor;37 private Point mousePos;38 private Node nearestNode;39 privateArrayList<String> pointList;40 private boolean isCtrlDown;41 42 public PointAction(MapFrame mapFrame, CommandLine parentPlugin) {43 super(null, "addsegment.png", null, mapFrame, ImageProvider.getCursor("crosshair", null));44 this.parentPlugin = parentPlugin;45 cursorCrosshair = ImageProvider.getCursor("crosshair", null);46 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode");47 currentCursor = cursorCrosshair;48 nearestNode = null;49 pointList = new ArrayList<String>();50 }51 52 @Override public void enterMode() {53 super.enterMode();54 if (getCurrentDataSet() == null) {55 Main.map.selectSelectTool(false);56 return;57 }58 currentCursor = cursorCrosshair;59 Main.map.mapView.addMouseListener(this);60 Main.map.mapView.addMouseMotionListener(this);61 try {62 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);63 } catch (SecurityException ex) {64 }65 }66 67 @Override public void exitMode() {68 super.exitMode();69 Main.map.mapView.removeMouseListener(this);70 Main.map.mapView.removeMouseMotionListener(this);71 try {72 Toolkit.getDefaultToolkit().removeAWTEventListener(this);73 } catch (SecurityException ex) {74 }75 }76 77 @Override public void mousePressed(MouseEvent e) {78 if (e.getButton() == MouseEvent.BUTTON1) {79 if (isCtrlDown) {80 if (pointList.size() > 0) {81 pointList.remove(pointList.size() - 1);82 updateTextEdit();83 }84 }85 else {86 LatLon coor;87 if (nearestNode == null)88 coor = Main.map.mapView.getLatLon(e.getX(), e.getY());89 else90 coor = nearestNode.getCoor();91 if (coor.isOutSideWorld()) {92 JOptionPane.showMessageDialog(Main.parent,tr("Can not draw outside of the world."));93 return;94 }95 String point = String.valueOf(coor.getX()) + "," + String.valueOf(coor.getY());96 int maxInstances = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum).maxInstances;97 if (maxInstances == 1) {98 parentPlugin.loadParameter(point, true);99 exitMode();100 }101 else {102 if (pointList.size() < maxInstances || maxInstances == 0) {103 pointList.add(point);104 updateTextEdit();105 }106 else107 System.out.println("Maximum instances!");108 }109 }110 }111 }112 113 @Override114 public void mouseMoved(MouseEvent e) {115 if (!Main.map.mapView.isActiveLayerDrawable())116 return;117 processMouseEvent(e);118 updCursor();119 Main.map.mapView.repaint();120 }121 122 @Override123 public void eventDispatched(AWTEvent arg0) {124 if (!(arg0 instanceof KeyEvent))125 return;126 KeyEvent ev = (KeyEvent) arg0;127 isCtrlDown = (ev.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0;128 if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) {129 ev.consume();130 cancelDrawing();131 }132 }133 134 private void updCursor() {135 if (mousePos != null) {136 if (!Main.isDisplayingMapView())137 return;138 nearestNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate);139 if (nearestNode != null) {140 setCursor(cursorJoinNode);141 }142 else {143 setCursor(cursorCrosshair);144 }145 }146 }147 148 private void processMouseEvent(MouseEvent e) {149 if (e != null) {150 mousePos = e.getPoint();151 }152 }153 154 private void setCursor(final Cursor c) {155 if (currentCursor.equals(c))156 return;157 try {158 // We invoke this to prevent strange things from happening159 EventQueue.invokeLater(new Runnable() {160 @Override161 public void run() {162 // Don't change cursor when mode has changed already163 if (!(Main.map.mapMode instanceof PointAction))164 return;165 Main.map.mapView.setCursor(c);166 }167 });168 currentCursor = c;169 } catch (Exception e) {170 }171 }172 173 public void cancelDrawing() {174 if (Main.map == null || Main.map.mapView == null)175 return;176 Main.map.statusLine.setHeading(-1);177 Main.map.statusLine.setAngle(-1);178 Main.map.mapView.repaint();179 updateStatusLine();180 parentPlugin.abortInput();181 }182 183 public String currentValue() {184 String out = "";185 boolean first = true;186 for (String point : pointList) {187 if (!first)188 out += ";";189 out += point;190 first = false;191 }192 return out;193 }194 195 private void updateTextEdit() {196 Parameter currentParameter = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum);197 String prefix = tr(currentParameter.description);198 prefix += parentPlugin.commandSymbol;199 String value = currentValue();200 parentPlugin.textField.setText(prefix + value);201 }33 private final CommandLine parentPlugin; 34 final private Cursor cursorCrosshair; 35 final private Cursor cursorJoinNode; 36 private Cursor currentCursor; 37 private Point mousePos; 38 private Node nearestNode; 39 private final ArrayList<String> pointList; 40 private boolean isCtrlDown; 41 42 public PointAction(MapFrame mapFrame, CommandLine parentPlugin) { 43 super(null, "addsegment.png", null, mapFrame, ImageProvider.getCursor("crosshair", null)); 44 this.parentPlugin = parentPlugin; 45 cursorCrosshair = ImageProvider.getCursor("crosshair", null); 46 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); 47 currentCursor = cursorCrosshair; 48 nearestNode = null; 49 pointList = new ArrayList<String>(); 50 } 51 52 @Override public void enterMode() { 53 super.enterMode(); 54 if (getCurrentDataSet() == null) { 55 Main.map.selectSelectTool(false); 56 return; 57 } 58 currentCursor = cursorCrosshair; 59 Main.map.mapView.addMouseListener(this); 60 Main.map.mapView.addMouseMotionListener(this); 61 try { 62 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 63 } catch (SecurityException ex) { 64 } 65 } 66 67 @Override public void exitMode() { 68 super.exitMode(); 69 Main.map.mapView.removeMouseListener(this); 70 Main.map.mapView.removeMouseMotionListener(this); 71 try { 72 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 73 } catch (SecurityException ex) { 74 } 75 } 76 77 @Override public void mousePressed(MouseEvent e) { 78 if (e.getButton() == MouseEvent.BUTTON1) { 79 if (isCtrlDown) { 80 if (pointList.size() > 0) { 81 pointList.remove(pointList.size() - 1); 82 updateTextEdit(); 83 } 84 } 85 else { 86 LatLon coor; 87 if (nearestNode == null) 88 coor = Main.map.mapView.getLatLon(e.getX(), e.getY()); 89 else 90 coor = nearestNode.getCoor(); 91 if (coor.isOutSideWorld()) { 92 JOptionPane.showMessageDialog(Main.parent,tr("Can not draw outside of the world.")); 93 return; 94 } 95 String point = String.valueOf(coor.getX()) + "," + String.valueOf(coor.getY()); 96 int maxInstances = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum).maxInstances; 97 if (maxInstances == 1) { 98 parentPlugin.loadParameter(point, true); 99 exitMode(); 100 } 101 else { 102 if (pointList.size() < maxInstances || maxInstances == 0) { 103 pointList.add(point); 104 updateTextEdit(); 105 } 106 else 107 Main.info("Maximum instances!"); 108 } 109 } 110 } 111 } 112 113 @Override 114 public void mouseMoved(MouseEvent e) { 115 if (!Main.map.mapView.isActiveLayerDrawable()) 116 return; 117 processMouseEvent(e); 118 updCursor(); 119 Main.map.mapView.repaint(); 120 } 121 122 @Override 123 public void eventDispatched(AWTEvent arg0) { 124 if (!(arg0 instanceof KeyEvent)) 125 return; 126 KeyEvent ev = (KeyEvent) arg0; 127 isCtrlDown = (ev.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0; 128 if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) { 129 ev.consume(); 130 cancelDrawing(); 131 } 132 } 133 134 private void updCursor() { 135 if (mousePos != null) { 136 if (!Main.isDisplayingMapView()) 137 return; 138 nearestNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate); 139 if (nearestNode != null) { 140 setCursor(cursorJoinNode); 141 } 142 else { 143 setCursor(cursorCrosshair); 144 } 145 } 146 } 147 148 private void processMouseEvent(MouseEvent e) { 149 if (e != null) { 150 mousePos = e.getPoint(); 151 } 152 } 153 154 private void setCursor(final Cursor c) { 155 if (currentCursor.equals(c)) 156 return; 157 try { 158 // We invoke this to prevent strange things from happening 159 EventQueue.invokeLater(new Runnable() { 160 @Override 161 public void run() { 162 // Don't change cursor when mode has changed already 163 if (!(Main.map.mapMode instanceof PointAction)) 164 return; 165 Main.map.mapView.setCursor(c); 166 } 167 }); 168 currentCursor = c; 169 } catch (Exception e) { 170 } 171 } 172 173 public void cancelDrawing() { 174 if (Main.map == null || Main.map.mapView == null) 175 return; 176 Main.map.statusLine.setHeading(-1); 177 Main.map.statusLine.setAngle(-1); 178 Main.map.mapView.repaint(); 179 updateStatusLine(); 180 parentPlugin.abortInput(); 181 } 182 183 public String currentValue() { 184 String out = ""; 185 boolean first = true; 186 for (String point : pointList) { 187 if (!first) 188 out += ";"; 189 out += point; 190 first = false; 191 } 192 return out; 193 } 194 195 private void updateTextEdit() { 196 Parameter currentParameter = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum); 197 String prefix = tr(currentParameter.description); 198 prefix += parentPlugin.commandSymbol; 199 String value = currentValue(); 200 parentPlugin.textField.setText(prefix + value); 201 } 202 202 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java
r29769 r30669 1 1 /* 2 2 * WayAction.java 3 * 3 * 4 4 * Copyright 2011 Hind <foxhind@gmail.com> 5 * 5 * 6 6 */ 7 7 … … 25 25 26 26 public class WayAction extends MapMode implements AWTEventListener { 27 privateCommandLine parentPlugin;27 private final CommandLine parentPlugin; 28 28 final private Cursor cursorNormal, cursorActive; 29 29 private Cursor currentCursor; … … 33 33 // private Type type; 34 34 35 public WayAction(MapFrame mapFrame, CommandLine parentPlugin) {36 super(null, "addsegment.png", null, mapFrame, ImageProvider.getCursor("normal", "selection"));37 this.parentPlugin = parentPlugin;38 /* 35 public WayAction(MapFrame mapFrame, CommandLine parentPlugin) { 36 super(null, "addsegment.png", null, mapFrame, ImageProvider.getCursor("normal", "selection")); 37 this.parentPlugin = parentPlugin; 38 /* 39 39 this.type = type; 40 40 switch (type) { … … 48 48 break; 49 49 case WAY: 50 */ 51 cursorNormal = ImageProvider.getCursor("normal", "selection");52 cursorActive = ImageProvider.getCursor("normal", "joinway");53 /* 50 */ 51 cursorNormal = ImageProvider.getCursor("normal", "selection"); 52 cursorActive = ImageProvider.getCursor("normal", "joinway"); 53 /* 54 54 break; 55 55 default: … … 58 58 break; 59 59 } 60 */ 60 */ 61 61 currentCursor = cursorNormal; 62 62 nearestWay = null; 63 }63 } 64 64 65 @Override public void enterMode() {66 super.enterMode();65 @Override public void enterMode() { 66 super.enterMode(); 67 67 currentCursor = cursorNormal; 68 68 Main.map.mapView.addMouseListener(this); … … 72 72 } catch (SecurityException ex) { 73 73 } 74 }74 } 75 75 76 @Override public void exitMode() {77 super.exitMode();78 Main.map.mapView.removeMouseListener(this);76 @Override public void exitMode() { 77 super.exitMode(); 78 Main.map.mapView.removeMouseListener(this); 79 79 Main.map.mapView.removeMouseMotionListener(this); 80 80 try { … … 82 82 } catch (SecurityException ex) { 83 83 } 84 }84 } 85 85 86 86 @Override … … 100 100 processMouseEvent(e); 101 101 if (nearestWay != null) { 102 if (isCtrlDown) {103 Main.main.getCurrentDataSet().clearSelection(nearestWay);104 Main.map.mapView.repaint();105 }106 else {107 int maxInstances = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum).maxInstances;108 switch (maxInstances) {109 case 0:110 Main.main.getCurrentDataSet().addSelected(nearestWay);111 Main.map.mapView.repaint();112 break;113 case 1:114 Main.main.getCurrentDataSet().addSelected(nearestWay);115 Main.map.mapView.repaint();116 parentPlugin.loadParameter(nearestWay, true);117 exitMode();118 break;119 default:120 if (Main.main.getCurrentDataSet().getSelected().size() < maxInstances) {121 Main.main.getCurrentDataSet().addSelected(nearestWay);122 Main.map.mapView.repaint();123 }124 else125 System.out.println("Maximum instances!");126 }127 }128 }102 if (isCtrlDown) { 103 Main.main.getCurrentDataSet().clearSelection(nearestWay); 104 Main.map.mapView.repaint(); 105 } 106 else { 107 int maxInstances = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum).maxInstances; 108 switch (maxInstances) { 109 case 0: 110 Main.main.getCurrentDataSet().addSelected(nearestWay); 111 Main.map.mapView.repaint(); 112 break; 113 case 1: 114 Main.main.getCurrentDataSet().addSelected(nearestWay); 115 Main.map.mapView.repaint(); 116 parentPlugin.loadParameter(nearestWay, true); 117 exitMode(); 118 break; 119 default: 120 if (Main.main.getCurrentDataSet().getSelected().size() < maxInstances) { 121 Main.main.getCurrentDataSet().addSelected(nearestWay); 122 Main.map.mapView.repaint(); 123 } 124 else 125 Main.info("Maximum instances!"); 126 } 127 } 128 } 129 129 super.mousePressed(e); 130 130 } 131 131 132 @Override133 public void eventDispatched(AWTEvent arg0) {132 @Override 133 public void eventDispatched(AWTEvent arg0) { 134 134 if (!(arg0 instanceof KeyEvent)) 135 return;135 return; 136 136 KeyEvent ev = (KeyEvent) arg0; 137 137 isCtrlDown = (ev.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0; … … 145 145 if (mousePos != null) { 146 146 if (!Main.isDisplayingMapView()) 147 return;147 return; 148 148 nearestWay = Main.map.mapView.getNearestWay(mousePos, OsmPrimitive.isUsablePredicate); 149 149 if (nearestWay != null) {
Note:
See TracChangeset
for help on using the changeset viewer.
