Changeset 8980 in josm for trunk/src/org


Ignore:
Timestamp:
2015-11-02T21:19:25+01:00 (4 years ago)
Author:
simon04
Message:

fix #9463 - Properties dialog: add text field for tag filtering

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/properties
Files:
1 added
1 edited

Legend:

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

    r8863 r8980  
    99import java.awt.GridBagLayout;
    1010import java.awt.Point;
     11import java.awt.TextField;
    1112import java.awt.event.ActionEvent;
    1213import java.awt.event.InputEvent;
     
    1415import java.awt.event.MouseAdapter;
    1516import java.awt.event.MouseEvent;
     17import java.beans.PropertyChangeEvent;
     18import java.beans.PropertyChangeListener;
    1619import java.net.HttpURLConnection;
    1720import java.net.URI;
     
    4245import javax.swing.KeyStroke;
    4346import javax.swing.ListSelectionModel;
     47import javax.swing.RowFilter;
    4448import javax.swing.event.ListSelectionEvent;
    4549import javax.swing.event.ListSelectionListener;
     
    4852import javax.swing.table.TableColumnModel;
    4953import javax.swing.table.TableModel;
     54import javax.swing.table.TableRowSorter;
    5055
    5156import org.openstreetmap.josm.Main;
     
    5762import org.openstreetmap.josm.actions.relation.SelectRelationAction;
    5863import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
     64import org.openstreetmap.josm.actions.search.SearchCompiler;
    5965import org.openstreetmap.josm.command.ChangeCommand;
    6066import org.openstreetmap.josm.command.ChangePropertyCommand;
     
    6874import org.openstreetmap.josm.data.osm.RelationMember;
    6975import org.openstreetmap.josm.data.osm.Tag;
     76import org.openstreetmap.josm.data.osm.Tagged;
    7077import org.openstreetmap.josm.data.osm.Way;
    7178import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
     
    8592import org.openstreetmap.josm.gui.help.HelpUtil;
    8693import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     94import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    8795import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler;
    88 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    8996import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
    9097import org.openstreetmap.josm.gui.util.GuiHelper;
    9198import org.openstreetmap.josm.gui.util.HighlightHelper;
     99import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator;
     100import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
     101import org.openstreetmap.josm.gui.widgets.JosmTextField;
    92102import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    93103import org.openstreetmap.josm.tools.GBC;
     
    128138     * The tag data of selected objects.
    129139     */
    130     private final DefaultTableModel tagData = new ReadOnlyTableModel();
     140    private final ReadOnlyTableModel tagData = new ReadOnlyTableModel();
     141    private final TableRowSorter<ReadOnlyTableModel> tagRowSorter = new TableRowSorter<>(tagData);
     142    private final JosmTextField tagTableFilter;
    131143
    132144    /**
     
    243255        buildMembershipTable();
    244256
     257        tagTableFilter = setupFilter();
     258
    245259        // combine both tables and wrap them in a scrollPane
    246260        boolean top = Main.pref.getBoolean("properties.presets.top", true);
     
    252266        }
    253267        bothTables.add(selectSth, GBC.eol().fill().insets(10, 10, 10, 10));
     268        bothTables.add(tagTableFilter, GBC.eol().fill(GBC.HORIZONTAL));
    254269        bothTables.add(tagTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
    255270        bothTables.add(tagTable, GBC.eol().fill(GBC.BOTH));
     
    294309        tagTable.getColumnModel().getColumn(0).setCellRenderer(cellRenderer);
    295310        tagTable.getColumnModel().getColumn(1).setCellRenderer(cellRenderer);
     311        tagTable.setRowSorter(tagRowSorter);
    296312    }
    297313
     
    456472    }
    457473
     474    public void setFilter(final SearchCompiler.Match filter) {
     475        this.tagRowSorter.setRowFilter(new SearchBasedRowFilter(filter));
     476    }
     477
    458478    /**
    459479     * Assigns all needed keys like Enter and Spacebar to most important actions.
     
    498518                KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "onHelp");
    499519        getActionMap().put("onHelp", helpAction);
     520    }
     521
     522    private JosmTextField setupFilter() {
     523        final JosmTextField f = new DisableShortcutsOnFocusGainedTextField();
     524        f.setToolTipText(tr("Tag filter"));
     525        final CompileSearchTextDecorator decorator = CompileSearchTextDecorator.decorate(f);
     526        f.addPropertyChangeListener("filter", new PropertyChangeListener() {
     527            @Override
     528            public void propertyChange(PropertyChangeEvent evt) {
     529                setFilter(decorator.getMatch());
     530            }
     531        });
     532        return f;
    500533    }
    501534
     
    686719        tagTable.setVisible(hasTags);
    687720        tagTable.getTableHeader().setVisible(hasTags);
     721        tagTableFilter.setVisible(hasTags);
    688722        selectSth.setVisible(!hasSelection);
    689723        pluginHook.setVisible(hasSelection);
Note: See TracChangeset for help on using the changeset viewer.