Changeset 56 in josm


Ignore:
Timestamp:
2006-02-21T10:01:48+01:00 (18 years ago)
Author:
imi
Message:

hacked the ConcurrentModificationException again by widen the range of the try statement.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/MapStatus.java

    r51 r56  
    4646 */
    4747public class MapStatus extends JPanel {
    48 
     48       
    4949        /**
    5050         * The MapView this status belongs.
     
    5959         */
    6060        JTextField nameText = new JTextField(30);
    61 
     61       
    6262        /**
    6363         * The collector class that waits for notification and then update
     
    8383                 */
    8484                boolean exitCollector = false;
    85 
     85               
    8686                /**
    8787                 * Execution function for the Collector.
     
    9999                                if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null)
    100100                                        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;
    110101
    111102                                // This try/catch is a hack to stop the flooding bug reports about this.
     
    113104                                // access to the data need to be restarted, if the main thread modifies
    114105                                // the data.
    115                                 OsmPrimitive osmNearest = null;
    116106                                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;
    117118                                        // Set the text label in the bottom status bar
    118119                                        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                                        }
    119175                                } catch (ConcurrentModificationException x) {
    120                                 }
    121                                 if (osmNearest != null) {
    122                                         SelectionComponentVisitor visitor = new SelectionComponentVisitor();
    123                                         osmNearest.visit(visitor);
    124                                         nameText.setText(visitor.name);
    125                                 } else
    126                                         nameText.setText("");
    127                                
    128                                 // Popup Information
    129                                 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                                                         @Override
    152                                                         public void mouseEntered(MouseEvent e) {
    153                                                                 l.setText("<html><u color='blue'>"+text.toString()+"</u></html>");
    154                                                         }
    155                                                         @Override
    156                                                         public void mouseExited(MouseEvent e) {
    157                                                                 l.setText("<html>"+text.toString()+"</html>");
    158                                                         }
    159                                                         @Override
    160                                                         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;
    175176                                }
    176177                        }
    177178                }
    178179        }
    179 
     180       
    180181        /**
    181182         * Everything, the collector is interested of. Access must be synchronized.
     
    220221                add(new JLabel(" Object "));
    221222                add(nameText);
    222 
     223               
    223224                // The background thread
    224225                final Collector collector = new Collector();
    225226                new Thread(collector).start();
    226 
     227               
    227228                // Listen to keyboard/mouse events for pressing/releasing alt key and
    228229                // inform the collector.
Note: See TracChangeset for help on using the changeset viewer.