Changeset 10191 in josm


Ignore:
Timestamp:
2016-05-11T18:28:35+02:00 (9 years ago)
Author:
Don-vip
Message:

fix #7302 - Field showing name of object under cursor is often too short. Adapt it dynamically so it always displays at least 20 characters for width of 1280 pixels or less, and at most 80 characters for width of 1920 pixels or more

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

Legend:

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

    r10179 r10191  
    2121import java.awt.event.AWTEventListener;
    2222import java.awt.event.ActionEvent;
     23import java.awt.event.ComponentAdapter;
     24import java.awt.event.ComponentEvent;
    2325import java.awt.event.InputEvent;
    2426import java.awt.event.KeyAdapter;
     
    197199            tr("The length of the new way segment being drawn."), 10, PROP_BACKGROUND_COLOR.get());
    198200    private final ImageLabel nameText = new ImageLabel("name",
    199             tr("The name of the object at the mouse pointer."), 20, PROP_BACKGROUND_COLOR.get());
     201            tr("The name of the object at the mouse pointer."), getNameLabelCharacterCount(Main.parent), PROP_BACKGROUND_COLOR.get());
    200202    private final JosmTextField helpText = new JosmTextField();
    201203    private final JProgressBar progressBar = new JProgressBar();
     204    private final transient ComponentAdapter mvComponentAdapter;
    202205    public final transient BackgroundProgressMonitor progressMonitor = new BackgroundProgressMonitor();
    203206
     
    948951        Main.pref.addPreferenceChangeListener(this);
    949952
     953        mvComponentAdapter = new ComponentAdapter() {
     954            @Override
     955            public void componentResized(ComponentEvent e) {
     956                nameText.setCharCount(getNameLabelCharacterCount(Main.parent));
     957                revalidate();
     958            }
     959        };
     960        mv.addComponentListener(mvComponentAdapter);
     961
    950962        // The background thread
    951963        thread = new Thread(collector, "Map Status Collector");
     
    10781090        SystemOfMeasurement.removeSoMChangeListener(this);
    10791091        Main.pref.removePreferenceChangeListener(this);
     1092        mv.removeComponentListener(mvComponentAdapter);
    10801093
    10811094        // MapFrame gets destroyed when the last layer is removed, but the status line background
     
    11171130        PROP_ACTIVE_FOREGROUND_COLOR.get();
    11181131    }
     1132
     1133    private static int getNameLabelCharacterCount(Component parent) {
     1134        int w = parent != null ? parent.getWidth() : 800;
     1135        return Math.min(80, 20 + Math.max(0, w-1280) * 60 / (1920-1280));
     1136    }
    11191137}
  • trunk/src/org/openstreetmap/josm/gui/widgets/ImageLabel.java

    r10179 r10191  
    2020    private final JLabel imgLabel = new JLabel();
    2121    private final JLabel tf = new JLabel();
    22     private final int charCount;
     22    private int charCount;
    2323
    2424    /**
     
    3636        add(tf, GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2, 1, 1, 0));
    3737        setToolTipText(tooltip);
    38         this.charCount = charCount;
     38        setCharCount(charCount);
    3939    }
    4040
     
    6464        return new Dimension(25 + charCount*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);
    6565    }
     66
     67    /**
     68     * Returns the preferred char count.
     69     * @return the preferred char count
     70     * @since 10191
     71     */
     72    public final int getCharCount() {
     73        return charCount;
     74    }
     75
     76    /**
     77     * Sets the preferred char count.
     78     * @param charCount the preferred char count
     79     * @since 10191
     80     */
     81    public final void setCharCount(int charCount) {
     82        this.charCount = charCount;
     83    }
    6684}
Note: See TracChangeset for help on using the changeset viewer.