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 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 boolean showHiddenMarkers = true;
89 public jalview.bin.JalviewLite applet;
93 Stack historyList = new Stack();
95 Stack redoList = new Stack();
97 public void finalize()
105 public AlignViewport(AlignmentI al, JalviewLite applet)
107 calculator = new jalview.workers.AlignCalcManager();
108 this.applet = applet;
110 // we always pad gaps
111 this.setPadGaps(true);
113 this.endRes = al.getWidth() - 1;
115 this.endSeq = al.getHeight() - 1;
118 // get the width and height scaling factors if they were specified
119 String param = applet.getParameter("widthScale");
124 widthScale = new Float(param).floatValue();
125 } catch (Exception e)
128 if (widthScale <= 1.0)
131 .println("Invalid alignment character width scaling factor ("
132 + widthScale + "). Ignoring.");
138 .println("Alignment character width scaling factor is now "
142 param = applet.getParameter("heightScale");
147 heightScale = new Float(param).floatValue();
148 } catch (Exception e)
151 if (heightScale <= 1.0)
154 .println("Invalid alignment character height scaling factor ("
155 + heightScale + "). Ignoring.");
161 .println("Alignment character height scaling factor is now "
168 MAC = new jalview.util.Platform().isAMac();
172 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
174 showAnnotation = applet.getDefaultParameter("showAnnotation",
177 showConservation = applet.getDefaultParameter("showConservation",
180 showQuality = applet.getDefaultParameter("showQuality", showQuality);
182 showConsensus = applet.getDefaultParameter("showConsensus",
185 showUnconserved = applet.getDefaultParameter("showUnconserved",
188 String param = applet.getParameter("upperCase");
191 if (param.equalsIgnoreCase("bold"))
193 upperCasebold = true;
196 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
198 followHighlight = applet.getDefaultParameter("automaticScrolling",
200 followSelection = followHighlight;
202 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
205 normaliseSequenceLogo = applet.getDefaultParameter(
206 "normaliseSequenceLogo", applet.getDefaultParameter(
207 "normaliseLogo", normaliseSequenceLogo));
209 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
212 showGroupConservation = applet.getDefaultParameter(
213 "showGroupConservation", showGroupConservation);
215 showConsensusHistogram = applet.getDefaultParameter(
216 "showConsensusHistogram", showConsensusHistogram);
222 String colour = applet.getParameter("defaultColour");
226 colour = applet.getParameter("userDefinedColour");
229 colour = "User Defined";
235 globalColourScheme = ColourSchemeProperty.getColour(alignment,
237 if (globalColourScheme != null)
239 globalColourScheme.setConsensus(hconsensus);
243 if (applet.getParameter("userDefinedColour") != null)
245 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
246 .getParameter("userDefinedColour"));
249 initAutoAnnotation();
254 * get the consensus sequence as displayed under the PID consensus annotation
257 * @return consensus sequence as a new sequence object
259 public SequenceI getConsensusSeq()
261 if (consensus == null)
263 updateConsensus(null);
265 if (consensus == null)
269 StringBuffer seqs = new StringBuffer();
270 for (int i = 0; i < consensus.annotations.length; i++)
272 if (consensus.annotations[i] != null)
274 if (consensus.annotations[i].description.charAt(0) == '[')
276 seqs.append(consensus.annotations[i].description.charAt(1));
280 seqs.append(consensus.annotations[i].displayCharacter);
284 SequenceI sq = new Sequence("Consensus", seqs.toString());
285 sq.setDescription("Percentage Identity Consensus "
286 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
290 public int getStartRes()
295 public int getEndRes()
300 public int getStartSeq()
305 public void setStartRes(int res)
310 public void setStartSeq(int seq)
315 public void setEndRes(int res)
317 if (res > alignment.getWidth() - 1)
319 // log.System.out.println(" Corrected res from " + res + " to maximum " +
320 // (alignment.getWidth()-1));
321 res = alignment.getWidth() - 1;
330 public void setEndSeq(int seq)
332 if (seq > alignment.getHeight())
334 seq = alignment.getHeight();
343 public int getEndSeq()
348 java.awt.Frame nullFrame;
350 protected FeatureSettings featureSettings = null;
352 private float heightScale = 1, widthScale = 1;
354 public void setFont(Font f)
357 if (nullFrame == null)
359 nullFrame = new java.awt.Frame();
360 nullFrame.addNotify();
363 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
364 setCharHeight((int) (heightScale * fm.getHeight()));
365 charWidth = (int) (widthScale * fm.charWidth('M'));
369 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
370 fm = nullFrame.getGraphics().getFontMetrics(f2);
371 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
375 public Font getFont()
380 public int getCharWidth()
385 public void setCharHeight(int h)
390 public int getCharHeight()
395 public void setWrappedWidth(int w)
397 this.wrappedWidth = w;
400 public int getwrappedWidth()
405 public AlignmentI getAlignment()
410 public void setAlignment(AlignmentI align)
412 this.alignment = align;
415 public void setWrapAlignment(boolean state)
417 wrapAlignment = state;
420 public void setShowText(boolean state)
425 public void setRenderGaps(boolean state)
430 public boolean getColourText()
432 return showColourText;
435 public void setColourText(boolean state)
437 showColourText = state;
440 public void setShowBoxes(boolean state)
445 public boolean getWrapAlignment()
447 return wrapAlignment;
450 public boolean getShowText()
455 public boolean getShowBoxes()
460 public char getGapCharacter()
462 return getAlignment().getGapCharacter();
465 public void setGapCharacter(char gap)
467 if (getAlignment() != null)
469 getAlignment().setGapCharacter(gap);
473 public void resetSeqLimits(int height)
475 setEndSeq(height / getCharHeight());
478 public void setCurrentTree(NJTree tree)
483 public NJTree getCurrentTree()
488 public boolean getShowJVSuffix()
493 public void setShowJVSuffix(boolean b)
498 public boolean getShowAnnotation()
500 return showAnnotation;
503 public void setShowAnnotation(boolean b)
508 public boolean getScaleAboveWrapped()
510 return scaleAboveWrapped;
513 public boolean getScaleLeftWrapped()
515 return scaleLeftWrapped;
518 public boolean getScaleRightWrapped()
520 return scaleRightWrapped;
523 public void setScaleAboveWrapped(boolean b)
525 scaleAboveWrapped = b;
528 public void setScaleLeftWrapped(boolean b)
530 scaleLeftWrapped = b;
533 public void setScaleRightWrapped(boolean b)
535 scaleRightWrapped = b;
538 public void setIgnoreGapsConsensus(boolean b)
540 ignoreGapsInConsensusCalculation = b;
541 updateConsensus(null);
542 if (globalColourScheme != null)
544 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
545 ignoreGapsInConsensusCalculation);
550 public boolean getShowHiddenMarkers()
552 return showHiddenMarkers;
555 public void setShowHiddenMarkers(boolean show)
557 showHiddenMarkers = show;
560 boolean centreColumnLabels;
562 public boolean getCentreColumnLabels()
564 return centreColumnLabels;
567 public boolean followHighlight = true;
569 public boolean getFollowHighlight()
571 return followHighlight;
574 public boolean followSelection = true;
577 * @return true if view selection should always follow the selections
578 * broadcast by other selection sources
580 public boolean getFollowSelection()
582 return followSelection;
585 public void sendSelection()
587 jalview.structure.StructureSelectionManager
588 .getStructureSelectionManager(applet).sendSelection(
589 new SequenceGroup(getSelectionGroup()),
590 new ColumnSelection(getColumnSelection()), this);
594 * synthesize a column selection if none exists so it covers the given
595 * selection group. if wholewidth is false, no column selection is made if the
596 * selection group covers the whole alignment width.
601 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
605 && (sgs = sg.getStartRes()) >= 0
606 && sg.getStartRes() <= (sge = sg.getEndRes())
607 && (colSel == null || colSel.getSelected() == null || colSel
608 .getSelected().size() == 0))
610 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
617 colSel = new ColumnSelection();
619 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
621 colSel.addElement(cspos);
627 public boolean hasHiddenColumns()
629 return hasHiddenColumns;
632 public boolean isNormaliseSequenceLogo()
634 return normaliseSequenceLogo;
637 public void setNormaliseSequenceLogo(boolean state)
639 normaliseSequenceLogo = state;
644 * @return true if alignment characters should be displayed
646 public boolean isValidCharWidth()
648 return validCharWidth;