2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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;
95 Hashtable sequenceColours;
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 setThreshold(int thresh)
494 public int getThreshold()
499 public void setIncrement(int inc)
504 public int getIncrement()
509 public void resetSeqLimits(int height)
511 setEndSeq(height / getCharHeight());
514 public void setCurrentTree(NJTree tree)
519 public NJTree getCurrentTree()
524 public boolean getShowJVSuffix()
529 public void setShowJVSuffix(boolean b)
534 public boolean getShowAnnotation()
536 return showAnnotation;
539 public void setShowAnnotation(boolean b)
544 public boolean getScaleAboveWrapped()
546 return scaleAboveWrapped;
549 public boolean getScaleLeftWrapped()
551 return scaleLeftWrapped;
554 public boolean getScaleRightWrapped()
556 return scaleRightWrapped;
559 public void setScaleAboveWrapped(boolean b)
561 scaleAboveWrapped = b;
564 public void setScaleLeftWrapped(boolean b)
566 scaleLeftWrapped = b;
569 public void setScaleRightWrapped(boolean b)
571 scaleRightWrapped = b;
574 public void setIgnoreGapsConsensus(boolean b)
576 ignoreGapsInConsensusCalculation = b;
577 updateConsensus(null);
578 if (globalColourScheme != null)
580 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
581 ignoreGapsInConsensusCalculation);
586 public boolean getShowHiddenMarkers()
588 return showHiddenMarkers;
591 public void setShowHiddenMarkers(boolean show)
593 showHiddenMarkers = show;
596 public Color getSequenceColour(SequenceI seq)
598 if (sequenceColours == null || !sequenceColours.containsKey(seq))
604 return (Color) sequenceColours.get(seq);
608 public void setSequenceColour(SequenceI seq, Color col)
610 if (sequenceColours == null)
612 sequenceColours = new Hashtable();
617 sequenceColours.remove(seq);
621 sequenceColours.put(seq, col);
625 boolean centreColumnLabels;
627 public boolean getCentreColumnLabels()
629 return centreColumnLabels;
632 public void updateSequenceIdColours()
635 for (SequenceGroup sg : alignment.getGroups())
637 if (sg.idColour != null)
639 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
641 this.setSequenceColour(s, sg.idColour);
647 public boolean followHighlight = true;
649 public boolean getFollowHighlight()
651 return followHighlight;
654 public boolean followSelection = true;
657 * @return true if view selection should always follow the selections
658 * broadcast by other selection sources
660 public boolean getFollowSelection()
662 return followSelection;
665 public void sendSelection()
667 jalview.structure.StructureSelectionManager
668 .getStructureSelectionManager(applet).sendSelection(
669 new SequenceGroup(getSelectionGroup()),
670 new ColumnSelection(getColumnSelection()), this);
674 * synthesize a column selection if none exists so it covers the given
675 * selection group. if wholewidth is false, no column selection is made if the
676 * selection group covers the whole alignment width.
681 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
685 && (sgs = sg.getStartRes()) >= 0
686 && sg.getStartRes() <= (sge = sg.getEndRes())
687 && (colSel == null || colSel.getSelected() == null || colSel
688 .getSelected().size() == 0))
690 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
697 colSel = new ColumnSelection();
699 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
701 colSel.addElement(cspos);
707 public boolean hasHiddenColumns()
709 return hasHiddenColumns;
712 public boolean isNormaliseSequenceLogo()
714 return normaliseSequenceLogo;
717 public void setNormaliseSequenceLogo(boolean state)
719 normaliseSequenceLogo = state;
724 * @return true if alignment characters should be displayed
726 public boolean isValidCharWidth()
728 return validCharWidth;