Changeset 30669 in osm


Ignore:
Timestamp:
2014-09-23T11:27:10+02:00 (10 years ago)
Author:
donvip
Message:

[josm_commandline] replace calls to System.out/err to Main.info/warn/error

Location:
applications/editors/josm/plugins/CommandLine/src/CommandLine
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java

    r29769 r30669  
    11/*
    22 *      AnyAction.java
    3  *     
     3 *
    44 *      Copyright 2010 Hind <foxhind@gmail.com>
    5  *     
     5 *
    66 */
    77
     
    2424
    2525public class AnyAction extends MapMode implements AWTEventListener {
    26         private CommandLine parentPlugin;
     26    private final CommandLine parentPlugin;
    2727    final private Cursor cursorNormal, cursorActive;
    2828    private Cursor currentCursor;
     
    3131    private boolean isCtrlDown;
    3232
    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");
    3838        currentCursor = cursorNormal;
    3939        nearestPrimitive = null;
    40         }
     40    }
    4141
    42         @Override public void enterMode() {
    43                 super.enterMode();
     42    @Override public void enterMode() {
     43        super.enterMode();
    4444        currentCursor = cursorNormal;
    4545        Main.map.mapView.addMouseListener(this);
     
    4949        } catch (SecurityException ex) {
    5050        }
    51         }
     51    }
    5252
    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);
    5656        Main.map.mapView.removeMouseMotionListener(this);
    5757        try {
     
    5959        } catch (SecurityException ex) {
    6060        }
    61         }
     61    }
    6262
    6363    @Override
     
    7777        processMouseEvent(e);
    7878        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                                         else
    102                                                 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        }
    106106        super.mousePressed(e);
    107107    }
    108108
    109         @Override
    110         public void eventDispatched(AWTEvent arg0) {
     109    @Override
     110    public void eventDispatched(AWTEvent arg0) {
    111111        if (!(arg0 instanceof KeyEvent))
    112                 return;
     112            return;
    113113        KeyEvent ev = (KeyEvent) arg0;
    114114        isCtrlDown = (ev.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0;
     
    121121    private void updCursor() {
    122122        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        }
    133133    }
    134134
    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    }
    138138
    139139    private void setCursor(final Cursor c) {
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/Command.java

    r29854 r30669  
    11/*
    22 *      Command.java
    3  * 
     3 *
    44 *      Copyright 2011 Hind <foxhind@gmail.com>
    5  * 
     5 *
    66 */
    77
     
    3333    public boolean loadObject(Object obj) {
    3434        Parameter currentParameter = parameters.get(currentParameterNum);
    35         //System.out.println("Parameter " + String.valueOf(currentParameterNum) + " (" + currentParameter.name + ")");
    3635        if (currentParameter.maxInstances == 1) {
    37             //System.out.println("mI = 1");
    38             //System.out.println("Candidate: " + String.valueOf(obj));
    3936            if (isPair(obj, currentParameter)) {
    4037                currentParameter.setValue(obj);
    41                 //System.out.println("Accepted");
    4238                return true;
    4339            }
    4440        }
    4541        else {
    46             //System.out.println("mI = " + String.valueOf(currentParameter.maxInstances));
    4742            ArrayList<OsmPrimitive> multiValue = currentParameter.getValueList();
    4843            if (obj instanceof Collection) {
    4944                if ( ((Collection<?>)obj).size() > currentParameter.maxInstances && currentParameter.maxInstances != 0)
    5045                    return false;
    51                 //System.out.println("Candidate (selected) accepted");
    5246                multiValue.clear();
    5347                multiValue.addAll((Collection<OsmPrimitive>)obj);
     
    5650            else if (obj instanceof OsmPrimitive) {
    5751                if (multiValue.size() < currentParameter.maxInstances || currentParameter.maxInstances == 0) {
    58                     //System.out.println("Candidate: " + String.valueOf(obj));
    5952                    if (isPair(obj, currentParameter)) {
    6053                        multiValue.add((OsmPrimitive)obj);
    61                         //System.out.println("Accepted, added to list");
    6254                        return true;
    6355                    }
    6456                    else {
    6557                        if (nextParameter() && multiValue.size() > 0) {
    66                             //System.out.println("Not accepted but considering for next Parameter");
    6758                            return loadObject(obj);
    6859                        }
     
    7162                else {
    7263                    if (nextParameter()) {
    73                         //System.out.println("Not accepted but considering for next Parameter");
    7464                        return loadObject(obj);
    7565                    }
     
    7767            }
    7868            else if (obj instanceof String) {
    79                 //System.out.println("Candidate: " + (String)obj);
    8069                if (isPair(obj, currentParameter)) {
    8170                    currentParameter.setValue(obj);
    82                     //System.out.println("Accepted");
    8371                    return true;
    8472                }
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java

    r30668 r30669  
    223223
    224224    @Override
    225     public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame)
    226     {
     225    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    227226        currentMapFrame = newFrame;
    228227        if (oldFrame == null && newFrame != null) {
     
    411410        }
    412411        else {
    413             System.out.println("Invalid argument");
     412            Main.info("Invalid argument");
    414413            endInput();
    415414        }
     
    429428            currentCommand.resetLoading();
    430429        }
    431         //System.out.println("Selected before " + String.valueOf(currentCommand.currentParameterNum) + "\n");
    432430    }
    433431
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/GpxFilter.java

    r29505 r30669  
    11/*
    22 *      GpxFilter.java
    3  *     
     3 *
    44 *      Copyright 2011 Hind <foxhind@gmail.com>
    5  *     
     5 *
    66 */
    77
     
    2020
    2121public class GpxFilter {
    22         private BBox bbox;
    23         private GpxData data;
     22    private BBox bbox;
     23    private final GpxData data;
    2424
    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    }
    2929
    30         public void initBboxFilter(BBox bbox) {
    31                 this.bbox = bbox;
    32         }
     30    public void initBboxFilter(BBox bbox) {
     31        this.bbox = bbox;
     32    }
    3333
    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    }
    6259
    63         public GpxData getGpxData() {
    64                 return data;
    65         }
     60    public GpxData getGpxData() {
     61        return data;
     62    }
    6663}
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java

    r29819 r30669  
    11/*
    22 *        Loader.java
    3  *       
     3 *
    44 *        Copyright 2011 Hind <foxhind@gmail.com>
    5  *       
     5 *
    66 */
    7  
     7
    88package CommandLine;
    99
     
    1414import javax.xml.parsers.SAXParserFactory;
    1515
     16import org.openstreetmap.josm.Main;
    1617import org.xml.sax.Attributes;
    1718import org.xml.sax.SAXException;
     
    2021
    2122public class Loader extends DefaultHandler {
    22         private String dirToScan;
    23         private String currentFile; // For debug XML-files
    24         private String currentTag;
    25         private Command currentCommand;
    26         private Parameter currentParameter;
    27         private ArrayList<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;
    2829
    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    }
    3435
    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();
    5641
    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    }
    6857
    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    }
    7469
    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;
    12875
    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    }
    152129
    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    }
    169153
    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    }
    174171
    175         @Override
    176         public void error(SAXParseException ex) {
    177                 System.err.println("Error in 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    }
    179176
    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    }
    185187}
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java

    r30523 r30669  
    135135                    currentPrimitive = n;
    136136                    externalIdMap.put(source.getPrimitiveId(), n);
    137                     //System.out.println("NODE " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(n.getUniqueId()) );
    138137                }
    139138                else if (qName.equals("way")) {
     
    153152                    currentWayNodes.clear();
    154153                    externalIdMap.put(source.getPrimitiveId(), w);
    155                     //System.out.println("WAY " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(w.getUniqueId()) );
    156154                }
    157155                else if (qName.equals("nd")) {
     
    161159                    if (id == 0)
    162160                        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()));
    164161                    Node node = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE));
    165162                    if (node == null || node.isModified()) {
     
    188185                    currentRelationMembers.clear();
    189186                    externalIdMap.put(source.getPrimitiveId(), r);
    190                     //System.out.println("RELATION " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(r.getUniqueId()) );
    191187                }
    192188                else if (qName.equals("member")) {
     
    211207                    String role = atts.getValue("role");
    212208
    213                     //System.out.println("MEMBER " + value.toUpperCase() + " " +String.valueOf(id) + " HAS ADDED TO RELATION " + String.valueOf(currentPrimitive.getUniqueId()));
    214209                    OsmPrimitive member = externalIdMap.get(new SimplePrimitiveId(id, type));
    215210                    if (member == null) {
     
    233228                }
    234229                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));
    236231                }
    237232            }
     
    248243                }
    249244                else if (currentPrimitive.isModified()) {
    250                     //System.out.println(String.valueOf(currentPrimitive.getUniqueId()) + " IS MODIFIED BY SCRIPT");
    251245                    cmds.add(new ChangeCommand(Main.main.getEditLayer(), targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
    252246                }
     
    393387                } catch(NumberFormatException e) {
    394388                    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()));
    396390                        current.setChangesetId(0);
    397391                    } else {
     
    401395                if (current.getChangesetId() <=0) {
    402396                    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()));
    404398                        current.setChangesetId(0);
    405399                    } else {
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java

    r29769 r30669  
    11/*
    22 *        PointAction.java
    3  *       
     3 *
    44 *        Copyright 2011 Hind <foxhind@gmail.com>
    5  *       
     5 *
    66 */
    77
     
    3131
    3232public class PointAction extends MapMode implements AWTEventListener {
    33         private 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 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                                                 System.out.println("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         }
     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    }
    202202}
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java

    r29769 r30669  
    11/*
    22 *      WayAction.java
    3  *     
     3 *
    44 *      Copyright 2011 Hind <foxhind@gmail.com>
    5  *     
     5 *
    66 */
    77
     
    2525
    2626public class WayAction extends MapMode implements AWTEventListener {
    27         private CommandLine parentPlugin;
     27    private final CommandLine parentPlugin;
    2828    final private Cursor cursorNormal, cursorActive;
    2929    private Cursor currentCursor;
     
    3333    // private Type type;
    3434
    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        /*
    3939                this.type = type;
    4040                switch (type) {
     
    4848                                break;
    4949                        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        /*
    5454                                break;
    5555                        default:
     
    5858                                break;
    5959                }
    60 */
     60         */
    6161        currentCursor = cursorNormal;
    6262        nearestWay = null;
    63         }
     63    }
    6464
    65         @Override public void enterMode() {
    66                 super.enterMode();
     65    @Override public void enterMode() {
     66        super.enterMode();
    6767        currentCursor = cursorNormal;
    6868        Main.map.mapView.addMouseListener(this);
     
    7272        } catch (SecurityException ex) {
    7373        }
    74         }
     74    }
    7575
    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);
    7979        Main.map.mapView.removeMouseMotionListener(this);
    8080        try {
     
    8282        } catch (SecurityException ex) {
    8383        }
    84         }
     84    }
    8585
    8686    @Override
     
    100100        processMouseEvent(e);
    101101        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                                         else
    125                                                 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        }
    129129        super.mousePressed(e);
    130130    }
    131131
    132         @Override
    133         public void eventDispatched(AWTEvent arg0) {
     132    @Override
     133    public void eventDispatched(AWTEvent arg0) {
    134134        if (!(arg0 instanceof KeyEvent))
    135                 return;
     135            return;
    136136        KeyEvent ev = (KeyEvent) arg0;
    137137        isCtrlDown = (ev.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0;
     
    145145        if (mousePos != null) {
    146146            if (!Main.isDisplayingMapView())
    147                     return;
     147                return;
    148148            nearestWay = Main.map.mapView.getNearestWay(mousePos, OsmPrimitive.isUsablePredicate);
    149149            if (nearestWay != null) {
Note: See TracChangeset for help on using the changeset viewer.