X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=ad9ad1dd3f49f7f1ffd15f43cee105b1bb814315;hb=ef36c8bbd6c5eef95e4d1a2cff57ea772af5110b;hp=3979ebecf3af9e9e09bdfa72d3aeb7c894bef6cf;hpb=391968dd70ca76090306df9b5852bbef10ab4ede;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 3979ebe..ad9ad1d 100755 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -28,239 +28,239 @@ import java.awt.event.*; import javax.swing.table.*; import java.io.*; import jalview.io.JalviewFileChooser; +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.Color; +import org.biojava.dasobert.dasregistry.DasSource; +import org.biojava.dasobert.dasregistry.DasCoordinateSystem; public class FeatureSettings extends JPanel { + DasSourceBrowser dassourceBrowser; + JPanel settingsPane = new JPanel(); + JPanel dasSettingsPane = new JPanel(); final FeatureRenderer fr; - final AlignmentPanel ap; - final AlignViewport av; - Hashtable allFeatures; + final AlignFrame af; Object [][] originalData; final JInternalFrame frame; JScrollPane scrollPane = new JScrollPane(); JTable table; JPanel groupPanel; + JSlider transparency = new JSlider(); - public FeatureSettings(AlignViewport av, final AlignmentPanel ap) + JPanel transPanel = new JPanel(new FlowLayout()); + boolean alignmentHasFeatures = false; + + public FeatureSettings(AlignFrame af) { - this.ap = ap; - this.av = av; - fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); - av.alignment.getSequences(); - frame = new JInternalFrame(); - frame.setContentPane(this); - Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 300); + this.af = af; + fr = af.getFeatureRenderer(); - setTableData(); + transparency.setMaximum( 100 - (int)(fr.transparency*100) ) ; - final JSlider transparency = new JSlider(0, 70, 0); - transparency.addChangeListener(new ChangeListener() - { - public void stateChanged(ChangeEvent evt) - { - fr.setTransparency( (float) (100 - transparency.getValue()) / 100f); - ap.repaint(); - } - }); + try + { + jbInit(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } - JPanel transPanel = new JPanel(new FlowLayout()); - transPanel.add(new JLabel("Transparency")); - transPanel.add(transparency); + dassourceBrowser = new DasSourceBrowser(); + dasSettingsPane.add(dassourceBrowser, BorderLayout.CENTER); - ////////////////////////////////////////////// - //We're going to need those OK cancel buttons - JPanel buttonPanel = new JPanel(new FlowLayout()); - JButton button = new JButton("OK"); - button.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - try - { - frame.setClosed(true); - } - catch (Exception exe) - {} - } - }); - buttonPanel.add(button); - button = new JButton("Cancel"); - button.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - try - { - updateFeatureRenderer(originalData); - frame.setClosed(true); - } - catch (Exception exe) - {} - } - }); - buttonPanel.add(button); - button = new JButton("Load Colours"); - button.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - load(); - } - }); - buttonPanel.add(button); - button = new JButton("Save Colours"); - button.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - save(); - } - }); - buttonPanel.add(button); - this.setLayout(new BorderLayout()); - JPanel bigPanel = new JPanel(new BorderLayout()); - bigPanel.add(transPanel, BorderLayout.SOUTH); - bigPanel.add(scrollPane, BorderLayout.CENTER); - if(groupPanel!=null) - { - groupPanel.setLayout( - new GridLayout(groupPanel.getComponentCount()/3, 4)); - groupPanel.validate(); - bigPanel.add(groupPanel, BorderLayout.NORTH); - } - add(bigPanel, BorderLayout.CENTER); - add(buttonPanel, BorderLayout.SOUTH); + if (af.getViewport().featuresDisplayed == null || fr.renderOrder==null) + fr.findAllFeatures(); + setTableData(); + + frame = new JInternalFrame(); + frame.setContentPane(this); + Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 450); + frame.setLayer(JLayeredPane.PALETTE_LAYER); } - void setTableData() + public void setTableData() { + alignmentHasFeatures = false; + if (fr.featureGroups == null) fr.featureGroups = new Hashtable(); - else - fr.featureGroups.clear(); - allFeatures = new Hashtable(); - SequenceFeature[] features; + Vector allFeatures = new Vector(); + Vector allGroups = new Vector(); + SequenceFeature[] tmpfeatures; + String group; - for (int i = 0; i < av.alignment.getHeight(); i++) - { - features = av.alignment.getSequenceAt(i).getDatasetSequence(). - getSequenceFeatures(); + for (int i = 0; i < af.getViewport().alignment.getHeight(); i++) + { + if (af.getViewport().alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures() == null) + continue; - if (features == null) - continue; + alignmentHasFeatures = true; - int index = 0; - while (index < features.length) - { - if(features[index].getFeatureGroup()!=null - && !fr.featureGroups.containsKey(features[index].getFeatureGroup())) + tmpfeatures = af.getViewport().alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures(); + + int index = 0; + while (index < tmpfeatures.length) + { + if(tmpfeatures[index].begin == 0 && tmpfeatures[index].end ==0) + { + index++; + continue; + } + + if(tmpfeatures[index].getFeatureGroup()!=null) + { + group = tmpfeatures[index].featureGroup; + if(!allGroups.contains(group)) + { + allGroups.addElement(group); + + boolean visible = true; + if (fr.featureGroups.containsKey(group)) + { + visible = ( (Boolean) fr.featureGroups.get(group)).booleanValue(); + } + else + { + fr.featureGroups.put(group, new Boolean(visible)); + if (groupPanel == null) + { + groupPanel = new JPanel(); + } + + 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(true); + } + }); + groupPanel.add(check); + } + } + + } + + if (!allFeatures.contains(tmpfeatures[index].getType())) { - fr.featureGroups.put(features[index].getFeatureGroup(), new Boolean(true)); - if(groupPanel==null) - groupPanel = new JPanel(); - - final JCheckBox check = new JCheckBox(features[index].getFeatureGroup(), true); - check.setFont(new Font("Serif", Font.BOLD, 12)); - check.addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent evt) - { - if (fr.featureGroups.containsKey(check.getText())) - { - fr.featureGroups.put(check.getText(), - new Boolean(check.isSelected())); - ap.seqPanel.seqCanvas.repaint(); - if (ap.overviewPanel != null) - ap.overviewPanel.updateOverviewImage(); - } - resetTable(); - } - }); - groupPanel.add(check); + allFeatures.addElement(tmpfeatures[index].getType()); } - if (!allFeatures.contains(features[index].getType())) - { - if(features[index].featureGroup!=null) - allFeatures.put(features[index].getType(), features[index].featureGroup); - else - allFeatures.put(features[index].getType(), "NOGROUP"); - } - index++; + index ++; } } - if(allFeatures.size()<1) - { - try - { frame.setClosed(true); } - catch (Exception ex){} - JOptionPane.showInternalMessageDialog( - Desktop.desktop, "No features have been added to this alignment!", - "No Sequence Features", JOptionPane.WARNING_MESSAGE); - return; + if(!alignmentHasFeatures) + { + // try + // { frame.setClosed(true); } + // catch (Exception ex){} + + // JOptionPane.showInternalMessageDialog( + /// Desktop.desktop, "No features have been added to this alignment!", + // + // return; } - resetTable(); + resetTable(false); } - void resetTable() + + void resetTable(boolean groupsChanged) { - int fSize = allFeatures.size(); + SequenceFeature [] tmpfeatures; + String group=null, type; + Vector visibleChecks = new Vector(); - String type; - boolean originalExists = false; - if (originalData != null) - originalExists = true; - else - originalData = new Object[fSize][3]; + //Find out which features should be visible depending on which groups + //are selected / deselected + for (int i = 0; i < af.getViewport().alignment.getHeight(); i++) + { - Object[][] tmp = new Object[fSize][3]; - int tmpIndex = 0; + tmpfeatures = af.getViewport().alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures(); + if (tmpfeatures == null) + continue; - Enumeration en = allFeatures.keys(); - int i=0; - while(en.hasMoreElements()) - { - type = en.nextElement().toString(); - Color col = fr.getColour(type); + int index = 0; + while (index < tmpfeatures.length) + { + group = tmpfeatures[index].featureGroup; + + if(tmpfeatures[index].begin==0 && tmpfeatures[index].end==0) + { + index ++; + continue; + } + if (group==null || fr.featureGroups.get(group)==null || + ((Boolean) fr.featureGroups.get(group)).booleanValue()) + { + type = tmpfeatures[index].getType(); + if(!visibleChecks.contains(type) ) + { + visibleChecks.addElement(type); + } + } + index++; + } + } + + int fSize = visibleChecks.size(); + Object [][] data = new Object[fSize][3]; + int dataIndex = 0; - //This will ignore any features which are in groups not shown - if(fr.featureGroups==null - || ((Boolean)fr.featureGroups.get(allFeatures.get(type))).booleanValue()) + if(fr.renderOrder!=null) + { + //First add the checks in the previous render order, + //in case the window has been closed and reopened + for(int ro=fr.renderOrder.length-1; ro>-1; ro--) { - tmp[tmpIndex][0] = type; - tmp[tmpIndex][1] = col; - if (av.featuresDisplayed != null) - tmp[tmpIndex][2] = new Boolean(av.featuresDisplayed.containsKey(type)); - else - tmp[tmpIndex][2] = new Boolean(true); - - tmpIndex++; - } + type = fr.renderOrder[ro]; + if(!visibleChecks.contains(type)) + continue; - if (!originalExists) - { - originalData[i][0] = type; - originalData[i][1] = col; - if (av.featuresDisplayed != null) - originalData[i][2] = new Boolean(av.featuresDisplayed.contains(type)); - else - originalData[i][2] = new Boolean(true); + data[dataIndex][0] = type; + data[dataIndex][1] = fr.getColour(type); + data[dataIndex][2] = new Boolean(af.getViewport().featuresDisplayed.containsKey(type)); + dataIndex++; + visibleChecks.removeElement(type); } - i++; } - Object [][]data = new Object[tmpIndex][3]; - System.arraycopy(tmp, 0, data,0, tmpIndex); + fSize = visibleChecks.size(); + for(int i=0; i0) + { + iSize = af.getViewport().getSelectionGroup().getSize(false); + dataset = new SequenceI[iSize]; + seqs = af.getViewport().getSelectionGroup(). + getSequencesInOrder( + af.getViewport().getAlignment()); + } + else + { + iSize = af.getViewport().getAlignment().getHeight(); + seqs = af.getViewport().getAlignment().getSequencesArray(); + } + dataset = new SequenceI[iSize]; + for (int i = 0; i < iSize; i++) + { + dataset[i] = seqs[i].getDatasetSequence(); + } + + new jalview.io.DasSequenceFeatureFetcher( + dataset, + af, + selectedSources); + + af.getViewport().setShowSequenceFeatures(true); + af.showSeqFeatures.setSelected(true); + } + + public void saveDAS_actionPerformed(ActionEvent e) + { + dassourceBrowser.saveProperties(jalview.bin.Cache.applicationProperties); + } ///////////////////////////////////////////////////////////////////////// // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html @@ -431,6 +615,11 @@ public class FeatureSettings extends JPanel return data; } + public void setData(Object[][] data) + { + this.data = data; + } + public int getColumnCount() { return columnNames.length; }