Changeset 151 in josm


Ignore:
Timestamp:
2006-10-07T00:14:05+02:00 (18 years ago)
Author:
imi
Message:
  • changed move action to move the object under cursor, not the selected one
  • fixed plugins under linux/mac
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • build.xml

    r147 r151  
    11<project name="openstreetmap" default="dist" basedir=".">
    22
    3         <property name="src" location="src" />
    4         <property name="po" location="po" />
    5         <property name="build" location="build" />
    6         <property name="dist" location="dist" />
    7         <property name="lib" location="lib" />
    8        
     3        <!-- All jar files necessary to run only JOSM (no tests) -->
     4        <fileset id="josm_required_libs" dir="lib">
     5                <include name="gettext-commons-0.9.jar"/>
     6                <include name="metadata-extractor-2.3.1.jar"/>
     7                <include name="MinML2.jar"/>
     8        </fileset>
     9
     10        <!-- Java classpath addition (all jar files to compile tests with this) -->
    911        <path id="classpath">
    10                 <fileset dir="${lib}">
     12                <fileset dir="lib">
    1113                        <include name="**/*.jar"/>
    1214                </fileset>
    1315        </path>
    1416
    15         <path id="srcfiles">
    16                 <fileset dir="${src}">
    17                         <include name="**/*.java"/>
    18                 </fileset>
    19         </path>
    20 
    21         <target name="init">
    22                 <mkdir dir="${build}" />
    23                 <mkdir dir="${dist}" />
    24         </target>
    25 
    26         <target name="compile" depends="init">
    27                 <javac srcdir="${src}" classpathref="classpath" destdir="${build}">
    28                         <include name="org/openstreetmap/josm/gui/MainApplication.java"/>
    29                         <include name="org/openstreetmap/josm/gui/MainApplet.java"/>
    30                         <include name="org/openstreetmap/josm/plugins/**/*.java"/>
    31                 </javac>
    32         </target>
    33 
    3417        <target name="dist" depends="compile">
    3518                <!-- jars -->
    36                 <unjar src="${lib}/MinML2.jar" dest="${build}" />
    37                 <unjar src="${lib}/gettext-commons-0.9.jar" dest="${build}" />
    38                 <unjar src="${lib}/metadata-extractor-2.3.1.jar" dest="${build}" />
     19                <unjar dest="build">
     20                        <fileset refid="josm_required_libs" />
     21                </unjar>
    3922
    4023                <!-- images -->
    41                 <copy todir="${build}/images">
     24                <copy todir="build/images">
    4225                        <fileset dir="images" />
    4326                </copy>
    44                 <copy todir="${build}/org/openstreetmap/josm">
    45                         <fileset dir="${po}/org/openstreetmap/josm" />
     27                <copy todir="build/org/openstreetmap/josm">
     28                        <fileset dir="po/org/openstreetmap/josm" />
    4629                </copy>
    47                 <jar destfile="${dist}/josm-custom.jar" basedir="${build}">
     30               
     31                <!-- create josm-custom.jar -->
     32                <jar destfile="dist/josm-custom.jar" basedir="build">
    4833                        <manifest>
    4934                                <attribute name="Main-class" value="org.openstreetmap.josm.gui.MainApplication" />
     
    5237        </target>
    5338
    54         <target name="clean">
    55                 <delete dir="${build}" />
    56                 <delete dir="${dist}" />
    57         </target>
    58 
    59 
    6039        <target name="gettext" depends="init">
    61         <exec executable="find" output="${build}/alljava.txt">
    62                 <arg line="${src} -name '*.java'"/>
     40        <exec executable="find" output="build/alljava.txt">
     41                <arg line="src -name '*.java'"/>
    6342        </exec>
    6443        <exec executable="xgettext">
    65                 <arg line="-ktr -ktrn:1,2 -ktrc -kmarktr -Ljava -o${po}/keys.pot -f${build}/alljava.txt"/>
     44                <arg line="-ktr -ktrn:1,2 -ktrc -kmarktr -Ljava -opo/keys.pot -fbuild/alljava.txt"/>
    6645        </exec>
    6746        <apply executable="msgmerge">
    6847                <arg value="-U"/>
    6948                        <srcfile/>
    70                 <arg file="${po}/keys.pot"/>
    71                 <fileset dir="${po}">
     49                <arg file="po/keys.pot"/>
     50                <fileset dir="po">
    7251                        <include name="*.po"/>
    7352                </fileset>
     
    7655        <!-- FIXME: somehow iterate the po-directory and create the java files -->
    7756        <exec executable="msgfmt">
    78                 <arg line="--java2 -d${po} -rorg.openstreetmap.josm.Translation -lde ${po}/de.po"/>
     57                <arg line="--java2 -dpo -rorg.openstreetmap.josm.Translation -lde po/de.po"/>
    7958        </exec>
    8059        <exec executable="msgfmt">
    81                 <arg line="--java2 -d${po} -rorg.openstreetmap.josm.Translation -lfr ${po}/fr.po"/>
     60                <arg line="--java2 -dpo -rorg.openstreetmap.josm.Translation -lfr po/fr.po"/>
    8261        </exec>
    8362        <exec executable="msgfmt">
    84                 <arg line="--java2 -d${po} -rorg.openstreetmap.josm.Translation -len_GB ${po}/en_GB.po"/>
     63                <arg line="--java2 -dpo -rorg.openstreetmap.josm.Translation -len_GB po/en_GB.po"/>
    8564        </exec>
    8665        <exec executable="msgfmt">
    87                 <arg line="--java2 -d${po} -rorg.openstreetmap.josm.Translation -lro ${po}/ro.po"/>
     66                <arg line="--java2 -dpo -rorg.openstreetmap.josm.Translation -lro po/ro.po"/>
    8867        </exec>
    8968    </target>
    9069
     70        <target name="compile" depends="init">
     71                <javac srcdir="src" classpathref="classpath" destdir="build" />
     72        </target>
     73
     74    <target name="compile-tests" depends="compile">
     75       
     76    </target>
     77
     78
     79        <target name="init">
     80                <mkdir dir="build" />
     81                <mkdir dir="dist" />
     82        </target>
     83
     84        <target name="clean">
     85                <delete dir="build" />
     86                <delete dir="dist" />
     87        </target>
     88
    9189</project>
  • src/org/openstreetmap/josm/actions/mapmode/MoveAction.java

    r113 r151  
    55import java.awt.Cursor;
    66import java.awt.Point;
     7import java.awt.Rectangle;
    78import java.awt.event.KeyEvent;
    89import java.awt.event.MouseEvent;
     
    1920import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor;
    2021import org.openstreetmap.josm.gui.MapFrame;
     22import org.openstreetmap.josm.gui.SelectionManager;
     23import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;
    2124import org.openstreetmap.josm.tools.ImageProvider;
    2225/**
    2326 * Move is an action that can move all kind of OsmPrimitives (except Keys for now).
    24  *
    25  * If any object is selected, all selected objects are moved. If no object is
    26  * selected, the nearest object will be selected and moved. In this case, the
    27  * object will be unselected as soon as movement stopped.
     27 *
     28 * If an selected object is under the mouse when dragging, move all selected objects.
     29 * If an unselected object is under the mouse when dragging, it becomes selected
     30 * and will be moved.
     31 * If no object is under the mouse, move all selected objects (if any)
    2832 *
    2933 * @author imi
    3034 */
    31 public class MoveAction extends MapMode {
     35public class MoveAction extends MapMode implements SelectionEnded {
    3236        /**
    3337         * The old cursor before the user pressed the mouse button.
     
    3842         */
    3943        private Point mousePos;
    40         /**
    41          * Non-<code>null</code>, if no object was selected before movement
    42          * (and so the object get unselected after mouse release).
    43          */
    44         private OsmPrimitive singleOsmPrimitive;
     44        private SelectionManager selectionManager;
     45        private boolean selectionMode = false;
    4546
    4647        /**
     
    5051        public MoveAction(MapFrame mapFrame) {
    5152                super(tr("Move"),
    52                                 "move", 
    53                                 tr("Move selected objects around."),
    54                                 KeyEvent.VK_M, 
    55                                 mapFrame, 
     53                                "move",
     54                                tr("Move around objects that are under the mouse or selected."),
     55                                KeyEvent.VK_M,
     56                                mapFrame,
    5657                                ImageProvider.getCursor("normal", "move"));
     58                selectionManager = new SelectionManager(this, false, mapFrame.mapView);
    5759        }
    5860
     
    6971        }
    7072
    71        
     73
    7274        /**
    7375         * If the left mouse button is pressed, move all currently selected
    74          * objects.
     76         * objects (if one of them is under the mouse) or the current one under the
     77         * mouse (which will become selected).
    7578         */
    7679        @Override public void mouseDragged(MouseEvent e) {
    7780                if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0)
    7881                        return;
     82
     83                if (selectionMode)
     84                        return;
    7985               
    80                 if (mousePos == null) {
     86                if (mousePos == null)
    8187                        mousePos = e.getPoint();
    82                         singleOsmPrimitive = null;
    83                 }
    8488
    85                 EastNorth mouseGeo = Main.map.mapView.getEastNorth(e.getX(), e.getY());
    86                 EastNorth mouseStartGeo = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y);
    87                 double dx = mouseGeo.east() - mouseStartGeo.east();
    88                 double dy = mouseGeo.north() - mouseStartGeo.north();
     89                EastNorth mouseEN = Main.map.mapView.getEastNorth(e.getX(), e.getY());
     90                EastNorth mouseStartEN = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y);
     91                double dx = mouseEN.east() - mouseStartEN.east();
     92                double dy = mouseEN.north() - mouseStartEN.north();
    8993                if (dx == 0 && dy == 0)
    9094                        return;
     
    9296                Collection<OsmPrimitive> selection = Main.ds.getSelected();
    9397                Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
    94                
     98
    9599                // check if any coordinate would be outside the world
    96100                for (OsmPrimitive osm : affectedNodes) {
     
    100104                        }
    101105                }
    102                
     106
    103107                Command c = !Main.main.editLayer().commands.isEmpty() ? Main.main.editLayer().commands.getLast() : null;
    104108                if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects))
     
    106110                else
    107111                        Main.main.editLayer().add(new MoveCommand(selection, dx, dy));
    108                
     112
    109113                Main.map.mapView.repaint();
    110114                mousePos = e.getPoint();
     
    124128                        return;
    125129
    126                 if (Main.ds.getSelected().size() == 0) {
    127                         OsmPrimitive osm = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
    128                         if (osm != null)
    129                                 Main.ds.setSelected(osm);
    130                         singleOsmPrimitive = osm;
    131                         Main.map.mapView.repaint();
    132                 } else
    133                         singleOsmPrimitive = null;
    134                
     130                Collection<OsmPrimitive> sel = Main.ds.getSelected();
     131                OsmPrimitive osm = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
     132                if (osm != null) {
     133                if (!sel.contains(osm))
     134                        Main.ds.setSelected(osm);
     135                oldCursor = Main.map.mapView.getCursor();
     136                Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
     137        } else {
     138                selectionMode = true;
     139                        selectionManager.register(Main.map.mapView);
     140        }
     141
     142                Main.map.mapView.repaint();
     143
    135144                mousePos = e.getPoint();
    136                 oldCursor = Main.map.mapView.getCursor();
    137                 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    138145        }
    139        
     146
    140147        /**
    141148         * Restore the old mouse cursor.
    142149         */
    143150        @Override public void mouseReleased(MouseEvent e) {
    144                 Main.map.mapView.setCursor(oldCursor);
    145                 if (singleOsmPrimitive != null) {
    146                         Main.ds.clearSelection();
    147                         Main.map.mapView.repaint();
    148                 }
     151                if (selectionMode) {
     152                        selectionManager.unregister(Main.map.mapView);
     153                        selectionMode = false;
     154                } else
     155                        Main.map.mapView.setCursor(oldCursor);
    149156        }
     157
     158       
     159        public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
     160                SelectionAction.selectEverythingInRectangle(selectionManager, r, alt, shift, ctrl);
     161    }
    150162}
  • src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java

    r118 r151  
    138138         */
    139139        public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
    140                 if (shift && ctrl)
     140                selectEverythingInRectangle(selectionManager, r, alt, shift, ctrl);
     141        }
     142
     143        public static void selectEverythingInRectangle(SelectionManager selectionManager, Rectangle r, boolean alt, boolean shift, boolean ctrl) {
     144            if (shift && ctrl)
    141145                        return; // not allowed together
    142146
     
    155159                Main.ds.setSelected(curSel);
    156160                Main.map.mapView.repaint();
    157         }
     161    }
    158162
    159163        @Override public void mouseDragged(MouseEvent e) {
  • src/org/openstreetmap/josm/plugins/PluginLoader.java

    r149 r151  
    4343                try {
    4444                        ClassLoader loader = URLClassLoader.newInstance(
    45                                         new URL[]{new URL("file:/"+pluginFile.getAbsolutePath())},
     45                                        new URL[]{new URL("file://"+pluginFile.getAbsolutePath())},
    4646                                        getClass().getClassLoader());
    4747                        Object plugin = Class.forName(pluginClass, true, loader).newInstance();
  • test/org/openstreetmap/josm/plugins/PluginLoaderTest.java

    r149 r151  
    22
    33import java.io.File;
    4 import java.lang.reflect.Field;
    54
    65import junit.framework.TestCase;
     
    2423                PluginProxy plugin = loader.loadPlugin(getClass().getName()+"$TestPlugin", new File("foo.jar"));
    2524                assertTrue(plugin.plugin instanceof TestPlugin);
    26                 Field nameField = Plugin.class.getDeclaredField("name");
    27                 nameField.setAccessible(true);
    28                 assertEquals("foo", nameField.get(plugin.plugin));
    2925        }
    3026       
Note: See TracChangeset for help on using the changeset viewer.