2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.analysis.NJTree;
24 import jalview.api.AlignViewportI;
25 import jalview.bin.JalviewLite;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.ColumnSelection;
28 import jalview.datamodel.Sequence;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.datamodel.SequenceI;
31 import jalview.schemes.ColourSchemeProperty;
32 import jalview.schemes.UserColourScheme;
33 import jalview.structure.SelectionSource;
34 import jalview.structure.VamsasSource;
35 import jalview.viewmodel.AlignmentViewport;
38 import java.util.Stack;
40 public class AlignViewport extends AlignmentViewport implements
41 AlignViewportI, SelectionSource, VamsasSource
51 boolean cursorMode = false;
53 boolean showJVSuffix = true;
55 boolean showText = true;
57 boolean showColourText = false;
59 boolean showBoxes = true;
61 boolean wrapAlignment = false;
63 boolean renderGaps = true;
65 boolean showAnnotation = true;
67 boolean upperCasebold = false;
75 Font font = new Font("SansSerif", Font.PLAIN, 10);
77 boolean validCharWidth = true;
83 NJTree currentTree = null;
85 boolean scaleAboveWrapped = true;
87 boolean scaleLeftWrapped = true;
89 boolean scaleRightWrapped = true;
91 boolean showHiddenMarkers = true;
93 public jalview.bin.JalviewLite applet;
97 Stack historyList = new Stack();
99 Stack redoList = new Stack();
101 private AnnotationColumnChooser annotationColumnSelectionState;
103 public void finalize()
111 public AlignViewport(AlignmentI al, JalviewLite applet)
113 calculator = new jalview.workers.AlignCalcManager();
114 this.applet = applet;
116 // we always pad gaps
117 this.setPadGaps(true);
119 this.endRes = al.getWidth() - 1;
121 this.endSeq = al.getHeight() - 1;
124 // get the width and height scaling factors if they were specified
125 String param = applet.getParameter("widthScale");
130 widthScale = new Float(param).floatValue();
131 } catch (Exception e)
134 if (widthScale <= 1.0)
137 .println("Invalid alignment character width scaling factor ("
138 + widthScale + "). Ignoring.");
144 .println("Alignment character width scaling factor is now "
148 param = applet.getParameter("heightScale");
153 heightScale = new Float(param).floatValue();
154 } catch (Exception e)
157 if (heightScale <= 1.0)
160 .println("Invalid alignment character height scaling factor ("
161 + heightScale + "). Ignoring.");
167 .println("Alignment character height scaling factor is now "
174 MAC = new jalview.util.Platform().isAMac();
178 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
180 showAnnotation = applet.getDefaultParameter("showAnnotation",
183 showConservation = applet.getDefaultParameter("showConservation",
186 showQuality = applet.getDefaultParameter("showQuality", showQuality);
188 showConsensus = applet.getDefaultParameter("showConsensus",
191 showUnconserved = applet.getDefaultParameter("showUnconserved",
194 String param = applet.getParameter("upperCase");
197 if (param.equalsIgnoreCase("bold"))
199 upperCasebold = true;
202 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
204 followHighlight = applet.getDefaultParameter("automaticScrolling",
206 followSelection = followHighlight;
208 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
211 normaliseSequenceLogo = applet.getDefaultParameter(
212 "normaliseSequenceLogo", applet.getDefaultParameter(
213 "normaliseLogo", normaliseSequenceLogo));
215 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
218 showGroupConservation = applet.getDefaultParameter(
219 "showGroupConservation", showGroupConservation);
221 showConsensusHistogram = applet.getDefaultParameter(
222 "showConsensusHistogram", showConsensusHistogram);
228 String colour = applet.getParameter("defaultColour");
232 colour = applet.getParameter("userDefinedColour");
235 colour = "User Defined";
241 globalColourScheme = ColourSchemeProperty.getColour(alignment,
243 if (globalColourScheme != null)
245 globalColourScheme.setConsensus(hconsensus);
249 if (applet.getParameter("userDefinedColour") != null)
251 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
252 .getParameter("userDefinedColour"));
255 initAutoAnnotation();
260 * get the consensus sequence as displayed under the PID consensus annotation
263 * @return consensus sequence as a new sequence object
265 public SequenceI getConsensusSeq()
267 if (consensus == null)
269 updateConsensus(null);
271 if (consensus == null)
275 StringBuffer seqs = new StringBuffer();
276 for (int i = 0; i < consensus.annotations.length; i++)
278 if (consensus.annotations[i] != null)
280 if (consensus.annotations[i].description.charAt(0) == '[')
282 seqs.append(consensus.annotations[i].description.charAt(1));
286 seqs.append(consensus.annotations[i].displayCharacter);
290 SequenceI sq = new Sequence("Consensus", seqs.toString());
291 sq.setDescription("Percentage Identity Consensus "
292 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
296 public int getStartRes()
301 public int getEndRes()
306 public int getStartSeq()
311 public void setStartRes(int res)
316 public void setStartSeq(int seq)
321 public void setEndRes(int res)
323 if (res > alignment.getWidth() - 1)
325 // log.System.out.println(" Corrected res from " + res + " to maximum " +
326 // (alignment.getWidth()-1));
327 res = alignment.getWidth() - 1;
336 public void setEndSeq(int seq)
338 if (seq > alignment.getHeight())
340 seq = alignment.getHeight();
349 public int getEndSeq()
354 java.awt.Frame nullFrame;
356 protected FeatureSettings featureSettings = null;
358 private float heightScale = 1, widthScale = 1;
360 public void setFont(Font f)
363 if (nullFrame == null)
365 nullFrame = new java.awt.Frame();
366 nullFrame.addNotify();
369 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
370 setCharHeight((int) (heightScale * fm.getHeight()));
371 charWidth = (int) (widthScale * fm.charWidth('M'));
375 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
376 fm = nullFrame.getGraphics().getFontMetrics(f2);
377 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
381 public Font getFont()
386 public int getCharWidth()
391 public void setCharHeight(int h)
396 public int getCharHeight()
401 public void setWrappedWidth(int w)
403 this.wrappedWidth = w;
406 public int getwrappedWidth()
411 public AlignmentI getAlignment()
416 public void setAlignment(AlignmentI align)
418 this.alignment = align;
421 public void setWrapAlignment(boolean state)
423 wrapAlignment = state;
426 public void setShowText(boolean state)
431 public void setRenderGaps(boolean state)
436 public boolean getColourText()
438 return showColourText;
441 public void setColourText(boolean state)
443 showColourText = state;
446 public void setShowBoxes(boolean state)
451 public boolean getWrapAlignment()
453 return wrapAlignment;
456 public boolean getShowText()
461 public boolean getShowBoxes()
466 public char getGapCharacter()
468 return getAlignment().getGapCharacter();
471 public void setGapCharacter(char gap)
473 if (getAlignment() != null)
475 getAlignment().setGapCharacter(gap);
479 public void resetSeqLimits(int height)
481 setEndSeq(height / getCharHeight());
484 public void setCurrentTree(NJTree tree)
489 public NJTree getCurrentTree()
494 public boolean getShowJVSuffix()
499 public void setShowJVSuffix(boolean b)
504 public boolean getShowAnnotation()
506 return showAnnotation;
509 public void setShowAnnotation(boolean b)
514 public boolean getScaleAboveWrapped()
516 return scaleAboveWrapped;
519 public boolean getScaleLeftWrapped()
521 return scaleLeftWrapped;
524 public boolean getScaleRightWrapped()
526 return scaleRightWrapped;
529 public void setScaleAboveWrapped(boolean b)
531 scaleAboveWrapped = b;
534 public void setScaleLeftWrapped(boolean b)
536 scaleLeftWrapped = b;
539 public void setScaleRightWrapped(boolean b)
541 scaleRightWrapped = b;
544 public void setIgnoreGapsConsensus(boolean b)
546 ignoreGapsInConsensusCalculation = b;
547 updateConsensus(null);
548 if (globalColourScheme != null)
550 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
551 ignoreGapsInConsensusCalculation);
556 public boolean getShowHiddenMarkers()
558 return showHiddenMarkers;
561 public void setShowHiddenMarkers(boolean show)
563 showHiddenMarkers = show;
566 boolean centreColumnLabels;
568 public boolean getCentreColumnLabels()
570 return centreColumnLabels;
573 public boolean followHighlight = true;
575 public boolean getFollowHighlight()
577 return followHighlight;
580 public boolean followSelection = true;
583 * @return true if view selection should always follow the selections
584 * broadcast by other selection sources
586 public boolean getFollowSelection()
588 return followSelection;
591 public void sendSelection()
593 jalview.structure.StructureSelectionManager
594 .getStructureSelectionManager(applet).sendSelection(
595 new SequenceGroup(getSelectionGroup()),
596 new ColumnSelection(getColumnSelection()), this);
600 * synthesize a column selection if none exists so it covers the given
601 * selection group. if wholewidth is false, no column selection is made if the
602 * selection group covers the whole alignment width.
607 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
611 && (sgs = sg.getStartRes()) >= 0
612 && sg.getStartRes() <= (sge = sg.getEndRes())
613 && (colSel == null || colSel.getSelected() == null || colSel
614 .getSelected().size() == 0))
616 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
623 colSel = new ColumnSelection();
625 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
627 colSel.addElement(cspos);
632 public boolean isNormaliseSequenceLogo()
634 return normaliseSequenceLogo;
637 public void setNormaliseSequenceLogo(boolean state)
639 normaliseSequenceLogo = state;
644 * @return true if alignment characters should be displayed
646 public boolean isValidCharWidth()
648 return validCharWidth;
651 public AnnotationColumnChooser getAnnotationColumnSelectionState()
653 return annotationColumnSelectionState;
656 public void setAnnotationColumnSelectionState(
657 AnnotationColumnChooser annotationColumnSelectionState)
659 this.annotationColumnSelectionState = annotationColumnSelectionState;