Changeset 25044 in osm for applications


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

Icons with menu and panel support for CommandLine plugin

Location:
applications/editors/josm
Files:
1 added
5 edited

Legend:

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

    r25037 r25044  
    33
    44    <!-- enter the SVN commit message -->
    5     <property name="commit.message" value="Initial commit" />
     5    <property name="commit.message" value="Icons with menu and panel support" />
    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/Command.java

    r25038 r25044  
    22 *      Command.java
    33 *     
    4  *      Copyright 2010 Hind <foxhind@gmail.com>
     4 *      Copyright 2011 Hind <foxhind@gmail.com>
    55 *     
    66 */
     
    2222        public String name;                                             // Command name
    2323        public String run;                                              // Executable file with arguments ("nya.exe {arg1} {arg2} ... {argn}")
     24        public String icon;                                             // Icon file name
    2425        public ArrayList<Parameter> parameters; // Required parameters list
    2526        public ArrayList<Parameter> optParameters;      // Optional parameters list
     
    2728        public boolean tracks;
    2829       
    29         public Command () {     parameters = new ArrayList<Parameter>(); optParameters = new ArrayList<Parameter>(); currentParameterNum = 0; tracks = false; }
     30        public Command () {     parameters = new ArrayList<Parameter>(); optParameters = new ArrayList<Parameter>(); currentParameterNum = 0; tracks = false; icon = ""; }
    3031
    3132        public boolean loadObject(Object obj) {
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java

    r25038 r25044  
    22 *      CommandLine.java
    33 *     
    4  *      Copyright 2010 Hind <foxhind@gmail.com>
     4 *      Copyright 2011 Hind <foxhind@gmail.com>
    55 *     
    66 *      This program is free software; you can redistribute it and/or modify
     
    2222package CommandLine;
    2323
     24import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    2425import static org.openstreetmap.josm.tools.I18n.tr;
     26import static org.openstreetmap.josm.tools.I18n.marktr;
    2527
    2628import java.awt.BorderLayout;
     
    4345import java.util.regex.*;
    4446import javax.swing.JTextField;
     47import javax.swing.JMenu;
     48import javax.swing.JMenuItem;
    4549
    4650import org.openstreetmap.josm.Main;
     
    7680        private Mode mode;
    7781        private ArrayList<Command> commands;
     82        private JMenu commandMenu;
    7883        protected Command currentCommand;
    7984        protected String commandSymbol;
    80         private History history;
    81         private MapFrame currentMapFrame;
    82         private MapMode previousMode;
     85        protected History history;
     86        protected MapFrame currentMapFrame;
     87        protected MapMode previousMode;
    8388
    8489        public CommandLine(PluginInformation info) {
     
    104109                                                                Command command = findCommand(commandText, true);
    105110                                                                if (command != null) {
    106                                                                         currentCommand = command;
    107                                                                         currentCommand.resetLoading();
    108                                                                         parseSelection(Main.main.getCurrentDataSet().getSelected());
    109                                                                         previousMode = Main.map.mapMode;
    110                                                                         if (currentCommand.currentParameterNum < currentCommand.parameters.size())
    111                                                                                 setMode(Mode.SELECTION);
    112                                                                         else
    113                                                                                 runTool();
     111                                                                        startCommand(command);
    114112                                                                }
    115113                                                                else
     
    193191                };
    194192
    195                 MainMenu.add(Main.main.menu.toolsMenu, new CommandLineAction(this));
     193                if ( Main.main.menu != null ) {
     194                        commandMenu = Main.main.menu.addMenu(marktr("Commands") , KeyEvent.VK_C, Main.main.menu.defaultMenuPos, ht("/Plugin/CommandLine"));
     195                        MainMenu.add(Main.main.menu.toolsMenu, new CommandLineAction(this));
     196                }
    196197                loadCommands();
    197198                setMode(Mode.IDLE);
     199        }
     200
     201        public void startCommand(String commandName) {
     202                Command command = findCommand(commandName, true);
     203                if (command != null) {
     204                        startCommand(command);
     205                }
     206        }
     207
     208        protected void startCommand(Command command) {
     209                if (Main.map == null)
     210                        return;
     211                DataSet ds = Main.main.getCurrentDataSet();
     212                if (ds == null)
     213                        return;
     214                currentCommand = command;
     215                currentCommand.resetLoading();
     216                parseSelection(ds.getSelected());
     217                if (!(Main.map.mapMode instanceof AnyAction || Main.map.mapMode instanceof DummyAction || Main.map.mapMode instanceof LengthAction || Main.map.mapMode instanceof NodeAction || Main.map.mapMode instanceof PointAction || Main.map.mapMode instanceof RelationAction || Main.map.mapMode instanceof WayAction)) {
     218                        previousMode = Main.map.mapMode;
     219                }
     220                if (currentCommand.currentParameterNum < currentCommand.parameters.size())
     221                        setMode(Mode.SELECTION);
     222                else
     223                        runTool();
    198224        }
    199225
     
    209235                Loader loader = new Loader(getPluginDir());
    210236                commands = loader.load(); // lol
     237
     238                for (Command command : commands) {
     239                        commandMenu.add(new CommandAction(command, this));
     240                }
    211241        }
    212242
     
    227257        }
    228258       
    229         private void setMode(Mode targetMode) {
     259        protected void setMode(Mode targetMode) {
    230260                DataSet currentDataSet = Main.main.getCurrentDataSet();
    231261                if (currentDataSet != null) {
     
    295325        public void endInput() {
    296326                setMode(Mode.IDLE);
    297                 //System.out.print(String.valueOf());
    298327                Main.map.selectMapMode(previousMode);
    299328                Main.map.mapView.repaint();
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java

    r25038 r25044  
    22 *        Loader.java
    33 *       
    4  *        Copyright 2010 Hind <foxhind@gmail.com>
     4 *        Copyright 2011 Hind <foxhind@gmail.com>
    55 *       
    66 */
     
    7979                                else if (Name.equals("run"))
    8080                                        currentCommand.run = Value;
    81                                 else if (Name.equals("tracks"))
     81                                else if (Name.equals("tracks")) {
    8282                                        if (Value.equals("bbox"))
    8383                                                currentCommand.tracks = true;
     84                                }
     85                                else if (Name.equals("icon")) {
     86                                        currentCommand.icon = Value;
     87                                }
    8488                        }
    8589                }
Note: See TracChangeset for help on using the changeset viewer.