Changeset 56 in josm for src/org/openstreetmap
- Timestamp:
- 2006-02-21T10:01:48+01:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/MapStatus.java
r51 r56 46 46 */ 47 47 public class MapStatus extends JPanel { 48 48 49 49 /** 50 50 * The MapView this status belongs. … … 59 59 */ 60 60 JTextField nameText = new JTextField(30); 61 61 62 62 /** 63 63 * The collector class that waits for notification and then update … … 83 83 */ 84 84 boolean exitCollector = false; 85 85 86 86 /** 87 87 * Execution function for the Collector. … … 99 99 if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null) 100 100 continue; // freeze display when holding down ctrl 101 Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos);102 103 if (osms == null && osmStatus == null && ms.modifiers == oldModifiers)104 continue;105 if (osms != null && osms.equals(osmStatus) && ms.modifiers == oldModifiers)106 continue;107 108 osmStatus = osms;109 oldModifiers = ms.modifiers;110 101 111 102 // This try/catch is a hack to stop the flooding bug reports about this. … … 113 104 // access to the data need to be restarted, if the main thread modifies 114 105 // the data. 115 OsmPrimitive osmNearest = null;116 106 try { 107 Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos); 108 109 if (osms == null && osmStatus == null && ms.modifiers == oldModifiers) 110 continue; 111 if (osms != null && osms.equals(osmStatus) && ms.modifiers == oldModifiers) 112 continue; 113 114 osmStatus = osms; 115 oldModifiers = ms.modifiers; 116 117 OsmPrimitive osmNearest = null; 117 118 // Set the text label in the bottom status bar 118 119 osmNearest = mv.getNearest(ms.mousePos, (ms.modifiers & MouseEvent.ALT_DOWN_MASK) != 0); 120 if (osmNearest != null) { 121 SelectionComponentVisitor visitor = new SelectionComponentVisitor(); 122 osmNearest.visit(visitor); 123 nameText.setText(visitor.name); 124 } else 125 nameText.setText(""); 126 127 // Popup Information 128 if ((ms.modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0 && osms != null) { 129 if (popup != null) 130 popup.hide(); 131 132 JPanel c = new JPanel(new GridBagLayout()); 133 for (final OsmPrimitive osm : osms) { 134 SelectionComponentVisitor visitor = new SelectionComponentVisitor(); 135 osm.visit(visitor); 136 final StringBuilder text = new StringBuilder(); 137 if (osm.id == 0 || osm.modified || osm.modifiedProperties) 138 visitor.name = "<i><b>"+visitor.name+"*</b></i>"; 139 text.append(visitor.name); 140 if (osm.id != 0) 141 text.append("<br>id="+osm.id); 142 if (osm.keys != null) 143 for (Entry<Key, String> e : osm.keys.entrySet()) 144 text.append("<br>"+e.getKey().name+"="+e.getValue()); 145 final JLabel l = new JLabel("<html>"+text.toString()+"</html>", visitor.icon, JLabel.HORIZONTAL); 146 l.setFont(l.getFont().deriveFont(Font.PLAIN)); 147 l.setVerticalTextPosition(JLabel.TOP); 148 l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 149 l.addMouseListener(new MouseAdapter(){ 150 @Override 151 public void mouseEntered(MouseEvent e) { 152 l.setText("<html><u color='blue'>"+text.toString()+"</u></html>"); 153 } 154 @Override 155 public void mouseExited(MouseEvent e) { 156 l.setText("<html>"+text.toString()+"</html>"); 157 } 158 @Override 159 public void mouseClicked(MouseEvent e) { 160 Main.main.ds.clearSelection(); 161 osm.setSelected(true); 162 mv.repaint(); 163 } 164 }); 165 c.add(l, GBC.eol()); 166 } 167 168 Point p = mv.getLocationOnScreen(); 169 popup = PopupFactory.getSharedInstance().getPopup(mv, c, p.x+ms.mousePos.x+16, p.y+ms.mousePos.y+16); 170 popup.show(); 171 } else if (popup != null) { 172 popup.hide(); 173 popup = null; 174 } 119 175 } catch (ConcurrentModificationException x) { 120 }121 if (osmNearest != null) {122 SelectionComponentVisitor visitor = new SelectionComponentVisitor();123 osmNearest.visit(visitor);124 nameText.setText(visitor.name);125 } else126 nameText.setText("");127 128 // Popup Information129 if ((ms.modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0 && osms != null) {130 if (popup != null)131 popup.hide();132 133 JPanel c = new JPanel(new GridBagLayout());134 for (final OsmPrimitive osm : osms) {135 SelectionComponentVisitor visitor = new SelectionComponentVisitor();136 osm.visit(visitor);137 final StringBuilder text = new StringBuilder();138 if (osm.id == 0 || osm.modified || osm.modifiedProperties)139 visitor.name = "<i><b>"+visitor.name+"*</b></i>";140 text.append(visitor.name);141 if (osm.id != 0)142 text.append("<br>id="+osm.id);143 if (osm.keys != null)144 for (Entry<Key, String> e : osm.keys.entrySet())145 text.append("<br>"+e.getKey().name+"="+e.getValue());146 final JLabel l = new JLabel("<html>"+text.toString()+"</html>", visitor.icon, JLabel.HORIZONTAL);147 l.setFont(l.getFont().deriveFont(Font.PLAIN));148 l.setVerticalTextPosition(JLabel.TOP);149 l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));150 l.addMouseListener(new MouseAdapter(){151 @Override152 public void mouseEntered(MouseEvent e) {153 l.setText("<html><u color='blue'>"+text.toString()+"</u></html>");154 }155 @Override156 public void mouseExited(MouseEvent e) {157 l.setText("<html>"+text.toString()+"</html>");158 }159 @Override160 public void mouseClicked(MouseEvent e) {161 Main.main.ds.clearSelection();162 osm.setSelected(true);163 mv.repaint();164 }165 });166 c.add(l, GBC.eol());167 }168 169 Point p = mv.getLocationOnScreen();170 popup = PopupFactory.getSharedInstance().getPopup(mv, c, p.x+ms.mousePos.x+16, p.y+ms.mousePos.y+16);171 popup.show();172 } else if (popup != null) {173 popup.hide();174 popup = null;175 176 } 176 177 } 177 178 } 178 179 } 179 180 180 181 /** 181 182 * Everything, the collector is interested of. Access must be synchronized. … … 220 221 add(new JLabel(" Object ")); 221 222 add(nameText); 222 223 223 224 // The background thread 224 225 final Collector collector = new Collector(); 225 226 new Thread(collector).start(); 226 227 227 228 // Listen to keyboard/mouse events for pressing/releasing alt key and 228 229 // inform the collector.
Note:
See TracChangeset
for help on using the changeset viewer.