2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
24 import jalview.analysis.*;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
28 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.structure.SelectionSource;
31 import jalview.structure.VamsasSource;
32 import jalview.viewmodel.AlignmentViewport;
33 import jalview.workers.ConservationThread;
34 import jalview.workers.ConsensusThread;
36 public class AlignViewport extends AlignmentViewport implements AlignViewportI, SelectionSource, VamsasSource
46 boolean cursorMode = false;
48 boolean showJVSuffix = true;
50 boolean showText = true;
52 boolean showColourText = false;
54 boolean showBoxes = true;
56 boolean wrapAlignment = false;
58 boolean renderGaps = true;
60 boolean showSequenceFeatures = false;
62 boolean showAnnotation = true;
64 boolean upperCasebold = false;
73 Font font = new Font("SansSerif", Font.PLAIN, 10);
75 boolean validCharWidth = true;
81 NJTree currentTree = null;
83 boolean scaleAboveWrapped = true;
85 boolean scaleLeftWrapped = true;
87 boolean scaleRightWrapped = true;
89 // The following vector holds the features which are
90 // currently visible, in the correct order or rendering
91 public Hashtable featuresDisplayed;
94 boolean showHiddenMarkers = true;
96 public jalview.bin.JalviewLite applet;
98 Hashtable sequenceColours;
102 Stack historyList = new Stack();
104 Stack redoList = new Stack();
106 public void finalize() {
113 public AlignViewport(AlignmentI al, JalviewLite applet)
115 calculator = new jalview.workers.AlignCalcManager();
116 this.applet = applet;
118 // we always pad gaps
119 this.setPadGaps(true);
121 this.endRes = al.getWidth() - 1;
123 this.endSeq = al.getHeight() - 1;
126 // get the width and height scaling factors if they were specified
127 String param = applet.getParameter("widthScale");
132 widthScale = new Float(param).floatValue();
133 } catch (Exception e)
136 if (widthScale <= 1.0)
139 .println("Invalid alignment character width scaling factor ("
140 + widthScale + "). Ignoring.");
146 .println("Alignment character width scaling factor is now "
150 param = applet.getParameter("heightScale");
155 heightScale = new Float(param).floatValue();
156 } catch (Exception e)
159 if (heightScale <= 1.0)
162 .println("Invalid alignment character height scaling factor ("
163 + heightScale + "). Ignoring.");
169 .println("Alignment character height scaling factor is now "
176 MAC = new jalview.util.Platform().isAMac();
180 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
182 showAnnotation = applet.getDefaultParameter("showAnnotation", showAnnotation);
184 showConservation = applet.getDefaultParameter("showConservation", showConservation);
186 showQuality = applet.getDefaultParameter("showQuality", showQuality);
188 showConsensus = applet.getDefaultParameter("showConsensus", showConsensus);
190 showUnconserved = applet.getDefaultParameter("showUnconserved", showUnconserved);
192 String param = applet.getParameter("upperCase");
195 if (param.equalsIgnoreCase("bold"))
197 upperCasebold = true;
200 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
202 followHighlight = applet.getDefaultParameter("automaticScrolling",followHighlight);
203 followSelection = followHighlight;
205 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo", showSequenceLogo);
207 normaliseSequenceLogo = applet.getDefaultParameter("normaliseSequenceLogo", normaliseSequenceLogo);
209 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus", showGroupConsensus);
211 showGroupConservation = applet.getDefaultParameter("showGroupConservation", showGroupConservation);
213 showConsensusHistogram = applet.getDefaultParameter("showConsensusHistogram", showConsensusHistogram);
219 String colour = applet.getParameter("defaultColour");
223 colour = applet.getParameter("userDefinedColour");
226 colour = "User Defined";
232 globalColourScheme = ColourSchemeProperty.getColour(alignment,
234 if (globalColourScheme != null)
236 globalColourScheme.setConsensus(hconsensus);
240 if (applet.getParameter("userDefinedColour") != null)
242 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
243 .getParameter("userDefinedColour"));
246 initAutoAnnotation();
250 public void showSequenceFeatures(boolean b)
252 showSequenceFeatures = b;
255 public boolean getShowSequenceFeatures()
257 return showSequenceFeatures;
262 * get the consensus sequence as displayed under the PID consensus annotation
265 * @return consensus sequence as a new sequence object
267 public SequenceI getConsensusSeq()
269 if (consensus == null)
271 updateConsensus(null);
273 if (consensus == null)
277 StringBuffer seqs = new StringBuffer();
278 for (int i = 0; i < consensus.annotations.length; i++)
280 if (consensus.annotations[i] != null)
282 if (consensus.annotations[i].description.charAt(0) == '[')
284 seqs.append(consensus.annotations[i].description.charAt(1));
288 seqs.append(consensus.annotations[i].displayCharacter);
292 SequenceI sq = new Sequence("Consensus", seqs.toString());
293 sq.setDescription("Percentage Identity Consensus "
294 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
298 public int getStartRes()
303 public int getEndRes()
308 public int getStartSeq()
313 public void setStartRes(int res)
318 public void setStartSeq(int seq)
323 public void setEndRes(int res)
325 if (res > alignment.getWidth() - 1)
327 // log.System.out.println(" Corrected res from " + res + " to maximum " +
328 // (alignment.getWidth()-1));
329 res = alignment.getWidth() - 1;
338 public void setEndSeq(int seq)
340 if (seq > alignment.getHeight())
342 seq = alignment.getHeight();
351 public int getEndSeq()
356 java.awt.Frame nullFrame;
358 protected FeatureSettings featureSettings = null;
360 private float heightScale = 1, widthScale = 1;
362 public void setFont(Font f)
365 if (nullFrame == null)
367 nullFrame = new java.awt.Frame();
368 nullFrame.addNotify();
371 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
372 setCharHeight((int) (heightScale * fm.getHeight()));
373 charWidth = (int) (widthScale * fm.charWidth('M'));
377 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
378 fm = nullFrame.getGraphics().getFontMetrics(f2);
379 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
383 public Font getFont()
388 public int getCharWidth()
393 public void setCharHeight(int h)
398 public int getCharHeight()
403 public void setWrappedWidth(int w)
405 this.wrappedWidth = w;
408 public int getwrappedWidth()
413 public AlignmentI getAlignment()
418 public void setAlignment(AlignmentI align)
420 this.alignment = align;
423 public void setWrapAlignment(boolean state)
425 wrapAlignment = state;
428 public void setShowText(boolean state)
433 public void setRenderGaps(boolean state)
438 public boolean getColourText()
440 return showColourText;
443 public void setColourText(boolean state)
445 showColourText = state;
448 public void setShowBoxes(boolean state)
453 public boolean getWrapAlignment()
455 return wrapAlignment;
458 public boolean getShowText()
463 public boolean getShowBoxes()
468 public char getGapCharacter()
470 return getAlignment().getGapCharacter();
473 public void setGapCharacter(char gap)
475 if (getAlignment() != null)
477 getAlignment().setGapCharacter(gap);
481 public void setThreshold(int thresh)
486 public int getThreshold()
491 public void setIncrement(int inc)
496 public int getIncrement()
501 public void resetSeqLimits(int height)
503 setEndSeq(height / getCharHeight());
506 public void setCurrentTree(NJTree tree)
511 public NJTree getCurrentTree()
516 public boolean getShowJVSuffix()
521 public void setShowJVSuffix(boolean b)
526 public boolean getShowAnnotation()
528 return showAnnotation;
531 public void setShowAnnotation(boolean b)
536 public boolean getScaleAboveWrapped()
538 return scaleAboveWrapped;
541 public boolean getScaleLeftWrapped()
543 return scaleLeftWrapped;
546 public boolean getScaleRightWrapped()
548 return scaleRightWrapped;
551 public void setScaleAboveWrapped(boolean b)
553 scaleAboveWrapped = b;
556 public void setScaleLeftWrapped(boolean b)
558 scaleLeftWrapped = b;
561 public void setScaleRightWrapped(boolean b)
563 scaleRightWrapped = b;
566 public void setIgnoreGapsConsensus(boolean b)
568 ignoreGapsInConsensusCalculation = b;
569 updateConsensus(null);
570 if (globalColourScheme != null)
572 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
573 ignoreGapsInConsensusCalculation);
582 public boolean getShowHiddenMarkers()
584 return showHiddenMarkers;
587 public void setShowHiddenMarkers(boolean show)
589 showHiddenMarkers = show;
592 public Color getSequenceColour(SequenceI seq)
594 if (sequenceColours == null || !sequenceColours.containsKey(seq))
600 return (Color) sequenceColours.get(seq);
604 public void setSequenceColour(SequenceI seq, Color col)
606 if (sequenceColours == null)
608 sequenceColours = new Hashtable();
613 sequenceColours.remove(seq);
617 sequenceColours.put(seq, col);
621 boolean centreColumnLabels;
623 public boolean getCentreColumnLabels()
625 return centreColumnLabels;
628 public void updateSequenceIdColours()
631 for (SequenceGroup sg:alignment.getGroups())
633 if (sg.idColour != null)
635 for (SequenceI s:sg.getSequences(getHiddenRepSequences()))
637 this.setSequenceColour(s, sg.idColour);
643 public boolean followHighlight = true;
645 public boolean getFollowHighlight()
647 return followHighlight;
650 public boolean followSelection = true;
653 * @return true if view selection should always follow the selections
654 * broadcast by other selection sources
656 public boolean getFollowSelection()
658 return followSelection;
660 public void sendSelection()
662 jalview.structure.StructureSelectionManager
663 .getStructureSelectionManager(applet).sendSelection(
664 new SequenceGroup(getSelectionGroup()),
665 new ColumnSelection(getColumnSelection()), this);
672 * synthesize a column selection if none exists so it covers the given
673 * selection group. if wholewidth is false, no column selection is made if the
674 * selection group covers the whole alignment width.
679 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
683 && (sgs = sg.getStartRes()) >= 0
684 && sg.getStartRes() <= (sge = sg.getEndRes())
685 && (colSel == null || colSel.getSelected() == null || colSel
686 .getSelected().size() == 0))
688 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
695 colSel = new ColumnSelection();
697 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
699 colSel.addElement(cspos);
705 public boolean hasHiddenColumns()
707 return hasHiddenColumns;
710 public boolean isNormaliseSequenceLogo()
712 return normaliseSequenceLogo;
715 public void setNormaliseSequenceLogo(boolean state)
717 normaliseSequenceLogo = state;
722 * @return true if alignment characters should be displayed
724 public boolean isValidCharWidth()
726 return validCharWidth;