X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FFeatureRenderer.java;h=e11f1b484f1aea73fa822b58b35a3a61b64063df;hb=dfa04e77181fccfa6229ffef1591fc9c622d9b39;hp=c2c24622490dc835e25e7df1834f7c86459a973d;hpb=262352d44a49e6102a9e80b0c006ea9331ed0c67;p=jalview.git diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java old mode 100755 new mode 100644 index c2c2462..e11f1b4 --- a/src/jalview/appletgui/FeatureRenderer.java +++ b/src/jalview/appletgui/FeatureRenderer.java @@ -1,20 +1,20 @@ /* - * 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.8.0b1) + * Copyright (C) 2014 The Jalview Authors * - * 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. + * + * 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.appletgui; @@ -24,10 +24,10 @@ import java.awt.*; import java.awt.event.*; -import jalview.appletgui.FeatureSettings.MyCheckbox; import jalview.datamodel.*; import jalview.schemes.AnnotationColourGradient; import jalview.schemes.GraduatedColor; +import jalview.util.MessageManager; /** * DOCUMENT ME! @@ -35,7 +35,7 @@ import jalview.schemes.GraduatedColor; * @author $author$ * @version $Revision$ */ -public class FeatureRenderer +public class FeatureRenderer implements jalview.api.FeatureRenderer { AlignViewport av; @@ -79,12 +79,41 @@ public class FeatureRenderer } } - public void transferSettings(FeatureRenderer fr) + public void transferSettings(jalview.api.FeatureRenderer _fr) { - renderOrder = fr.renderOrder; - featureGroups = fr.featureGroups; - featureColours = fr.featureColours; - transparency = fr.transparency; + if (_fr instanceof FeatureRenderer) + { + FeatureRenderer fr = (FeatureRenderer) _fr; + renderOrder = fr.renderOrder; + 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); + } + } + } + } + else + { + throw new Error( + "Implementation error: cannot port feature settings from implementation of type " + + _fr.getClass() + " to " + getClass()); + } } static String lastFeatureAdded; @@ -98,29 +127,33 @@ public class FeatureRenderer 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; } @@ -130,49 +163,57 @@ public class FeatureRenderer } 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) { - int width=getWidth(),height=getHeight(); - if (isGcol) { - if (isColourByLabel) + Dimension d = getSize(); + if (isGcol) { - g.setColor(Color.white); - g.fillRect(width/2, 0,width/2, 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(width/2, 0,width/2, 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(MessageManager.getString("label.label"), 0, 0); + } + else + { + g.setColor(maxCol); + g.fillRect(d.width / 2, 0, d.width / 2, d.height); + + } } } @@ -197,7 +238,7 @@ public class FeatureRenderer final FeatureRenderer fr = this; Panel panel = new Panel(new GridLayout(3, 1)); - + featureIndex = 0; // feature to be amended. Panel tmp; @@ -243,7 +284,7 @@ public class FeatureRenderer ap.seqPanel.seqCanvas.highlightSearchResults(highlight); } - Color col = getColour(name.getText()); + Object col = getFeatureStyle(name.getText()); if (col == null) { col = new jalview.schemes.UserColourScheme() @@ -335,7 +376,7 @@ public class FeatureRenderer } else { - dialog.ok.setLabel("Amend"); + dialog.ok.setLabel(MessageManager.getString("label.amend")); dialog.buttonPanel.add(deleteButton, 1); deleteButton.addActionListener(new ActionListener() { @@ -363,29 +404,22 @@ public class FeatureRenderer colourPanel.updateColor(fcol); dialog.setResizable(true); // TODO: render the graduated color in the box. - if (fcol instanceof Color) + colourPanel.addMouseListener(new java.awt.event.MouseAdapter() { - 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) { new UserDefinedColours(fr, ap.alignFrame); } - }); - - } - else - { - colourPanel.addMouseListener(new java.awt.event.MouseAdapter() - { - public void mousePressed(java.awt.event.MouseEvent evt) + else { - FeatureColourChooser fcc = new FeatureColourChooser(ap.alignFrame, name.getText()); - fcc.setFocusable(true); + FeatureColourChooser fcc = new FeatureColourChooser( + ap.alignFrame, name.getText()); dialog.transferFocus(); } - }); - } + } + }); dialog.setVisible(true); jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile(); @@ -412,7 +446,8 @@ public class FeatureRenderer sf.type = lastFeatureAdded; sf.featureGroup = lastFeatureGroupAdded; sf.description = lastDescriptionAdded; - if (fcol instanceof Color) { + if (!colourPanel.isGcol) + { // update colour - otherwise its already done. setColour(sf.type, colourPanel.getBackground()); } @@ -456,13 +491,14 @@ public class FeatureRenderer } 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, @@ -474,17 +510,18 @@ public class FeatureRenderer tro[0] = renderOrder[renderOrder.length - 1]; System.arraycopy(renderOrder, 0, tro, 1, renderOrder.length - 1); renderOrder = tro; - - ap.paintAlignment(true); - - return true; } else { + // no update to the alignment return false; } } - + // refresh the alignment and the feature settings dialog + if (av.featureSettings != null) + { + av.featureSettings.refreshTable(); + } // findAllFeatures(); ap.paintAlignment(true); @@ -654,16 +691,16 @@ public class FeatureRenderer 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()) @@ -673,10 +710,11 @@ public class FeatureRenderer 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); } } @@ -740,6 +778,20 @@ public class FeatureRenderer 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(); @@ -747,10 +799,10 @@ public class FeatureRenderer av.featuresDisplayed = new Hashtable(); Vector allfeatures = new Vector(); minmax = new Hashtable(); - - for (int i = 0; i < av.alignment.getHeight(); i++) + AlignmentI alignment = av.getAlignment(); + for (int i = 0; i < alignment.getHeight(); i++) { - SequenceFeature[] features = av.alignment.getSequenceAt(i) + SequenceFeature[] features = alignment.getSequenceAt(i) .getSequenceFeatures(); if (features == null) @@ -770,8 +822,8 @@ public class FeatureRenderer { 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( @@ -860,6 +912,7 @@ public class FeatureRenderer throw new Error("Implementation Error: Unrecognised render object " + fc.getClass() + " for features of type " + featureType); } + /** * * @param sequenceFeature @@ -871,7 +924,11 @@ public class FeatureRenderer if (fc instanceof GraduatedColor) { return ((GraduatedColor) fc).isColored(sequenceFeature); - } else { return true; } + } + else + { + return true; + } } /** @@ -934,7 +991,7 @@ public class FeatureRenderer 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) @@ -1020,9 +1077,9 @@ public class FeatureRenderer for (int i = 0; i < toset.length; i++) { Object st = featureGroups.get(toset[i]); + featureGroups.put(toset[i], new Boolean(visible)); if (st != null) { - featureGroups.put(toset[i], new Boolean(visible)); rdrw = rdrw || (visible != ((Boolean) st).booleanValue()); } } @@ -1046,6 +1103,8 @@ public class FeatureRenderer } } + ArrayList hiddenGroups = new ArrayList(); + /** * analyse alignment for groups and hash tables (used to be embedded in * FeatureSettings.setTableData) @@ -1059,29 +1118,34 @@ public class FeatureRenderer { featureGroups = new Hashtable(); } - Vector allFeatures = new Vector(); - Vector allGroups = new Vector(); + hiddenGroups = new ArrayList(); + hiddenGroups.addAll(featureGroups.keySet()); + ArrayList allFeatures = new ArrayList(); + ArrayList allGroups = new ArrayList(); SequenceFeature[] tmpfeatures; String group; - for (int i = 0; i < av.alignment.getHeight(); i++) + AlignmentI alignment = av.getAlignment(); + for (int i = 0; i < alignment.getHeight(); i++) { - if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null) + if (alignment.getSequenceAt(i).getSequenceFeatures() == null) { continue; } alignmentHasFeatures = true; - tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures(); + tmpfeatures = alignment.getSequenceAt(i).getSequenceFeatures(); int index = 0; while (index < tmpfeatures.length) { if (tmpfeatures[index].getFeatureGroup() != null) { group = tmpfeatures[index].featureGroup; + // Remove group from the hiddenGroup list + hiddenGroups.remove(group); if (!allGroups.contains(group)) { - allGroups.addElement(group); + allGroups.add(group); boolean visible = true; if (featureGroups.containsKey(group)) @@ -1097,7 +1161,7 @@ public class FeatureRenderer if (!allFeatures.contains(tmpfeatures[index].getType())) { - allFeatures.addElement(tmpfeatures[index].getType()); + allFeatures.add(tmpfeatures[index].getType()); } index++; } @@ -1126,16 +1190,17 @@ public class FeatureRenderer Vector allFeatures = new Vector(); SequenceFeature[] tmpfeatures; String group; - for (int i = 0; i < av.alignment.getHeight(); i++) + AlignmentI alignment = av.getAlignment(); + for (int i = 0; i < alignment.getHeight(); i++) { - if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null) + if (alignment.getSequenceAt(i).getSequenceFeatures() == null) { continue; } alignmentHasFeatures = true; - tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures(); + tmpfeatures = alignment.getSequenceAt(i).getSequenceFeatures(); int index = 0; while (index < tmpfeatures.length) {