/*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
*/
package jalview.appletgui;
* @author $author$
* @version $Revision$
*/
-public class FeatureRenderer
+public class FeatureRenderer implements jalview.api.FeatureRenderer
{
AlignViewport av;
featureGroups = fr.featureGroups;
featureColours = fr.featureColours;
transparency = fr.transparency;
+ if (av!=null && fr.av!=null && fr.av!=av)
+ {
+ if (fr.av.featuresDisplayed!=null)
+ {
+ if (av.featuresDisplayed==null)
+ {
+ av.featuresDisplayed = new Hashtable();
+ } else {
+ av.featuresDisplayed.clear();
+ }
+ Enumeration en=fr.av.featuresDisplayed.keys();
+ while (en.hasMoreElements())
+ {
+ av.featuresDisplayed.put(en.nextElement(), Boolean.TRUE);
+ }
+ }
+ }
}
static String lastFeatureAdded;
boolean deleteFeature = false;
FeatureColourPanel colourPanel;
- class FeatureColourPanel extends Panel {
- String label="";
-
+
+ class FeatureColourPanel extends Panel
+ {
+ String label = "";
+
private Color maxCol;
- private boolean isColourByLabel,isGcol;
+
+ private boolean isColourByLabel, isGcol;
+
/**
* render a feature style in the amend feature dialog box
*/
public void updateColor(Object newcol)
{
-
- Color bg,col=null;
- GraduatedColor gcol=null;
+
+ Color bg, col = null;
+ GraduatedColor gcol = null;
String vlabel = "";
if (newcol instanceof Color)
{
- isGcol=false;
+ isGcol = false;
col = (Color) newcol;
gcol = null;
}
else if (newcol instanceof GraduatedColor)
{
- isGcol=true;
+ isGcol = true;
gcol = (GraduatedColor) newcol;
col = null;
}
}
if (col != null)
{
- setBackground(bg=col);
+ setBackground(bg = col);
}
else
{
- if (gcol.getThreshType()!=AnnotationColourGradient.NO_THRESHOLD)
+ if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
{
- vlabel += " "+((gcol.getThreshType()==AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)" : "(<)");
+ vlabel += " "
+ + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
+ : "(<)");
}
- if (isColourByLabel=gcol.isColourByLabel()) {
- setBackground(bg=Color.white);
+ if (isColourByLabel = gcol.isColourByLabel())
+ {
+ setBackground(bg = Color.white);
vlabel += " (by Label)";
- } else {
- setBackground(bg=gcol.getMinColor());
+ }
+ else
+ {
+ setBackground(bg = gcol.getMinColor());
maxCol = gcol.getMaxColor();
}
}
- label=vlabel;
+ label = vlabel;
setBackground(bg);
repaint();
}
- FeatureColourPanel() {
+
+ FeatureColourPanel()
+ {
super(null);
}
- public void paint(Graphics g)
+
+ public void paint(Graphics g)
{
Dimension d = getSize();
- if (isGcol) {
- if (isColourByLabel)
+ if (isGcol)
{
- g.setColor(Color.white);
- g.fillRect(d.width/2, 0,d.width/2, d.height);
- g.setColor(Color.black);
- Font f=new Font("Verdana", Font.PLAIN,
- 10);
- g.setFont(f);
- g.drawString("Label", 0, 0);
- }
- else
- {
- g.setColor(maxCol);
- g.fillRect(d.width/2, 0,d.width/2, d.height);
-
- }
+ if (isColourByLabel)
+ {
+ g.setColor(Color.white);
+ g.fillRect(d.width / 2, 0, d.width / 2, d.height);
+ g.setColor(Color.black);
+ Font f = new Font("Verdana", Font.PLAIN, 10);
+ g.setFont(f);
+ g.drawString("Label", 0, 0);
+ }
+ else
+ {
+ g.setColor(maxCol);
+ g.fillRect(d.width / 2, 0, d.width / 2, d.height);
+
+ }
}
}
final FeatureRenderer fr = this;
Panel panel = new Panel(new GridLayout(3, 1));
-
+
featureIndex = 0; // feature to be amended.
Panel tmp;
dialog.setResizable(true);
// TODO: render the graduated color in the box.
colourPanel.addMouseListener(new java.awt.event.MouseAdapter()
+ {
+ public void mousePressed(java.awt.event.MouseEvent evt)
{
- public void mousePressed(java.awt.event.MouseEvent evt)
+ if (!colourPanel.isGcol)
{
- if (!colourPanel.isGcol)
- {
- new UserDefinedColours(fr, ap.alignFrame);
- } else {
- FeatureColourChooser fcc = new FeatureColourChooser(ap.alignFrame, name.getText());
- dialog.transferFocus();
- }
+ new UserDefinedColours(fr, ap.alignFrame);
}
- });
+ else
+ {
+ FeatureColourChooser fcc = new FeatureColourChooser(
+ ap.alignFrame, name.getText());
+ dialog.transferFocus();
+ }
+ }
+ });
dialog.setVisible(true);
jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
sf.type = lastFeatureAdded;
sf.featureGroup = lastFeatureGroupAdded;
sf.description = lastDescriptionAdded;
- if (!colourPanel.isGcol) {
+ if (!colourPanel.isGcol)
+ {
// update colour - otherwise its already done.
setColour(sf.type, colourPanel.getBackground());
}
}
col = colourPanel.getBackground();
- //setColour(lastFeatureAdded, fcol);
+ // setColour(lastFeatureAdded, fcol);
if (lastFeatureGroupAdded != null)
{
featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
}
- if (fcol instanceof Color) {
+ if (fcol instanceof Color)
+ {
setColour(lastFeatureAdded, fcol);
}
av.featuresDisplayed.put(lastFeatureAdded,
}
}
// refresh the alignment and the feature settings dialog
- if (av.featureSettings!=null)
+ if (av.featureSettings != null)
{
av.featureSettings.refreshTable();
}
else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
{
- renderFeature(g, seq, seq
- .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
- .findIndex(sequenceFeatures[sfindex].begin) - 1,
+ renderFeature(g, seq,
+ seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
+ seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
getColour(sequenceFeatures[sfindex])
// new Color(((Integer) av.featuresDisplayed
// .get(sequenceFeatures[sfindex].type)).intValue())
, start, end, y1);
- renderFeature(g, seq, seq
- .findIndex(sequenceFeatures[sfindex].end) - 1, seq
- .findIndex(sequenceFeatures[sfindex].end) - 1,
+ renderFeature(g, seq,
+ seq.findIndex(sequenceFeatures[sfindex].end) - 1,
+ seq.findIndex(sequenceFeatures[sfindex].end) - 1,
getColour(sequenceFeatures[sfindex])
// new Color(((Integer) av.featuresDisplayed
// .get(sequenceFeatures[sfindex].type)).intValue())
else
{
if (showFeature(sequenceFeatures[sfindex]))
- { renderFeature(g, seq, seq
- .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
- .findIndex(sequenceFeatures[sfindex].end) - 1,
- getColour(sequenceFeatures[sfindex]), start, end, y1);
+ {
+ renderFeature(g, seq,
+ seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
+ seq.findIndex(sequenceFeatures[sfindex].end) - 1,
+ getColour(sequenceFeatures[sfindex]), start, end, y1);
}
}
Hashtable minmax = null;
+ /**
+ * Called when alignment in associated view has new/modified features to
+ * discover and display.
+ *
+ */
+ public void featuresAdded()
+ {
+ lastSeq = null;
+ findAllFeatures();
+ }
+
+ /**
+ * find all features on the alignment
+ */
void findAllFeatures()
{
jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
{
if (getColour(features[index].getType()) == null)
{
- featureColours.put(features[index].getType(), ucs
- .createColourFromName(features[index].getType()));
+ featureColours.put(features[index].getType(),
+ ucs.createColourFromName(features[index].getType()));
}
av.featuresDisplayed.put(features[index].getType(), new Integer(
throw new Error("Implementation Error: Unrecognised render object "
+ fc.getClass() + " for features of type " + featureType);
}
+
/**
*
* @param sequenceFeature
if (fc instanceof GraduatedColor)
{
return ((GraduatedColor) fc).isColored(sequenceFeature);
- } else { return true; }
+ }
+ else
+ {
+ return true;
+ }
}
/**
for (int i = 0; i < data.length; i++)
{
String type = data[i][0].toString();
- setColour(type, data[i][1]);
+ setColour(type, data[i][1]);
if (((Boolean) data[i][2]).booleanValue())
{
av.featuresDisplayed.put(type, new Integer(getColour(type)