\r
import java.util.*;\r
\r
+import java.awt.image.*;\r
+\r
\r
/**\r
* DOCUMENT ME!\r
initColours();\r
}\r
\r
-\r
- public Color findFeatureColour(Color initialCol, SequenceI seq, int i)\r
+ public void transferSettings(FeatureRenderer fr)\r
{\r
- if(!av.showSequenceFeatures)\r
- return initialCol;\r
-\r
- lastSequence = seq;\r
- sequenceFeatures = lastSequence.getDatasetSequence().getSequenceFeatures();\r
- if(sequenceFeatures==null)\r
- return initialCol;\r
-\r
- sfSize = sequenceFeatures.length;\r
-\r
- if(jalview.util.Comparison.isGap(lastSequence.getCharAt(i)))\r
- return Color.white;\r
-\r
- currentColour = null;\r
-\r
- drawSequence(null, lastSequence, lastSequence.findPosition(i), -1,-1, -1, -1);\r
+ renderOrder = fr.renderOrder;\r
+ featureGroups = fr.featureGroups;\r
+ featureColours = fr.featureColours;\r
+ transparency = fr.transparency;\r
+ }\r
\r
- if(currentColour==null)\r
- return initialCol;\r
+ BufferedImage offscreenImage;\r
+ boolean offscreenRender = false;\r
+ public Color findFeatureColour(Color initialCol, SequenceI seq, int res)\r
+ {\r
+ int seqindex = av.alignment.findIndex(seq);\r
\r
- return new Color( ((Integer)currentColour).intValue() );\r
+ return new Color( findFeatureColour (initialCol.getRGB(),\r
+ seqindex, res ));\r
}\r
+\r
/**\r
* This is used by the Molecule Viewer to get the accurate colour\r
* of the rendered sequence\r
*/\r
-\r
- boolean overview = false;\r
-\r
- int white = Color.white.getRGB();\r
public int findFeatureColour(int initialCol, int seqIndex, int column)\r
{\r
if(!av.showSequenceFeatures)\r
sfSize = sequenceFeatures.length;\r
}\r
\r
-\r
if(jalview.util.Comparison.isGap(lastSequence.getCharAt(column)))\r
return Color.white.getRGB();\r
\r
+\r
+ //Only bother making an offscreen image if transparency is applied\r
+ if(transparency!=1.0f && offscreenImage==null)\r
+ {\r
+ offscreenImage = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);\r
+ }\r
+\r
currentColour = null;\r
\r
- drawSequence(null, lastSequence, lastSequence.findPosition(column), -1,-1, -1, -1);\r
+ offscreenRender = true;\r
+\r
+ if(offscreenImage!=null)\r
+ {\r
+ offscreenImage.setRGB(0,0,initialCol);\r
+ drawSequence(offscreenImage.getGraphics(),\r
+ lastSequence,\r
+ column,column,0);\r
+\r
+ return offscreenImage.getRGB(0,0);\r
+ }\r
+ else\r
+ {\r
+ drawSequence(null,\r
+ lastSequence,\r
+ lastSequence.findPosition(column),\r
+ -1, -1);\r
+\r
+ if (currentColour == null)\r
+ return initialCol;\r
+ else\r
+ return ((Integer)currentColour).intValue();\r
+ }\r
\r
- if(currentColour==null)\r
- return initialCol;\r
\r
- return ((Integer)currentColour).intValue();\r
}\r
\r
\r
int sfSize, sfindex, spos, epos;\r
\r
public void drawSequence(Graphics g, SequenceI seq,\r
- int start, int end, int y1, int width, int height)\r
+ int start, int end, int y1)\r
{\r
- if ( seq.getDatasetSequence().getSequenceFeatures() == null\r
+ if ( seq.getDatasetSequence().getSequenceFeatures() == null\r
|| seq.getDatasetSequence().getSequenceFeatures().length==0)\r
return;\r
\r
if (av.featuresDisplayed == null || renderOrder==null)\r
{\r
findAllFeatures();\r
+ if(av.featuresDisplayed.size()<1)\r
+ return;\r
+\r
sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();\r
sfSize = sequenceFeatures.length;\r
}\r
AlphaComposite.SRC_OVER, transparency));\r
}\r
\r
- if(!overview)\r
+ if(!offscreenRender)\r
{\r
spos = lastSequence.findPosition(start);\r
epos = lastSequence.findPosition(end);\r
}\r
\r
+\r
String type;\r
for(int renderIndex=0; renderIndex<renderOrder.length; renderIndex++)\r
{\r
type = renderOrder[renderIndex];\r
+ if(!av.featuresDisplayed.containsKey(type))\r
+ continue;\r
\r
// loop through all features in sequence to find\r
// current feature to render\r
for (sfindex = 0; sfindex < sfSize; sfindex++)\r
{\r
+ if(sequenceFeatures.length<=sfindex)\r
+ {\r
+ continue;\r
+ }\r
if (!sequenceFeatures[sfindex].type.equals(type))\r
continue;\r
\r
continue;\r
}\r
\r
- if (!overview && (sequenceFeatures[sfindex].getBegin() > epos\r
+ if (!offscreenRender && (sequenceFeatures[sfindex].getBegin() > epos\r
|| sequenceFeatures[sfindex].getEnd() < spos))\r
continue;\r
\r
- if (overview)\r
+ if (offscreenRender && offscreenImage==null)\r
{\r
-\r
- if (sequenceFeatures[sfindex].begin - 1 <= start &&\r
- sequenceFeatures[sfindex].end + 1 >= start)\r
+ if (sequenceFeatures[sfindex].begin <= start &&\r
+ sequenceFeatures[sfindex].end >= start)\r
{\r
currentColour = av.featuresDisplayed.get(sequenceFeatures[sfindex].\r
- type);\r
+ type);\r
}\r
-\r
}\r
else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))\r
{\r
seq.findIndex(sequenceFeatures[sfindex].begin) - 1,\r
new Color( ( (Integer) av.featuresDisplayed.get(\r
sequenceFeatures[sfindex].type)).intValue()),\r
- start, end, y1, width, height);\r
+ start, end, y1);\r
renderFeature(g, seq,\r
seq.findIndex(sequenceFeatures[sfindex].end) - 1,\r
seq.findIndex(sequenceFeatures[sfindex].end) - 1,\r
new Color( ( (Integer) av.featuresDisplayed.get(\r
sequenceFeatures[sfindex].type)).intValue()),\r
- start, end, y1, width, height);\r
+ start, end, y1);\r
\r
}\r
else\r
seq.findIndex(sequenceFeatures[sfindex].begin) - 1,\r
seq.findIndex(sequenceFeatures[sfindex].end) - 1,\r
getColour(sequenceFeatures[sfindex].type),\r
- start, end, y1, width, height);\r
+ start, end, y1);\r
\r
\r
}\r
char s;\r
int i;\r
void renderFeature(Graphics g, SequenceI seq,\r
- int fstart, int fend, Color featureColour, int start, int end, int y1, int width, int height)\r
+ int fstart, int fend, Color featureColour, int start, int end, int y1)\r
{\r
\r
if (((fstart <= end) && (fend >= start)))\r
{\r
fend = end;\r
}\r
-\r
+ int pady = (y1 + av.charHeight) - av.charHeight / 5;\r
for (i = fstart; i <= fend; i++)\r
{\r
s = seq.getSequence().charAt(i);\r
\r
g.setColor(featureColour);\r
\r
- g.fillRect( (i - start) * width, y1, width, height);\r
+ g.fillRect( (i - start) * av.charWidth, y1, av.charWidth,av.charHeight);\r
+\r
+ if(offscreenRender)\r
+ continue;\r
\r
g.setColor(Color.white);\r
- charOffset = (width - fm.charWidth(s)) / 2;\r
+ charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
g.drawString(String.valueOf(s),\r
- charOffset + (width * (i - start)),\r
- (y1 + height) - height / 5); //pady = height / 5;\r
+ charOffset + (av.charWidth * (i - start)),\r
+ pady);\r
\r
}\r
}\r
void findAllFeatures()\r
{\r
av.featuresDisplayed = new Hashtable();\r
+ Vector allfeatures = new Vector();\r
for (int i = 0; i < av.alignment.getHeight(); i++)\r
{\r
- SequenceFeature [] features = av.alignment.getSequenceAt(i).getDatasetSequence().\r
- getSequenceFeatures();\r
+ SequenceFeature [] features\r
+ = av.alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures();\r
\r
if (features == null)\r
continue;\r
{\r
av.featuresDisplayed.put(features[index].getType(),\r
new Integer( getColour(features[index].getType()).getRGB()) );\r
+ allfeatures.addElement(features[index].getType());\r
}\r
index++;\r
}\r
}\r
\r
- renderOrder = new String[av.featuresDisplayed.size()];\r
- Enumeration en = av.featuresDisplayed.keys();\r
- int i = 0;\r
+ renderOrder = new String[allfeatures.size()];\r
+ Enumeration en = allfeatures.elements();\r
+ int i = allfeatures.size()-1;\r
while(en.hasMoreElements())\r
{\r
renderOrder[i] = en.nextElement().toString();\r
- i++;\r
+ i--;\r
}\r
}\r
\r
return (Color)featureColours.get(featureType);\r
}\r
\r
- public void addNewFeature(String name, Color col)\r
+ public void addNewFeature(String name, Color col, String group)\r
{\r
\r
setColour(name, col);\r
if(av.featuresDisplayed==null)\r
av.featuresDisplayed = new Hashtable();\r
\r
+ if(group == null)\r
+ group = "NOGROUP";\r
\r
- av.featuresDisplayed.put(name, "NOGROUP");\r
+ av.featuresDisplayed.put(name, new Integer(col.getRGB()));\r
}\r
\r
public void setColour(String featureType, Color col)\r
// The feature table will display high priority\r
// features at the top, but theses are the ones\r
// we need to render last, so invert the data\r
- av.featuresDisplayed.clear();\r
+ if(av.featuresDisplayed!=null)\r
+ av.featuresDisplayed.clear();\r
+ else\r
+ av.featuresDisplayed = new Hashtable();\r
\r
renderOrder = new String[data.length];\r
\r
- if(data.length>0)\r
- for(int i=data.length-1; i>-1; i--)\r
- {\r
- String type = data[i][0].toString();\r
- setColour(type, (Color)data[i][1]);\r
- if( ((Boolean)data[i][2]).booleanValue() )\r
- {\r
- av.featuresDisplayed.put(type, new Integer(getColour(type).getRGB()));\r
- }\r
- renderOrder[i] = type;\r
- }\r
+ if (data.length > 0)\r
+ for (int i = 0; i < data.length; i++)\r
+ {\r
+ String type = data[i][0].toString();\r
+ setColour(type, (Color) data[i][1]);\r
+ if ( ( (Boolean) data[i][2]).booleanValue())\r
+ {\r
+ av.featuresDisplayed.put(type, new Integer(getColour(type).getRGB()));\r
+ }\r
+\r
+ renderOrder[data.length - i - 1] = type;\r
+ }\r
\r
}\r
\r
final FeatureRenderer fr;\r
final AlignmentPanel ap;\r
final AlignViewport av;\r
- Hashtable allFeatures;\r
Object [][] originalData;\r
final JInternalFrame frame;\r
JScrollPane scrollPane = new JScrollPane();\r
JTable table;\r
JPanel groupPanel;\r
\r
+ boolean alignmentHasFeatures = false;\r
+\r
public FeatureSettings(AlignViewport av, final AlignmentPanel ap)\r
{\r
this.ap = ap;\r
if(groupPanel!=null)\r
{\r
groupPanel.setLayout(\r
- new GridLayout(groupPanel.getComponentCount()/3, 4));\r
+ new GridLayout(fr.featureGroups.size() / 4 + 1, 4));\r
+\r
groupPanel.validate();\r
bigPanel.add(groupPanel, BorderLayout.NORTH);\r
}\r
\r
void setTableData()\r
{\r
+ alignmentHasFeatures = false;\r
+\r
if (fr.featureGroups == null)\r
fr.featureGroups = new Hashtable();\r
- else\r
- fr.featureGroups.clear();\r
\r
- allFeatures = new Hashtable();\r
- SequenceFeature[] features;\r
+ Vector allFeatures = new Vector();\r
+ Vector allGroups = new Vector();\r
+ SequenceFeature[] tmpfeatures;\r
+ String group;\r
\r
- for (int i = 0; i < av.alignment.getHeight(); i++)\r
- {\r
- features = av.alignment.getSequenceAt(i).getDatasetSequence().\r
- getSequenceFeatures();\r
+ for (int i = 0; i < av.alignment.getHeight(); i++)\r
+ {\r
+ if (av.alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures() == null)\r
+ continue;\r
\r
- if (features == null)\r
- continue;\r
+ alignmentHasFeatures = true;\r
\r
- int index = 0;\r
- while (index < features.length)\r
- {\r
- if(features[index].getFeatureGroup()!=null\r
- && !fr.featureGroups.containsKey(features[index].getFeatureGroup()))\r
+ tmpfeatures = av.alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures();\r
+ int index = 0;\r
+ while (index < tmpfeatures.length)\r
+ {\r
+ if(tmpfeatures[index].getFeatureGroup()!=null)\r
+ {\r
+ group = tmpfeatures[index].featureGroup;\r
+ if(!allGroups.contains(group))\r
+ {\r
+ allGroups.addElement(group);\r
+\r
+ boolean visible = true;\r
+ if (fr.featureGroups.containsKey(group))\r
+ {\r
+ visible = ( (Boolean) fr.featureGroups.get(group)).booleanValue();\r
+ }\r
+\r
+ fr.featureGroups.put(group, new Boolean(visible));\r
+\r
+ if (groupPanel == null)\r
+ {\r
+ groupPanel = new JPanel();\r
+ }\r
+\r
+ final JCheckBox check = new JCheckBox(group, visible);\r
+ check.setFont(new Font("Serif", Font.BOLD, 12));\r
+ check.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent evt)\r
+ {\r
+ fr.featureGroups.put(check.getText(),\r
+ new Boolean(check.isSelected()));\r
+ ap.seqPanel.seqCanvas.repaint();\r
+ if (ap.overviewPanel != null)\r
+ ap.overviewPanel.updateOverviewImage();\r
+\r
+ resetTable(true);\r
+ }\r
+ });\r
+ groupPanel.add(check);\r
+\r
+ }\r
+\r
+ }\r
+\r
+ if (!allFeatures.contains(tmpfeatures[index].getType()))\r
{\r
- fr.featureGroups.put(features[index].getFeatureGroup(), new Boolean(true));\r
- if(groupPanel==null)\r
- groupPanel = new JPanel();\r
-\r
- final JCheckBox check = new JCheckBox(features[index].getFeatureGroup(), true);\r
- check.setFont(new Font("Serif", Font.BOLD, 12));\r
- check.addItemListener(new ItemListener()\r
- {\r
- public void itemStateChanged(ItemEvent evt)\r
- {\r
- if (fr.featureGroups.containsKey(check.getText()))\r
- {\r
- fr.featureGroups.put(check.getText(),\r
- new Boolean(check.isSelected()));\r
- ap.seqPanel.seqCanvas.repaint();\r
- if (ap.overviewPanel != null)\r
- ap.overviewPanel.updateOverviewImage();\r
- }\r
- resetTable();\r
- }\r
- });\r
- groupPanel.add(check);\r
+ allFeatures.addElement(tmpfeatures[index].getType());\r
}\r
- if (!allFeatures.contains(features[index].getType()))\r
- {\r
- if(features[index].featureGroup!=null)\r
- allFeatures.put(features[index].getType(), features[index].featureGroup);\r
- else\r
- allFeatures.put(features[index].getType(), "NOGROUP");\r
- }\r
- index++;\r
+ index ++;\r
}\r
}\r
- if(allFeatures.size()<1)\r
+\r
+\r
+ if(!alignmentHasFeatures)\r
{\r
try\r
{ frame.setClosed(true); }\r
return;\r
}\r
\r
- resetTable();\r
+ resetTable(false);\r
}\r
\r
- void resetTable()\r
+ void resetTable(boolean groupsChanged)\r
{\r
- int fSize = allFeatures.size();\r
+ SequenceFeature [] tmpfeatures;\r
+ String group=null, type;\r
+ Vector visibleChecks = new Vector();\r
\r
- String type;\r
- boolean originalExists = false;\r
- if (originalData != null)\r
- originalExists = true;\r
- else\r
- originalData = new Object[fSize][3];\r
+ //Find out which features should be visible depending on which groups\r
+ //are selected / deselected\r
+ for (int i = 0; i < av.alignment.getHeight(); i++)\r
+ {\r
+ if (av.alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures() == null)\r
+ continue;\r
\r
- Object[][] tmp = new Object[fSize][3];\r
- int tmpIndex = 0;\r
+ tmpfeatures = av.alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures();\r
+ int index = 0;\r
+ while (index < tmpfeatures.length)\r
+ {\r
+ group = tmpfeatures[index].featureGroup;\r
\r
- Enumeration en = allFeatures.keys();\r
- int i=0;\r
- while(en.hasMoreElements())\r
- {\r
- type = en.nextElement().toString();\r
- Color col = fr.getColour(type);\r
+ if (group==null || fr.featureGroups.get(group)==null ||\r
+ ((Boolean) fr.featureGroups.get(group)).booleanValue())\r
+ {\r
+ type = tmpfeatures[index].getType();\r
+ if(!visibleChecks.contains(type) )\r
+ {\r
+ visibleChecks.addElement(type);\r
+ }\r
+ }\r
+ index++;\r
+ }\r
+ }\r
+\r
+ int fSize = visibleChecks.size();\r
+ Object [][] data = new Object[fSize][3];\r
+ int dataIndex = 0;\r
\r
- //This will ignore any features which are in groups not shown\r
- Object visibleGroup = fr.featureGroups.get(allFeatures.get(type));\r
- if(visibleGroup == null\r
- || ((Boolean)(visibleGroup)).booleanValue())\r
+ if(fr.renderOrder!=null)\r
+ {\r
+ //First add the checks in the previous render order,\r
+ //in case the window has been closed and reopened\r
+ for(int ro=fr.renderOrder.length-1; ro>-1; ro--)\r
{\r
- tmp[tmpIndex][0] = type;\r
- tmp[tmpIndex][1] = col;\r
- if (av.featuresDisplayed != null)\r
- tmp[tmpIndex][2] = new Boolean(av.featuresDisplayed.containsKey(type));\r
- else\r
- tmp[tmpIndex][2] = new Boolean(true);\r
-\r
- tmpIndex++;\r
- }\r
+ type = fr.renderOrder[ro];\r
\r
+ if(!visibleChecks.contains(type))\r
+ continue;\r
\r
- if (!originalExists)\r
- {\r
- originalData[i][0] = type;\r
- originalData[i][1] = col;\r
- if (av.featuresDisplayed != null)\r
- originalData[i][2] = new Boolean(av.featuresDisplayed.contains(type));\r
- else\r
- originalData[i][2] = new Boolean(true);\r
+ data[dataIndex][0] = type;\r
+ data[dataIndex][1] = fr.getColour(type);\r
+ data[dataIndex][2] = new Boolean(av.featuresDisplayed.containsKey(type));\r
+ dataIndex++;\r
+ visibleChecks.removeElement(type);\r
}\r
- i++;\r
}\r
\r
- Object [][]data = new Object[tmpIndex][3];\r
- System.arraycopy(tmp, 0, data,0, tmpIndex);\r
+ fSize = visibleChecks.size();\r
+ for(int i=0; i<fSize; i++)\r
+ {\r
+ //These must be extra features belonging to the group\r
+ //which was just selected\r
+ type = visibleChecks.elementAt(i).toString();\r
+ data[dataIndex][0] = type;\r
+ data[dataIndex][1] = fr.getColour(type);\r
+ data[dataIndex][2] = new Boolean(true);\r
+ dataIndex++;\r
+ }\r
+\r
+ if(originalData==null)\r
+ {\r
+ originalData = new Object[data.length][3];\r
+ System.arraycopy(data,0,originalData,0,data.length);\r
+ }\r
\r
table = new JTable(new FeatureTableModel(data));\r
scrollPane.setViewportView(table);\r
return data;\r
}\r
\r
+ public void setData(Object[][] data)\r
+ {\r
+ this.data = data;\r
+ }\r
+\r
public int getColumnCount() {\r
return columnNames.length;\r
}\r