Changeset 5616 in josm for trunk/src/org
- Timestamp:
- 2012-12-09T23:35:59+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r5517 r5616 6 6 import static org.openstreetmap.josm.tools.I18n.trn; 7 7 8 import java.awt.BorderLayout; 9 import java.awt.Color; 8 10 import java.awt.Point; 9 11 import java.awt.event.ActionEvent; … … 28 30 import javax.swing.JList; 29 31 import javax.swing.JMenuItem; 32 import javax.swing.JPanel; 33 import javax.swing.JScrollPane; 34 import javax.swing.JTextField; 30 35 import javax.swing.KeyStroke; 31 36 import javax.swing.ListSelectionModel; 32 37 import javax.swing.SwingUtilities; 38 import javax.swing.UIManager; 39 import javax.swing.event.DocumentEvent; 40 import javax.swing.event.DocumentListener; 33 41 import javax.swing.event.ListSelectionEvent; 34 42 import javax.swing.event.ListSelectionListener; … … 36 44 37 45 import org.openstreetmap.josm.Main; 46 import org.openstreetmap.josm.actions.search.SearchCompiler; 38 47 import org.openstreetmap.josm.command.Command; 39 48 import org.openstreetmap.josm.command.SequenceCommand; … … 68 77 import org.openstreetmap.josm.tools.ImageProvider; 69 78 import org.openstreetmap.josm.tools.InputMapUtils; 79 import org.openstreetmap.josm.tools.Predicate; 70 80 import org.openstreetmap.josm.tools.Shortcut; 81 import org.openstreetmap.josm.tools.Utils; 71 82 72 83 /** … … 142 153 displaylist.addListSelectionListener(selectAction); 143 154 144 createLayout(displaylist, true, Arrays.asList(new SideButton[] { 155 final JTextField filter = new JTextField(); 156 filter.setToolTipText(tr("Relation list filter")); 157 filter.getDocument().addDocumentListener(new DocumentListener() { 158 159 private void setFilter() { 160 try { 161 filter.setBackground(UIManager.getColor("TextField.background")); 162 filter.setToolTipText(tr("Relation list filter")); 163 model.setFilter(SearchCompiler.compile(filter.getText(), false, false)); 164 } catch (SearchCompiler.ParseError ex) { 165 filter.setBackground(new Color(255, 224, 224)); 166 filter.setToolTipText(ex.getMessage()); 167 model.setFilter(new SearchCompiler.Always()); 168 } 169 } 170 171 @Override 172 public void insertUpdate(DocumentEvent e) { 173 setFilter(); 174 } 175 176 @Override 177 public void removeUpdate(DocumentEvent e) { 178 setFilter(); 179 } 180 181 @Override 182 public void changedUpdate(DocumentEvent e) { 183 setFilter(); 184 } 185 }); 186 187 JPanel pane = new JPanel(new BorderLayout()); 188 pane.add(filter, BorderLayout.NORTH); 189 pane.add(new JScrollPane(displaylist), BorderLayout.CENTER); 190 createLayout(pane, false, Arrays.asList(new SideButton[]{ 145 191 new SideButton(newAction, false), 146 192 new SideButton(editAction, false), … … 643 689 private class RelationListModel extends AbstractListModel { 644 690 private final ArrayList<Relation> relations = new ArrayList<Relation>(); 691 private ArrayList<Relation> filteredRelations; 645 692 private DefaultListSelectionModel selectionModel; 693 private SearchCompiler.Match filter; 646 694 647 695 public RelationListModel(DefaultListSelectionModel selectionModel) { … … 760 808 } 761 809 810 public void setFilter(final SearchCompiler.Match filter) { 811 this.filter = filter; 812 this.filteredRelations = new ArrayList<Relation>(Utils.filter(relations, new Predicate<Relation>() { 813 @Override 814 public boolean evaluate(Relation r) { 815 return filter.match(r); 816 } 817 })); 818 List<Relation> sel = getSelectedRelations(); 819 fireContentsChanged(this, 0, getSize()); 820 setSelectedRelations(sel); 821 updateTitle(); 822 } 823 824 private List<Relation> getVisibleRelations() { 825 return filteredRelations == null ? relations : filteredRelations; 826 } 827 828 @Override 762 829 public Object getElementAt(int index) { 763 if (index < 0 || index >= relations.size()) return null; 764 return relations.get(index); 765 } 766 830 if (index < 0 || index >= getVisibleRelations().size()) return null; 831 return getVisibleRelations().get(index); 832 } 833 834 @Override 767 835 public int getSize() { 768 return relations.size();836 return getVisibleRelations().size(); 769 837 } 770 838 … … 837 905 838 906 public void updateTitle() { 839 if (getSize() > 0) { 907 if (relations.size() > 0 && relations.size() != getSize()) { 908 RelationListDialog.this.setTitle(tr("Relations: {0}/{1}", getSize(), relations.size())); 909 } else if (getSize() > 0) { 840 910 RelationListDialog.this.setTitle(tr("Relations: {0}", getSize())); 841 911 } else {
Note:
See TracChangeset
for help on using the changeset viewer.