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


Ignore:
Timestamp:
2017-11-25T00:10:36+01:00 (6 years ago)
Author:
Don-vip
Message:

see #15550 - better (?) resizing of note tooltips

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r13128 r13157  
    2525import javax.swing.Icon;
    2626import javax.swing.ImageIcon;
     27import javax.swing.JEditorPane;
    2728import javax.swing.JWindow;
    2829import javax.swing.SwingUtilities;
    2930import javax.swing.UIManager;
     31import javax.swing.plaf.basic.BasicHTML;
     32import javax.swing.text.View;
    3033
    3134import org.openstreetmap.josm.Main;
     
    227230
    228231    private void fixPanelSize(MapView mv, String text) {
    229         Dimension d = displayedPanel.getPreferredSize();
    230         if (d.width > mv.getWidth() / 2) {
     232        int maxWidth = mv.getWidth() * 2/3;
     233        JEditorPane pane = displayedPanel.getEditorPane();
     234        if (pane.getPreferredSize().width > maxWidth && Config.getPref().getBoolean("note.text.break-on-sentence-mark", false)) {
    231235            // To make sure long notes are displayed correctly
    232236            displayedPanel.setText(insertLineBreaks(text));
     237        }
     238        // If still too large, enforce maximum size
     239        Dimension d = pane.getPreferredSize();
     240        if (d.width > maxWidth) {
     241            View v = (View) pane.getClientProperty(BasicHTML.propertyKey);
     242            if (v == null) {
     243                BasicHTML.updateRenderer(pane, text);
     244                v = (View) pane.getClientProperty(BasicHTML.propertyKey);
     245            }
     246            if (v != null) {
     247                v.setSize(maxWidth, 0);
     248                int w = (int) Math.ceil(v.getPreferredSpan(View.X_AXIS)) + 30;
     249                int h = (int) Math.ceil(v.getPreferredSpan(View.Y_AXIS)) + 10;
     250                pane.setPreferredSize(new Dimension(w, h));
     251            }
    233252        }
    234253    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/JMultilineLabel.java

    r11452 r13157  
    4646     */
    4747    public JMultilineLabel(String text, boolean allBold) {
     48        this(text, allBold, false);
     49    }
     50
     51    /**
     52     * Constructs a normal label but adds HTML tags if not already done so.
     53     * Supports both newline characters (<code>\n</code>) as well as the HTML
     54     * <code>&lt;br&gt;</code> to insert new lines.
     55     *
     56     * Use setMaxWidth to limit the width of the label.
     57     * @param text The text to display
     58     * @param allBold If {@code true}, makes all text to be displayed in bold
     59     * @param focusable indicates whether this label is focusable
     60     * @since 13157
     61     */
     62    public JMultilineLabel(String text, boolean allBold, boolean focusable) {
    4863        JosmEditorPane.makeJLabelLike(this, allBold);
    4964        String html = text.trim().replaceAll("\n", "<br>");
     
    5166            html = "<html>" + html + "</html>";
    5267        }
    53         setFocusable(false);
     68        setFocusable(focusable);
    5469        super.setText(html);
    5570    }
Note: See TracChangeset for help on using the changeset viewer.