Changeset 36 in josm for src/org/openstreetmap/josm/gui
- Timestamp:
- 2005-12-29T02:06:38+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm/gui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/MapStatus.java
r22 r36 2 2 3 3 import java.awt.AWTEvent; 4 import java.awt.Font; 5 import java.awt.GridBagLayout; 4 6 import java.awt.Point; 5 7 import java.awt.Toolkit; … … 10 12 import java.beans.PropertyChangeEvent; 11 13 import java.beans.PropertyChangeListener; 14 import java.util.Collection; 12 15 import java.util.Map.Entry; 13 16 … … 63 66 * The last object displayed in status line. 64 67 */ 65 OsmPrimitive osmStatus; 66 /** 67 * A visitor to retrieve name information about the osm primitive 68 */ 69 private SelectionComponentVisitor visitor = new SelectionComponentVisitor(); 68 Collection<OsmPrimitive> osmStatus; 70 69 /** 71 70 * The old modifiers, that was pressed the last time this collector ran. … … 96 95 if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null) 97 96 continue; // freeze display when holding down ctrl 98 OsmPrimitive osm = mv.getNearest(ms.mousePos, (ms.modifiers & MouseEvent.ALT_DOWN_MASK) != 0); 99 if (osm == osmStatus && ms.modifiers == oldModifiers) 97 Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos); 98 99 if (osms == null && osmStatus == null && ms.modifiers == oldModifiers) 100 100 continue; 101 osmStatus = osm; 101 if (osms != null && osms.equals(osmStatus) && ms.modifiers == oldModifiers) 102 continue; 103 104 osmStatus = osms; 102 105 oldModifiers = ms.modifiers; 103 if (osm != null) { 104 osm.visit(visitor); 106 107 // Set the text label in the bottom status bar 108 OsmPrimitive osmNearest = mv.getNearest(ms.mousePos, (ms.modifiers & MouseEvent.ALT_DOWN_MASK) != 0); 109 if (osmNearest != null) { 110 SelectionComponentVisitor visitor = new SelectionComponentVisitor(); 111 osmNearest.visit(visitor); 105 112 nameText.setText(visitor.name); 106 113 } else … … 108 115 109 116 // Popup Information 110 if ((ms.modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0 && osm != null) {117 if ((ms.modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0 && osms != null) { 111 118 if (popup != null) 112 119 popup.hide(); 113 120 114 StringBuilder text = new StringBuilder("<html>"); 115 text.append(visitor.name); 116 if (osm.keys != null) { 117 for (Entry<Key, String> e : osm.keys.entrySet()) { 118 text.append("<br>"); 119 text.append(e.getKey().name); 120 text.append("="); 121 text.append(e.getValue()); 122 } 121 JPanel c = new JPanel(new GridBagLayout()); 122 for (OsmPrimitive osm : osms) { 123 SelectionComponentVisitor visitor = new SelectionComponentVisitor(); 124 osm.visit(visitor); 125 StringBuilder text = new StringBuilder("<html>"); 126 if (osm.id == 0 || osm.modified || osm.modifiedProperties) 127 visitor.name = "<i><b>"+visitor.name+"*</b></i>"; 128 text.append(visitor.name); 129 if (osm.id != 0) 130 text.append("<br>id="+osm.id); 131 if (osm.keys != null) 132 for (Entry<Key, String> e : osm.keys.entrySet()) 133 text.append("<br>"+e.getKey().name+"="+e.getValue()); 134 JLabel l = new JLabel(text.toString()+"</html>", visitor.icon, JLabel.HORIZONTAL); 135 l.setFont(l.getFont().deriveFont(Font.PLAIN)); 136 l.setVerticalTextPosition(JLabel.TOP); 137 c.add(l, GBC.eol()); 123 138 } 124 JLabel l = new JLabel(text.toString(), visitor.icon, JLabel.HORIZONTAL);125 l.setVerticalTextPosition(JLabel.TOP);126 139 127 140 Point p = mv.getLocationOnScreen(); 128 popup = PopupFactory.getSharedInstance().getPopup(mv, l, p.x+ms.mousePos.x+16, p.y+ms.mousePos.y+16);141 popup = PopupFactory.getSharedInstance().getPopup(mv, c, p.x+ms.mousePos.x+16, p.y+ms.mousePos.y+16); 129 142 popup.show(); 130 143 } else if (popup != null) { -
src/org/openstreetmap/josm/gui/MapView.java
r35 r36 11 11 import java.util.Collection; 12 12 import java.util.Collections; 13 import java.util.HashSet; 13 14 import java.util.LinkedList; 14 15 … … 137 138 // autoselect the new layer 138 139 setActiveLayer(layer); 140 recalculateCenterScale(); 139 141 } 140 142 … … 292 294 } 293 295 296 /** 297 * @return A list of all objects that are nearest to 298 * the mouse. To do this, first the nearest object is 299 * determined. 300 * 301 * If its a node, return all line segments and 302 * streets the node is part of, as well as all nodes 303 * (with their line segments and tracks) with the same 304 * location. 305 * 306 * If its a line segment, return all tracks this segment 307 * belongs to as well as all line segments that are between 308 * the same nodes (in both direction) with all their tracks. 309 * 310 * @return A collection of all items or <code>null</code> 311 * if no item under or near the point. The returned 312 * list is never empty. 313 */ 314 public Collection<OsmPrimitive> getAllNearest(Point p) { 315 OsmPrimitive osm = getNearest(p, false); 316 if (osm == null) 317 return null; 318 Collection<OsmPrimitive> c = new HashSet<OsmPrimitive>(); 319 c.add(osm); 320 if (osm instanceof Node) { 321 Node node = (Node)osm; 322 for (Node n : Main.main.ds.nodes) 323 if (n.coor.equalsLatLon(node.coor)) 324 c.add(n); 325 for (LineSegment ls : Main.main.ds.lineSegments) 326 // line segments never match nodes, so they are skipped by contains 327 if (c.contains(ls.start) || c.contains(ls.end)) 328 c.add(ls); 329 } 330 if (osm instanceof LineSegment) { 331 LineSegment line = (LineSegment)osm; 332 for (LineSegment ls : Main.main.ds.lineSegments) 333 if (ls.equalPlace(line)) 334 c.add(ls); 335 } 336 if (osm instanceof Node || osm instanceof LineSegment) { 337 for (Track t : Main.main.ds.tracks) { 338 for (LineSegment ls : t.segments) { 339 if (c.contains(ls)) { 340 c.add(t); 341 break; 342 } 343 } 344 } 345 } 346 return c; 347 } 294 348 295 349 /** -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r30 r36 96 96 97 97 final JOptionPane optionPane = new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 98 final JDialog dlg = optionPane.createDialog( PropertiesDialog.this, "Change values?");98 final JDialog dlg = optionPane.createDialog(Main.main, "Change values?"); 99 99 dlg.addWindowFocusListener(new WindowFocusListener(){ 100 100 public void windowGainedFocus(WindowEvent e) { … … 162 162 JTextField values = new JTextField(); 163 163 p2.add(values, BorderLayout.CENTER); 164 int answer = JOptionPane.showConfirmDialog( PropertiesDialog.this, p,164 int answer = JOptionPane.showConfirmDialog(Main.main, p, 165 165 "Change values?", JOptionPane.OK_CANCEL_OPTION); 166 166 if (answer != JOptionPane.OK_OPTION) … … 251 251 else if (e.getActionCommand().equals("Edit")) { 252 252 if (sel == -1) 253 JOptionPane.showMessageDialog( PropertiesDialog.this, "Please select the row to edit.");253 JOptionPane.showMessageDialog(Main.main, "Please select the row to edit."); 254 254 else 255 255 edit(sel); 256 256 } else if (e.getActionCommand().equals("Delete")) { 257 257 if (sel == -1) 258 JOptionPane.showMessageDialog( PropertiesDialog.this, "Please select the row to delete.");258 JOptionPane.showMessageDialog(Main.main, "Please select the row to delete."); 259 259 else 260 260 delete(sel);
Note:
See TracChangeset
for help on using the changeset viewer.