Changeset 3356 in josm for trunk


Ignore:
Timestamp:
2010-06-29T17:19:26+02:00 (10 years ago)
Author:
bastiK
Message:

added filter tests

Location:
trunk
Files:
3 added
1 edited
1 moved

Legend:

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

    r3355 r3356  
    2626import org.openstreetmap.josm.actions.search.SearchAction;
    2727import org.openstreetmap.josm.data.osm.Filter;
    28 import org.openstreetmap.josm.data.osm.Filters;
    2928import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
    3029import org.openstreetmap.josm.data.osm.event.DataSetListener;
     
    4342
    4443    private JTable userTable;
    45     private Filters filters = new Filters();
     44    private FilterTableModel filterModel = new FilterTableModel();
    4645    private SideButton addButton;
    4746    private SideButton editButton;
     
    6160    public void showNotify() {
    6261        DatasetEventManager.getInstance().addDatasetListener(listenerAdapter, FireMode.IN_EDT_CONSOLIDATED);
    63         filters.executeFilters();
     62        filterModel.executeFilters();
    6463    }
    6564
     
    6766    public void hideNotify() {
    6867        DatasetEventManager.getInstance().removeDatasetListener(listenerAdapter);
    69         filters.clearFilterFlags();
     68        filterModel.clearFilterFlags();
    7069        Main.map.mapView.repaint();
    7170    }
     
    7978                Filter filter = (Filter)SearchAction.showSearchDialog(new Filter());
    8079                if(filter != null){
    81                     filters.addFilter(filter);
     80                    filterModel.addFilter(filter);
    8281                }
    8382            }
     
    9089                int index = userTable.getSelectionModel().getMinSelectionIndex();
    9190                if(index < 0) return;
    92                 Filter f = filters.getFilter(index);
     91                Filter f = filterModel.getFilter(index);
    9392                Filter filter = (Filter)SearchAction.showSearchDialog(f);
    9493                if(filter != null){
    95                     filters.setFilter(index, filter);
     94                    filterModel.setFilter(index, filter);
    9695                }
    9796            }
     
    104103                int index = userTable.getSelectionModel().getMinSelectionIndex();
    105104                if(index < 0) return;
    106                 filters.removeFilter(index);
     105                filterModel.removeFilter(index);
    107106            }
    108107        });
     
    114113                int index = userTable.getSelectionModel().getMinSelectionIndex();
    115114                if(index < 0) return;
    116                 filters.moveUpFilter(index);
     115                filterModel.moveUpFilter(index);
    117116                userTable.getSelectionModel().setSelectionInterval(index-1, index-1);
    118117            }
     
    125124                int index = userTable.getSelectionModel().getMinSelectionIndex();
    126125                if(index < 0) return;
    127                 filters.moveDownFilter(index);
     126                filterModel.moveDownFilter(index);
    128127                userTable.getSelectionModel().setSelectionInterval(index+1, index+1);
    129128            }
     
    144143        JPanel pnl = new JPanel();
    145144        pnl.setLayout(new BorderLayout());
    146         userTable = new JTable(filters){
     145        userTable = new JTable(filterModel){
    147146            @Override
    148147            protected JTableHeader createDefaultTableHeader() {
     
    183182
    184183    public void processDatasetEvent(AbstractDatasetChangedEvent event) {
    185         filters.executeFilters();
     184        filterModel.executeFilters();
    186185    }
    187186
     
    189188        @Override
    190189        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row,int column) {
    191             Filters model = (Filters)table.getModel();
     190            FilterTableModel model = (FilterTableModel)table.getModel();
    192191            Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    193192            cell.setEnabled(model.isCellEnabled(row, column));
     
    198197    static class BooleanRenderer extends JCheckBox implements TableCellRenderer {
    199198        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row,int column) {
    200             Filters model = (Filters)table.getModel();
     199            FilterTableModel model = (FilterTableModel)table.getModel();
    201200            setSelected((Boolean)value);
    202201            setEnabled(model.isCellEnabled(row, column));
     
    209208        SwingUtilities.invokeLater(new Runnable() {
    210209            public void run() {
    211                 setTitle(tr("Filter Hidden:{0} Disabled:{1}", filters.disabledAndHiddenCount, filters.disabledCount));
     210                setTitle(tr("Filter Hidden:{0} Disabled:{1}", filterModel.disabledAndHiddenCount, filterModel.disabledCount));
    212211            }
    213212        });
     
    215214
    216215    public void drawOSDText(Graphics2D g) {
    217         filters.drawOSDText(g);
     216        filterModel.drawOSDText(g);
    218217    }
    219218}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/FilterTableModel.java

    r3355 r3356  
    1 package org.openstreetmap.josm.data.osm;
     1package org.openstreetmap.josm.gui.dialogs;
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
     
    2121import org.openstreetmap.josm.Main;
    2222import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
     23import org.openstreetmap.josm.data.osm.DataSet;
     24import org.openstreetmap.josm.data.osm.Filter;
     25import org.openstreetmap.josm.data.osm.FilterMatcher;
     26import org.openstreetmap.josm.data.osm.FilterWorker;
     27import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2328
    2429/**
     
    2631 * @author Petr_Dlouhý
    2732 */
    28 public class Filters extends AbstractTableModel {
     33public class FilterTableModel extends AbstractTableModel {
    2934
    3035    // number of primitives that are disabled but not hidden
     
    3338    public int disabledAndHiddenCount;
    3439
    35     public Filters() {
     40    public FilterTableModel() {
    3641        loadPrefs();
    3742    }
     
    5459
    5560
    56     /**
    57      * Apply the filters to the primitives of the data set.
    58      *
    59      * There are certain rules to ensure that a way is not displayed "naked"
    60      * without its nodes (1) and on the other hand to avoid hiding a way but
    61      * leaving its nodes visible as a cloud of points (2).
    62      *
    63      * In normal (non-inverted) mode only problem (2) is relevant.
    64      * Untagged child nodes of filtered ways that are not used by other
    65      * unfiltered ways are filtered as well.
    66      *
    67      * If a filter applies explicitly to a node, (2) is ignored and it
    68      * is filtered in any case.
    69      *
    70      * In inverted mode usually only problem (1) is relevant.
    71      * If the inverted filter applies explicitly to a node, this no longer
    72      * means it is filtered in any case:
    73      * E.g. the filter [searchtext="highway=footway", inverted=true] displays
    74      * the footways only. But that does not mean, the nodes of the footway
    75      * (which do not have the highway tag) should be filtered as well.
    76      *
    77      * So first the Filter is applied for ways and relations. Then to nodes
    78      * (but hides them only if they are not used by any unfiltered way).
    79      */
     61   
    8062    public void executeFilters() {
    8163        DataSet ds = Main.main.getCurrentDataSet();
     
    8567        final Collection<OsmPrimitive> all = ds.allNonDeletedCompletePrimitives();
    8668
    87         for (OsmPrimitive primitive: all) {
    88             if (filterMatcher.isHidden(primitive)) {
    89                 primitive.setDisabledState(true);
    90             } else if (filterMatcher.isDisabled(primitive)) {
    91                 primitive.setDisabledState(false);
    92             } else {
    93                 primitive.unsetDisabledState();
    94             }
    95         }
    96 
    97         for (OsmPrimitive primitive: all) {
    98             if (primitive instanceof Way && primitive.isDisabled()) {
    99                 Way w = (Way)primitive;
    100                 for (Node n: w.getNodes()) {
    101 
    102                     if (n.isTagged()) {
    103                         continue;
    104                     }
    105 
    106                     boolean disabled = w.isDisabled();
    107                     boolean hidden = w.isDisabledAndHidden();
    108                     for (OsmPrimitive ref: n.getReferrers()) {
    109                         if (ref instanceof Way) {
    110                             disabled = disabled && ref.isDisabled();
    111                             hidden = hidden && ref.isDisabledAndHidden();
    112                         }
    113                     }
    114 
    115                     if (disabled) {
    116                         n.setDisabledState(hidden);
    117                     }
    118                 }
    119             }
    120         }
     69        FilterWorker.executeFilters(all, filterMatcher);
    12170
    12271        disabledCount = 0;
     
    14796        DataSet ds = Main.main.getCurrentDataSet();
    14897        if (ds != null) {
    149             for (OsmPrimitive osm : ds.allPrimitives()) {
    150                 osm.unsetDisabledState();
    151             }
     98            FilterWorker.clearFilterFlags(ds.allPrimitives());
    15299        }
    153100        disabledCount = 0;
Note: See TracChangeset for help on using the changeset viewer.