- Timestamp:
- 2006-04-22T01:47:07+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/AutoScaleAction.java
r68 r91 3 3 import java.awt.event.ActionEvent; 4 4 import java.awt.event.KeyEvent; 5 import java.util.Collection; 5 6 6 7 import javax.swing.KeyStroke; 8 import javax.swing.MenuElement; 7 9 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.data.SelectionChangedListener; 12 import org.openstreetmap.josm.data.coor.EastNorth; 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 8 16 import org.openstreetmap.josm.gui.MapFrame; 9 import org.openstreetmap.josm.gui. MapView;17 import org.openstreetmap.josm.gui.layer.Layer; 10 18 11 19 /** … … 13 21 * @author imi 14 22 */ 15 public class AutoScaleAction extends JosmAction { 16 /** 17 * The mapView this action operates on. 18 */ 19 private final MapView mapView; 23 public class AutoScaleAction extends GroupAction { 24 25 private enum AutoScaleMode {data, selection, layer, conflict} 26 private AutoScaleMode mode = AutoScaleMode.data; 27 private final MapFrame mapFrame; 28 29 private class Action extends JosmAction { 30 private final AutoScaleMode mode; 31 public Action(AutoScaleMode mode) { 32 super("Auto Scale: "+mode, "dialogs/autoscale/"+mode, "Auto zoom the view to "+mode+". Disabled if the view is moved.", "Alt-A", KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.ALT_MASK)); 33 this.mode = mode; 34 } 35 public void actionPerformed(ActionEvent e) { 36 AutoScaleAction.this.mode = mode; 37 if (e.getSource() instanceof MenuElement) 38 setAutoScaleOnMapView(); 39 else 40 mapFrame.mapView.setAutoScale(!mapFrame.mapView.isAutoScale()); 41 } 42 } 20 43 21 public AutoScaleAction(MapFrame mapFrame) { 22 super("Auto Scale", "autoscale", "Zoom the view to show the whole layer. Disabled if the view is moved.", "Alt-A", KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.ALT_MASK)); 23 mapView = mapFrame.mapView; 44 public AutoScaleAction(final MapFrame mapFrame) { 45 for (AutoScaleMode mode : AutoScaleMode.values()) 46 actions.add(new Action(mode)); 47 setCurrent(0); 48 this.mapFrame = mapFrame; 49 Main.ds.addSelectionChangedListener(new SelectionChangedListener(){ 50 public void selectionChanged(Collection<OsmPrimitive> newSelection) { 51 if (mode == AutoScaleMode.selection) 52 mapFrame.mapView.recalculateCenterScale(); 53 } 54 }); 24 55 } 25 56 57 public BoundingXYVisitor getBoundingBox() { 58 BoundingXYVisitor v = new BoundingXYVisitor(); 59 switch (mode) { 60 case data: 61 for (Layer l : mapFrame.mapView.getAllLayers()) 62 l.visitBoundingBox(v); 63 break; 64 case layer: 65 mapFrame.mapView.getActiveLayer().visitBoundingBox(v); 66 break; 67 case selection: 68 case conflict: 69 Collection<OsmPrimitive> sel = mode == AutoScaleMode.selection ? Main.ds.getSelected() : mapFrame.conflictDialog.conflicts.keySet(); 70 for (OsmPrimitive osm : sel) 71 osm.visit(v); 72 // special case to zoom nicely to one single node 73 if (v.min != null && v.max != null && v.min.north() == v.max.north() && v.min.east() == v.max.east()) { 74 EastNorth en = Main.proj.latlon2eastNorth(new LatLon(0.02, 0.02)); 75 v.min = new EastNorth(v.min.east()-en.east(), v.min.north()-en.north()); 76 v.max = new EastNorth(v.max.east()+en.east(), v.max.north()+en.north()); 77 } 78 break; 79 } 80 return v; 81 } 26 82 27 public void actionPerformed(ActionEvent e) { 28 mapView.setAutoScale(!mapView.isAutoScale()); 29 } 83 private void setAutoScaleOnMapView() { 84 if (mapFrame.mapView.isAutoScale()) 85 mapFrame.mapView.recalculateCenterScale(); 86 else 87 mapFrame.mapView.setAutoScale(true); 88 } 30 89 } -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r86 r91 63 63 } 64 64 65 /**66 * Does nothing. Only to subclass.67 */65 public void mouseReleased(MouseEvent e) {} 66 public void mouseExited(MouseEvent e) {} 67 public void mousePressed(MouseEvent e) {} 68 68 public void mouseClicked(MouseEvent e) {} 69 /**70 * Does nothing. Only to subclass.71 */72 public void mousePressed(MouseEvent e) {}73 /**74 * Does nothing. Only to subclass.75 */76 public void mouseReleased(MouseEvent e) {}77 /**78 * Does nothing. Only to subclass.79 */80 69 public void mouseEntered(MouseEvent e) {} 81 /**82 * Does nothing. Only to subclass.83 */84 public void mouseExited(MouseEvent e) {}85 /**86 * Does nothing. Only to subclass.87 */88 70 public void mouseMoved(MouseEvent e) {} 89 /**90 * Does nothing. Only to subclass.91 */92 71 public void mouseDragged(MouseEvent e) {} 93 72 } -
src/org/openstreetmap/josm/command/ConflictResolveCommand.java
r90 r91 44 44 } 45 45 } 46 for (OsmPrimitive k :completed)47 conflictDialog.conflicts.remove(k);48 if (!completed.isEmpty())46 if (!completed.isEmpty()) { 47 for (OsmPrimitive k : completed) 48 conflictDialog.conflicts.remove(k); 49 49 conflictDialog.rebuildList(); 50 Main.main.getMapFrame().mapView.recalculateCenterScale(); // in case of auto-zoom 51 } 50 52 } 51 53 -
src/org/openstreetmap/josm/data/osm/DataSet.java
r86 r91 151 151 listeners.remove(listener); 152 152 } 153 154 public void addAllSelectionListener(DataSet ds) { 155 listeners.addAll(ds.listeners); 156 } 153 157 } -
src/org/openstreetmap/josm/gui/IconToggleButton.java
r90 r91 1 1 package org.openstreetmap.josm.gui; 2 2 3 import java.awt.event.MouseAdapter; 4 import java.awt.event.MouseEvent; 3 5 import java.beans.PropertyChangeEvent; 4 6 import java.beans.PropertyChangeListener; … … 15 17 public class IconToggleButton extends JToggleButton implements PropertyChangeListener { 16 18 19 public boolean groupbutton; 20 17 21 /** 18 22 * Construct the toggle button with the given action. … … 25 29 if (o != null) 26 30 setToolTipText(o.toString()); 31 32 action.addPropertyChangeListener(this); 27 33 28 action.addPropertyChangeListener(this); 34 addMouseListener(new MouseAdapter(){ 35 @Override public void mousePressed(MouseEvent e) { 36 groupbutton = e.getX() > getWidth()/3 && e.getY() > getHeight()/3; 37 } 38 }); 29 39 } 30 40 -
src/org/openstreetmap/josm/gui/MapFrame.java
r90 r91 12 12 import javax.swing.ButtonGroup; 13 13 import javax.swing.JPanel; 14 import javax.swing.JToggleButton;15 14 import javax.swing.JToolBar; 16 15 17 16 import org.openstreetmap.josm.Main; 18 17 import org.openstreetmap.josm.actions.AutoScaleAction; 18 import org.openstreetmap.josm.actions.mapmode.AddNodeAction; 19 19 import org.openstreetmap.josm.actions.mapmode.AddSegmentAction; 20 import org.openstreetmap.josm.actions.mapmode.AddNodeAction;21 20 import org.openstreetmap.josm.actions.mapmode.AddWayAction; 22 21 import org.openstreetmap.josm.actions.mapmode.DeleteAction; … … 70 69 setLayout(new BorderLayout()); 71 70 72 add(mapView = new MapView(layer), BorderLayout.CENTER); 71 AutoScaleAction autoScaleAction = new AutoScaleAction(this); 72 add(mapView = new MapView(autoScaleAction), BorderLayout.CENTER); 73 mapView.addLayer(layer); 73 74 74 75 // toolbar … … 92 93 // autoScale 93 94 toolBarActions.addSeparator(); 94 final JToggleButton autoScaleButton = new IconToggleButton(new AutoScaleAction(this));95 final IconToggleButton autoScaleButton = new IconToggleButton(autoScaleAction); 95 96 toolBarActions.add(autoScaleButton); 96 97 autoScaleButton.setText(null); -
src/org/openstreetmap/josm/gui/MapView.java
r86 r91 12 12 13 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.actions.AutoScaleAction; 14 15 import org.openstreetmap.josm.data.Bounds; 15 16 import org.openstreetmap.josm.data.SelectionChangedListener; 16 17 import org.openstreetmap.josm.data.coor.EastNorth; 17 18 import org.openstreetmap.josm.data.coor.LatLon; 18 import org.openstreetmap.josm.data.osm.DataSet;19 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 20 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 71 71 */ 72 72 private Collection<LayerChangeListener> listeners = new LinkedList<LayerChangeListener>(); 73 74 /** 75 * Construct a MapView. 76 * @param layer The first layer in the view. 77 */ 78 public MapView(Layer layer) { 73 74 private final AutoScaleAction autoScaleAction; 75 76 public MapView(AutoScaleAction autoScaleAction) { 77 this.autoScaleAction = autoScaleAction; 79 78 addComponentListener(new ComponentAdapter(){ 80 79 @Override public void componentResized(ComponentEvent e) { … … 83 82 }); 84 83 new MapMover(this); 85 addLayer(layer); 86 84 87 85 // listend to selection changes to redraw the map 88 86 Main.ds.addSelectionChangedListener(new SelectionChangedListener(){ 89 87 public void selectionChanged(Collection<OsmPrimitive> newSelection) { 90 88 repaint(); 91 89 } 92 90 }); 93 91 } … … 101 99 final OsmDataLayer dataLayer = (OsmDataLayer)layer; 102 100 if (editLayer != null) { 103 // merge the layer into the existing one104 if (!editLayer.isMergable(layer))105 throw new IllegalArgumentException("Cannot merge argument");106 101 editLayer.mergeFrom(layer); 107 102 repaint(); … … 109 104 } 110 105 editLayer = dataLayer; 106 dataLayer.data.addAllSelectionListener(Main.ds); 107 Main.ds = dataLayer.data; 111 108 dataLayer.addModifiedListener(new ModifiedChangedListener(){ 112 109 public void modifiedChanged(boolean value, OsmDataLayer source) { … … 117 114 118 115 // add as a new layer 119 120 121 122 116 if (layer instanceof WmsServerLayer) 117 layers.add(layers.size(), layer); 118 else 119 layers.add(0, layer); 123 120 124 121 for (LayerChangeListener l : listeners) … … 127 124 // autoselect the new layer 128 125 setActiveLayer(layer); 129 recalculateCenterScale();130 126 } 131 127 … … 207 203 * scale, if in autoScale mode. 208 204 */ 209 void recalculateCenterScale() { 205 public void recalculateCenterScale() { 210 206 if (autoScale) { 211 207 // -20 to leave some border … … 217 213 h = 20; 218 214 219 BoundingXYVisitor v = new BoundingXYVisitor(); 220 for (Layer l : layers) 221 l.visitBoundingBox(v); 215 BoundingXYVisitor v = autoScaleAction.getBoundingBox(); 222 216 223 217 boolean oldAutoScale = autoScale; 224 218 EastNorth oldCenter = center; 225 219 double oldScale = this.scale; 226 220 227 221 if (v.min == null || v.max == null || v.min.equals(v.max)) { 228 222 // no bounds means whole world … … 238 232 scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen 239 233 } 240 234 241 235 if (!center.equals(oldCenter)) 242 236 firePropertyChange("center", oldCenter, center); … … 275 269 /** 276 270 * Set the active selection to the given value and raise an layerchange event. 277 * Also, swap the active dataset in Main.main if it is a datalayer.278 271 */ 279 272 public void setActiveLayer(Layer layer) { … … 282 275 Layer old = activeLayer; 283 276 activeLayer = layer; 284 if (layer instanceof OsmDataLayer)285 Main.ds = ((OsmDataLayer)layer).data;286 277 if (old != layer) { 287 278 for (LayerChangeListener l : listeners) … … 304 295 public OsmDataLayer editLayer() { 305 296 if (editLayer == null) 306 addLayer(new OsmDataLayer( new DataSet(), "unnamed", false));297 addLayer(new OsmDataLayer(Main.ds, "unnamed", false)); 307 298 return editLayer; 308 299 } … … 319 310 320 311 super.zoomTo(newCenter, scale); 321 312 322 313 recalculateCenterScale(); 323 314 324 315 if (!oldCenter.equals(center)) 325 316 firePropertyChange("center", oldCenter, center); -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r86 r91 102 102 JList layers = new JList(model); 103 103 /** 104 * The invisible icon blended over invisible layers.105 */106 static final Icon invisible = ImageProvider.get("layer", "invisible");107 108 /**109 104 * The merge action. This is only called, if the current selection and its 110 105 * item below are editable datasets and the merge button is clicked. … … 139 134 Icon icon = layer.getIcon(); 140 135 if (!layer.visible) 141 icon = ImageProvider.overlay(icon, invisible, OverlayPosition.SOUTHEAST); 136 icon = ImageProvider.overlay(icon, "invisible", OverlayPosition.SOUTHEAST); 142 137 label.setIcon(icon); 143 138 label.setToolTipText(layer.getToolTipText()); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r90 r91 10 10 import java.awt.event.MouseAdapter; 11 11 import java.awt.event.MouseEvent; 12 import java.io.IOException; 13 import java.io.InputStreamReader; 14 import java.io.Reader; 15 import java.net.MalformedURLException; 16 import java.net.URL; 12 17 import java.util.Collection; 13 18 import java.util.LinkedList; 19 import java.util.Map; 14 20 15 21 import javax.swing.ButtonGroup; … … 30 36 import org.openstreetmap.josm.gui.MapFrame; 31 37 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 38 import org.openstreetmap.josm.io.OsmIdReader; 32 39 import org.openstreetmap.josm.tools.GBC; 33 40 import org.openstreetmap.josm.tools.ImageProvider; 34 41 import org.openstreetmap.josm.tools.SearchCompiler; 42 import org.xml.sax.SAXException; 35 43 36 44 /** … … 120 128 return; 121 129 lastSearch = input.getText(); 122 SearchCompiler.Match matcher = SearchCompiler.compile(lastSearch); 123 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 124 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) { 125 if (replace.isSelected()) { 126 if (matcher.match(osm)) 130 Collection<OsmPrimitive> sel = null; 131 if (lastSearch.startsWith("http://")) 132 sel = selectFromWebsite(lastSearch, replace.isSelected(), add.isSelected(), remove.isSelected()); 133 if (sel == null) { 134 sel = Main.ds.getSelected(); 135 SearchCompiler.Match matcher = SearchCompiler.compile(lastSearch); 136 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) { 137 if (replace.isSelected()) { 138 if (matcher.match(osm)) 139 sel.add(osm); 140 else 141 sel.remove(osm); 142 } else if (add.isSelected() && !osm.selected && matcher.match(osm)) 127 143 sel.add(osm); 128 else 144 else if (remove.isSelected() && osm.selected && matcher.match(osm)) 129 145 sel.remove(osm); 130 } else if (add.isSelected() && !osm.selected && matcher.match(osm)) 131 sel.add(osm); 132 else if (remove.isSelected() && osm.selected && matcher.match(osm)) 133 sel.remove(osm); 146 } 134 147 } 135 148 Main.ds.setSelected(sel); … … 141 154 selectionChanged(Main.ds.getSelected()); 142 155 } 156 157 private Collection<OsmPrimitive> selectFromWebsite(String url, boolean replace, boolean add, boolean remove) { 158 Collection<OsmPrimitive> sel = replace ? new LinkedList<OsmPrimitive>() : Main.ds.allNonDeletedPrimitives(); 159 try { 160 Reader in = new InputStreamReader(new URL(url).openStream()); 161 Map<Long, String> ids = OsmIdReader.parseIds(in); 162 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) { 163 if (ids.containsKey(osm.id) && osm.getClass().getName().toLowerCase().endsWith(ids.get(osm.id))) { 164 if (remove) 165 sel.remove(osm); 166 else 167 sel.add(osm); 168 } 169 } 170 } catch (MalformedURLException e) { 171 return null; 172 } catch (IOException e) { 173 e.printStackTrace(); 174 JOptionPane.showMessageDialog(Main.main, "Could not read from url: '"+url+"'"); 175 } catch (SAXException e) { 176 e.printStackTrace(); 177 JOptionPane.showMessageDialog(Main.main, "Parsing error in url: '"+url+"'"); 178 } 179 return sel; 180 } 143 181 144 182 @Override public void setVisible(boolean b) { -
src/org/openstreetmap/josm/io/OsmReader.java
r86 r91 11 11 import org.openstreetmap.josm.data.coor.LatLon; 12 12 import org.openstreetmap.josm.data.osm.DataSet; 13 import org.openstreetmap.josm.data.osm.Segment;14 13 import org.openstreetmap.josm.data.osm.Node; 15 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.osm.Segment; 16 16 import org.openstreetmap.josm.data.osm.Way; 17 17 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; … … 113 113 throw new SAXException(x.getMessage(), x); 114 114 } catch (NullPointerException x) { 115 x.printStackTrace(); // SAXException does not chain correctly 115 116 throw new SAXException("NullPointerException. Possible some missing tags.", x); 116 117 } -
src/org/openstreetmap/josm/tools/ImageProvider.java
r79 r91 27 27 * @author imi 28 28 */ 29 public final static class OverlayPosition { 30 private OverlayPosition() {} 31 public static OverlayPosition NORTHWEST = new OverlayPosition(); 32 public static OverlayPosition NORTHEAST = new OverlayPosition(); 33 public static OverlayPosition SOUTHWEST = new OverlayPosition(); 34 public static OverlayPosition SOUTHEAST = new OverlayPosition(); 35 } 36 29 public static enum OverlayPosition {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST} 37 30 38 31 /** … … 71 64 72 65 /** 73 * Return an icon that represent the overlay of the two given icons. The66 * @return an icon that represent the overlay of the two given icons. The 74 67 * second icon is layed on the first relative to the given position. 75 *76 * @param ground The ground icon (base)77 * @param overlay The icon to put on top of the ground (overlay)78 * @return The merged icon.79 68 */ 80 public static Icon overlay(Icon ground, Iconoverlay, OverlayPosition pos) {69 public static Icon overlay(Icon ground, String overlayImage, OverlayPosition pos) { 81 70 GraphicsConfiguration conf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); 82 71 int w = ground.getIconWidth(); 83 72 int h = ground.getIconHeight(); 73 ImageIcon overlay = ImageProvider.get("overlay",overlayImage); 84 74 int wo = overlay.getIconWidth(); 85 75 int ho = overlay.getIconHeight(); … … 88 78 ground.paintIcon(null, g, 0, 0); 89 79 int x = 0, y = 0; 90 if (pos == OverlayPosition.NORTHWEST) { 80 switch (pos) { 81 case NORTHWEST: 91 82 x = 0; 92 83 y = 0; 93 } else if (pos == OverlayPosition.NORTHEAST) { 84 break; 85 case NORTHEAST: 94 86 x = w-wo; 95 87 y = 0; 96 } else if (pos == OverlayPosition.SOUTHWEST) { 88 break; 89 case SOUTHWEST: 97 90 x = 0; 98 91 y = h-ho; 99 } else if (pos == OverlayPosition.SOUTHEAST) { 92 break; 93 case SOUTHEAST: 100 94 x = w-wo; 101 95 y = h-ho; 96 break; 102 97 } 103 98 overlay.paintIcon(null, g, x, y);
Note:
See TracChangeset
for help on using the changeset viewer.