X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=ea492e245bc134a1ca76a15210afe2b3d389ec80;hb=50ea78c7b98de7614cd386956e9aa0ee73dd7936;hp=6c5990a80aff82a1adec14bc38264c7c8fbfd115;hpb=2bc54fc3fc79e09819a6e650ecd38446322a5f3c;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 6c5990a..ea492e2 100755 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -37,7 +37,7 @@ public class FeatureSettings extends JPanel { DasSourceBrowser dassourceBrowser; - jalview.io.DasSequenceFeatureFetcher dasFeatureFetcher; + jalview.ws.DasSequenceFeatureFetcher dasFeatureFetcher; JPanel settingsPane = new JPanel(); JPanel dasSettingsPane = new JPanel(); @@ -132,13 +132,13 @@ public class FeatureSettings { if (!fs.resettingTable && !fs.handlingUpdate) { fs.handlingUpdate=true; - fs.resetTable(new String[] {}); // groups may be added + fs.resetTable(null); // new groups may be added with new seuqence feature types only fs.handlingUpdate=false; } } - + }); - + frame = new JInternalFrame(); frame.setContentPane(this); Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 450); @@ -157,7 +157,7 @@ public class FeatureSettings * true when Feature Settings are updating from feature renderer */ private boolean handlingUpdate=false; - + /** * contains a float[3] for each feature type string. created by setTableData */ @@ -198,57 +198,10 @@ public class FeatureSettings if (!allGroups.contains(group)) { allGroups.addElement(group); - - boolean visible; - if (fr.featureGroups.containsKey(group)) + if (group!=null) { - visible = ( (Boolean) fr.featureGroups.get(group)).booleanValue(); - } else { - visible=true; //initGroups || fr.av.featuresDisplayed.containsKey(tmpfeatures[index].getType()); + checkGroupState(group); } - - if (groupPanel == null) - { - groupPanel = new JPanel(); - } - - boolean alreadyAdded = false; - for (int g = 0; g < groupPanel.getComponentCount(); g++) - { - if ( ( (JCheckBox) groupPanel.getComponent(g)) - .getText().equals(group)) - { - alreadyAdded = true; - break; - } - } - - if (alreadyAdded) - { - - continue; - } - - fr.featureGroups.put(group, new Boolean(visible)); - final String grp = group; - final JCheckBox check = new JCheckBox(group, visible); - check.setFont(new Font("Serif", Font.BOLD, 12)); - check.addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent evt) - { - fr.featureGroups.put(check.getText(), - new Boolean(check.isSelected())); - af.alignPanel.seqPanel.seqCanvas.repaint(); - if (af.alignPanel.overviewPanel != null) - { - af.alignPanel.overviewPanel.updateOverviewImage(); - } - - resetTable(new String[] { grp } ); - } - }); - groupPanel.add(check); } } @@ -259,17 +212,79 @@ public class FeatureSettings index++; } } - + resetTable(null); validate(); } + /** + * + * @param group + * @return true if group has been seen before and is already added to set. + */ + private boolean checkGroupState(String group) { + boolean visible; + if (fr.featureGroups.containsKey(group)) + { + visible = ( (Boolean) fr.featureGroups.get(group)).booleanValue(); + } else { + visible=true; // new group is always made visible + } + + if (groupPanel == null) + { + groupPanel = new JPanel(); + } + + boolean alreadyAdded = false; + for (int g = 0; g < groupPanel.getComponentCount(); g++) + { + if ( ( (JCheckBox) groupPanel.getComponent(g)) + .getText().equals(group)) + { + alreadyAdded = true; + ((JCheckBox)groupPanel.getComponent(g)).setSelected(visible); + break; + } + } + + if (alreadyAdded) + { + + return true; + } + + fr.featureGroups.put(group, new Boolean(visible)); + final String grp = group; + final JCheckBox check = new JCheckBox(group, visible); + check.setFont(new Font("Serif", Font.BOLD, 12)); + check.addItemListener(new ItemListener() + { + public void itemStateChanged(ItemEvent evt) + { + fr.featureGroups.put(check.getText(), + new Boolean(check.isSelected())); + af.alignPanel.seqPanel.seqCanvas.repaint(); + if (af.alignPanel.overviewPanel != null) + { + af.alignPanel.overviewPanel.updateOverviewImage(); + } + + resetTable(new String[] { grp } ); + } + }); + groupPanel.add(check); + return false; + } boolean resettingTable=false; - void resetTable(String[] groupChanged) + synchronized void resetTable(String[] groupChanged) { + if (resettingTable==true) + { + return; + } resettingTable=true; typeWidth=new Hashtable(); - Vector groupchanged = new Vector(); // TODO: change avWidth calculation to 'per-sequence' average and use long rather than float float[] avWidth=null; SequenceFeature[] tmpfeatures; @@ -303,6 +318,8 @@ public class FeatureSettings if (group == null || fr.featureGroups.get(group) == null || ( (Boolean) fr.featureGroups.get(group)).booleanValue()) { + if (group!=null) + checkGroupState(group); type = tmpfeatures[index].getType(); if (!visibleChecks.contains(type)) { @@ -551,16 +568,16 @@ public class FeatureSettings boolean sort=false; for (int i=0;i0) sort = sort || width[i-1]>width[i]; @@ -568,7 +585,7 @@ public class FeatureSettings if (sort) jalview.util.QuickSort.sort(width, data); // update global priority order - + updateFeatureRenderer(data,false); table.repaint(); } @@ -591,11 +608,6 @@ public class FeatureSettings { fr.setFeaturePriority(data, visibleNew); af.alignPanel.paintAlignment(true); - - if (af.alignPanel.overviewPanel != null) - { - af.alignPanel.overviewPanel.updateOverviewImage(); - } } int selectedRow = -1; @@ -740,23 +752,32 @@ public class FeatureSettings fetchDAS.setEnabled(false); cancelDAS.setEnabled(true); 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(Vector selectedSources, boolean checkDbRefs, boolean promptFetchDbRefs) + { SequenceI[] dataset, seqs; int iSize; - - if (af.getViewport().getSelectionGroup() != null - && af.getViewport().getSelectionGroup().getSize() > 0) + AlignViewport vp = af.getViewport(); + if (vp.getSelectionGroup() != null + && vp.getSelectionGroup().getSize() > 0) { - iSize = af.getViewport().getSelectionGroup().getSize(); + iSize = vp.getSelectionGroup().getSize(); dataset = new SequenceI[iSize]; - seqs = af.getViewport().getSelectionGroup(). + seqs = vp.getSelectionGroup(). getSequencesInOrder( - af.getViewport().getAlignment()); + vp.getAlignment()); } else { - iSize = af.getViewport().getAlignment().getHeight(); - seqs = af.getViewport().getAlignment().getSequencesArray(); + iSize = vp.getAlignment().getHeight(); + seqs = vp.getAlignment().getSequencesArray(); } dataset = new SequenceI[iSize]; @@ -765,15 +786,64 @@ public class FeatureSettings dataset[i] = seqs[i].getDatasetSequence(); } + cancelDAS.setEnabled(true); dasFeatureFetcher = - new jalview.io.DasSequenceFeatureFetcher( + new jalview.ws.DasSequenceFeatureFetcher( dataset, this, - selectedSources); - cancelDAS.setEnabled(true); + selectedSources, checkDbRefs, promptFetchDbRefs); af.getViewport().setShowSequenceFeatures(true); af.showSeqFeatures.setSelected(true); } + /** + * 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 + */ + public void fetchDasFeatures(Vector sources) + { + Thread thr = new Thread(new Runnable() { + public void run() { + // this actually initialises the das source list + dassourceBrowser.paintComponent(null); // yuk + } + }); + thr.start(); + while (dassourceBrowser.loadingDasSources || dassourceBrowser.dasSources==null) + { + try { Thread.sleep(10); } catch (Exception e) {}; + } + Vector resolved = new Vector(); + if (sources!=null) + { + for (int i=0;i0) + { + final Vector dassources = resolved; + SwingUtilities.invokeLater(new Runnable() { + + public void run() + { + fetchDAS.setEnabled(false); + cancelDAS.setEnabled(true); + doDasFeatureFetch(dassources, true, false); + + }}); + } + } public void saveDAS_actionPerformed(ActionEvent e) { @@ -788,10 +858,24 @@ public class FeatureSettings public void cancelDAS_actionPerformed(ActionEvent e) { - dasFeatureFetcher.cancel(); + if (dasFeatureFetcher!=null) + { + dasFeatureFetcher.cancel(); + } fetchDAS.setEnabled(true); cancelDAS.setEnabled(false); } + public void noDasSourceActive() + { + complete(); + JOptionPane.showInternalConfirmDialog(Desktop.desktop, + "No das sources were selected.\n" + + "Please select some sources and\n" + +" try again.", + "No Sources Selected", + JOptionPane.DEFAULT_OPTION, + JOptionPane.INFORMATION_MESSAGE); + } ///////////////////////////////////////////////////////////////////////// // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html