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
37 AlignViewportI, SelectionSource, VamsasSource
47 boolean cursorMode = false;
49 boolean showJVSuffix = true;
51 boolean showText = true;
53 boolean showColourText = false;
55 boolean showBoxes = true;
57 boolean wrapAlignment = false;
59 boolean renderGaps = true;
61 boolean showSequenceFeatures = false;
63 boolean showAnnotation = true;
65 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;
93 boolean showHiddenMarkers = true;
95 public jalview.bin.JalviewLite applet;
97 Hashtable sequenceColours;
101 Stack historyList = new Stack();
103 Stack redoList = new Stack();
105 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",
185 showConservation = applet.getDefaultParameter("showConservation",
188 showQuality = applet.getDefaultParameter("showQuality", showQuality);
190 showConsensus = applet.getDefaultParameter("showConsensus",
193 showUnconserved = applet.getDefaultParameter("showUnconserved",
196 String param = applet.getParameter("upperCase");
199 if (param.equalsIgnoreCase("bold"))
201 upperCasebold = true;
204 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
206 followHighlight = applet.getDefaultParameter("automaticScrolling",
208 followSelection = followHighlight;
210 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
213 normaliseSequenceLogo = applet.getDefaultParameter(
214 "normaliseSequenceLogo", applet.getDefaultParameter(
215 "normaliseLogo", normaliseSequenceLogo));
217 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
220 showGroupConservation = applet.getDefaultParameter(
221 "showGroupConservation", showGroupConservation);
223 showConsensusHistogram = applet.getDefaultParameter(
224 "showConsensusHistogram", showConsensusHistogram);
230 String colour = applet.getParameter("defaultColour");
234 colour = applet.getParameter("userDefinedColour");
237 colour = "User Defined";
243 globalColourScheme = ColourSchemeProperty.getColour(alignment,
245 if (globalColourScheme != null)
247 globalColourScheme.setConsensus(hconsensus);
251 if (applet.getParameter("userDefinedColour") != null)
253 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
254 .getParameter("userDefinedColour"));
257 initAutoAnnotation();
261 public void showSequenceFeatures(boolean b)
263 showSequenceFeatures = b;
266 public boolean getShowSequenceFeatures()
268 return showSequenceFeatures;
272 * get the consensus sequence as displayed under the PID consensus annotation
275 * @return consensus sequence as a new sequence object
277 public SequenceI getConsensusSeq()
279 if (consensus == null)
281 updateConsensus(null);
283 if (consensus == null)
287 StringBuffer seqs = new StringBuffer();
288 for (int i = 0; i < consensus.annotations.length; i++)
290 if (consensus.annotations[i] != null)
292 if (consensus.annotations[i].description.charAt(0) == '[')
294 seqs.append(consensus.annotations[i].description.charAt(1));
298 seqs.append(consensus.annotations[i].displayCharacter);
302 SequenceI sq = new Sequence("Consensus", seqs.toString());
303 sq.setDescription("Percentage Identity Consensus "
304 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
308 public int getStartRes()
313 public int getEndRes()
318 public int getStartSeq()
323 public void setStartRes(int res)
328 public void setStartSeq(int seq)
333 public void setEndRes(int res)
335 if (res > alignment.getWidth() - 1)
337 // log.System.out.println(" Corrected res from " + res + " to maximum " +
338 // (alignment.getWidth()-1));
339 res = alignment.getWidth() - 1;
348 public void setEndSeq(int seq)
350 if (seq > alignment.getHeight())
352 seq = alignment.getHeight();
361 public int getEndSeq()
366 java.awt.Frame nullFrame;
368 protected FeatureSettings featureSettings = null;
370 private float heightScale = 1, widthScale = 1;
372 public void setFont(Font f)
375 if (nullFrame == null)
377 nullFrame = new java.awt.Frame();
378 nullFrame.addNotify();
381 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
382 setCharHeight((int) (heightScale * fm.getHeight()));
383 charWidth = (int) (widthScale * fm.charWidth('M'));
387 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
388 fm = nullFrame.getGraphics().getFontMetrics(f2);
389 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
393 public Font getFont()
398 public int getCharWidth()
403 public void setCharHeight(int h)
408 public int getCharHeight()
413 public void setWrappedWidth(int w)
415 this.wrappedWidth = w;
418 public int getwrappedWidth()
423 public AlignmentI getAlignment()
428 public void setAlignment(AlignmentI align)
430 this.alignment = align;
433 public void setWrapAlignment(boolean state)
435 wrapAlignment = state;
438 public void setShowText(boolean state)
443 public void setRenderGaps(boolean state)
448 public boolean getColourText()
450 return showColourText;
453 public void setColourText(boolean state)
455 showColourText = state;
458 public void setShowBoxes(boolean state)
463 public boolean getWrapAlignment()
465 return wrapAlignment;
468 public boolean getShowText()
473 public boolean getShowBoxes()
478 public char getGapCharacter()
480 return getAlignment().getGapCharacter();
483 public void setGapCharacter(char gap)
485 if (getAlignment() != null)
487 getAlignment().setGapCharacter(gap);
491 public void setThreshold(int thresh)
496 public int getThreshold()
501 public void setIncrement(int inc)
506 public int getIncrement()
511 public void resetSeqLimits(int height)
513 setEndSeq(height / getCharHeight());
516 public void setCurrentTree(NJTree tree)
521 public NJTree getCurrentTree()
526 public boolean getShowJVSuffix()
531 public void setShowJVSuffix(boolean b)
536 public boolean getShowAnnotation()
538 return showAnnotation;
541 public void setShowAnnotation(boolean b)
546 public boolean getScaleAboveWrapped()
548 return scaleAboveWrapped;
551 public boolean getScaleLeftWrapped()
553 return scaleLeftWrapped;
556 public boolean getScaleRightWrapped()
558 return scaleRightWrapped;
561 public void setScaleAboveWrapped(boolean b)
563 scaleAboveWrapped = b;
566 public void setScaleLeftWrapped(boolean b)
568 scaleLeftWrapped = b;
571 public void setScaleRightWrapped(boolean b)
573 scaleRightWrapped = b;
576 public void setIgnoreGapsConsensus(boolean b)
578 ignoreGapsInConsensusCalculation = b;
579 updateConsensus(null);
580 if (globalColourScheme != null)
582 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
583 ignoreGapsInConsensusCalculation);
588 public boolean getShowHiddenMarkers()
590 return showHiddenMarkers;
593 public void setShowHiddenMarkers(boolean show)
595 showHiddenMarkers = show;
598 public Color getSequenceColour(SequenceI seq)
600 if (sequenceColours == null || !sequenceColours.containsKey(seq))
606 return (Color) sequenceColours.get(seq);
610 public void setSequenceColour(SequenceI seq, Color col)
612 if (sequenceColours == null)
614 sequenceColours = new Hashtable();
619 sequenceColours.remove(seq);
623 sequenceColours.put(seq, col);
627 boolean centreColumnLabels;
629 public boolean getCentreColumnLabels()
631 return centreColumnLabels;
634 public void updateSequenceIdColours()
637 for (SequenceGroup sg : alignment.getGroups())
639 if (sg.idColour != null)
641 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
643 this.setSequenceColour(s, sg.idColour);
649 public boolean followHighlight = true;
651 public boolean getFollowHighlight()
653 return followHighlight;
656 public boolean followSelection = true;
659 * @return true if view selection should always follow the selections
660 * broadcast by other selection sources
662 public boolean getFollowSelection()
664 return followSelection;
667 public void sendSelection()
669 jalview.structure.StructureSelectionManager
670 .getStructureSelectionManager(applet).sendSelection(
671 new SequenceGroup(getSelectionGroup()),
672 new ColumnSelection(getColumnSelection()), this);
676 * synthesize a column selection if none exists so it covers the given
677 * selection group. if wholewidth is false, no column selection is made if the
678 * selection group covers the whole alignment width.
683 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
687 && (sgs = sg.getStartRes()) >= 0
688 && sg.getStartRes() <= (sge = sg.getEndRes())
689 && (colSel == null || colSel.getSelected() == null || colSel
690 .getSelected().size() == 0))
692 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
699 colSel = new ColumnSelection();
701 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
703 colSel.addElement(cspos);
709 public boolean hasHiddenColumns()
711 return hasHiddenColumns;
714 public boolean isNormaliseSequenceLogo()
716 return normaliseSequenceLogo;
719 public void setNormaliseSequenceLogo(boolean state)
721 normaliseSequenceLogo = state;
726 * @return true if alignment characters should be displayed
728 public boolean isValidCharWidth()
730 return validCharWidth;