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 boolean showHiddenMarkers = true;
91 public jalview.bin.JalviewLite applet;
95 Stack historyList = new Stack();
97 Stack redoList = new Stack();
99 public void finalize()
107 public AlignViewport(AlignmentI al, JalviewLite applet)
109 calculator = new jalview.workers.AlignCalcManager();
110 this.applet = applet;
112 // we always pad gaps
113 this.setPadGaps(true);
115 this.endRes = al.getWidth() - 1;
117 this.endSeq = al.getHeight() - 1;
120 // get the width and height scaling factors if they were specified
121 String param = applet.getParameter("widthScale");
126 widthScale = new Float(param).floatValue();
127 } catch (Exception e)
130 if (widthScale <= 1.0)
133 .println("Invalid alignment character width scaling factor ("
134 + widthScale + "). Ignoring.");
140 .println("Alignment character width scaling factor is now "
144 param = applet.getParameter("heightScale");
149 heightScale = new Float(param).floatValue();
150 } catch (Exception e)
153 if (heightScale <= 1.0)
156 .println("Invalid alignment character height scaling factor ("
157 + heightScale + "). Ignoring.");
163 .println("Alignment character height scaling factor is now "
170 MAC = new jalview.util.Platform().isAMac();
174 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
176 showAnnotation = applet.getDefaultParameter("showAnnotation",
179 showConservation = applet.getDefaultParameter("showConservation",
182 showQuality = applet.getDefaultParameter("showQuality", showQuality);
184 showConsensus = applet.getDefaultParameter("showConsensus",
187 showUnconserved = applet.getDefaultParameter("showUnconserved",
190 String param = applet.getParameter("upperCase");
193 if (param.equalsIgnoreCase("bold"))
195 upperCasebold = true;
198 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
200 followHighlight = applet.getDefaultParameter("automaticScrolling",
202 followSelection = followHighlight;
204 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
207 normaliseSequenceLogo = applet.getDefaultParameter(
208 "normaliseSequenceLogo", applet.getDefaultParameter(
209 "normaliseLogo", normaliseSequenceLogo));
211 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
214 showGroupConservation = applet.getDefaultParameter(
215 "showGroupConservation", showGroupConservation);
217 showConsensusHistogram = applet.getDefaultParameter(
218 "showConsensusHistogram", showConsensusHistogram);
224 String colour = applet.getParameter("defaultColour");
228 colour = applet.getParameter("userDefinedColour");
231 colour = "User Defined";
237 globalColourScheme = ColourSchemeProperty.getColour(alignment,
239 if (globalColourScheme != null)
241 globalColourScheme.setConsensus(hconsensus);
245 if (applet.getParameter("userDefinedColour") != null)
247 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
248 .getParameter("userDefinedColour"));
251 initAutoAnnotation();
255 public void showSequenceFeatures(boolean b)
257 showSequenceFeatures = b;
260 public boolean getShowSequenceFeatures()
262 return showSequenceFeatures;
266 * get the consensus sequence as displayed under the PID consensus annotation
269 * @return consensus sequence as a new sequence object
271 public SequenceI getConsensusSeq()
273 if (consensus == null)
275 updateConsensus(null);
277 if (consensus == null)
281 StringBuffer seqs = new StringBuffer();
282 for (int i = 0; i < consensus.annotations.length; i++)
284 if (consensus.annotations[i] != null)
286 if (consensus.annotations[i].description.charAt(0) == '[')
288 seqs.append(consensus.annotations[i].description.charAt(1));
292 seqs.append(consensus.annotations[i].displayCharacter);
296 SequenceI sq = new Sequence("Consensus", seqs.toString());
297 sq.setDescription("Percentage Identity Consensus "
298 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
302 public int getStartRes()
307 public int getEndRes()
312 public int getStartSeq()
317 public void setStartRes(int res)
322 public void setStartSeq(int seq)
327 public void setEndRes(int res)
329 if (res > alignment.getWidth() - 1)
331 // log.System.out.println(" Corrected res from " + res + " to maximum " +
332 // (alignment.getWidth()-1));
333 res = alignment.getWidth() - 1;
342 public void setEndSeq(int seq)
344 if (seq > alignment.getHeight())
346 seq = alignment.getHeight();
355 public int getEndSeq()
360 java.awt.Frame nullFrame;
362 protected FeatureSettings featureSettings = null;
364 private float heightScale = 1, widthScale = 1;
366 public void setFont(Font f)
369 if (nullFrame == null)
371 nullFrame = new java.awt.Frame();
372 nullFrame.addNotify();
375 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
376 setCharHeight((int) (heightScale * fm.getHeight()));
377 charWidth = (int) (widthScale * fm.charWidth('M'));
381 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
382 fm = nullFrame.getGraphics().getFontMetrics(f2);
383 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
387 public Font getFont()
392 public int getCharWidth()
397 public void setCharHeight(int h)
402 public int getCharHeight()
407 public void setWrappedWidth(int w)
409 this.wrappedWidth = w;
412 public int getwrappedWidth()
417 public AlignmentI getAlignment()
422 public void setAlignment(AlignmentI align)
424 this.alignment = align;
427 public void setWrapAlignment(boolean state)
429 wrapAlignment = state;
432 public void setShowText(boolean state)
437 public void setRenderGaps(boolean state)
442 public boolean getColourText()
444 return showColourText;
447 public void setColourText(boolean state)
449 showColourText = state;
452 public void setShowBoxes(boolean state)
457 public boolean getWrapAlignment()
459 return wrapAlignment;
462 public boolean getShowText()
467 public boolean getShowBoxes()
472 public char getGapCharacter()
474 return getAlignment().getGapCharacter();
477 public void setGapCharacter(char gap)
479 if (getAlignment() != null)
481 getAlignment().setGapCharacter(gap);
485 public void resetSeqLimits(int height)
487 setEndSeq(height / getCharHeight());
490 public void setCurrentTree(NJTree tree)
495 public NJTree getCurrentTree()
500 public boolean getShowJVSuffix()
505 public void setShowJVSuffix(boolean b)
510 public boolean getShowAnnotation()
512 return showAnnotation;
515 public void setShowAnnotation(boolean b)
520 public boolean getScaleAboveWrapped()
522 return scaleAboveWrapped;
525 public boolean getScaleLeftWrapped()
527 return scaleLeftWrapped;
530 public boolean getScaleRightWrapped()
532 return scaleRightWrapped;
535 public void setScaleAboveWrapped(boolean b)
537 scaleAboveWrapped = b;
540 public void setScaleLeftWrapped(boolean b)
542 scaleLeftWrapped = b;
545 public void setScaleRightWrapped(boolean b)
547 scaleRightWrapped = b;
550 public void setIgnoreGapsConsensus(boolean b)
552 ignoreGapsInConsensusCalculation = b;
553 updateConsensus(null);
554 if (globalColourScheme != null)
556 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
557 ignoreGapsInConsensusCalculation);
562 public boolean getShowHiddenMarkers()
564 return showHiddenMarkers;
567 public void setShowHiddenMarkers(boolean show)
569 showHiddenMarkers = show;
572 boolean centreColumnLabels;
574 public boolean getCentreColumnLabels()
576 return centreColumnLabels;
579 public boolean followHighlight = true;
581 public boolean getFollowHighlight()
583 return followHighlight;
586 public boolean followSelection = true;
589 * @return true if view selection should always follow the selections
590 * broadcast by other selection sources
592 public boolean getFollowSelection()
594 return followSelection;
597 public void sendSelection()
599 jalview.structure.StructureSelectionManager
600 .getStructureSelectionManager(applet).sendSelection(
601 new SequenceGroup(getSelectionGroup()),
602 new ColumnSelection(getColumnSelection()), this);
606 * synthesize a column selection if none exists so it covers the given
607 * selection group. if wholewidth is false, no column selection is made if the
608 * selection group covers the whole alignment width.
613 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
617 && (sgs = sg.getStartRes()) >= 0
618 && sg.getStartRes() <= (sge = sg.getEndRes())
619 && (colSel == null || colSel.getSelected() == null || colSel
620 .getSelected().size() == 0))
622 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
629 colSel = new ColumnSelection();
631 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
633 colSel.addElement(cspos);
639 public boolean hasHiddenColumns()
641 return hasHiddenColumns;
644 public boolean isNormaliseSequenceLogo()
646 return normaliseSequenceLogo;
649 public void setNormaliseSequenceLogo(boolean state)
651 normaliseSequenceLogo = state;
656 * @return true if alignment characters should be displayed
658 public boolean isValidCharWidth()
660 return validCharWidth;