- // todo: gif for - button
- JButton removeCondition = new BasicArrowButton(SwingConstants.WEST);
- removeCondition.setToolTipText(MessageManager
- .getString("label.delete_row"));
- removeCondition.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- filters.remove(filterIndex);
- filtersChanged();
- }
- });
- filterRow.add(removeCondition);
- }
-
- return filterRow;
- }
-
- /**
- * A helper method to build the drop-down choice of attributes for a feature.
- * Where metadata is available with a description for an attribute, that is
- * added as a tooltip.
- *
- * @param featureType
- * @param attNames
- */
- protected JComboBox<String> populateAttributesDropdown(
- String featureType, List<String> attNames)
- {
- List<String> tooltips = new ArrayList<>();
- FeatureAttributes fa = FeatureAttributes.getInstance();
- for (String attName : attNames)
- {
- String desc = fa.getDescription(featureType, attName);
- if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH)
- {
- desc = desc.substring(0, MAX_TOOLTIP_LENGTH) + "...";
- }
- tooltips.add(desc == null ? "" : desc);
- }
-
- JComboBox<String> attCombo = JvSwingUtils.buildComboWithTooltips(
- attNames, tooltips);
- if (attNames.isEmpty())
- {
- attCombo.setToolTipText(MessageManager
- .getString("label.no_attributes"));
- }
- return attCombo;
- }
-
- /**
- * Action on any change to feature filtering, namely
- * <ul>
- * <li>change of selected attribute</li>
- * <li>change of selected condition</li>
- * <li>change of match pattern</li>
- * <li>removal of a condition</li>
- * </ul>
- * The action should be to
- * <ul>
- * <li>parse and validate the filters</li>
- * <li>if valid, update the filter text box</li>
- * <li>and apply the filters to the viewport</li>
- * </ul>
- */
- protected void filtersChanged()
- {
- /*
- * update the filter conditions for the feature type
- */
- String featureType = (String) filteredFeatureChoice.getSelectedItem();
- boolean anded = andFilters.isSelected();
- KeyedMatcherSetI combined = new KeyedMatcherSet();
-
- for (KeyedMatcherI filter : filters)
- {
- String pattern = filter.getMatcher().getPattern();
- if (pattern.trim().length() > 0)
- {
- if (anded)
- {
- combined.and(filter);
- }
- else
- {
- combined.or(filter);
- }
- }
- }
-
- /*
- * save the filter conditions in the FeatureRenderer
- * (note this might now be an empty filter with no conditions)
- */
- fr.setFeatureFilter(featureType, combined);
-
- filtersAsText.setText(combined.toString());
-
- refreshFiltersDisplay();
-
- af.alignPanel.paintAlignment(true, true);
- }
-
- /**
- * Constructs a filter condition from the given input fields, and replaces the
- * condition at filterIndex with the new one
- *
- * @param attCombo
- * @param condCombo
- * @param valueField
- * @param filterIndex
- */
- protected void updateFilter(JComboBox<String> attCombo,
- JComboBox<Condition> condCombo, JTextField valueField,
- int filterIndex)
- {
- String attName = (String) attCombo.getSelectedItem();
- Condition cond = (Condition) condCombo.getSelectedItem();
- String pattern = valueField.getText();
- KeyedMatcherI km = new KeyedMatcher(attName, cond, pattern);
-
- filters.set(filterIndex, km);
- }
-
- public void fetchDAS_actionPerformed(ActionEvent e)
- {
- fetchDAS.setEnabled(false);
- cancelDAS.setEnabled(true);
- dassourceBrowser.setGuiEnabled(false);
- Vector<jalviewSourceI> selectedSources = dassourceBrowser
- .getSelectedSources();
- doDasFeatureFetch(selectedSources, true, true);
- }
-
- /**
- * get the features from selectedSources for all or the current selection
- *
- * @param selectedSources
- * @param checkDbRefs
- * @param promptFetchDbRefs
- */
- private void doDasFeatureFetch(List<jalviewSourceI> selectedSources,
- boolean checkDbRefs, boolean promptFetchDbRefs)
- {
- SequenceI[] dataset, seqs;
- int iSize;
- AlignmentViewport vp = af.getViewport();
- if (vp.getSelectionGroup() != null
- && vp.getSelectionGroup().getSize() > 0)
- {
- iSize = vp.getSelectionGroup().getSize();
- dataset = new SequenceI[iSize];
- seqs = vp.getSelectionGroup().getSequencesInOrder(vp.getAlignment());
- }
- else
- {
- iSize = vp.getAlignment().getHeight();
- seqs = vp.getAlignment().getSequencesArray();
- }
-
- dataset = new SequenceI[iSize];
- for (int i = 0; i < iSize; i++)
- {
- dataset[i] = seqs[i].getDatasetSequence();
- }
-
- cancelDAS.setEnabled(true);
- dasFeatureFetcher = new jalview.ws.DasSequenceFeatureFetcher(dataset,
- this, selectedSources, checkDbRefs, promptFetchDbRefs);
- af.getViewport().setShowSequenceFeatures(true);
- af.showSeqFeatures.setSelected(true);
- }
-
- /**
- * blocking call to initialise the das source browser
- */
- public void initDasSources()
- {
- dassourceBrowser.initDasSources();
- }
-
- /**
- * examine the current list of das sources and return any matching the given
- * nicknames in sources
- *
- * @param sources
- * Vector of Strings to resolve to DAS source nicknames.
- * @return sources that are present in source list.
- */
- public List<jalviewSourceI> resolveSourceNicknames(Vector<String> sources)
- {
- return dassourceBrowser.sourceRegistry.resolveSourceNicknames(sources);
- }
-
- /**
- * get currently selected das sources. ensure you have called initDasSources
- * before calling this.
- *
- * @return vector of selected das source nicknames
- */
- public Vector<jalviewSourceI> getSelectedSources()
- {
- return dassourceBrowser.getSelectedSources();
- }
-
- /**
- * properly initialise DAS fetcher and then initiate a new thread to fetch
- * features from the named sources (rather than any turned on by default)
- *
- * @param sources
- * @param block
- * if true then runs in same thread, otherwise passes to the Swing
- * executor
- */
- public void fetchDasFeatures(Vector<String> sources, boolean block)
- {
- initDasSources();
- List<jalviewSourceI> resolved = dassourceBrowser.sourceRegistry
- .resolveSourceNicknames(sources);
- if (resolved.size() == 0)
- {
- resolved = dassourceBrowser.getSelectedSources();
- }
- if (resolved.size() > 0)
- {
- final List<jalviewSourceI> dassources = resolved;
- fetchDAS.setEnabled(false);
- // cancelDAS.setEnabled(true); doDasFetch does this.
- Runnable fetcher = new Runnable()
- {
-
- @Override
- public void run()
- {
- doDasFeatureFetch(dassources, true, false);
-
- }
- };
- if (block)
- {
- fetcher.run();
- }
- else
- {
- SwingUtilities.invokeLater(fetcher);
- }
- }
- }
-
- public void saveDAS_actionPerformed(ActionEvent e)
- {
- dassourceBrowser
- .saveProperties(jalview.bin.Cache.applicationProperties);
- }
-
- public void complete()
- {
- fetchDAS.setEnabled(true);
- cancelDAS.setEnabled(false);
- dassourceBrowser.setGuiEnabled(true);
-
- }
-
- public void cancelDAS_actionPerformed(ActionEvent e)
- {
- if (dasFeatureFetcher != null)
- {
- dasFeatureFetcher.cancel();
- }
- complete();
- }
-
- public void noDasSourceActive()
- {
- complete();
- JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
- MessageManager.getString("label.no_das_sources_selected_warn"),
- MessageManager.getString("label.no_das_sources_selected_title"),
- JvOptionPane.DEFAULT_OPTION, JvOptionPane.INFORMATION_MESSAGE);
- }
-
- /**
- * Answers true unless a numeric condition has been selected with a
- * non-numeric value. Sets the value field to RED with a tooltip if in error.
- * <p>
- * If the pattern entered is empty, this method returns false, but does not
- * mark the field as invalid. This supports selecting an attribute for a new
- * condition before a match pattern has been entered.
- *
- * @param value
- * @param condCombo
- */
- protected boolean validateFilter(JTextField value,
- JComboBox<Condition> condCombo)
- {
- if (value == null || condCombo == null)
- {
- return true; // fields not populated
- }
-
- Condition cond = (Condition) condCombo.getSelectedItem();
- value.setBackground(Color.white);
- value.setToolTipText("");
- String v1 = value.getText().trim();
- if (v1.length() == 0)
- {
- return false;
- }
-
- if (cond.isNumeric())
- {
- try
- {
- Float.valueOf(v1);
- } catch (NumberFormatException e)
- {
- value.setBackground(Color.red);
- value.setToolTipText(MessageManager
- .getString("label.numeric_required"));
- return false;
- }
- }
-
- return true;
- }
-
- // ///////////////////////////////////////////////////////////////////////
- // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
- // ///////////////////////////////////////////////////////////////////////
- class FeatureTableModel extends AbstractTableModel
- {
- FeatureTableModel(Object[][] data)
- {
- this.data = data;
- }
-
- private String[] columnNames = {
- MessageManager.getString("label.feature_type"),
- MessageManager.getString("action.colour"),
- MessageManager.getString("label.display") };
-
- private Object[][] data;
-
- public Object[][] getData()
- {
- return data;
- }
-
- public void setData(Object[][] data)
- {
- this.data = data;
- }
-
- @Override
- public int getColumnCount()
- {
- return columnNames.length;