2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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.AlignViewportI;
27 import jalview.datamodel.*;
28 import jalview.schemes.*;
29 import jalview.structure.SelectionSource;
30 import jalview.structure.VamsasSource;
31 import jalview.viewmodel.AlignmentViewport;
33 public class AlignViewport extends AlignmentViewport implements
34 AlignViewportI, SelectionSource, VamsasSource
44 boolean cursorMode = false;
46 boolean showJVSuffix = true;
48 boolean showText = true;
50 boolean showColourText = false;
52 boolean showBoxes = true;
54 boolean wrapAlignment = false;
56 boolean renderGaps = true;
58 boolean showSequenceFeatures = false;
60 boolean showAnnotation = true;
62 boolean upperCasebold = false;
70 Font font = new Font("SansSerif", Font.PLAIN, 10);
72 boolean validCharWidth = true;
78 NJTree currentTree = null;
80 boolean scaleAboveWrapped = true;
82 boolean scaleLeftWrapped = true;
84 boolean scaleRightWrapped = true;
86 // The following vector holds the features which are
87 // currently visible, in the correct order or rendering
88 public Hashtable featuresDisplayed;
90 boolean showHiddenMarkers = true;
92 public jalview.bin.JalviewLite applet;
96 Stack historyList = new Stack();
98 Stack redoList = new Stack();
100 public void finalize()
108 public AlignViewport(AlignmentI al, JalviewLite applet)
110 calculator = new jalview.workers.AlignCalcManager();
111 this.applet = applet;
113 // we always pad gaps
114 this.setPadGaps(true);
116 this.endRes = al.getWidth() - 1;
118 this.endSeq = al.getHeight() - 1;
121 // get the width and height scaling factors if they were specified
122 String param = applet.getParameter("widthScale");
127 widthScale = new Float(param).floatValue();
128 } catch (Exception e)
131 if (widthScale <= 1.0)
134 .println("Invalid alignment character width scaling factor ("
135 + widthScale + "). Ignoring.");
141 .println("Alignment character width scaling factor is now "
145 param = applet.getParameter("heightScale");
150 heightScale = new Float(param).floatValue();
151 } catch (Exception e)
154 if (heightScale <= 1.0)
157 .println("Invalid alignment character height scaling factor ("
158 + heightScale + "). Ignoring.");
164 .println("Alignment character height scaling factor is now "
171 MAC = new jalview.util.Platform().isAMac();
175 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
177 showAnnotation = applet.getDefaultParameter("showAnnotation",
180 showConservation = applet.getDefaultParameter("showConservation",
183 showQuality = applet.getDefaultParameter("showQuality", showQuality);
185 showConsensus = applet.getDefaultParameter("showConsensus",
188 showUnconserved = applet.getDefaultParameter("showUnconserved",
191 String param = applet.getParameter("upperCase");
194 if (param.equalsIgnoreCase("bold"))
196 upperCasebold = true;
199 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
201 followHighlight = applet.getDefaultParameter("automaticScrolling",
203 followSelection = followHighlight;
205 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
208 normaliseSequenceLogo = applet.getDefaultParameter(
209 "normaliseSequenceLogo", applet.getDefaultParameter(
210 "normaliseLogo", normaliseSequenceLogo));
212 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
215 showGroupConservation = applet.getDefaultParameter(
216 "showGroupConservation", showGroupConservation);
218 showConsensusHistogram = applet.getDefaultParameter(
219 "showConsensusHistogram", showConsensusHistogram);
225 String colour = applet.getParameter("defaultColour");
229 colour = applet.getParameter("userDefinedColour");
232 colour = "User Defined";
238 globalColourScheme = ColourSchemeProperty.getColour(alignment,
240 if (globalColourScheme != null)
242 globalColourScheme.setConsensus(hconsensus);
246 if (applet.getParameter("userDefinedColour") != null)
248 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
249 .getParameter("userDefinedColour"));
252 initAutoAnnotation();
256 public void showSequenceFeatures(boolean b)
258 showSequenceFeatures = b;
261 public boolean getShowSequenceFeatures()
263 return showSequenceFeatures;
267 * get the consensus sequence as displayed under the PID consensus annotation
270 * @return consensus sequence as a new sequence object
272 public SequenceI getConsensusSeq()
274 if (consensus == null)
276 updateConsensus(null);
278 if (consensus == null)
282 StringBuffer seqs = new StringBuffer();
283 for (int i = 0; i < consensus.annotations.length; i++)
285 if (consensus.annotations[i] != null)
287 if (consensus.annotations[i].description.charAt(0) == '[')
289 seqs.append(consensus.annotations[i].description.charAt(1));
293 seqs.append(consensus.annotations[i].displayCharacter);
297 SequenceI sq = new Sequence("Consensus", seqs.toString());
298 sq.setDescription("Percentage Identity Consensus "
299 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
303 public int getStartRes()
308 public int getEndRes()
313 public int getStartSeq()
318 public void setStartRes(int res)
323 public void setStartSeq(int seq)
328 public void setEndRes(int res)
330 if (res > alignment.getWidth() - 1)
332 // log.System.out.println(" Corrected res from " + res + " to maximum " +
333 // (alignment.getWidth()-1));
334 res = alignment.getWidth() - 1;
343 public void setEndSeq(int seq)
345 if (seq > alignment.getHeight())
347 seq = alignment.getHeight();
356 public int getEndSeq()
361 java.awt.Frame nullFrame;
363 protected FeatureSettings featureSettings = null;
365 private float heightScale = 1, widthScale = 1;
367 public void setFont(Font f)
370 if (nullFrame == null)
372 nullFrame = new java.awt.Frame();
373 nullFrame.addNotify();
376 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
377 setCharHeight((int) (heightScale * fm.getHeight()));
378 charWidth = (int) (widthScale * fm.charWidth('M'));
382 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
383 fm = nullFrame.getGraphics().getFontMetrics(f2);
384 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
388 public Font getFont()
393 public int getCharWidth()
398 public void setCharHeight(int h)
403 public int getCharHeight()
408 public void setWrappedWidth(int w)
410 this.wrappedWidth = w;
413 public int getwrappedWidth()
418 public AlignmentI getAlignment()
423 public void setAlignment(AlignmentI align)
425 this.alignment = align;
428 public void setWrapAlignment(boolean state)
430 wrapAlignment = state;
433 public void setShowText(boolean state)
438 public void setRenderGaps(boolean state)
443 public boolean getColourText()
445 return showColourText;
448 public void setColourText(boolean state)
450 showColourText = state;
453 public void setShowBoxes(boolean state)
458 public boolean getWrapAlignment()
460 return wrapAlignment;
463 public boolean getShowText()
468 public boolean getShowBoxes()
473 public char getGapCharacter()
475 return getAlignment().getGapCharacter();
478 public void setGapCharacter(char gap)
480 if (getAlignment() != null)
482 getAlignment().setGapCharacter(gap);
486 public void setThreshold(int thresh)
491 public int getThreshold()
496 public void setIncrement(int inc)
501 public int getIncrement()
506 public void resetSeqLimits(int height)
508 setEndSeq(height / getCharHeight());
511 public void setCurrentTree(NJTree tree)
516 public NJTree getCurrentTree()
521 public boolean getShowJVSuffix()
526 public void setShowJVSuffix(boolean b)
531 public boolean getShowAnnotation()
533 return showAnnotation;
536 public void setShowAnnotation(boolean b)
541 public boolean getScaleAboveWrapped()
543 return scaleAboveWrapped;
546 public boolean getScaleLeftWrapped()
548 return scaleLeftWrapped;
551 public boolean getScaleRightWrapped()
553 return scaleRightWrapped;
556 public void setScaleAboveWrapped(boolean b)
558 scaleAboveWrapped = b;
561 public void setScaleLeftWrapped(boolean b)
563 scaleLeftWrapped = b;
566 public void setScaleRightWrapped(boolean b)
568 scaleRightWrapped = b;
571 public void setIgnoreGapsConsensus(boolean b)
573 ignoreGapsInConsensusCalculation = b;
574 updateConsensus(null);
575 if (globalColourScheme != null)
577 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
578 ignoreGapsInConsensusCalculation);
583 public boolean getShowHiddenMarkers()
585 return showHiddenMarkers;
588 public void setShowHiddenMarkers(boolean show)
590 showHiddenMarkers = show;
593 boolean centreColumnLabels;
595 public boolean getCentreColumnLabels()
597 return centreColumnLabels;
600 public boolean followHighlight = true;
602 public boolean getFollowHighlight()
604 return followHighlight;
607 public boolean followSelection = true;
610 * @return true if view selection should always follow the selections
611 * broadcast by other selection sources
613 public boolean getFollowSelection()
615 return followSelection;
618 public void sendSelection()
620 jalview.structure.StructureSelectionManager
621 .getStructureSelectionManager(applet).sendSelection(
622 new SequenceGroup(getSelectionGroup()),
623 new ColumnSelection(getColumnSelection()), this);
627 * synthesize a column selection if none exists so it covers the given
628 * selection group. if wholewidth is false, no column selection is made if the
629 * selection group covers the whole alignment width.
634 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
638 && (sgs = sg.getStartRes()) >= 0
639 && sg.getStartRes() <= (sge = sg.getEndRes())
640 && (colSel == null || colSel.getSelected() == null || colSel
641 .getSelected().size() == 0))
643 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
650 colSel = new ColumnSelection();
652 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
654 colSel.addElement(cspos);
660 public boolean hasHiddenColumns()
662 return hasHiddenColumns;
665 public boolean isNormaliseSequenceLogo()
667 return normaliseSequenceLogo;
670 public void setNormaliseSequenceLogo(boolean state)
672 normaliseSequenceLogo = state;
677 * @return true if alignment characters should be displayed
679 public boolean isValidCharWidth()
681 return validCharWidth;