commit 5908bdda0af3ec3f2d718560b50ef6e40cbfdb2a
Author: Simon Legner <Simon.Legner@gmail.com>
Date: 2020-01-27 20:51:04 +0100
autofilter
diff --git a/src/org/openstreetmap/josm/gui/autofilter/AutoFilterButton.java b/src/org/openstreetmap/josm/gui/autofilter/AutoFilterButton.java
index a3e6d40aa..27c97dd0b 100644
|
a
|
b
|
|
| 7 | 7 | import java.awt.RenderingHints; |
| 8 | 8 | import java.awt.event.ActionEvent; |
| 9 | 9 | |
| | 10 | import javax.swing.AbstractAction; |
| 10 | 11 | import javax.swing.BorderFactory; |
| 11 | 12 | import javax.swing.JButton; |
| 12 | 13 | |
| 13 | 14 | import org.openstreetmap.josm.actions.JosmAction; |
| | 15 | import org.openstreetmap.josm.actions.PreferencesAction; |
| 14 | 16 | import org.openstreetmap.josm.data.preferences.NamedColorProperty; |
| 15 | 17 | import org.openstreetmap.josm.gui.MainApplication; |
| | 18 | import org.openstreetmap.josm.gui.preferences.display.DrawingPreference; |
| 16 | 19 | |
| 17 | 20 | /** |
| 18 | 21 | * A button associated to an auto filter. If clicked twice, the filter is reset. |
| … |
… |
protected void paintComponent(Graphics g) {
|
| 62 | 65 | g.fillRoundRect(0, 0, getWidth(), getHeight(), 3, 3); |
| 63 | 66 | super.paintComponent(g); |
| 64 | 67 | } |
| | 68 | |
| | 69 | static AutoFilterButton forOsmKey(String key) { |
| | 70 | final AutoFilterButton button = new AutoFilterButton(new AutoFilter(key, "", null)); |
| | 71 | button.setAction(new AbstractAction(key) { |
| | 72 | @Override |
| | 73 | public void actionPerformed(ActionEvent e) { |
| | 74 | PreferencesAction.forPreferenceSubTab("", "null", DrawingPreference.class).actionPerformed(e); |
| | 75 | } |
| | 76 | }); |
| | 77 | return button; |
| | 78 | } |
| 65 | 79 | } |
diff --git a/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java b/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java
index 0b33f328f..5d32de6c7 100644
|
a
|
b
|
public boolean match(OsmPrimitive osm) {
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | private synchronized void addNewButtons(NavigableSet<String> values) { |
| | 184 | if (values.isEmpty()) { |
| | 185 | return; |
| | 186 | } |
| 184 | 187 | int i = 0; |
| 185 | 188 | int maxWidth = 16; |
| 186 | | MapView mapView = MainApplication.getMap().mapView; |
| | 189 | final AutoFilterButton keyButton = AutoFilterButton.forOsmKey(enabledRule.getKey()); |
| | 190 | addButton(keyButton, "-999", i++); |
| 187 | 191 | for (final String value : values.descendingSet()) { |
| 188 | 192 | CompiledFilter filter = new CompiledFilter(enabledRule.getKey(), value); |
| 189 | 193 | String label = enabledRule.getValueFormatter().apply(value); |
| … |
… |
private synchronized void addNewButtons(NavigableSet<String> values) {
|
| 192 | 196 | if (autoFilter.equals(currentAutoFilter)) { |
| 193 | 197 | button.getModel().setPressed(true); |
| 194 | 198 | } |
| 195 | | buttons.put(value, button); |
| 196 | 199 | maxWidth = Math.max(maxWidth, button.getPreferredSize().width); |
| 197 | | mapView.add(button).setLocation(3, 60 + 22*i++); |
| | 200 | addButton(button, value, i++); |
| 198 | 201 | } |
| 199 | 202 | for (AutoFilterButton b : buttons.values()) { |
| 200 | | b.setSize(maxWidth, 20); |
| | 203 | b.setSize(b == keyButton ? b.getPreferredSize().width : maxWidth, 20); |
| 201 | 204 | } |
| 202 | | mapView.validate(); |
| | 205 | MainApplication.getMap().mapView.validate(); |
| | 206 | } |
| | 207 | |
| | 208 | private void addButton(AutoFilterButton button, String value, int i) { |
| | 209 | MapView mapView = MainApplication.getMap().mapView; |
| | 210 | buttons.put(value, button); |
| | 211 | mapView.add(button).setLocation(3, 60 + 22*i); |
| 203 | 212 | } |
| 204 | 213 | |
| 205 | 214 | private void removeAllButtons() { |