Ignore:
Timestamp:
2011-01-14T18:15:45+01:00 (13 years ago)
Author:
hind
Message:

New types: 'imageryurl', 'imageryoffset' and 'username'. Initial log support (last message field).

Location:
applications/editors/josm/plugins/CommandLine
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/CommandLine/build.xml

    r25044 r25052  
    33
    44    <!-- enter the SVN commit message -->
    5     <property name="commit.message" value="Icons with menu and panel support" />
     5    <property name="commit.message" value="New types imageryurl, imageryoffset and username" />
    66    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    77    <property name="plugin.main.version" value="3751" />
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java

    r25038 r25052  
    169169        Main.map.mapView.repaint();
    170170        updateStatusLine();
    171         parentPlugin.endInput();
     171        parentPlugin.abortInput();
    172172    }
    173173}
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/Command.java

    r25044 r25052  
    164164                                }
    165165                                break;
     166                        case USERNAME:
     167                                if (obj instanceof String) return true;
     168                                break;
     169                        case IMAGERYURL:
     170                                if (obj instanceof String) return true;
     171                                break;
     172                        case IMAGERYOFFSET:
     173                                if (obj instanceof String) return true;
     174                                break;
    166175                }
    167176                return false;
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java

    r25044 r25052  
    4747import javax.swing.JMenu;
    4848import javax.swing.JMenuItem;
     49import javax.swing.JToolBar;
    4950
    5051import org.openstreetmap.josm.Main;
     
    5253import org.openstreetmap.josm.command.MoveCommand;
    5354import org.openstreetmap.josm.command.SequenceCommand;
     55import org.openstreetmap.josm.data.gpx.GpxData;
     56import org.openstreetmap.josm.data.gpx.GpxTrack;
     57import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
     58import org.openstreetmap.josm.data.gpx.WayPoint;
     59import org.openstreetmap.josm.data.imagery.ImageryInfo;
     60import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    5461import org.openstreetmap.josm.data.osm.BBox;
    5562import org.openstreetmap.josm.data.osm.Node;
     
    5966import org.openstreetmap.josm.data.osm.DataSet;
    6067import org.openstreetmap.josm.data.osm.DataSetMerger;
    61 import org.openstreetmap.josm.data.gpx.GpxData;
    62 import org.openstreetmap.josm.data.gpx.GpxTrack;
    63 import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
    64 import org.openstreetmap.josm.data.gpx.WayPoint;
    6568import org.openstreetmap.josm.gui.layer.GpxLayer;
     69import org.openstreetmap.josm.gui.layer.ImageryLayer;
    6670import org.openstreetmap.josm.gui.layer.Layer;
    6771import org.openstreetmap.josm.gui.MainMenu;
     
    7781public class CommandLine extends Plugin {
    7882        protected JTextField textField;
     83        protected JTextField historyField;
    7984        private String prefix;
    8085        private Mode mode;
     
    9196                commandSymbol = ": ";
    9297                history = new History(100);
     98                historyField = new JTextField();
    9399                textField = new JTextField() {
    94100                        @Override
     
    226232        public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame)
    227233        {
    228                 if (oldFrame==null && newFrame!=null) {
     234                if (oldFrame == null && newFrame != null) {
    229235                        currentMapFrame = newFrame;
    230                         currentMapFrame.add(textField,BorderLayout.NORTH);
    231                 }
     236                        JToolBar tb = new JToolBar();
     237                        tb.setLayout(new BorderLayout());
     238                        tb.setFloatable(false);
     239                        tb.setOrientation(JToolBar.HORIZONTAL);
     240                        tb.add(historyField, BorderLayout.NORTH);
     241                        tb.add(textField, BorderLayout.SOUTH);
     242                        currentMapFrame.add(tb, BorderLayout.NORTH);
     243                        printHistory("Loaded CommandLine, version " + getPluginInformation().version);
     244                }
     245        }
     246
     247        protected void printHistory(String text) {
     248                historyField.setText(text);
    232249        }
    233250
    234251        private void loadCommands() {
    235                 Loader loader = new Loader(getPluginDir());
    236                 commands = loader.load(); // lol
    237 
     252                commands = (new Loader(getPluginDir())).load();
    238253                for (Command command : commands) {
    239254                        commandMenu.add(new CommandAction(command, this));
     
    272287                        mode = Mode.SELECTION;
    273288                        Parameter currentParameter = currentCommand.parameters.get(currentCommand.currentParameterNum);
    274                         prefix = tr(currentParameter.description);
     289                        prefix = tr(currentParameter.description == null ? currentParameter.name : currentParameter.description);
    275290                        if (currentParameter.getRawValue() instanceof Relay)
    276291                                prefix = prefix + " (" + ((Relay)(currentParameter.getRawValue())).getOptionsString() + ")";
     
    299314                                        action = new LengthAction(currentMapFrame, this);
    300315                                        break;
     316                                case USERNAME:
     317                                        loadParameter((Object)Main.pref.get("osm-server.username", null), true);
     318                                        action = new DummyAction(currentMapFrame, this);
     319                                        break;
     320                                case IMAGERYURL:
     321                                        Layer layer = Main.map.mapView.getActiveLayer();
     322                                        if (layer != null) {
     323                                                if (layer instanceof ImageryLayer) {
     324                                                }
     325                                                else {
     326                                                        List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class);
     327                                                        if (imageryLayers.size() == 1) {
     328                                                                layer = imageryLayers.get(0);
     329                                                        }
     330                                                        else {
     331                                                                endInput();
     332                                                                return;
     333                                                        }
     334                                                }
     335                                        }
     336                                        ImageryInfo info = ((ImageryLayer)layer).getInfo();
     337                                        String url = info.getURL();
     338                                        String itype = info.getImageryType().getUrlString();
     339                                        loadParameter((Object)(url.equals("") ? itype : url), true);
     340                                        action = new DummyAction(currentMapFrame, this);
     341                                        break;
     342                                case IMAGERYOFFSET:
     343                                        Layer olayer = Main.map.mapView.getActiveLayer();
     344                                        if (olayer != null) {
     345                                                if (olayer instanceof ImageryLayer) {
     346                                                }
     347                                                else {
     348                                                        List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class);
     349                                                        if (imageryLayers.size() == 1) {
     350                                                                olayer = imageryLayers.get(0);
     351                                                        }
     352                                                        else {
     353                                                                endInput();
     354                                                                return;
     355                                                        }
     356                                                }
     357                                        }
     358                                        loadParameter((Object)(String.valueOf(((ImageryLayer)olayer).getDx()) + "," + String.valueOf(((ImageryLayer)olayer).getDy())), true);
     359                                        action = new DummyAction(currentMapFrame, this);
     360                                        break;
    301361                                default:
    302362                                        action = new DummyAction(currentMapFrame, this);
     
    311371                        prefix = tr("Processing...");
    312372                        textField.setText(prefix);
     373                        Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    313374                }
    314375        }
     
    321382        public void deactivate() {
    322383                Main.map.mapView.requestFocus();
     384        }
     385
     386        public void abortInput() {
     387                printHistory(tr("Aborted") + ".");
     388                endInput();
    323389        }
    324390
     
    333399                        if (currentCommand.hasNextParameter()) {
    334400                                if (next) {
     401                                        Parameter currentParameter = currentCommand.parameters.get(currentCommand.currentParameterNum);
     402                                        String prefix = tr(currentParameter.description == null ? currentParameter.name : currentParameter.description);
     403                                        prefix += commandSymbol;
     404                                        String value = currentParameter.getValue();
     405                                        printHistory(prefix + value);
    335406                                        currentCommand.nextParameter();
    336407                                        setMode(Mode.SELECTION);
     
    360431                        currentCommand.resetLoading();
    361432                }
    362                 System.out.println("Selected before " + String.valueOf(currentCommand.currentParameterNum) + "\n");
     433                //System.out.println("Selected before " + String.valueOf(currentCommand.currentParameterNum) + "\n");
    363434        }
    364435
     
    371442        public void runTool() {
    372443                setMode(Mode.PROCESSING);
    373                 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    374444                String commandToRun = currentCommand.run;
    375445
     
    495565
    496566                // Read stdout stream
     567                final OsmToCmd osmToCmd = new OsmToCmd(this, Main.main.getCurrentDataSet());
    497568                Thread osmParseThread = new Thread(new Runnable() {
    498569                        public void run() {
     
    501572                                        HashMap<Long, Long> inexiDMap = new HashMap<Long, Long>();
    502573                                        final InputStream inputStream = tp.process.getInputStream();
    503                                         final List<org.openstreetmap.josm.command.Command> cmdlist = new OsmToCmd(Main.main.getCurrentDataSet(), inputStream).getCommandList();
    504                                         //OsmReaderMod.deleteInexiDMap();
     574                                        osmToCmd.parseStream(inputStream);
     575                                        final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList();
    505576                                        if (!cmdlist.isEmpty()) {
    506577                                                SequenceCommand cmd = new SequenceCommand(commandName, cmdlist);
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java

    r25038 r25052  
    5656        Main.map.mapView.repaint();
    5757        updateStatusLine();
    58         parentPlugin.endInput();
     58        parentPlugin.abortInput();
    5959    }
    6060}
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java

    r25038 r25052  
    101101                Main.map.statusLine.setAngle(-1);
    102102                updateStatusLine();
    103                 parentPlugin.endInput();
     103                parentPlugin.abortInput();
    104104        }
    105105
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java

    r25044 r25052  
    106106                                        else if (Value.equals("string")) currentParameter.type = Type.STRING;
    107107                                        else if (Value.equals("relay")) currentParameter.type = Type.RELAY;
     108                                        else if (Value.equals("username")) currentParameter.type = Type.USERNAME;
     109                                        else if (Value.equals("imageryurl")) currentParameter.type = Type.IMAGERYURL;
     110                                        else if (Value.equals("imageryoffset")) currentParameter.type = Type.IMAGERYOFFSET;
    108111                                }
    109112                                else if (Name.equals("maxinstances")) {
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java

    r25038 r25052  
    22 *      NodeAction.java
    33 *     
    4  *      Copyright 2010 Hind <foxhind@gmail.com>
     4 *      Copyright 2011 Hind <foxhind@gmail.com>
    55 *     
    66 */
     
    109109                                        }
    110110                                        else
    111                                                 System.out.println("Maximum instances!");
     111                                                parentPlugin.printHistory("Maximum instances is " + String.valueOf(maxInstances));
    112112                                }
    113113                        }
     
    170170        Main.map.mapView.repaint();
    171171        updateStatusLine();
    172         parentPlugin.endInput();
     172        parentPlugin.abortInput();
    173173    }
    174174}
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java

    r25038 r25052  
     1/*
     2 *        OsmToCmd.java
     3 *       
     4 *        Copyright 2011 Hind <foxhind@gmail.com>
     5 *       
     6 */
     7
    18package CommandLine;
    29
     
    1219import javax.xml.parsers.ParserConfigurationException;
    1320import javax.xml.parsers.SAXParserFactory;
     21import javax.xml.parsers.SAXParser;
    1422
    1523import org.openstreetmap.josm.Main;
     
    3240import org.xml.sax.SAXParseException;
    3341import org.xml.sax.helpers.DefaultHandler;
     42import org.xml.sax.ext.LexicalHandler;
    3443
    3544final class OsmToCmd {
     45        private CommandLine parentPlugin;
    3646        private final DataSet targetDataSet;
    3747        private final LinkedList<Command> cmds = new LinkedList<Command>();
    3848        private HashMap<PrimitiveId, OsmPrimitive> externalIdMap; // Maps external ids to internal primitives
    39        
    40         public OsmToCmd(DataSet targetDataSet, InputStream stream) throws IllegalDataException {
     49
     50        public OsmToCmd(CommandLine parentPlugin, DataSet targetDataSet) {
     51                this.parentPlugin = parentPlugin;
    4152                this.targetDataSet = targetDataSet;
    4253                externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>();
    43                 parseStream(stream);
    4454        }
    4555
    46         private void parseStream(InputStream stream) throws IllegalDataException {
     56        public void parseStream(InputStream stream) throws IllegalDataException {
    4757                try {
    4858                        InputSource inputSource = new InputSource(UTFInputStreamReader.create(stream, "UTF-8"));
    49                         SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new Parser());
     59                        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
     60                        Parser handler = new Parser();
     61                        parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
     62                        parser.parse(inputSource, handler);
    5063                } catch(ParserConfigurationException e) {
    5164                        throw new IllegalDataException(e.getMessage(), e);
     
    6376        }
    6477       
    65         private class Parser extends DefaultHandler {
     78        private class Parser extends DefaultHandler implements LexicalHandler {
    6679                private Locator locator;
    6780               
     
    259272                }
    260273
     274                @Override
     275                public void comment(char[] ch, int start, int length) {
     276                        parentPlugin.printHistory(String.valueOf(ch));
     277                }
     278               
     279                public void startCDATA() {
     280                }
     281               
     282                public void endCDATA() {
     283                }
     284               
     285                public void startEntity(String name) {
     286                }
     287               
     288                public void endEntity(String name) {
     289                }
     290               
     291                public void startDTD(String name, String publicId, String systemId) {
     292                }
     293               
     294                public void endDTD() {
     295                }
     296               
    261297                private double getDouble(Attributes atts, String value) {
    262298                        return Double.parseDouble(atts.getValue(value));
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/Parameter.java

    r25038 r25052  
    22 *      Parameter.java
    33 *     
    4  *      Copyright 2010 Hind <foxhind@gmail.com>
     4 *      Copyright 2011 Hind <foxhind@gmail.com>
    55 *     
    66 */
    77 
    88package CommandLine;
     9
     10import static org.openstreetmap.josm.tools.I18n.tr;
    911
    1012import java.util.ArrayList;
     
    1517import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1618import org.openstreetmap.josm.data.osm.Way;
     19import org.openstreetmap.josm.data.osm.Relation;
    1720
    1821public class Parameter {
     
    4144                                break;
    4245                        case STRING:
    43                                 out = "\"" + String.valueOf(value) + "\"";
     46                                out = String.valueOf(value);
    4447                                break;
    4548                        case RELAY:
    4649                                out = String.valueOf(((Relay)value).getValue());
     50                                break;
     51                        case NODE:
     52                                out = String.valueOf(valueList.size()) + " " + tr("nodes");
     53                                break;
     54                        case WAY:
     55                                out = String.valueOf(valueList.size()) + " " + tr("ways");
     56                                break;
     57                        case RELATION:
     58                                out = String.valueOf(valueList.size()) + " " + tr("relations");
     59                                break;
     60                        case ANY:
     61                                out = String.valueOf(valueList.size()) + " " + tr("OSM objects");
     62                                break;
     63                        case USERNAME:
     64                                out = String.valueOf(value);
     65                                break;
     66                        case IMAGERYURL:
     67                                out = String.valueOf(value);
     68                                break;
     69                        case IMAGERYOFFSET:
     70                                out = String.valueOf(value);
    4771                                break;
    4872                }
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java

    r25038 r25052  
    22 *        PointAction.java
    33 *       
    4  *        Copyright 2010 Hind <foxhind@gmail.com>
     4 *        Copyright 2011 Hind <foxhind@gmail.com>
    55 *       
    66 */
     
    178178                Main.map.mapView.repaint();
    179179                updateStatusLine();
    180                 parentPlugin.endInput();
     180                parentPlugin.abortInput();
    181181        }
    182182
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java

    r25038 r25052  
    22 *      RelationAction.java
    33 *     
    4  *      Copyright 2010 Hind <foxhind@gmail.com>
     4 *      Copyright 2011 Hind <foxhind@gmail.com>
    55 *     
    66 */
     
    5656        Main.map.mapView.repaint();
    5757        updateStatusLine();
    58         parentPlugin.endInput();
     58        parentPlugin.abortInput();
    5959    }
    6060}
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/Type.java

    r25038 r25052  
    1919package CommandLine;
    2020
    21 public enum Type { NODE, WAY, RELATION, ANY, POINT, LENGTH, NATURAL, STRING, TRIGGER, RELAY }
     21public enum Type { NODE, WAY, RELATION, ANY, POINT, LENGTH, NATURAL, STRING, TRIGGER, RELAY, USERNAME, IMAGERYURL, IMAGERYOFFSET }
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java

    r25038 r25052  
    22 *      WayAction.java
    33 *     
    4  *      Copyright 2010 Hind <foxhind@gmail.com>
     4 *      Copyright 2011 Hind <foxhind@gmail.com>
    55 *     
    66 */
     
    191191        Main.map.mapView.repaint();
    192192        updateStatusLine();
    193         parentPlugin.endInput();
     193        parentPlugin.abortInput();
    194194    }
    195195}
Note: See TracChangeset for help on using the changeset viewer.