Changeset 17768 in josm


Ignore:
Timestamp:
2021-04-13T18:05:39+02:00 (3 years ago)
Author:
simon04
Message:

fix #19645 - Add a search icon to search boxes of lists (icon by Klumbumbus, PD and CC0 licensed)

Location:
trunk
Files:
1 added
11 edited

Legend:

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

    r17714 r17768  
    5353import org.openstreetmap.josm.gui.util.DocumentAdapter;
    5454import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
     55import org.openstreetmap.josm.gui.widgets.FilterField;
    5556import org.openstreetmap.josm.gui.widgets.JosmTextField;
    5657import org.openstreetmap.josm.spi.preferences.Config;
     
    233234    private JosmTextField setupFilter() {
    234235        final JosmTextField f = new DisableShortcutsOnFocusGainedTextField();
     236        FilterField.setSearchIcon(f);
    235237        f.setToolTipText(tr("Note filter"));
    236238        f.getDocument().addDocumentListener(DocumentAdapter.create(ignore -> {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r17422 r17768  
    8585import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator;
    8686import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
     87import org.openstreetmap.josm.gui.widgets.FilterField;
    8788import org.openstreetmap.josm.gui.widgets.JosmTextField;
    8889import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    322323    private JosmTextField setupFilter() {
    323324        final JosmTextField f = new DisableShortcutsOnFocusGainedTextField();
     325        FilterField.setSearchIcon(f);
    324326        f.setToolTipText(tr("Relation list filter"));
    325327        final CompileSearchTextDecorator decorator = CompileSearchTextDecorator.decorate(f);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r17585 r17768  
    107107import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator;
    108108import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
     109import org.openstreetmap.josm.gui.widgets.FilterField;
    109110import org.openstreetmap.josm.gui.widgets.JosmTextField;
    110111import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    544545    private JosmTextField setupFilter() {
    545546        final JosmTextField f = new DisableShortcutsOnFocusGainedTextField();
     547        FilterField.setSearchIcon(f);
    546548        f.setToolTipText(tr("Tag filter"));
    547549        final CompileSearchTextDecorator decorator = CompileSearchTextDecorator.decorate(f);
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java

    r17713 r17768  
    2727import javax.swing.JButton;
    2828import javax.swing.JFileChooser;
    29 import javax.swing.JLabel;
    3029import javax.swing.JMenu;
    3130import javax.swing.JOptionPane;
     
    5453import org.openstreetmap.josm.gui.util.GuiHelper;
    5554import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
     55import org.openstreetmap.josm.gui.widgets.FilterField;
    5656import org.openstreetmap.josm.gui.widgets.JosmTextField;
    5757import org.openstreetmap.josm.spi.preferences.Config;
     
    168168        final JPanel txtFilterPanel = new JPanel(new GridBagLayout());
    169169        p.add(txtFilterPanel, GBC.eol().fill(GBC.HORIZONTAL));
    170         txtFilter = new JosmTextField();
    171         JLabel lbFilter = new JLabel(tr("Search:"));
    172         lbFilter.setLabelFor(txtFilter);
    173         txtFilterPanel.add(lbFilter, GBC.std().insets(0, 0, 5, 0));
    174         txtFilterPanel.add(txtFilter, GBC.eol().fill(GBC.HORIZONTAL));
     170        txtFilter = new FilterField();
     171        txtFilterPanel.add(txtFilter, GBC.eol().insets(0, 0, 0, 5).fill(GBC.HORIZONTAL));
    175172        txtFilter.getDocument().addDocumentListener(DocumentAdapter.create(ignore -> applyFilter()));
    176173        readPreferences(Preferences.main());
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java

    r17648 r17768  
    373373        JPanel panel = new JPanel(new GridBagLayout());
    374374        panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    375         panel.add(colorFilter, GBC.eol().fill(HORIZONTAL));
     375        panel.add(colorFilter, GBC.eol().insets(0, 0, 0, 5).fill(HORIZONTAL));
    376376        JScrollPane scrollpane = new JScrollPane(colors);
    377377        scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    r17332 r17768  
    99import java.awt.BorderLayout;
    1010import java.awt.Component;
    11 import java.awt.GridBagConstraints;
    1211import java.awt.GridBagLayout;
    1312import java.awt.GridLayout;
    14 import java.awt.Insets;
    1513import java.awt.event.ActionEvent;
    1614import java.awt.event.ComponentAdapter;
     
    2826
    2927import javax.swing.AbstractAction;
    30 import javax.swing.BorderFactory;
    3128import javax.swing.ButtonGroup;
    3229import javax.swing.DefaultListModel;
     
    167164    private JPanel buildSearchFieldPanel() {
    168165        JPanel pnl = new JPanel(new GridBagLayout());
    169         pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    170         GridBagConstraints gc = new GridBagConstraints();
    171 
    172         gc.anchor = GridBagConstraints.NORTHWEST;
    173         gc.fill = HORIZONTAL;
    174         gc.weightx = 0.0;
    175         gc.insets = new Insets(0, 0, 0, 3);
    176166        pnl.add(GBC.glue(0, 0));
    177167
    178         gc.weightx = 1.0;
    179168        ButtonGroup bg = new ButtonGroup();
    180169        JPanel radios = new JPanel();
    181         addRadioButton(bg, radios, new JRadioButton(trc("plugins", "All"), true), gc, PluginInstallation.ALL);
    182         addRadioButton(bg, radios, new JRadioButton(trc("plugins", "Installed")), gc, PluginInstallation.INSTALLED);
    183         addRadioButton(bg, radios, new JRadioButton(trc("plugins", "Available")), gc, PluginInstallation.AVAILABLE);
    184         pnl.add(radios, gc);
    185 
    186         gc.gridx = 0;
    187         gc.weightx = 0.0;
    188         pnl.add(new JLabel(tr("Search:")), gc);
    189 
    190         gc.gridx = 1;
    191         gc.weightx = 1.0;
     170        addRadioButton(bg, radios, new JRadioButton(trc("plugins", "All"), true), PluginInstallation.ALL);
     171        addRadioButton(bg, radios, new JRadioButton(trc("plugins", "Installed")), PluginInstallation.INSTALLED);
     172        addRadioButton(bg, radios, new JRadioButton(trc("plugins", "Available")), PluginInstallation.AVAILABLE);
     173        pnl.add(radios, GBC.eol().fill(HORIZONTAL));
     174
    192175        pnl.add(new FilterField().filter(expr -> {
    193176            model.filterDisplayedPlugins(expr);
    194177            pnlPluginPreferences.refreshView();
    195         }), gc);
     178        }), GBC.eol().insets(0, 0, 0, 5).fill(HORIZONTAL));
    196179        return pnl;
    197180    }
    198181
    199     private void addRadioButton(ButtonGroup bg, JPanel pnl, JRadioButton rb, GridBagConstraints gc, PluginInstallation value) {
     182    private void addRadioButton(ButtonGroup bg, JPanel pnl, JRadioButton rb, PluginInstallation value) {
    200183        bg.add(rb);
    201         pnl.add(rb, gc);
     184        pnl.add(rb, GBC.std());
    202185        rb.addActionListener(e -> {
    203186            model.filterDisplayedPlugins(value);
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CodeSelectionPanel.java

    r16960 r17768  
    2323import org.openstreetmap.josm.gui.preferences.projection.CodeProjectionChoice.CodeComparator;
    2424import org.openstreetmap.josm.gui.util.TableHelper;
     25import org.openstreetmap.josm.gui.widgets.FilterField;
    2526import org.openstreetmap.josm.gui.widgets.JosmTextField;
    2627import org.openstreetmap.josm.tools.GBC;
     
    3233public class CodeSelectionPanel extends JPanel implements ListSelectionListener, DocumentListener {
    3334
    34     private final JosmTextField filter = new JosmTextField(30);
     35    private final JosmTextField filter = new FilterField();
    3536    private final ProjectionCodeModel model = new ProjectionCodeModel();
    3637    private JTable table;
     
    104105
    105106        this.setLayout(new GridBagLayout());
    106         this.add(filter, GBC.eol().weight(1.0, 0.0));
     107        this.add(filter, GBC.eol().fill(GBC.HORIZONTAL).weight(1.0, 0.0));
    107108        this.add(scroll, GBC.eol().fill(GBC.HORIZONTAL));
    108109    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java

    r17733 r17768  
    88import java.awt.Component;
    99import java.awt.Dimension;
    10 import java.awt.GridBagConstraints;
    1110import java.awt.GridBagLayout;
    1211import java.awt.GridLayout;
    13 import java.awt.Insets;
    1412import java.awt.Toolkit;
    1513import java.awt.event.KeyEvent;
     
    2119
    2220import javax.swing.AbstractAction;
    23 import javax.swing.BorderFactory;
    2421import javax.swing.BoxLayout;
    2522import javax.swing.DefaultComboBoxModel;
     
    4441import org.openstreetmap.josm.gui.widgets.FilterField;
    4542import org.openstreetmap.josm.gui.widgets.JosmComboBox;
     43import org.openstreetmap.josm.tools.GBC;
    4644import org.openstreetmap.josm.tools.KeyboardUtils;
    4745import org.openstreetmap.josm.tools.Logging;
     
    251249        // copied from PluginPreference
    252250        JPanel pnl = new JPanel(new GridBagLayout());
    253         pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    254         GridBagConstraints gc = new GridBagConstraints();
    255 
    256         gc.anchor = GridBagConstraints.NORTHWEST;
    257         gc.fill = GridBagConstraints.HORIZONTAL;
    258         gc.weightx = 0.0;
    259         gc.insets = new Insets(0, 0, 0, 5);
    260         pnl.add(new JLabel(tr("Search:")), gc);
    261 
    262         gc.gridx = 1;
    263         gc.weightx = 1.0;
    264         pnl.add(filterField, gc);
    265         pnl.setMaximumSize(new Dimension(300, 10));
     251        pnl.add(filterField, GBC.eol().insets(0, 0, 0, 5).fill(GBC.HORIZONTAL));
     252        pnl.setMaximumSize(new Dimension(Integer.MAX_VALUE, 10));
    266253        return pnl;
    267254    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/FilterField.java

    r16643 r17768  
    1818import javax.swing.table.TableRowSorter;
    1919
     20import org.openstreetmap.josm.tools.ImageProvider;
    2021import org.openstreetmap.josm.tools.Logging;
    2122import org.openstreetmap.josm.tools.Utils;
     
    3132     */
    3233    public FilterField() {
     34        setSearchIcon(this);
    3335        setToolTipText(tr("Enter a search expression"));
    3436        SelectAllOnFocusGainedDecorator.decorate(this);
     37    }
     38
     39    /**
     40     * Sets the search icon for the given text field
     41     * @param textField the text field
     42     * @since 17768
     43     */
     44    public static void setSearchIcon(JosmTextField textField) {
     45        textField.setIcon(ImageProvider.get("listsearch"));
    3546    }
    3647
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java

    r14977 r17768  
    1111import java.awt.event.FocusListener;
    1212
     13import javax.swing.BorderFactory;
     14import javax.swing.Icon;
    1315import javax.swing.JTextField;
     16import javax.swing.border.Border;
    1417import javax.swing.text.Document;
    1518
     
    3134    private final PopupMenuLauncher launcher;
    3235    private String hint;
     36    private Icon icon;
     37    private int leftInsets;
    3338
    3439    /**
     
    149154
    150155    /**
     156     * Returns the icon to display
     157     * @return the icon to display
     158     * @since 17768
     159     */
     160    public Icon getIcon() {
     161        return icon;
     162    }
     163
     164    /**
     165     * Sets the icon to display
     166     * @param icon the icon to set
     167     * @since 17768
     168     */
     169    public void setIcon(Icon icon) {
     170        this.icon = icon;
     171        if (icon != null) {
     172            this.leftInsets = getInsets().left;
     173            Border original = getBorder();
     174            Border margin = BorderFactory.createEmptyBorder(0, icon.getIconWidth(), 0, 0);
     175            setBorder(original == null ? margin : BorderFactory.createCompoundBorder(original, margin));
     176        }
     177    }
     178
     179    /**
    151180     * Empties the internal undo manager.
    152181     * @since 14977
     
    159188    public void paint(Graphics g) {
    160189        super.paint(g);
     190        if (icon != null) {
     191            int h = getHeight() - icon.getIconHeight();
     192            icon.paintIcon(this, g, Math.min(leftInsets, h / 2), h / 2);
     193        }
    161194        if (hint != null && !hint.isEmpty() && getText().isEmpty() && !isFocusOwner()) {
    162195            // Taken from http://stackoverflow.com/a/24571681/2257172
  • trunk/src/org/openstreetmap/josm/gui/widgets/SearchTextResultListPanel.java

    r17713 r17768  
    4343        super(new BorderLayout());
    4444
    45         edSearchText = new JosmTextField();
     45        edSearchText = new FilterField();
    4646        edSearchText.getDocument().addDocumentListener(DocumentAdapter.create(ignore -> filterItems()));
    4747        edSearchText.addKeyListener(new KeyAdapter() {
Note: See TracChangeset for help on using the changeset viewer.