Changeset 15 in josm for src/org/openstreetmap/josm/gui
- Timestamp:
- 2005-10-07T01:13:49+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm/gui
- Files:
-
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/Layer.java
r14 r15 3 3 import java.awt.Graphics; 4 4 import java.awt.Point; 5 import java.awt.event.ActionEvent;6 5 import java.awt.event.ComponentEvent; 7 6 import java.awt.event.ComponentListener; 8 import java.awt.event.KeyEvent; 9 10 import javax.swing.AbstractAction; 11 import javax.swing.ImageIcon; 7 import java.beans.PropertyChangeEvent; 8 import java.beans.PropertyChangeListener; 9 12 10 import javax.swing.JComponent; 13 11 import javax.swing.event.ChangeEvent; … … 27 25 /** 28 26 * This is a component used in the MapFrame for browsing the map. It use is to 29 * provide the MapMode's enough capabilities to operate. 27 * provide the MapMode's enough capabilities to operate. 30 28 * 31 * MapView holds the map data, organize it, convert it, provide access to it.29 * Layer holds one dataset. There can be more than one Layer active. 32 30 * 33 * MapView hold meta-data about the data set currently displayed, as scale level, 34 * center point viewed, what scrolling mode or editing mode is selected or with 35 * what projection the map is viewed etc.. 36 * 31 * Layer hold data of the current displayed graphics as scale level and 32 * center point view. 33 * 37 34 * @author imi 38 35 */ 39 public class MapView extends JComponent implements ComponentListener, ChangeListener { 40 41 /** 42 * Toggles the autoScale feature of the mapView 43 * @author imi 44 */ 45 public class AutoScaleAction extends AbstractAction { 46 public AutoScaleAction() { 47 super("Auto Scale", new ImageIcon(Main.class.getResource("/images/autoscale.png"))); 48 putValue(MNEMONIC_KEY, KeyEvent.VK_A); 49 } 50 public void actionPerformed(ActionEvent e) { 51 autoScale = !autoScale; 52 recalculateCenterScale(); 53 } 54 } 36 public class Layer extends JComponent implements ComponentListener, ChangeListener, PropertyChangeListener { 55 37 56 38 /** … … 69 51 70 52 /** 71 * Used projection method in this map72 */73 private Projection projection = Main.pref.projection.clone();74 75 /**76 53 * The underlying DataSet. 77 54 */ … … 84 61 85 62 /** 86 * Construct a MapView.87 */ 88 public MapView(DataSet dataSet) {63 * Construct a Layer. 64 */ 65 public Layer(DataSet dataSet) { 89 66 this.dataSet = dataSet; 90 67 addComponentListener(this); … … 93 70 new MapMover(this); 94 71 95 // initialize the projection96 setProjection(Main.pref.projection.clone());97 98 72 // initialize the drawing engine 99 73 engine = new SimpleEngine(this); 74 75 // initialize on the preferences for projection changes. 76 Main.pref.addPropertyChangeListener(this); 100 77 } 101 78 … … 120 97 p.y = (getHeight()/2.0 - y)*scale + center.y; 121 98 if (latlon) 122 getProjection().xy2latlon(p);99 Main.pref.getProjection().xy2latlon(p); 123 100 return p; 124 101 } … … 138 115 throw new IllegalArgumentException("point: Either lat/lon or x/y must be set."); 139 116 p = point.clone(); 140 projection.latlon2xy(p);117 Main.pref.getProjection().latlon2xy(p); 141 118 } 142 119 int x = ((int)Math.round((p.x-center.x) / scale + getWidth()/2)); … … 236 213 autoScale = false; 237 214 center = newCenter.clone(); 238 projection.xy2latlon(center);215 Main.pref.getProjection().xy2latlon(center); 239 216 this.scale = scale; 240 217 recalculateCenterScale(); … … 268 245 */ 269 246 public void stateChanged(ChangeEvent e) { 270 projection.init(dataSet); 271 recalculateCenterScale(); 272 } 273 274 /** 275 * Set a new projection method. This call is not cheap, as it will 276 * transform the whole underlying dataSet and repaint itself. 277 * 278 * @param projection The new projection method to set. 279 */ 280 public void setProjection(Projection projection) { 281 if (projection == this.projection) 282 return; 283 284 Projection oldProjection = this.projection; 285 286 if (this.projection != null) 287 this.projection.removeChangeListener(this); 288 this.projection = projection; 289 projection.addChangeListener(this); 290 291 stateChanged(new ChangeEvent(this)); 292 firePropertyChange("projection", oldProjection, projection); 293 } 294 295 /** 296 * Return the projection method for this map view. 297 * @return The projection method. 298 */ 299 public Projection getProjection() { 300 return projection; 247 initDataSet(); 248 } 249 250 /** 251 * Called when a property, as example the projection of the Main preferences 252 * changes. 253 */ 254 public void propertyChange(PropertyChangeEvent evt) { 255 if (evt.getPropertyName().equals("projection")) { 256 Projection oldProjection = (Projection)evt.getOldValue(); 257 if (oldProjection != null) 258 oldProjection.removeChangeListener(this); 259 260 Projection newProjection = (Projection)evt.getNewValue(); 261 if (newProjection != null) 262 newProjection.addChangeListener(this); 263 264 initDataSet(); 265 } 301 266 } 302 267 … … 322 287 if (this.autoScale != autoScale) { 323 288 this.autoScale = autoScale; 289 if (autoScale) 290 recalculateCenterScale(); 324 291 firePropertyChange("autoScale", !autoScale, autoScale); 325 292 } … … 333 300 } 334 301 302 /** 303 * Initialize the DataSet with the projection taken from the preference 304 * settings. 305 */ 306 public void initDataSet() { 307 for (Node n : dataSet.nodes) 308 Main.pref.getProjection().latlon2xy(n.coor); 309 recalculateCenterScale(); 310 } 335 311 336 312 … … 357 333 // no bounds means standard scale and center 358 334 center = new GeoPoint(51.526447, -0.14746371); 359 getProjection().latlon2xy(center);335 Main.pref.getProjection().latlon2xy(center); 360 336 scale = 10; 361 337 } else { 362 338 center = bounds.centerXY(); 363 getProjection().xy2latlon(center);339 Main.pref.getProjection().xy2latlon(center); 364 340 double scaleX = (bounds.max.x-bounds.min.x)/w; 365 341 double scaleY = (bounds.max.y-bounds.min.y)/h; -
src/org/openstreetmap/josm/gui/Main.java
r9 r15 19 19 import org.openstreetmap.josm.data.Preferences; 20 20 import org.openstreetmap.josm.data.Preferences.PreferencesException; 21 import org.openstreetmap.josm.data.osm.DataSet; 22 import org.openstreetmap.josm.data.projection.Projection; 21 23 22 24 /** … … 119 121 120 122 try { 121 UIManager.setLookAndFeel(pref. laf.getClassName());123 UIManager.setLookAndFeel(pref.getLaf().getClassName()); 122 124 } catch (Exception e) { 123 125 e.printStackTrace(); … … 131 133 132 134 /** 133 * Set the main's mapframe. If a changed old mapFrame is already set,134 * ask the user whether he want to save, discard or abort. If the user135 * Create and set the main's mapframe. If a changed old mapFrame is already 136 * set, ask the user whether he want to save, discard or abort. If the user 135 137 * aborts, nothing happens. 136 138 */ 137 public void setMapFrame(String name, MapFrame mapFrame) {139 public void setMapFrame(String name, DataSet dataSet) { 138 140 //TODO: Check for changes and ask user 141 MapFrame mapFrame = new MapFrame(dataSet); 139 142 this.name = name; 140 143 this.mapFrame = mapFrame; … … 144 147 panel.add(mapFrame.toolBarActions, BorderLayout.WEST); 145 148 panel.add(mapFrame.statusLine, BorderLayout.SOUTH); 149 for (Projection p : Preferences.allProjections) 150 p.init(dataSet); 151 mapFrame.layer.initDataSet(); 146 152 panel.setVisible(true); 147 153 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r9 r15 14 14 import javax.swing.JToolBar; 15 15 16 import org.openstreetmap.josm.actions.AutoScaleAction; 16 17 import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction; 17 18 import org.openstreetmap.josm.actions.mapmode.AddNodeAction; … … 25 26 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 26 27 import org.openstreetmap.josm.data.osm.DataSet; 27 import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;28 28 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; 29 29 … … 43 43 * The view control displayed. 44 44 */ 45 public MapView mapView;45 public Layer layer; 46 46 /** 47 47 * The toolbar with the action icons … … 61 61 setLayout(new BorderLayout()); 62 62 63 add( mapView = new MapView(dataSet), BorderLayout.CENTER);63 add(layer = new Layer(dataSet), BorderLayout.CENTER); 64 64 65 65 // toolbar … … 84 84 // autoScale 85 85 toolBarActions.addSeparator(); 86 final JToggleButton autoScaleButton = new IconToggleButton(this, mapView.new AutoScaleAction());86 final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(layer)); 87 87 toolBarActions.add(autoScaleButton); 88 88 autoScaleButton.setText(null); 89 autoScaleButton.setSelected( mapView.isAutoScale());90 mapView.addPropertyChangeListener(new PropertyChangeListener(){89 autoScaleButton.setSelected(layer.isAutoScale()); 90 layer.addPropertyChangeListener(new PropertyChangeListener(){ 91 91 public void propertyChange(PropertyChangeEvent evt) { 92 92 if (evt.getPropertyName().equals("autoScale")) 93 autoScaleButton.setSelected( mapView.isAutoScale());93 autoScaleButton.setSelected(layer.isAutoScale()); 94 94 } 95 95 }); 96 97 // properties98 toolBarActions.add(new IconToggleButton(this, new PropertiesDialog(this)));99 96 100 97 // selection dialog … … 110 107 111 108 // status line below the map 112 statusLine = new MapStatus( mapView);109 statusLine = new MapStatus(layer); 113 110 } 114 111 -
src/org/openstreetmap/josm/gui/MapMover.java
r6 r15 26 26 * The map to move around. 27 27 */ 28 private final MapViewmv;28 private final Layer mv; 29 29 /** 30 30 * The old cursor when we changed it to movement cursor. … … 34 34 /** 35 35 * Create a new MapMover 36 * @param mapViewThe map that should be moved.36 * @param layer The map that should be moved. 37 37 */ 38 public MapMover( MapView mapView) {39 this.mv = mapView;38 public MapMover(Layer layer) { 39 this.mv = layer; 40 40 mv.addMouseListener(this); 41 41 mv.addMouseMotionListener(this); -
src/org/openstreetmap/josm/gui/MapStatus.java
r9 r15 39 39 40 40 /** 41 * The MapViewthis status belongs.41 * The Layer this status belongs. 42 42 */ 43 final MapViewmv;43 final Layer mv; 44 44 /** 45 45 * The position of the mouse cursor. … … 145 145 146 146 /** 147 * Construct a new MapStatus and attach it to the map view.148 * @param mv The MapViewthe status line is part of.147 * Construct a new MapStatus and attach it to the Layer. 148 * @param mv The Layer the status line is part of. 149 149 */ 150 public MapStatus(final MapViewmv) {150 public MapStatus(final Layer mv) { 151 151 this.mv = mv; 152 152 -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r11 r15 48 48 public void actionPerformed(ActionEvent e) { 49 49 Preferences pref = new Preferences(); 50 pref. laf = (LookAndFeelInfo)lafCombo.getSelectedItem();51 pref. projection = (Projection)projectionCombo.getSelectedItem();52 pref. mergeNodes = mergeNodes.isSelected();53 Main.pref. projection = pref.projection;50 pref.setLaf((LookAndFeelInfo)lafCombo.getSelectedItem()); 51 pref.setProjection((Projection)projectionCombo.getSelectedItem()); 52 pref.setMergeNodes(mergeNodes.isSelected()); 53 Main.pref.setProjection(pref.getProjection()); 54 54 try { 55 55 pref.save(); … … 125 125 return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus); 126 126 }}); 127 lafCombo.setSelectedItem(pref. laf);127 lafCombo.setSelectedItem(pref.getLaf()); 128 128 lafCombo.addActionListener(new ActionListener(){ 129 129 public void actionPerformed(ActionEvent e) { … … 133 133 // projection method combo box 134 134 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 135 if (projectionCombo.getItemAt(i).getClass().equals(pref. projection.getClass())) {135 if (projectionCombo.getItemAt(i).getClass().equals(pref.getProjection().getClass())) { 136 136 projectionCombo.setSelectedIndex(i); 137 137 break; … … 160 160 map.add(labelNoteProjection, GBC.eol().insets(0,5,0,20)); 161 161 map.add(new JLabel("GPX import / export"), GBC.eol()); 162 mergeNodes.setSelected(pref. mergeNodes);162 mergeNodes.setSelected(pref.isMergeNodes()); 163 163 map.add(mergeNodes, GBC.eol()); 164 164 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); -
src/org/openstreetmap/josm/gui/SelectionManager.java
r8 r15 88 88 private Point mousePos; 89 89 /** 90 * The MapView, the selection rectangle is drawn onto.91 */ 92 private final MapViewmv;90 * The Layer, the selection rectangle is drawn onto. 91 */ 92 private final Layer mv; 93 93 /** 94 94 * Whether the selection rectangle must obtain the aspect ratio of the … … 104 104 * @param aspectRatio If true, the selection window must obtain the aspect 105 105 * ratio of the drawComponent. 106 * @param mapViewThe view, the rectangle is drawn onto.107 */ 108 public SelectionManager(SelectionEnded selectionEndedListener, boolean aspectRatio, MapView mapView) {106 * @param layer The view, the rectangle is drawn onto. 107 */ 108 public SelectionManager(SelectionEnded selectionEndedListener, boolean aspectRatio, Layer layer) { 109 109 this.selectionEndedListener = selectionEndedListener; 110 110 this.aspectRatio = aspectRatio; 111 this.mv = mapView;111 this.mv = layer; 112 112 } 113 113 -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r8 r15 1 1 package org.openstreetmap.josm.gui.dialogs; 2 2 3 import java.awt.event.ActionEvent;4 import java.awt.event.ActionListener;5 3 import java.awt.event.KeyEvent; 6 4 7 5 import javax.swing.BorderFactory; 8 6 import javax.swing.Box; 9 import javax.swing.BoxLayout;10 import javax.swing.JComboBox;11 import javax.swing.JComponent;12 import javax.swing.JLabel;13 import javax.swing.JPanel;14 import javax.swing.border.Border;15 7 16 import org.openstreetmap.josm.data.Preferences;17 import org.openstreetmap.josm.data.projection.Projection;18 8 import org.openstreetmap.josm.gui.Main; 19 9 import org.openstreetmap.josm.gui.MapFrame; … … 35 25 putValue(MNEMONIC_KEY, KeyEvent.VK_P); 36 26 37 final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0);27 // final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0); 38 28 Box panel = Box.createVerticalBox(); 39 29 40 30 // making an array of all projections and the current one within 41 Projection[] allProjections = Preferences.allProjections.clone();42 for (int i = 0; i < allProjections.length; ++i)43 if (allProjections[i].getClass() == frame.mapView.getProjection().getClass())44 allProjections[i] = frame.mapView.getProjection();45 46 // projection47 Box projectionPanel = Box.createHorizontalBox();48 projectionPanel.setBorder(panelBorder);49 projectionPanel.add(new JLabel("Projection"));50 final JComboBox projectionCombo = new JComboBox(allProjections);51 projectionPanel.add(projectionCombo);52 panel.add(projectionPanel);53 final JPanel configurationPanel = new JPanel();54 configurationPanel.setLayout(new BoxLayout(configurationPanel, BoxLayout.X_AXIS));55 56 // projections details57 projectionCombo.addActionListener(new ActionListener(){58 public void actionPerformed(ActionEvent e) {59 configurationPanel.removeAll();60 frame.mapView.setProjection((Projection)projectionCombo.getSelectedItem());61 JComponent panel = frame.mapView.getProjection().getConfigurationPanel();62 if (panel != null) {63 panel.setBorder(panelBorder);64 configurationPanel.add(panel);65 }66 pack();67 }68 });69 panel.add(configurationPanel);70 projectionCombo.setSelectedItem(frame.mapView.getProjection());31 // Projection[] allProjections = Preferences.allProjections.clone(); 32 // for (int i = 0; i < allProjections.length; ++i) 33 // if (allProjections[i].getClass() == frame.layer.getProjection().getClass()) 34 // allProjections[i] = frame.layer.getProjection(); 35 // 36 // // projection 37 // Box projectionPanel = Box.createHorizontalBox(); 38 // projectionPanel.setBorder(panelBorder); 39 // projectionPanel.add(new JLabel("Projection")); 40 // final JComboBox projectionCombo = new JComboBox(allProjections); 41 // projectionPanel.add(projectionCombo); 42 // panel.add(projectionPanel); 43 // final JPanel configurationPanel = new JPanel(); 44 // configurationPanel.setLayout(new BoxLayout(configurationPanel, BoxLayout.X_AXIS)); 45 // 46 // // projections details 47 // projectionCombo.addActionListener(new ActionListener(){ 48 // public void actionPerformed(ActionEvent e) { 49 // configurationPanel.removeAll(); 50 // frame.layer.setProjection((Projection)projectionCombo.getSelectedItem()); 51 // JComponent panel = frame.layer.getProjection().getConfigurationPanel(); 52 // if (panel != null) { 53 // panel.setBorder(panelBorder); 54 // configurationPanel.add(panel); 55 // } 56 // pack(); 57 // } 58 // }); 59 // panel.add(configurationPanel); 60 // projectionCombo.setSelectedItem(frame.layer.getProjection()); 71 61 72 62 panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r11 r15 2 2 3 3 import java.awt.event.ActionEvent; 4 import java.awt.event.KeyEvent;5 4 import java.util.HashMap; 6 5 import java.util.Map; … … 31 30 putValue(NAME, name); 32 31 putValue(MNEMONIC_KEY, mnemonic); 33 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_E,0));34 putValue(LONG_DESCRIPTION, "Open a selection list window.");32 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(mnemonic,0)); 33 putValue(LONG_DESCRIPTION, tooltip); 35 34 } 36 35 -
src/org/openstreetmap/josm/gui/engine/Engine.java
r8 r15 2 2 3 3 import java.awt.Graphics; 4 import java.beans.PropertyChangeEvent;5 import java.beans.PropertyChangeListener;6 4 7 5 import org.openstreetmap.josm.data.GeoPoint; … … 9 7 import org.openstreetmap.josm.data.osm.Node; 10 8 import org.openstreetmap.josm.data.osm.Track; 11 import org.openstreetmap.josm.data.projection.Projection; 12 import org.openstreetmap.josm.gui.MapView; 9 import org.openstreetmap.josm.gui.Layer; 13 10 14 11 /** … … 18 15 * @author imi 19 16 */ 20 abstract public class Engine implements PropertyChangeListener{17 abstract public class Engine { 21 18 22 /**23 * The projection method, this engine uses to render the graphics.24 */25 protected Projection projection;26 19 /** 27 20 * The Graphics surface to draw on. This should be set before each painting … … 30 23 protected Graphics g; 31 24 /** 32 * The mapView, this engine was created for.25 * The layer, this engine was created for. 33 26 */ 34 protected final MapView mv;27 protected final Layer layer; 35 28 36 29 37 30 /** 38 * Creates an Engine from an MapViewit belongs to.39 * @param mapViewThe mapview this engine belongs to.31 * Creates an Engine from an Layer it belongs to. 32 * @param layer The mapview this engine belongs to. 40 33 */ 41 public Engine(MapView mapView) { 42 mv = mapView; 43 mv.addPropertyChangeListener(this); 34 public Engine(Layer layer) { 35 this.layer = layer; 44 36 } 45 37 … … 73 65 */ 74 66 abstract public void drawPendingLineSegment(LineSegment ls); 75 76 /**77 * Called when the projection method for the map changed. Subclasses with78 * caches depending on the projection should empty the cache now.79 */80 public void propertyChange(PropertyChangeEvent e) {81 if (e.getPropertyName().equals("projection"))82 projection = (Projection)e.getNewValue();83 }84 67 } -
src/org/openstreetmap/josm/gui/engine/SimpleEngine.java
r8 r15 10 10 import org.openstreetmap.josm.data.osm.Node; 11 11 import org.openstreetmap.josm.data.osm.Track; 12 import org.openstreetmap.josm.gui. MapView;12 import org.openstreetmap.josm.gui.Layer; 13 13 14 14 /** … … 23 23 private final static Color darkgreen = new Color(0,128,0); 24 24 25 public SimpleEngine( MapView mapView) {26 super( mapView);25 public SimpleEngine(Layer layer) { 26 super(layer); 27 27 } 28 28 … … 33 33 public void drawBackground(GeoPoint ulGeo, GeoPoint lrGeo) { 34 34 g.setColor(Color.BLACK); 35 g.fillRect(0,0, mv.getWidth(),mv.getHeight());35 g.fillRect(0,0,layer.getWidth(),layer.getHeight()); 36 36 } 37 37 … … 109 109 private void drawLineSegment(LineSegment ls, Color color) { 110 110 g.setColor(ls.isSelected() ? Color.WHITE : color); 111 Point p1 = mv.getScreenPoint(ls.getStart().coor);112 Point p2 = mv.getScreenPoint(ls.getEnd().coor);111 Point p1 = layer.getScreenPoint(ls.getStart().coor); 112 Point p2 = layer.getScreenPoint(ls.getEnd().coor); 113 113 g.drawLine(p1.x, p1.y, p2.x, p2.y); 114 114 } … … 121 121 */ 122 122 private void drawNode(Node n, Color color) { 123 Point p = mv.getScreenPoint(n.coor);123 Point p = layer.getScreenPoint(n.coor); 124 124 g.setColor(color); 125 125 g.drawRect(p.x-1, p.y-1, 2, 2);
Note:
See TracChangeset
for help on using the changeset viewer.