Changeset 214 in josm for src/org


Ignore:
Timestamp:
2007-04-05T17:19:54+02:00 (17 years ago)
Author:
imi
Message:
  • fixed the confusing auto-zoom (moved to "View"-menu and made it one-time zoom)
  • added (incomplete) after named ways (now it's the same as unnamed ways)
Location:
src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r203 r214  
    55
    66import java.awt.event.ActionEvent;
    7 import java.awt.event.KeyEvent;
    87import java.util.Collection;
    98
    10 import javax.swing.AbstractAction;
    11 
    129import org.openstreetmap.josm.Main;
    13 import org.openstreetmap.josm.data.SelectionChangedListener;
    1410import org.openstreetmap.josm.data.coor.EastNorth;
    1511import org.openstreetmap.josm.data.coor.LatLon;
    1612import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1713import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    18 import org.openstreetmap.josm.gui.MapFrame;
    1914import org.openstreetmap.josm.gui.layer.Layer;
    20 import org.openstreetmap.josm.tools.ImageProvider;
    2115
    2216/**
     
    2418 * @author imi
    2519 */
    26 public class AutoScaleAction extends GroupAction {
     20public class AutoScaleAction extends JosmAction {
    2721
    28         private static final String[] modes = {
     22        public static final String[] modes = {
    2923                marktr("data"),
    3024                marktr("selection"),
     
    3226                marktr("conflict")
    3327        };
    34         private String mode = "data";
    35         private final MapFrame mapFrame;
     28        private final String mode;
    3629
    37         private class Action extends AbstractAction {
    38                 private final String mode;
    39                 public Action(String mode) {
    40                         super(tr("Auto Scale: {0}", tr(mode)), ImageProvider.get("dialogs/autoscale/"+mode));
    41                         String modeHelp = Character.toUpperCase(mode.charAt(0))+mode.substring(1);
    42                         putValue("help", "Action/AutoScale/"+modeHelp);
    43                         putValue(SHORT_DESCRIPTION, tr("Auto zoom the view (to {0}. Disabled if the view is moved)", tr(mode)));
    44                         this.mode = mode;
    45                 }
    46                 public void actionPerformed(ActionEvent e) {
    47                         AutoScaleAction.this.mode = mode;
    48                         if (mapFrame.mapView.isAutoScale())
    49                 mapFrame.mapView.recalculateCenterScale();
    50             else
    51                 mapFrame.mapView.setAutoScale(true);
    52                         putValue("active", true);
    53                 }
     30        public AutoScaleAction(String mode) {
     31                super(tr(mode), "dialogs/autoscale/"+mode, tr("Zoom the view to {0}."), 0, 0, true);
     32                String modeHelp = Character.toUpperCase(mode.charAt(0))+mode.substring(1);
     33                putValue("help", "Action/AutoScale/"+modeHelp);
     34                this.mode = mode;
    5435        }
    5536
    56         public AutoScaleAction(final MapFrame mapFrame) {
    57                 super(KeyEvent.VK_A, 0);
    58                 for (String mode : modes)
    59                         actions.add(new Action(mode));
    60                 setCurrent(0);
    61                 this.mapFrame = mapFrame;
    62                 Main.ds.listeners.add(new SelectionChangedListener(){
    63                         public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    64                                 if (mode.equals("selection"))
    65                                         mapFrame.mapView.recalculateCenterScale();
    66                         }
    67                 });
     37        public void actionPerformed(ActionEvent e) {
     38                if (Main.map != null)
     39                        Main.map.mapView.recalculateCenterScale(getBoundingBox());
     40                putValue("active", true);
    6841        }
    6942
    70         public BoundingXYVisitor getBoundingBox() {
     43        private BoundingXYVisitor getBoundingBox() {
    7144                BoundingXYVisitor v = new BoundingXYVisitor();
    7245                if (mode.equals("data")) {
    73                         for (Layer l : mapFrame.mapView.getAllLayers())
     46                        for (Layer l : Main.map.mapView.getAllLayers())
    7447                                l.visitBoundingBox(v);
    7548                } else if (mode.equals("layer"))
    76                         mapFrame.mapView.getActiveLayer().visitBoundingBox(v);
     49                        Main.map.mapView.getActiveLayer().visitBoundingBox(v);
    7750                else if (mode.equals("selection") || mode.equals("conflict")) {
    78                         Collection<OsmPrimitive> sel = mode.equals("selection") ? Main.ds.getSelected() : mapFrame.conflictDialog.conflicts.keySet();
     51                        Collection<OsmPrimitive> sel = mode.equals("selection") ? Main.ds.getSelected() : Main.map.conflictDialog.conflicts.keySet();
    7952                        for (OsmPrimitive osm : sel)
    8053                                osm.visit(v);
  • src/org/openstreetmap/josm/command/ConflictResolveCommand.java

    r114 r214  
    5555                                conflictDialog.conflicts.remove(k);
    5656                        conflictDialog.rebuildList();
    57                         Main.map.mapView.recalculateCenterScale(); // in case of auto-zoom
    5857                }
    5958        }
  • src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java

    r206 r214  
    8080                if (name == null) {
    8181                        AllNodesVisitor.getAllNodes(w.segments);
    82                         boolean incomplete = false;
    8382                        Set<Node> nodes = new HashSet<Node>();
    8483                        for (Segment ls : w.segments) {
     
    8685                                        nodes.add(ls.from);
    8786                                        nodes.add(ls.to);
    88                                 } else
    89                                         incomplete = true;
     87                                }
    9088                        }
    9189                        name = trn("{0} node", "{0} nodes", nodes.size(), nodes.size());
    92                         if (incomplete)
    93                                 name += " ("+tr("incomplete")+")";
    9490                }
     91                if (w.isIncomplete())
     92                        name += " ("+tr("incomplete")+")";
    9593                addId(w);
    9694                icon = ImageProvider.get("data", "way");
  • src/org/openstreetmap/josm/gui/MainMenu.java

    r213 r214  
    1111import org.openstreetmap.josm.actions.AlignInCircleAction;
    1212import org.openstreetmap.josm.actions.AlignInLineAction;
     13import org.openstreetmap.josm.actions.AutoScaleAction;
    1314import org.openstreetmap.josm.actions.CombineWayAction;
    1415import org.openstreetmap.josm.actions.DownloadAction;
     
    6566        public final Action about = new AboutAction();
    6667        public final DownloadIncompleteAction downloadIncomplete = new DownloadIncompleteAction();
    67 
     68       
    6869        public final JMenu layerMenu = new JMenu(tr("Layer"));
    6970        public final JMenu editMenu = new JMenu(tr("Edit"));
     71        public final JMenu viewMenu = new JMenu(tr("View"));
    7072        public final JMenu helpMenu = new JMenu(tr("Help"));
    7173        public final JMenu fileMenu = new JMenu(tr("Files"));
    7274        public final JMenu connectionMenu = new JMenu(tr("Connection"));
    7375        public final JMenu toolsMenu = new JMenu(tr("Tools"));
     76
     77        public final JMenu zoomToMenu = new JMenu(tr("Zoom To"));
    7478
    7579
     
    96100                editMenu.add(preferences);
    97101                add(editMenu);
     102               
     103                viewMenu.setMnemonic('V');
     104                viewMenu.setVisible(false);
     105                viewMenu.add(zoomToMenu);
     106                for (String mode : AutoScaleAction.modes)
     107                        zoomToMenu.add(new AutoScaleAction(mode));
     108                add(viewMenu);
    98109
    99110                toolsMenu.setMnemonic('T');
  • src/org/openstreetmap/josm/gui/MapFrame.java

    r208 r214  
    44import java.awt.Component;
    55import java.awt.Container;
    6 import java.awt.event.ActionEvent;
    7 import java.awt.event.ActionListener;
    8 import java.beans.PropertyChangeEvent;
    9 import java.beans.PropertyChangeListener;
    106
    117import javax.swing.AbstractButton;
     
    1713
    1814import org.openstreetmap.josm.Main;
    19 import org.openstreetmap.josm.actions.AutoScaleAction;
    2015import org.openstreetmap.josm.actions.mapmode.AddSegmentAction;
    2116import org.openstreetmap.josm.actions.mapmode.AddWayAction;
     
    8176                setLayout(new BorderLayout());
    8277
    83                 final AutoScaleAction autoScaleAction = new AutoScaleAction(this);
    84                 add(mapView = new MapView(autoScaleAction), BorderLayout.CENTER);
     78                add(mapView = new MapView(), BorderLayout.CENTER);
     79
     80                // show menu entry
     81                Main.main.menu.viewMenu.setVisible(true);
    8582
    8683                // toolbar
     
    9895                        toolGroup.add((AbstractButton)c);
    9996                toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
    100 
    101                 // autoScale
     97               
    10298                toolBarActions.addSeparator();
    103                 final IconToggleButton autoScaleButton = new IconToggleButton(autoScaleAction);
    104                 toolBarActions.add(autoScaleButton);
    105                 autoScaleButton.setText(null);
    106                 autoScaleButton.setSelected(mapView.isAutoScale());
    107                 autoScaleAction.putValue("active", true);
    108                 mapView.addPropertyChangeListener(new PropertyChangeListener(){
    109                         public void propertyChange(PropertyChangeEvent evt) {
    110                                 if (evt.getPropertyName().equals("autoScale")) {
    111                                         autoScaleAction.putValue("active", evt.getNewValue());
    112                                         autoScaleButton.setSelected((Boolean)evt.getNewValue());
    113                                 }
    114                         }
    115                 });
    116                 autoScaleButton.addActionListener(new ActionListener(){
    117                         public void actionPerformed(ActionEvent e) {
    118                                 if (!autoScaleButton.groupbutton)
    119                                         autoScaleButton.setSelected(true);
    120                         }
    121                 });
    122 
     99               
    123100                add(toggleDialogs, BorderLayout.EAST);
    124101                toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
     
    144121                        if (toolBarActions.getComponent(i) instanceof Destroyable)
    145122                                ((Destroyable)toolBarActions).destroy();
     123               
     124                // remove menu entries
     125                Main.main.menu.viewMenu.setVisible(false);
    146126    }
    147127
  • src/org/openstreetmap/josm/gui/MapView.java

    r206 r214  
    1616
    1717import org.openstreetmap.josm.Main;
    18 import org.openstreetmap.josm.actions.AutoScaleAction;
    1918import org.openstreetmap.josm.data.Bounds;
    2019import org.openstreetmap.josm.data.SelectionChangedListener;
     
    5554
    5655        /**
    57          * Whether to adjust the scale property on every resize.
    58          */
    59         private boolean autoScale = true;
    60 
    61         /**
    6256         * A list of all layers currently loaded.
    6357         */
     
    7670        private Collection<LayerChangeListener> listeners = new LinkedList<LayerChangeListener>();
    7771
    78         private final AutoScaleAction autoScaleAction;
    79 
    80 
    81         public MapView(AutoScaleAction autoScaleAction) {
    82                 this.autoScaleAction = autoScaleAction;
     72        public MapView() {
    8373                addComponentListener(new ComponentAdapter(){
    8474                        @Override public void componentResized(ComponentEvent e) {
    85                                 recalculateCenterScale();
     75                                recalculateCenterScale(null);
     76                                removeComponentListener(this);
    8677                        }
    8778                });
     79
    8880                new MapMover(this, true);
    8981
     
    113105                        if (editLayer != null) {
    114106                                editLayer.mergeFrom(layer);
    115                                 if (autoScale)
    116                                         recalculateCenterScale();
    117107                                repaint();
    118108                                return;
     
    204194
    205195        /**
    206          * @return Returns the autoScale.
    207          */
    208         public boolean isAutoScale() {
    209                 return autoScale;
    210         }
    211 
    212         /**
    213          * @param autoScale The autoScale to set.
    214          */
    215         public void setAutoScale(boolean autoScale) {
    216                 if (this.autoScale != autoScale) {
    217                         this.autoScale = autoScale;
    218                         firePropertyChange("autoScale", !autoScale, autoScale);
    219                         recalculateCenterScale();
    220                 }
    221         }
    222         /**
    223196         * Set the new dimension to the projection class. Also adjust the components
    224197         * scale, if in autoScale mode.
    225198         */
    226         public void recalculateCenterScale() {
    227                 if (autoScale) {
    228                         // -20 to leave some border
    229                         int w = getWidth()-20;
    230                         if (w < 20)
    231                                 w = 20;
    232                         int h = getHeight()-20;
    233                         if (h < 20)
    234                                 h = 20;
    235 
    236                         BoundingXYVisitor v = autoScaleAction.getBoundingBox();
    237 
    238                         boolean oldAutoScale = autoScale;
    239                         EastNorth oldCenter = center;
    240                         double oldScale = this.scale;
    241 
    242                         if (v.min == null || v.max == null || v.min.equals(v.max)) {
    243                                 // no bounds means whole world
    244                                 center = getProjection().latlon2eastNorth(new LatLon(0,0));
    245                                 EastNorth world = getProjection().latlon2eastNorth(new LatLon(Projection.MAX_LAT,Projection.MAX_LON));
    246                                 double scaleX = world.east()*2/w;
    247                                 double scaleY = world.north()*2/h;
    248                                 scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen
    249                         } else {
    250                                 center = new EastNorth(v.min.east()/2+v.max.east()/2, v.min.north()/2+v.max.north()/2);
    251                                 double scaleX = (v.max.east()-v.min.east())/w;
    252                                 double scaleY = (v.max.north()-v.min.north())/h;
    253                                 scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen
    254                         }
    255 
    256                         if (!center.equals(oldCenter))
    257                                 firePropertyChange("center", oldCenter, center);
    258                         if (oldAutoScale != autoScale)
    259                                 firePropertyChange("autoScale", oldAutoScale, autoScale);
    260                         if (oldScale != scale)
    261                                 firePropertyChange("scale", oldScale, scale);
    262                 }
     199        public void recalculateCenterScale(BoundingXYVisitor box) {
     200                // -20 to leave some border
     201                int w = getWidth()-20;
     202                if (w < 20)
     203                        w = 20;
     204                int h = getHeight()-20;
     205                if (h < 20)
     206                        h = 20;
     207
     208                EastNorth oldCenter = center;
     209                double oldScale = this.scale;
     210
     211                if (box == null || box.min == null || box.max == null || box.min.equals(box.max)) {
     212                        // no bounds means whole world
     213                        center = getProjection().latlon2eastNorth(new LatLon(0,0));
     214                        EastNorth world = getProjection().latlon2eastNorth(new LatLon(Projection.MAX_LAT,Projection.MAX_LON));
     215                        double scaleX = world.east()*2/w;
     216                        double scaleY = world.north()*2/h;
     217                        scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen
     218                } else {
     219                        center = new EastNorth(box.min.east()/2+box.max.east()/2, box.min.north()/2+box.max.north()/2);
     220                        double scaleX = (box.max.east()-box.min.east())/w;
     221                        double scaleY = (box.max.north()-box.min.north())/h;
     222                        scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen
     223                }
     224
     225                if (!center.equals(oldCenter))
     226                        firePropertyChange("center", oldCenter, center);
     227                if (oldScale != scale)
     228                        firePropertyChange("scale", oldScale, scale);
    263229                repaint();
    264230        }
     
    296262                Layer old = activeLayer;
    297263                activeLayer = layer;
    298                 if (old != layer) {
     264                if (old != layer)
    299265                        for (LayerChangeListener l : listeners)
    300266                                l.activeLayerChange(old, layer);
    301                         recalculateCenterScale();
    302                 }
    303267        }
    304268
     
    315279         */
    316280        @Override public void zoomTo(EastNorth newCenter, double scale) {
    317                 boolean oldAutoScale = autoScale;
    318281                EastNorth oldCenter = center;
    319282                double oldScale = this.scale;
    320                 autoScale = false;
    321 
    322283                super.zoomTo(newCenter, scale);
    323 
    324                 recalculateCenterScale();
    325 
    326284                if ((oldCenter == null && center != null) || !oldCenter.equals(center))
    327285                        firePropertyChange("center", oldCenter, center);
    328                 if (oldAutoScale != autoScale)
    329                         firePropertyChange("autoScale", oldAutoScale, autoScale);
    330286                if (oldScale != scale)
    331287                        firePropertyChange("scale", oldScale, scale);
Note: See TracChangeset for help on using the changeset viewer.