- bigPanel.add(scrollPane, java.awt.BorderLayout.CENTER);
- dasSettingsPane.add(dasButtonPanel, java.awt.BorderLayout.SOUTH);
- dasButtonPanel.add(fetchDAS);
- dasButtonPanel.add(cancelDAS);
- dasButtonPanel.add(saveDAS);
- settingsPane.add(bigPanel, java.awt.BorderLayout.CENTER);
- settingsPane.add(buttonPanel, java.awt.BorderLayout.SOUTH);
- }
-
- protected void sortByDens(String[] typ)
- {
- sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY);
- }
-
- protected void sortBy(String[] typ, String methodText, final String method)
- {
- if (typ == null)
- {
- typ = getDisplayedFeatureTypes();
- }
- String gps[] = null;
- gps = getDisplayedFeatureGroups();
- if (typ != null)
- {
- ArrayList types = new ArrayList();
- for (int i = 0; i < typ.length; i++)
- {
- if (typ[i] != null)
- {
- types.add(typ[i]);
- }
- typ = new String[types.size()];
- types.toArray(typ);
- }
- }
- if (gps != null)
- {
- ArrayList grps = new ArrayList();
-
- for (int i = 0; i < gps.length; i++)
- {
- if (gps[i] != null)
- {
- grps.add(gps[i]);
- }
- }
- gps = new String[grps.size()];
- grps.toArray(gps);
- }
- AlignmentPanel alignPanel = af.alignPanel;
- AlignmentI al = alignPanel.av.getAlignment();
-
- int start, stop;
- SequenceGroup sg = alignPanel.av.getSelectionGroup();
- if (sg != null)
- {
- start = sg.getStartRes();
- stop = sg.getEndRes();
- }
- else
- {
- start = 0;
- stop = al.getWidth();
- }
- SequenceI[] oldOrder = al.getSequencesArray();
- AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method);
- af.addHistoryItem(new OrderCommand(methodText, oldOrder, alignPanel.av
- .getAlignment()));
- alignPanel.paintAlignment(true);
-
- }
-
- protected void sortByScore(String[] typ)
- {
- sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE);
- }
-
- private String[] getDisplayedFeatureTypes()
- {
- String[] typ = null;
- if (fr != null)
- {
- synchronized (fr.renderOrder)
- {
- typ = new String[fr.renderOrder.length];
- System.arraycopy(fr.renderOrder, 0, typ, 0, typ.length);
- for (int i = 0; i < typ.length; i++)
- {
- if (af.viewport.featuresDisplayed.get(typ[i]) == null)
- {
- typ[i] = null;
- }
- }
- }
- }
- return typ;
- }
-
- private String[] getDisplayedFeatureGroups()
- {
- String[] gps = null;
- ArrayList<String> _gps = new ArrayList<String>();
- if (fr != null)
- {
-
- if (fr.featureGroups != null)
- {
- Iterator en = fr.featureGroups.keySet().iterator();
- int g = 0;
- boolean valid = false;
- while (en.hasNext())
- {
- String gp = (String) en.next();
- Boolean on = (Boolean) fr.featureGroups.get(gp);
- if (on != null && on.booleanValue())
- {
- valid = true;
- _gps.add(gp);
- }
- }
- if (!valid)
- {
- return null;
- }
- else
- {
- gps = new String[_gps.size()];
- _gps.toArray(gps);
- }
- }
- }
- return gps;
- }
-
- public void fetchDAS_actionPerformed(ActionEvent e)
- {
- fetchDAS.setEnabled(false);
- cancelDAS.setEnabled(true);
- dassourceBrowser.setGuiEnabled(false);
- Vector 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;
- AlignViewport 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 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 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 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()
- {
-
- 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();
- JOptionPane
- .showInternalConfirmDialog(
- Desktop.desktop,
- MessageManager
- .getString("label.no_das_sources_selected_warn"),
- MessageManager
- .getString("label.no_das_sources_selected_title"),
- JOptionPane.DEFAULT_OPTION,
- JOptionPane.INFORMATION_MESSAGE);