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;
27 import jalview.analysis.*;
28 import jalview.api.AlignViewportI;
30 import jalview.datamodel.*;
31 import jalview.schemes.*;
32 import jalview.structure.SelectionSource;
33 import jalview.structure.VamsasSource;
34 import jalview.viewmodel.AlignmentViewport;
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;
99 Stack historyList = new Stack();
101 Stack redoList = new Stack();
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();
259 public void showSequenceFeatures(boolean b)
261 showSequenceFeatures = b;
264 public boolean getShowSequenceFeatures()
266 return showSequenceFeatures;
270 * get the consensus sequence as displayed under the PID consensus annotation
273 * @return consensus sequence as a new sequence object
275 public SequenceI getConsensusSeq()
277 if (consensus == null)
279 updateConsensus(null);
281 if (consensus == null)
285 StringBuffer seqs = new StringBuffer();
286 for (int i = 0; i < consensus.annotations.length; i++)
288 if (consensus.annotations[i] != null)
290 if (consensus.annotations[i].description.charAt(0) == '[')
292 seqs.append(consensus.annotations[i].description.charAt(1));
296 seqs.append(consensus.annotations[i].displayCharacter);
300 SequenceI sq = new Sequence("Consensus", seqs.toString());
301 sq.setDescription("Percentage Identity Consensus "
302 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
306 public int getStartRes()
311 public int getEndRes()
316 public int getStartSeq()
321 public void setStartRes(int res)
326 public void setStartSeq(int seq)
331 public void setEndRes(int res)
333 if (res > alignment.getWidth() - 1)
335 // log.System.out.println(" Corrected res from " + res + " to maximum " +
336 // (alignment.getWidth()-1));
337 res = alignment.getWidth() - 1;
346 public void setEndSeq(int seq)
348 if (seq > alignment.getHeight())
350 seq = alignment.getHeight();
359 public int getEndSeq()
364 java.awt.Frame nullFrame;
366 protected FeatureSettings featureSettings = null;
368 private float heightScale = 1, widthScale = 1;
370 public void setFont(Font f)
373 if (nullFrame == null)
375 nullFrame = new java.awt.Frame();
376 nullFrame.addNotify();
379 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
380 setCharHeight((int) (heightScale * fm.getHeight()));
381 charWidth = (int) (widthScale * fm.charWidth('M'));
385 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
386 fm = nullFrame.getGraphics().getFontMetrics(f2);
387 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
391 public Font getFont()
396 public int getCharWidth()
401 public void setCharHeight(int h)
406 public int getCharHeight()
411 public void setWrappedWidth(int w)
413 this.wrappedWidth = w;
416 public int getwrappedWidth()
421 public AlignmentI getAlignment()
426 public void setAlignment(AlignmentI align)
428 this.alignment = align;
431 public void setWrapAlignment(boolean state)
433 wrapAlignment = state;
436 public void setShowText(boolean state)
441 public void setRenderGaps(boolean state)
446 public boolean getColourText()
448 return showColourText;
451 public void setColourText(boolean state)
453 showColourText = state;
456 public void setShowBoxes(boolean state)
461 public boolean getWrapAlignment()
463 return wrapAlignment;
466 public boolean getShowText()
471 public boolean getShowBoxes()
476 public char getGapCharacter()
478 return getAlignment().getGapCharacter();
481 public void setGapCharacter(char gap)
483 if (getAlignment() != null)
485 getAlignment().setGapCharacter(gap);
489 public void resetSeqLimits(int height)
491 setEndSeq(height / getCharHeight());
494 public void setCurrentTree(NJTree tree)
499 public NJTree getCurrentTree()
504 public boolean getShowJVSuffix()
509 public void setShowJVSuffix(boolean b)
514 public boolean getShowAnnotation()
516 return showAnnotation;
519 public void setShowAnnotation(boolean b)
524 public boolean getScaleAboveWrapped()
526 return scaleAboveWrapped;
529 public boolean getScaleLeftWrapped()
531 return scaleLeftWrapped;
534 public boolean getScaleRightWrapped()
536 return scaleRightWrapped;
539 public void setScaleAboveWrapped(boolean b)
541 scaleAboveWrapped = b;
544 public void setScaleLeftWrapped(boolean b)
546 scaleLeftWrapped = b;
549 public void setScaleRightWrapped(boolean b)
551 scaleRightWrapped = b;
554 public void setIgnoreGapsConsensus(boolean b)
556 ignoreGapsInConsensusCalculation = b;
557 updateConsensus(null);
558 if (globalColourScheme != null)
560 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
561 ignoreGapsInConsensusCalculation);
566 public boolean getShowHiddenMarkers()
568 return showHiddenMarkers;
571 public void setShowHiddenMarkers(boolean show)
573 showHiddenMarkers = show;
576 boolean centreColumnLabels;
578 public boolean getCentreColumnLabels()
580 return centreColumnLabels;
583 public boolean followHighlight = true;
585 public boolean getFollowHighlight()
587 return followHighlight;
590 public boolean followSelection = true;
593 * @return true if view selection should always follow the selections
594 * broadcast by other selection sources
596 public boolean getFollowSelection()
598 return followSelection;
601 public void sendSelection()
603 jalview.structure.StructureSelectionManager
604 .getStructureSelectionManager(applet).sendSelection(
605 new SequenceGroup(getSelectionGroup()),
606 new ColumnSelection(getColumnSelection()), this);
610 * synthesize a column selection if none exists so it covers the given
611 * selection group. if wholewidth is false, no column selection is made if the
612 * selection group covers the whole alignment width.
617 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
621 && (sgs = sg.getStartRes()) >= 0
622 && sg.getStartRes() <= (sge = sg.getEndRes())
623 && (colSel == null || colSel.getSelected() == null || colSel
624 .getSelected().size() == 0))
626 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
633 colSel = new ColumnSelection();
635 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
637 colSel.addElement(cspos);
643 public boolean hasHiddenColumns()
645 return hasHiddenColumns;
648 public boolean isNormaliseSequenceLogo()
650 return normaliseSequenceLogo;
653 public void setNormaliseSequenceLogo(boolean state)
655 normaliseSequenceLogo = state;
660 * @return true if alignment characters should be displayed
662 public boolean isValidCharWidth()
664 return validCharWidth;