Changeset 2137 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2009-09-14T21:57:36+02:00 (15 years ago)
Author:
xeen
Message:
  • close #3490 (Add editor username to middleclick menu)
  • improve overflow handling of middle mouse popup
File:
1 edited

Legend:

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

    r2127 r2137  
    3434import javax.swing.JLabel;
    3535import javax.swing.JPanel;
     36import javax.swing.JScrollPane;
    3637import javax.swing.JTextField;
    3738import javax.swing.Popup;
     
    194195                        }
    195196
    196                         JPanel c = new JPanel(new GridBagLayout());
    197                         c.setBorder(BorderFactory.createRaisedBevelBorder());
     197                        final JPanel c = new JPanel(new GridBagLayout());
    198198                        final JLabel lbl = new JLabel(
    199199                                "<html>"+tr("Middle click again, to cycle through.<br>"+
     
    240240        /**
    241241         * Creates a popup for the given content next to the cursor. Tries to
    242          * keep the popup on screen.
     242         * keep the popup on screen and shows a vertical scrollbar, if the
     243         * screen is too small.
    243244         * @param content
    244245         * @param ms
     
    257258            }
    258259            int yPos = p.y + ms.mousePos.y + 16;
    259             // Move the popup up if it would be cut off at its bottom
     260            // Move the popup up if it would be cut off at its bottom but do not
     261            // move it off screen on the top
    260262            if(yPos + dim.height > scrn.height - 5) {
    261                 yPos = scrn.height - dim.height - 5;
    262             }
     263                yPos = Math.max(5, scrn.height - dim.height - 5);
     264            }
     265
     266            // Create a JScrollPane around the content, in case there's still
     267            // not enough space
     268            JScrollPane sp = new JScrollPane(content);
     269            sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
     270            sp.setBorder(BorderFactory.createRaisedBevelBorder());
     271            // Implement max-size content-independent
     272            Dimension prefsize = sp.getPreferredSize();
     273            int w = Math.min(prefsize.width, scrn.width/2);
     274            int h = Math.min(prefsize.height, scrn.height - 10);
     275            sp.setPreferredSize(new Dimension(w, h));
    263276
    264277            PopupFactory pf = PopupFactory.getSharedInstance();
    265             return pf.getPopup(mv, content, xPos, yPos);
     278            return pf.getPopup(mv, sp, xPos, yPos);
    266279        }
    267280
     
    394407            String name = osm.getDisplayName(DefaultNameFormatter.getInstance());
    395408            if (osm.getId() == 0 || osm.isModified()) {
    396                 name = "<i><b>"+ osm.getDisplayName(DefaultNameFormatter.getInstance())+"*</b></i>";
     409                name = "<i><b>"+ name + "*</b></i>";
    397410            }
    398411            text.append(name);
     412
    399413            if (osm.getId() != 0) {
    400                 text.append("<br>id="+osm.getId());
    401             }
     414                text.append(" [id="+osm.getId()+"]");
     415            }
     416
     417            if(osm.user != null) {
     418                text.append(" [" + tr("User:") + " " + osm.user.getName() + "]");
     419            }
     420
    402421            for (Entry<String, String> e1 : osm.entrySet()) {
    403                 text.append("<br>"+e1.getKey()+"="+e1.getValue());
     422                text.append("<br>" + e1.getKey() + "=" + e1.getValue());
    404423            }
    405424
    406425            final JLabel l = new JLabel(
    407                     "<html>"+text.toString()+"</html>",
     426                    "<html>" +text.toString() + "</html>",
    408427                    ImageProvider.get(OsmPrimitiveType.from(osm)),
    409428                    JLabel.HORIZONTAL
Note: See TracChangeset for help on using the changeset viewer.