Changeset 22 in josm for src/org/openstreetmap/josm/gui
- Timestamp:
- 2005-10-23T22:13:33+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm/gui
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/ImageProvider.java
r21 r22 25 25 * @author imi 26 26 */ 27 public enum OverlayPosition {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST} ;27 public enum OverlayPosition {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST} 28 28 29 29 /** -
src/org/openstreetmap/josm/gui/MapStatus.java
r17 r22 47 47 * The position of the mouse cursor. 48 48 */ 49 privateJTextField positionText = new JTextField("-000.00000000000000 -000.00000000000000".length());49 JTextField positionText = new JTextField("-000.00000000000000 -000.00000000000000".length()); 50 50 /** 51 51 * The field holding the name of the object under the mouse. 52 52 */ 53 privateJTextField nameText = new JTextField(30);53 JTextField nameText = new JTextField(30); 54 54 55 55 /** … … 147 147 * The last sent mouse movement event. 148 148 */ 149 privateMouseState mouseState = new MouseState();149 MouseState mouseState = new MouseState(); 150 150 151 151 /** -
src/org/openstreetmap/josm/gui/MapView.java
r21 r22 32 32 * provide the MapMode's enough capabilities to operate. 33 33 * 34 * MapView holds the map data, organize it, convert it, provide access to it.35 *36 34 * MapView hold meta-data about the data set currently displayed, as scale level, 37 35 * center point viewed, what scrolling mode or editing mode is selected or with … … 87 85 */ 88 86 public MapView(Layer layer) { 89 if (layer.dataSet == null)90 throw new IllegalArgumentException("Initial layer must have a dataset.");91 92 87 addComponentListener(new ComponentAdapter(){ 93 88 @Override … … 118 113 // initialize the projection if it was the first layer 119 114 if (layers.size() == 1) 120 Main.pref.getProjection().init( layer.dataSet);115 Main.pref.getProjection().init(); 121 116 122 117 // initialize the dataset in the new layer … … 231 226 OsmPrimitive minPrimitive = null; 232 227 233 // calculate the object based on the current active dataset.234 DataSet ds = getActiveDataSet();235 236 228 // nodes 237 for (Node n : ds.nodes) {229 for (Node n : Main.main.ds.nodes) { 238 230 Point sp = getScreenPoint(n.coor); 239 231 double dist = p.distanceSq(sp); … … 247 239 248 240 // pending line segments 249 for (LineSegment ls : ds.pendingLineSegments()) {241 for (LineSegment ls : Main.main.ds.pendingLineSegments()) { 250 242 Point A = getScreenPoint(ls.getStart().coor); 251 243 Point B = getScreenPoint(ls.getEnd().coor); … … 262 254 // tracks & line segments 263 255 minDistanceSq = Double.MAX_VALUE; 264 for (Track t : ds.tracks()) {256 for (Track t : Main.main.ds.tracks()) { 265 257 for (LineSegment ls : t.segments()) { 266 258 Point A = getScreenPoint(ls.getStart().coor); … … 375 367 376 368 /** 377 * Return the dataSet for the current selected layer. If the active layer378 * does not have a dataset, return the DataSet from the next layer a.s.o.379 *380 * @return The DataSet of the current active layer.381 */382 public DataSet getActiveDataSet() {383 if (activeLayer.dataSet != null)384 return activeLayer.dataSet;385 for (Layer l : layers)386 if (l.dataSet != null)387 return l.dataSet;388 throw new IllegalStateException("No dataset found.");389 }390 391 /**392 369 * Change to the new projection. Recalculate the dataset and zoom, if autoZoom 393 370 * is active. … … 422 399 h = 20; 423 400 424 Bounds bounds = getActiveDataSet().getBoundsXY();401 Bounds bounds = Main.main.ds.getBoundsXY(); 425 402 426 403 boolean oldAutoScale = autoScale; -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r21 r22 91 91 * Indicate, that the application has to be restarted for the settings to take effect. 92 92 */ 93 privateboolean requiresRestart = false;93 boolean requiresRestart = false; 94 94 /** 95 95 * ComboBox with all look and feels. 96 96 */ 97 privateJComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());97 JComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels()); 98 98 /** 99 99 * Combobox with all projections available 100 100 */ 101 privateJComboBox projectionCombo = new JComboBox(Preferences.allProjections.clone());101 JComboBox projectionCombo = new JComboBox(Preferences.allProjections.clone()); 102 102 /** 103 103 * The main tab panel. … … 108 108 * Editfield for the Base url to the REST API from OSM. 109 109 */ 110 privateJTextField osmDataServer = new JTextField(20);110 JTextField osmDataServer = new JTextField(20); 111 111 /** 112 112 * Editfield for the username to the OSM account. 113 113 */ 114 privateJTextField osmDataUsername = new JTextField(20);114 JTextField osmDataUsername = new JTextField(20); 115 115 /** 116 116 * Passwordfield for the userpassword of the REST API. 117 117 */ 118 privateJPasswordField osmDataPassword = new JPasswordField(20);118 JPasswordField osmDataPassword = new JPasswordField(20); 119 119 /** 120 120 * The checkbox stating whether nodes should be merged together. 121 121 */ 122 privateJCheckBox drawRawGpsLines = new JCheckBox("Draw lines between raw gps points.");122 JCheckBox drawRawGpsLines = new JCheckBox("Draw lines between raw gps points."); 123 123 /** 124 124 * The checkbox stating whether raw gps lines should be forced. 125 125 */ 126 privateJCheckBox forceRawGpsLines = new JCheckBox("Force lines if no line segments imported.");126 JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no line segments imported."); 127 127 /** 128 128 * The checkbox stating whether nodes should be merged together. 129 129 */ 130 privateJCheckBox mergeNodes = new JCheckBox("Merge nodes with equal latitude/longitude.");130 JCheckBox mergeNodes = new JCheckBox("Merge nodes with equal latitude/longitude."); 131 131 132 132 /** -
src/org/openstreetmap/josm/gui/SelectionManager.java
r21 r22 15 15 import java.util.LinkedList; 16 16 17 import org.openstreetmap.josm. command.DataSet;17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.osm.LineSegment; 19 19 import org.openstreetmap.josm.data.osm.Node; … … 272 272 } else { 273 273 // nodes 274 DataSet ds = mv.getActiveDataSet(); 275 for (Node n : ds.nodes) { 274 for (Node n : Main.main.ds.nodes) { 276 275 if (r.contains(mv.getScreenPoint(n.coor))) 277 276 selection.add(n); … … 279 278 280 279 // pending line segments 281 for (LineSegment ls : ds.pendingLineSegments())280 for (LineSegment ls : Main.main.ds.pendingLineSegments()) 282 281 if (rectangleContainLineSegment(r, alt, ls)) 283 282 selection.add(ls); 284 283 285 284 // tracks 286 for (Track t : ds.tracks()) {285 for (Track t : Main.main.ds.tracks()) { 287 286 boolean wholeTrackSelected = !t.segments().isEmpty(); 288 287 for (LineSegment ls : t.segments()) -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r21 r22 8 8 import java.awt.event.ActionListener; 9 9 import java.awt.event.KeyEvent; 10 import java.io.IOException; 10 11 import java.util.Collection; 11 12 … … 16 17 import javax.swing.JLabel; 17 18 import javax.swing.JList; 19 import javax.swing.JOptionPane; 18 20 import javax.swing.JPanel; 19 21 import javax.swing.JScrollPane; … … 30 32 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 31 33 import org.openstreetmap.josm.gui.layer.Layer; 34 import org.openstreetmap.josm.io.OsmWriter; 32 35 33 36 /** … … 42 45 * The data model for the list component. 43 46 */ 44 privateDefaultListModel model = new DefaultListModel();47 DefaultListModel model = new DefaultListModel(); 45 48 /** 46 49 * The list component holding all layers. 47 50 */ 48 privateJList layers = new JList(model);51 JList layers = new JList(model); 49 52 /** 50 53 * The invisible icon blended over invisible layers. 51 54 */ 52 privatestatic final Icon invisible = ImageProvider.get("layer", "invisible");55 static final Icon invisible = ImageProvider.get("layer", "invisible"); 53 56 54 57 /** … … 69 72 */ 70 73 private JButton deleteButton = new JButton(ImageProvider.get("dialogs", "delete")); 71 74 /** 75 * Button for connecting disconnecting to the server. 76 */ 77 private JButton uploadButton = new JButton(ImageProvider.get("dialogs", "condiscon")); 78 72 79 /** 73 80 * Create an layerlist and attach it to the given mapView. … … 89 96 icon = ImageProvider.overlay(icon, invisible, ImageProvider.OverlayPosition.SOUTHEAST); 90 97 label.setIcon(icon); 91 98 92 99 DataSet ds = layer.dataSet; 93 100 if (ds != null) { … … 100 107 101 108 final MapView mapView = mapFrame.mapView; 102 109 103 110 Collection<Layer> data = mapView.getAllLayers(); 104 111 for (Layer l : data) … … 115 122 }); 116 123 mapView.addLayerChangeListener(this); 117 124 118 125 // Buttons 119 126 JPanel buttonPanel = new JPanel(new GridLayout(1, 5)); … … 173 180 mergeButton.setToolTipText("Merge the selected layer into the layer directly below."); 174 181 mergeButton.addActionListener(new ActionListener(){ 175 public void actionPerformed(ActionEvent e) { 176 Layer lFrom = (Layer)layers.getSelectedValue(); 177 DataSet dsFrom = lFrom.dataSet; 178 Layer lTo = (Layer)model.get(layers.getSelectedIndex()+1); 179 DataSet dsTo = lTo.dataSet; 180 dsTo.mergeFrom(dsFrom, Main.pref.mergeNodes); 181 layers.setSelectedValue(lTo, true); 182 mapView.removeLayer(lFrom); 182 public void actionPerformed(ActionEvent e) { 183 Layer lFrom = (Layer)layers.getSelectedValue(); 184 DataSet dsFrom = lFrom.dataSet; 185 Layer lTo = (Layer)model.get(layers.getSelectedIndex()+1); 186 DataSet dsTo = lTo.dataSet; 187 dsTo.mergeFrom(dsFrom, Main.pref.mergeNodes); 188 layers.setSelectedValue(lTo, true); 189 mapView.removeLayer(lFrom); 190 } 191 }); 192 buttonPanel.add(mergeButton); 193 194 uploadButton.setToolTipText("Upload changes to the server."); 195 uploadButton.addActionListener(new ActionListener(){ 196 public void actionPerformed(ActionEvent e) { 197 OsmWriter con = new OsmWriter(Main.pref.osmDataServer, Main.main.commands); 198 try { 199 con.output(); 200 } catch (IOException x) { 201 x.printStackTrace(); 202 JOptionPane.showMessageDialog(Main.main, "Not all changes could be uploaded."); 183 203 } 184 }); 185 buttonPanel.add(mergeButton); 186 204 } 205 }); 206 buttonPanel.add(uploadButton); 207 187 208 add(buttonPanel, BorderLayout.SOUTH); 188 209 … … 193 214 * Updates the state of the Buttons. 194 215 */ 195 privatevoid updateButtonEnabled() {216 void updateButtonEnabled() { 196 217 int sel = layers.getSelectedIndex(); 197 218 Layer l = (Layer)layers.getSelectedValue(); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r21 r22 17 17 18 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.command.DataSet;20 19 import org.openstreetmap.josm.data.SelectionChangedListener; 21 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 23 22 import org.openstreetmap.josm.gui.ImageProvider; 24 23 import org.openstreetmap.josm.gui.MapFrame; 25 import org.openstreetmap.josm.gui.MapView;26 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;27 import org.openstreetmap.josm.gui.layer.Layer;28 24 29 25 /** … … 34 30 * @author imi 35 31 */ 36 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener , LayerChangeListener{32 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener { 37 33 38 34 /** … … 44 40 */ 45 41 private JList displaylist = new JList(list); 46 /**47 * The dataset, all selections are part of.48 */49 private final MapView mapView;50 42 51 43 /** … … 55 47 public SelectionListDialog(MapFrame mapFrame) { 56 48 super(mapFrame, "Current Selection", "Selection List", "selectionlist", KeyEvent.VK_E, "Open a selection list window."); 57 this.mapView = mapFrame.mapView;58 49 setLayout(new BorderLayout()); 59 50 setSize(300,400); … … 84 75 getContentPane().add(button, BorderLayout.SOUTH); 85 76 86 selectionChanged( mapView.getActiveDataSet().getSelected());77 selectionChanged(Main.main.ds.getSelected()); 87 78 } 88 79 … … 90 81 public void setVisible(boolean b) { 91 82 if (b) { 92 mapView.addLayerChangeListener(this); 93 mapView.getActiveDataSet().addSelectionChangedListener(this); 94 selectionChanged(mapView.getActiveDataSet().getSelected()); 83 Main.main.ds.addSelectionChangedListener(this); 84 selectionChanged(Main.main.ds.getSelected()); 95 85 } else { 96 mapView.removeLayerChangeListener(this); 97 mapView.getActiveDataSet().removeSelectionChangedListener(this); 86 Main.main.ds.removeSelectionChangedListener(this); 98 87 } 99 88 super.setVisible(b); … … 118 107 */ 119 108 public void updateMap() { 120 DataSet ds = mapView.getActiveDataSet(); 121 ds.clearSelection(); 109 Main.main.ds.clearSelection(); 122 110 for (int i = 0; i < list.getSize(); ++i) 123 111 if (displaylist.isSelectedIndex(i)) 124 ((OsmPrimitive)list.get(i)).setSelected(true , ds);112 ((OsmPrimitive)list.get(i)).setSelected(true); 125 113 Main.main.getMapFrame().repaint(); 126 114 } 127 128 public void activeLayerChange(Layer oldLayer, Layer newLayer) {129 DataSet ds = oldLayer.dataSet;130 if (ds != null)131 ds.removeSelectionChangedListener(this);132 ds = newLayer.dataSet;133 if (ds != null)134 ds.addSelectionChangedListener(this);135 }136 137 /**138 * Does nothing. Only to satisfy LayerChangeListener139 */140 public void layerAdded(Layer newLayer) {}141 /**142 * Does nothing. Only to satisfy LayerChangeListener143 */144 public void layerRemoved(Layer oldLayer) {}145 115 } -
src/org/openstreetmap/josm/gui/layer/Layer.java
r21 r22 5 5 import javax.swing.Icon; 6 6 7 import org.openstreetmap.josm.command.DataSet;8 import org.openstreetmap.josm.data.osm.LineSegment;9 import org.openstreetmap.josm.data.osm.Node;10 import org.openstreetmap.josm.data.osm.Track;11 7 import org.openstreetmap.josm.gui.MapView; 12 import org.openstreetmap.josm.gui.engine.Engine;13 8 14 9 /** … … 34 29 public boolean visible = true; 35 30 /** 36 * The dataSet this layer operates on, if any. Not all layer may have a37 * dataset associated.38 */39 public final DataSet dataSet;40 /**41 31 * The name of this layer. 42 32 */ 43 33 public final String name; 44 /**45 * The engine used to draw the data.46 */47 private final Engine engine;48 34 49 35 /** 50 36 * Create the layer and fill in the necessary components. 51 * @param dataSet The DataSet, this layer operates on. Can be <code>null</code>.52 37 */ 53 public Layer(DataSet dataSet, Engine engine, String name) { 54 if (engine == null || name == null) 55 throw new NullPointerException(); 56 this.dataSet = dataSet; 38 public Layer(String name) { 57 39 this.name = name; 58 this.engine = engine;59 40 } 60 41 … … 63 44 * @param mv The object that can translate GeoPoints to screen coordinates. 64 45 */ 65 public final void paint(Graphics g, MapView mv) { 66 engine.init(g, mv); 67 68 for (Track t : dataSet.tracks()) 69 engine.drawTrack(t); 70 for (LineSegment ls : dataSet.pendingLineSegments()) 71 engine.drawPendingLineSegment(ls); 72 for (Node n : dataSet.nodes) 73 engine.drawNode(n); 74 } 75 46 abstract public void paint(Graphics g, MapView mv); 76 47 /** 77 48 * Return a representative small image for this layer. The image must not -
src/org/openstreetmap/josm/gui/layer/LayerFactory.java
r21 r22 19 19 */ 20 20 public static Layer create(DataSet dataSet, String name, boolean rawGps) { 21 Layer layer = rawGps ? new RawGpsDataLayer(dataSet, name) : new OsmDataLayer( dataSet,name);21 Layer layer = rawGps ? new RawGpsDataLayer(dataSet, name) : new OsmDataLayer(name); 22 22 return layer; 23 23 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r21 r22 1 1 package org.openstreetmap.josm.gui.layer; 2 3 import java.awt.Color; 4 import java.awt.Graphics; 5 import java.awt.Point; 6 import java.util.Collection; 7 import java.util.HashSet; 2 8 3 9 import javax.swing.Icon; 4 10 5 import org.openstreetmap.josm.command.DataSet; 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.osm.Key; 13 import org.openstreetmap.josm.data.osm.LineSegment; 14 import org.openstreetmap.josm.data.osm.Node; 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.Track; 17 import org.openstreetmap.josm.data.osm.visitor.Visitor; 6 18 import org.openstreetmap.josm.gui.ImageProvider; 7 import org.openstreetmap.josm.gui. engine.SimpleEngine;19 import org.openstreetmap.josm.gui.MapView; 8 20 9 21 /** … … 14 26 * @author imi 15 27 */ 16 public class OsmDataLayer extends Layer {28 public class OsmDataLayer extends Layer implements Visitor { 17 29 18 30 private static Icon icon; 31 private final static Color darkblue = new Color(0,0,128); 32 private final static Color darkgreen = new Color(0,128,0); 33 34 /** 35 * The data behind this layer. A list of primitives which are also in Main.main.ds. 36 */ 37 private final Collection<OsmPrimitive> data; 38 39 /** 40 * The mapview we are currently drawing on. 41 */ 42 private MapView mv; 43 /** 44 * The graphic environment we are drawing with. 45 */ 46 private Graphics g; 19 47 20 48 /** 21 49 * Construct a OsmDataLayer. 22 50 */ 23 protected OsmDataLayer(DataSet dataSet, String name) { 24 super(dataSet, new SimpleEngine(), name); 51 protected OsmDataLayer(Collection<OsmPrimitive> data, String name) { 52 super(name); 53 this.data = data; 25 54 } 26 55 … … 40 69 return true; 41 70 } 71 72 @Override 73 public void paint(Graphics g, MapView mv) { 74 this.mv = mv; 75 this.g = g; 76 for (OsmPrimitive osm : data) 77 osm.visit(this); 78 } 79 80 /** 81 * Draw a small rectangle. 82 * 83 * - White if selected (as always) 84 * - Yellow, if not used by any tracks or areas. 85 * - Green, if only used by pending line segments. 86 * - Darkblue, if used in tracks but are only as inbound node. Inbound are 87 * all nodes, that have only line segments of the same track and 88 * at least two different line segments attached. 89 * - Red otherwise (means, this is a dead end or is part of more than 90 * one track). 91 * 92 * @param n The node to draw. 93 */ 94 public void visit(Node n) { 95 if (n.isSelected()) { 96 drawNode(n, Color.WHITE); // selected 97 return; 98 } 99 100 Collection<LineSegment> lineSegments = n.getParentSegments(); 101 if (lineSegments.isEmpty()) { 102 drawNode(n, Color.YELLOW); // single waypoint only 103 return; 104 } 105 106 HashSet<Track> tracks = new HashSet<Track>(); 107 for (LineSegment ls : lineSegments) 108 tracks.addAll(ls.getParents()); 109 if (tracks.isEmpty()) { 110 drawNode(n, Color.GREEN); // pending line 111 return; 112 } 113 if (tracks.size() > 1) { 114 drawNode(n, Color.RED); // more than one track 115 return; 116 } 117 int segmentUsed = 0; 118 for (LineSegment ls : tracks.iterator().next().segments()) 119 if (n == ls.getStart() || n == ls.getEnd()) 120 ++segmentUsed; 121 drawNode(n, segmentUsed > 1 ? darkblue : Color.RED); 122 } 123 124 public void visit(LineSegment ls) { 125 g.setColor(ls.isSelected() ? Color.WHITE : darkblue); 126 if (Main.main.ds.pendingLineSegments().contains(ls)) 127 g.setColor(darkgreen); 128 Point p1 = mv.getScreenPoint(ls.getStart().coor); 129 Point p2 = mv.getScreenPoint(ls.getEnd().coor); 130 g.drawLine(p1.x, p1.y, p2.x, p2.y); 131 } 132 133 /** 134 * Draw a darkblue line for all line segments. 135 * @param t The track to draw. 136 */ 137 public void visit(Track t) { 138 for (LineSegment ls : t.segments()) 139 ls.visit(this); 140 } 141 142 public void visit(Key k) { 143 } 144 145 /** 146 * Draw the node as small rectangle with the given color. 147 * 148 * @param n The node to draw. 149 * @param color The color of the node. 150 */ 151 private void drawNode(Node n, Color color) { 152 Point p = mv.getScreenPoint(n.coor); 153 g.setColor(color); 154 g.drawRect(p.x-1, p.y-1, 2, 2); 155 } 42 156 } -
src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java
r21 r22 5 5 import org.openstreetmap.josm.command.DataSet; 6 6 import org.openstreetmap.josm.gui.ImageProvider; 7 import org.openstreetmap.josm.gui.engine.RawGpsEngine;8 7 9 8 /** … … 18 17 19 18 protected RawGpsDataLayer(DataSet dataSet, String name) { 20 super( dataSet, new RawGpsEngine(),name);19 super(name); 21 20 } 22 21
Note:
See TracChangeset
for help on using the changeset viewer.