2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.appletgui;
25 import jalview.analysis.*;
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;
34 public class AlignViewport extends AlignmentViewport implements
35 AlignViewportI, SelectionSource, VamsasSource
45 boolean cursorMode = false;
47 boolean showJVSuffix = true;
49 boolean showText = true;
51 boolean showColourText = false;
53 boolean showBoxes = true;
55 boolean wrapAlignment = false;
57 boolean renderGaps = true;
59 boolean showSequenceFeatures = false;
61 boolean showAnnotation = true;
63 boolean upperCasebold = false;
71 Font font = new Font("SansSerif", Font.PLAIN, 10);
73 boolean validCharWidth = true;
79 NJTree currentTree = null;
81 boolean scaleAboveWrapped = true;
83 boolean scaleLeftWrapped = true;
85 boolean scaleRightWrapped = true;
87 // The following vector holds the features which are
88 // currently visible, in the correct order or rendering
89 public Hashtable featuresDisplayed;
91 boolean showHiddenMarkers = true;
93 public jalview.bin.JalviewLite applet;
97 Stack historyList = new Stack();
99 Stack redoList = new Stack();
101 public void finalize()
109 public AlignViewport(AlignmentI al, JalviewLite applet)
111 calculator = new jalview.workers.AlignCalcManager();
112 this.applet = applet;
114 // we always pad gaps
115 this.setPadGaps(true);
117 this.endRes = al.getWidth() - 1;
119 this.endSeq = al.getHeight() - 1;
122 // get the width and height scaling factors if they were specified
123 String param = applet.getParameter("widthScale");
128 widthScale = new Float(param).floatValue();
129 } catch (Exception e)
132 if (widthScale <= 1.0)
135 .println("Invalid alignment character width scaling factor ("
136 + widthScale + "). Ignoring.");
142 .println("Alignment character width scaling factor is now "
146 param = applet.getParameter("heightScale");
151 heightScale = new Float(param).floatValue();
152 } catch (Exception e)
155 if (heightScale <= 1.0)
158 .println("Invalid alignment character height scaling factor ("
159 + heightScale + "). Ignoring.");
165 .println("Alignment character height scaling factor is now "
172 MAC = new jalview.util.Platform().isAMac();
176 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
178 showAnnotation = applet.getDefaultParameter("showAnnotation",
181 showConservation = applet.getDefaultParameter("showConservation",
184 showQuality = applet.getDefaultParameter("showQuality", showQuality);
186 showConsensus = applet.getDefaultParameter("showConsensus",
189 showUnconserved = applet.getDefaultParameter("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",
204 followSelection = followHighlight;
206 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
209 normaliseSequenceLogo = applet.getDefaultParameter(
210 "normaliseSequenceLogo", applet.getDefaultParameter(
211 "normaliseLogo", normaliseSequenceLogo));
213 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
216 showGroupConservation = applet.getDefaultParameter(
217 "showGroupConservation", showGroupConservation);
219 showConsensusHistogram = applet.getDefaultParameter(
220 "showConsensusHistogram", showConsensusHistogram);
226 String colour = applet.getParameter("defaultColour");
230 colour = applet.getParameter("userDefinedColour");
233 colour = "User Defined";
239 globalColourScheme = ColourSchemeProperty.getColour(alignment,
241 if (globalColourScheme != null)
243 globalColourScheme.setConsensus(hconsensus);
247 if (applet.getParameter("userDefinedColour") != null)
249 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
250 .getParameter("userDefinedColour"));
253 initAutoAnnotation();
257 public void showSequenceFeatures(boolean b)
259 showSequenceFeatures = b;
262 public boolean getShowSequenceFeatures()
264 return showSequenceFeatures;
268 * get the consensus sequence as displayed under the PID consensus annotation
271 * @return consensus sequence as a new sequence object
273 public SequenceI getConsensusSeq()
275 if (consensus == null)
277 updateConsensus(null);
279 if (consensus == null)
283 StringBuffer seqs = new StringBuffer();
284 for (int i = 0; i < consensus.annotations.length; i++)
286 if (consensus.annotations[i] != null)
288 if (consensus.annotations[i].description.charAt(0) == '[')
290 seqs.append(consensus.annotations[i].description.charAt(1));
294 seqs.append(consensus.annotations[i].displayCharacter);
298 SequenceI sq = new Sequence("Consensus", seqs.toString());
299 sq.setDescription("Percentage Identity Consensus "
300 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
304 public int getStartRes()
309 public int getEndRes()
314 public int getStartSeq()
319 public void setStartRes(int res)
324 public void setStartSeq(int seq)
329 public void setEndRes(int res)
331 if (res > alignment.getWidth() - 1)
333 // log.System.out.println(" Corrected res from " + res + " to maximum " +
334 // (alignment.getWidth()-1));
335 res = alignment.getWidth() - 1;
344 public void setEndSeq(int seq)
346 if (seq > alignment.getHeight())
348 seq = alignment.getHeight();
357 public int getEndSeq()
362 java.awt.Frame nullFrame;
364 protected FeatureSettings featureSettings = null;
366 private float heightScale = 1, widthScale = 1;
368 public void setFont(Font f)
371 if (nullFrame == null)
373 nullFrame = new java.awt.Frame();
374 nullFrame.addNotify();
377 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
378 setCharHeight((int) (heightScale * fm.getHeight()));
379 charWidth = (int) (widthScale * fm.charWidth('M'));
383 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
384 fm = nullFrame.getGraphics().getFontMetrics(f2);
385 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
389 public Font getFont()
394 public int getCharWidth()
399 public void setCharHeight(int h)
404 public int getCharHeight()
409 public void setWrappedWidth(int w)
411 this.wrappedWidth = w;
414 public int getwrappedWidth()
419 public AlignmentI getAlignment()
424 public void setAlignment(AlignmentI align)
426 this.alignment = align;
429 public void setWrapAlignment(boolean state)
431 wrapAlignment = state;
434 public void setShowText(boolean state)
439 public void setRenderGaps(boolean state)
444 public boolean getColourText()
446 return showColourText;
449 public void setColourText(boolean state)
451 showColourText = state;
454 public void setShowBoxes(boolean state)
459 public boolean getWrapAlignment()
461 return wrapAlignment;
464 public boolean getShowText()
469 public boolean getShowBoxes()
474 public char getGapCharacter()
476 return getAlignment().getGapCharacter();
479 public void setGapCharacter(char gap)
481 if (getAlignment() != null)
483 getAlignment().setGapCharacter(gap);
487 public void resetSeqLimits(int height)
489 setEndSeq(height / getCharHeight());
492 public void setCurrentTree(NJTree tree)
497 public NJTree getCurrentTree()
502 public boolean getShowJVSuffix()
507 public void setShowJVSuffix(boolean b)
512 public boolean getShowAnnotation()
514 return showAnnotation;
517 public void setShowAnnotation(boolean b)
522 public boolean getScaleAboveWrapped()
524 return scaleAboveWrapped;
527 public boolean getScaleLeftWrapped()
529 return scaleLeftWrapped;
532 public boolean getScaleRightWrapped()
534 return scaleRightWrapped;
537 public void setScaleAboveWrapped(boolean b)
539 scaleAboveWrapped = b;
542 public void setScaleLeftWrapped(boolean b)
544 scaleLeftWrapped = b;
547 public void setScaleRightWrapped(boolean b)
549 scaleRightWrapped = b;
552 public void setIgnoreGapsConsensus(boolean b)
554 ignoreGapsInConsensusCalculation = b;
555 updateConsensus(null);
556 if (globalColourScheme != null)
558 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
559 ignoreGapsInConsensusCalculation);
564 public boolean getShowHiddenMarkers()
566 return showHiddenMarkers;
569 public void setShowHiddenMarkers(boolean show)
571 showHiddenMarkers = show;
574 boolean centreColumnLabels;
576 public boolean getCentreColumnLabels()
578 return centreColumnLabels;
581 public boolean followHighlight = true;
583 public boolean getFollowHighlight()
585 return followHighlight;
588 public boolean followSelection = true;
591 * @return true if view selection should always follow the selections
592 * broadcast by other selection sources
594 public boolean getFollowSelection()
596 return followSelection;
599 public void sendSelection()
601 jalview.structure.StructureSelectionManager
602 .getStructureSelectionManager(applet).sendSelection(
603 new SequenceGroup(getSelectionGroup()),
604 new ColumnSelection(getColumnSelection()), this);
608 * synthesize a column selection if none exists so it covers the given
609 * selection group. if wholewidth is false, no column selection is made if the
610 * selection group covers the whole alignment width.
615 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
619 && (sgs = sg.getStartRes()) >= 0
620 && sg.getStartRes() <= (sge = sg.getEndRes())
621 && (colSel == null || colSel.getSelected() == null || colSel
622 .getSelected().size() == 0))
624 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
631 colSel = new ColumnSelection();
633 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
635 colSel.addElement(cspos);
641 public boolean hasHiddenColumns()
643 return hasHiddenColumns;
646 public boolean isNormaliseSequenceLogo()
648 return normaliseSequenceLogo;
651 public void setNormaliseSequenceLogo(boolean state)
653 normaliseSequenceLogo = state;
658 * @return true if alignment characters should be displayed
660 public boolean isValidCharWidth()
662 return validCharWidth;