Changeset 7505 in josm for trunk/src


Ignore:
Timestamp:
2014-09-05T16:28:05+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #10461 - Preset UI: show which tags will be changed

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

Legend:

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

    r7411 r7505  
    592592        private JComponent value;
    593593
    594         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     594        @Override
     595        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    595596
    596597            // find out if our key is already used in the selection.
     
    602603                initAutoCompletionField(textField, key);
    603604            }
     605            textField.setHint(key);
    604606            if (length != null && !length.isEmpty()) {
    605607                textField.setMaxChars(Integer.valueOf(length));
     
    12191221            AutoCompletingTextField tf = new AutoCompletingTextField();
    12201222            initAutoCompletionField(tf, key);
     1223            tf.setHint(key);
    12211224            if (length != null && !length.isEmpty()) {
    12221225                tf.setMaxChars(Integer.valueOf(length));
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java

    r7375 r7505  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.widgets;
     3
     4import java.awt.Color;
     5import java.awt.FontMetrics;
     6import java.awt.Graphics;
     7import java.awt.Graphics2D;
     8import java.awt.Insets;
     9import java.awt.RenderingHints;
     10import java.awt.event.FocusEvent;
     11import java.awt.event.FocusListener;
    312
    413import javax.swing.JTextField;
     
    615
    716/**
    8  * Subclass of {@link JTextField} that adds a "native" context menu (cut/copy/paste/select all).
     17 * Subclass of {@link JTextField} that adds a "native" context menu (cut/copy/paste/select all)
     18 * and an optional "hint" displayed when no text has been entered.
    919 * @since 5886
    1020 */
    11 public class JosmTextField extends JTextField {
     21public class JosmTextField extends JTextField implements FocusListener {
     22
     23    private String hint;
    1224
    1325    /**
     
    3446            setMinimumSize(getPreferredSize());
    3547        }
     48        addFocusListener(this);
    3649    }
    3750
     
    8497        this(null, null, 0);
    8598    }
     99
     100    /**
     101     * Replies the hint displayed when no text has been entered.
     102     * @return the hint
     103     * @since 7505
     104     */
     105    public final String getHint() {
     106        return hint;
     107    }
     108
     109    /**
     110     * Sets the hint to display when no text has been entered.
     111     * @param hint the hint to set
     112     * @since 7505
     113     */
     114    public final void setHint(String hint) {
     115        this.hint = hint;
     116    }
     117
     118    @Override
     119    public void paint(Graphics g) {
     120        super.paint(g);
     121        if (hint != null && !hint.isEmpty() && getText().isEmpty() && !isFocusOwner()) {
     122            // Taken from http://stackoverflow.com/a/24571681/2257172
     123            int h = getHeight();
     124            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     125            Insets ins = getInsets();
     126            FontMetrics fm = g.getFontMetrics();
     127            int c0 = getBackground().getRGB();
     128            int c1 = getForeground().getRGB();
     129            int m = 0xfefefefe;
     130            int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1);
     131            g.setColor(new Color(c2, true));
     132            g.drawString(hint, ins.left, h / 2 + fm.getAscent() / 2 - 2);
     133        }
     134    }
     135
     136    @Override
     137    public void focusGained(FocusEvent e) {
     138        repaint();
     139    }
     140
     141    @Override
     142    public void focusLost(FocusEvent e) {
     143        repaint();
     144    }
    86145}
Note: See TracChangeset for help on using the changeset viewer.