-
- initFiltersTab();
- }
-
- /**
- * Populates initial layout of the feature attribute filters panel
- */
- protected void initFiltersTab()
- {
- filters = new ArrayList<>();
-
- /*
- * choose feature type
- */
- JPanel chooseTypePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- chooseTypePanel.setBackground(Color.white);
- chooseTypePanel.setBorder(BorderFactory
- .createTitledBorder(MessageManager
- .getString("label.feature_type")));
- filteredFeatureChoice = new JComboBox<>();
- filteredFeatureChoice.addItemListener(new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- refreshFiltersDisplay();
- }
- });
- chooseTypePanel.add(new JLabel(MessageManager
- .getString("label.feature_to_filter")));
- chooseTypePanel.add(filteredFeatureChoice);
- populateFilterableFeatures();
-
- /*
- * the panel with the filters for the selected feature type
- */
- JPanel filtersPanel = new JPanel(new GridLayout(0, 1));
- filtersPanel.setBackground(Color.white);
- filtersPanel.setBorder(BorderFactory
- .createTitledBorder(MessageManager.getString("label.filters")));
-
- /*
- * add AND or OR radio buttons
- */
- JPanel andOrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- andOrPanel.setBackground(Color.white);
- andFilters = new JRadioButton("And");
- orFilters = new JRadioButton("Or");
- ActionListener actionListener = new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- filtersChanged();
- }
- };
- andFilters.addActionListener(actionListener);
- orFilters.addActionListener(actionListener);
- ButtonGroup andOr = new ButtonGroup();
- andOr.add(andFilters);
- andOr.add(orFilters);
- andFilters.setSelected(true);
- andOrPanel.add(new JLabel(MessageManager
- .getString("label.join_conditions")));
- andOrPanel.add(andFilters);
- andOrPanel.add(orFilters);
- filtersPanel.add(andOrPanel);
-
- /*
- * panel with filters - populated by refreshFiltersDisplay
- */
- chooseFiltersPanel = new JPanel(new GridLayout(0, 1));
- filtersPanel.add(chooseFiltersPanel);
-
- /*
- * a read-only text view of the current filters
- */
- JPanel showFiltersPanel = new JPanel(new BorderLayout(5, 5));
- showFiltersPanel.setBackground(Color.white);
- showFiltersPanel.setBorder(BorderFactory
- .createTitledBorder(MessageManager
- .getString("label.match_condition")));
- filtersAsText = new JTextArea();
- filtersAsText.setLineWrap(true);
- filtersAsText.setWrapStyleWord(true);
- showFiltersPanel.add(filtersAsText);
-
- filtersPane.setLayout(new BorderLayout());
- filtersPane.add(chooseTypePanel, BorderLayout.NORTH);
- filtersPane.add(filtersPanel, BorderLayout.CENTER);
- filtersPane.add(showFiltersPanel, BorderLayout.SOUTH);
-
- /*
- * update display for initial feature type selection
- */
- refreshFiltersDisplay();
- }
-
- /**
- * Adds entries to the 'choose feature to filter' drop-down choice. Only
- * feature types which have known attributes (so can be filtered) are
- * included, so recall this method to update the list (check for newly added
- * attributes).
- */
- protected void populateFilterableFeatures()
- {
- /*
- * suppress action handler while updating the list
- */
- ItemListener listener = filteredFeatureChoice.getItemListeners()[0];
- filteredFeatureChoice.removeItemListener(listener);
-
- filteredFeatureChoice.removeAllItems();
- ReverseListIterator<String> types = new ReverseListIterator<>(
- fr.getRenderOrder());
-
- boolean found = false;
- while (types.hasNext())
- {
- String type = types.next();
- if (FeatureAttributes.getInstance().hasAttributes(type))
- {
- filteredFeatureChoice.addItem(type);
- found = true;
- }
- }
- if (!found)
- {
- filteredFeatureChoice
- .addItem("No filterable feature attributes known");
- }
-
- filteredFeatureChoice.addItemListener(listener);
-
- }
-
- /**
- * Refreshes the display to show any filters currently configured for the
- * selected feature type (editable, with 'remove' option), plus one extra row
- * for adding a condition. This should be called on change of selected feature
- * type, or after a filter has been removed, added or amended.
- */
- protected void refreshFiltersDisplay()
- {
- /*
- * clear the panel and list of filter conditions
- */
- chooseFiltersPanel.removeAll();
-
- String selectedType = (String) filteredFeatureChoice.getSelectedItem();
-
- filters.clear();
-
- /*
- * look up attributes known for feature type
- */
- List<String> attNames = FeatureAttributes.getInstance().getAttributes(
- selectedType);
-
- /*
- * if this feature type has filters set, load them first
- */
- KeyedMatcherSetI featureFilters = fr.getFeatureFilter(selectedType);
- filtersAsText.setText("");
- if (featureFilters != null)
- {
- filtersAsText.setText(featureFilters.toString());
- if (!featureFilters.isAnded())
- {
- orFilters.setSelected(true);
- }
- Iterator<KeyedMatcherI> matchers = featureFilters.getMatchers();
- while (matchers.hasNext())
- {
- filters.add(matchers.next());
- }
- }
-
- /*
- * and an empty filter for the user to populate (add)
- */
- KeyedMatcherI noFilter = new KeyedMatcher("", Condition.values()[0], "");
- filters.add(noFilter);
-
- /*
- * render the conditions in rows, each in its own JPanel
- */
- int i = 0;
- for (KeyedMatcherI filter : filters)
- {
- String key = filter.getKey();
- Condition condition = filter.getMatcher()
- .getCondition();
- String pattern = filter.getMatcher().getPattern();
- JPanel row = addFilter(key, attNames, condition, pattern, i);
- chooseFiltersPanel.add(row);
- i++;
- }
-
- filtersPane.validate();
- filtersPane.repaint();