- Timestamp:
- 2007-04-05T17:19:54+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/AutoScaleAction.java
r203 r214 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.awt.event.KeyEvent;8 7 import java.util.Collection; 9 8 10 import javax.swing.AbstractAction;11 12 9 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.SelectionChangedListener;14 10 import org.openstreetmap.josm.data.coor.EastNorth; 15 11 import org.openstreetmap.josm.data.coor.LatLon; 16 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 13 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 18 import org.openstreetmap.josm.gui.MapFrame;19 14 import org.openstreetmap.josm.gui.layer.Layer; 20 import org.openstreetmap.josm.tools.ImageProvider;21 15 22 16 /** … … 24 18 * @author imi 25 19 */ 26 public class AutoScaleAction extends GroupAction {20 public class AutoScaleAction extends JosmAction { 27 21 28 p rivatestatic final String[] modes = {22 public static final String[] modes = { 29 23 marktr("data"), 30 24 marktr("selection"), … … 32 26 marktr("conflict") 33 27 }; 34 private String mode = "data"; 35 private final MapFrame mapFrame; 28 private final String mode; 36 29 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; 54 35 } 55 36 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); 68 41 } 69 42 70 p ublicBoundingXYVisitor getBoundingBox() {43 private BoundingXYVisitor getBoundingBox() { 71 44 BoundingXYVisitor v = new BoundingXYVisitor(); 72 45 if (mode.equals("data")) { 73 for (Layer l : mapFrame.mapView.getAllLayers())46 for (Layer l : Main.map.mapView.getAllLayers()) 74 47 l.visitBoundingBox(v); 75 48 } else if (mode.equals("layer")) 76 mapFrame.mapView.getActiveLayer().visitBoundingBox(v);49 Main.map.mapView.getActiveLayer().visitBoundingBox(v); 77 50 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(); 79 52 for (OsmPrimitive osm : sel) 80 53 osm.visit(v); -
src/org/openstreetmap/josm/command/ConflictResolveCommand.java
r114 r214 55 55 conflictDialog.conflicts.remove(k); 56 56 conflictDialog.rebuildList(); 57 Main.map.mapView.recalculateCenterScale(); // in case of auto-zoom58 57 } 59 58 } -
src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java
r206 r214 80 80 if (name == null) { 81 81 AllNodesVisitor.getAllNodes(w.segments); 82 boolean incomplete = false;83 82 Set<Node> nodes = new HashSet<Node>(); 84 83 for (Segment ls : w.segments) { … … 86 85 nodes.add(ls.from); 87 86 nodes.add(ls.to); 88 } else 89 incomplete = true; 87 } 90 88 } 91 89 name = trn("{0} node", "{0} nodes", nodes.size(), nodes.size()); 92 if (incomplete)93 name += " ("+tr("incomplete")+")";94 90 } 91 if (w.isIncomplete()) 92 name += " ("+tr("incomplete")+")"; 95 93 addId(w); 96 94 icon = ImageProvider.get("data", "way"); -
src/org/openstreetmap/josm/gui/MainMenu.java
r213 r214 11 11 import org.openstreetmap.josm.actions.AlignInCircleAction; 12 12 import org.openstreetmap.josm.actions.AlignInLineAction; 13 import org.openstreetmap.josm.actions.AutoScaleAction; 13 14 import org.openstreetmap.josm.actions.CombineWayAction; 14 15 import org.openstreetmap.josm.actions.DownloadAction; … … 65 66 public final Action about = new AboutAction(); 66 67 public final DownloadIncompleteAction downloadIncomplete = new DownloadIncompleteAction(); 67 68 68 69 public final JMenu layerMenu = new JMenu(tr("Layer")); 69 70 public final JMenu editMenu = new JMenu(tr("Edit")); 71 public final JMenu viewMenu = new JMenu(tr("View")); 70 72 public final JMenu helpMenu = new JMenu(tr("Help")); 71 73 public final JMenu fileMenu = new JMenu(tr("Files")); 72 74 public final JMenu connectionMenu = new JMenu(tr("Connection")); 73 75 public final JMenu toolsMenu = new JMenu(tr("Tools")); 76 77 public final JMenu zoomToMenu = new JMenu(tr("Zoom To")); 74 78 75 79 … … 96 100 editMenu.add(preferences); 97 101 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); 98 109 99 110 toolsMenu.setMnemonic('T'); -
src/org/openstreetmap/josm/gui/MapFrame.java
r208 r214 4 4 import java.awt.Component; 5 5 import 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;10 6 11 7 import javax.swing.AbstractButton; … … 17 13 18 14 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.actions.AutoScaleAction;20 15 import org.openstreetmap.josm.actions.mapmode.AddSegmentAction; 21 16 import org.openstreetmap.josm.actions.mapmode.AddWayAction; … … 81 76 setLayout(new BorderLayout()); 82 77 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); 85 82 86 83 // toolbar … … 98 95 toolGroup.add((AbstractButton)c); 99 96 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true); 100 101 // autoScale 97 102 98 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 123 100 add(toggleDialogs, BorderLayout.EAST); 124 101 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS)); … … 144 121 if (toolBarActions.getComponent(i) instanceof Destroyable) 145 122 ((Destroyable)toolBarActions).destroy(); 123 124 // remove menu entries 125 Main.main.menu.viewMenu.setVisible(false); 146 126 } 147 127 -
src/org/openstreetmap/josm/gui/MapView.java
r206 r214 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.actions.AutoScaleAction;19 18 import org.openstreetmap.josm.data.Bounds; 20 19 import org.openstreetmap.josm.data.SelectionChangedListener; … … 55 54 56 55 /** 57 * Whether to adjust the scale property on every resize.58 */59 private boolean autoScale = true;60 61 /**62 56 * A list of all layers currently loaded. 63 57 */ … … 76 70 private Collection<LayerChangeListener> listeners = new LinkedList<LayerChangeListener>(); 77 71 78 private final AutoScaleAction autoScaleAction; 79 80 81 public MapView(AutoScaleAction autoScaleAction) { 82 this.autoScaleAction = autoScaleAction; 72 public MapView() { 83 73 addComponentListener(new ComponentAdapter(){ 84 74 @Override public void componentResized(ComponentEvent e) { 85 recalculateCenterScale(); 75 recalculateCenterScale(null); 76 removeComponentListener(this); 86 77 } 87 78 }); 79 88 80 new MapMover(this, true); 89 81 … … 113 105 if (editLayer != null) { 114 106 editLayer.mergeFrom(layer); 115 if (autoScale)116 recalculateCenterScale();117 107 repaint(); 118 108 return; … … 204 194 205 195 /** 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 /**223 196 * Set the new dimension to the projection class. Also adjust the components 224 197 * scale, if in autoScale mode. 225 198 */ 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); 263 229 repaint(); 264 230 } … … 296 262 Layer old = activeLayer; 297 263 activeLayer = layer; 298 if (old != layer) {264 if (old != layer) 299 265 for (LayerChangeListener l : listeners) 300 266 l.activeLayerChange(old, layer); 301 recalculateCenterScale();302 }303 267 } 304 268 … … 315 279 */ 316 280 @Override public void zoomTo(EastNorth newCenter, double scale) { 317 boolean oldAutoScale = autoScale;318 281 EastNorth oldCenter = center; 319 282 double oldScale = this.scale; 320 autoScale = false;321 322 283 super.zoomTo(newCenter, scale); 323 324 recalculateCenterScale();325 326 284 if ((oldCenter == null && center != null) || !oldCenter.equals(center)) 327 285 firePropertyChange("center", oldCenter, center); 328 if (oldAutoScale != autoScale)329 firePropertyChange("autoScale", oldAutoScale, autoScale);330 286 if (oldScale != scale) 331 287 firePropertyChange("scale", oldScale, scale);
Note:
See TracChangeset
for help on using the changeset viewer.