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 Font font = new Font("SansSerif", Font.PLAIN, 10);
55 boolean validCharWidth = true;
57 NJTree currentTree = null;
59 public jalview.bin.JalviewLite applet;
63 Stack historyList = new Stack();
65 Stack redoList = new Stack();
67 private AnnotationColumnChooser annotationColumnSelectionState;
69 public void finalize()
77 public AlignViewport(AlignmentI al, JalviewLite applet)
80 calculator = new jalview.workers.AlignCalcManager();
84 this.setPadGaps(true);
86 this.endRes = al.getWidth() - 1;
88 this.endSeq = al.getHeight() - 1;
91 // get the width and height scaling factors if they were specified
92 String param = applet.getParameter("widthScale");
97 widthScale = new Float(param).floatValue();
101 if (widthScale <= 1.0)
104 .println("Invalid alignment character width scaling factor ("
105 + widthScale + "). Ignoring.");
111 .println("Alignment character width scaling factor is now "
115 param = applet.getParameter("heightScale");
120 heightScale = new Float(param).floatValue();
121 } catch (Exception e)
124 if (heightScale <= 1.0)
127 .println("Invalid alignment character height scaling factor ("
128 + heightScale + "). Ignoring.");
134 .println("Alignment character height scaling factor is now "
141 MAC = new jalview.util.Platform().isAMac();
145 setShowJVSuffix(applet.getDefaultParameter("showFullId",
148 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
149 isShowAnnotation()));
151 showConservation = applet.getDefaultParameter("showConservation",
154 showQuality = applet.getDefaultParameter("showQuality", showQuality);
156 showConsensus = applet.getDefaultParameter("showConsensus",
159 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
160 getShowUnconserved()));
162 String param = applet.getParameter("upperCase");
165 if (param.equalsIgnoreCase("bold"))
167 setUpperCasebold(true);
170 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
172 followHighlight = applet.getDefaultParameter("automaticScrolling",
174 followSelection = followHighlight;
176 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
179 normaliseSequenceLogo = applet.getDefaultParameter(
180 "normaliseSequenceLogo", applet.getDefaultParameter(
181 "normaliseLogo", normaliseSequenceLogo));
183 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
186 showGroupConservation = applet.getDefaultParameter(
187 "showGroupConservation", showGroupConservation);
189 showConsensusHistogram = applet.getDefaultParameter(
190 "showConsensusHistogram", showConsensusHistogram);
196 String colour = applet.getParameter("defaultColour");
200 colour = applet.getParameter("userDefinedColour");
203 colour = "User Defined";
209 globalColourScheme = ColourSchemeProperty.getColour(alignment,
211 if (globalColourScheme != null)
213 globalColourScheme.setConsensus(hconsensus);
217 if (applet.getParameter("userDefinedColour") != null)
219 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
220 .getParameter("userDefinedColour"));
223 initAutoAnnotation();
228 * get the consensus sequence as displayed under the PID consensus annotation
231 * @return consensus sequence as a new sequence object
233 public SequenceI getConsensusSeq()
235 if (consensus == null)
237 updateConsensus(null);
239 if (consensus == null)
243 StringBuffer seqs = new StringBuffer();
244 for (int i = 0; i < consensus.annotations.length; i++)
246 if (consensus.annotations[i] != null)
248 if (consensus.annotations[i].description.charAt(0) == '[')
250 seqs.append(consensus.annotations[i].description.charAt(1));
254 seqs.append(consensus.annotations[i].displayCharacter);
258 SequenceI sq = new Sequence("Consensus", seqs.toString());
259 sq.setDescription("Percentage Identity Consensus "
260 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
264 public int getStartRes()
269 public int getEndRes()
274 public int getStartSeq()
279 public void setStartRes(int res)
284 public void setStartSeq(int seq)
289 public void setEndRes(int res)
291 if (res > alignment.getWidth() - 1)
293 // log.System.out.println(" Corrected res from " + res + " to maximum " +
294 // (alignment.getWidth()-1));
295 res = alignment.getWidth() - 1;
304 public void setEndSeq(int seq)
306 if (seq > alignment.getHeight())
308 seq = alignment.getHeight();
317 public int getEndSeq()
322 java.awt.Frame nullFrame;
324 protected FeatureSettings featureSettings = null;
326 private float heightScale = 1, widthScale = 1;
328 public void setFont(Font f)
331 if (nullFrame == null)
333 nullFrame = new java.awt.Frame();
334 nullFrame.addNotify();
337 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
338 setCharHeight((int) (heightScale * fm.getHeight()));
339 setCharWidth((int) (widthScale * fm.charWidth('M')));
341 if (isUpperCasebold())
343 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
344 fm = nullFrame.getGraphics().getFontMetrics(f2);
345 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
349 public Font getFont()
355 public void resetSeqLimits(int height)
357 setEndSeq(height / getCharHeight());
360 public void setCurrentTree(NJTree tree)
365 public NJTree getCurrentTree()
371 boolean centreColumnLabels;
373 public boolean getCentreColumnLabels()
375 return centreColumnLabels;
378 public boolean followHighlight = true;
380 public boolean getFollowHighlight()
382 return followHighlight;
385 public boolean followSelection = true;
388 * @return true if view selection should always follow the selections
389 * broadcast by other selection sources
391 public boolean getFollowSelection()
393 return followSelection;
396 public void sendSelection()
398 jalview.structure.StructureSelectionManager
399 .getStructureSelectionManager(applet).sendSelection(
400 new SequenceGroup(getSelectionGroup()),
401 new ColumnSelection(getColumnSelection()), this);
405 * synthesize a column selection if none exists so it covers the given
406 * selection group. if wholewidth is false, no column selection is made if the
407 * selection group covers the whole alignment width.
412 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
416 && (sgs = sg.getStartRes()) >= 0
417 && sg.getStartRes() <= (sge = sg.getEndRes())
418 && (colSel == null || colSel.getSelected() == null || colSel
419 .getSelected().size() == 0))
421 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
428 colSel = new ColumnSelection();
430 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
432 colSel.addElement(cspos);
437 public boolean isNormaliseSequenceLogo()
439 return normaliseSequenceLogo;
442 public void setNormaliseSequenceLogo(boolean state)
444 normaliseSequenceLogo = state;
449 * @return true if alignment characters should be displayed
451 public boolean isValidCharWidth()
453 return validCharWidth;
456 public AnnotationColumnChooser getAnnotationColumnSelectionState()
458 return annotationColumnSelectionState;
461 public void setAnnotationColumnSelectionState(
462 AnnotationColumnChooser annotationColumnSelectionState)
464 this.annotationColumnSelectionState = annotationColumnSelectionState;