2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
18 package jalview.appletgui;
24 import jalview.analysis.*;
25 import jalview.api.AlignViewportI;
27 import jalview.datamodel.*;
28 import jalview.schemes.*;
29 import jalview.structure.SelectionSource;
30 import jalview.structure.VamsasSource;
31 import jalview.viewmodel.AlignmentViewport;
33 public class AlignViewport extends AlignmentViewport implements
34 AlignViewportI, SelectionSource, VamsasSource
44 boolean cursorMode = false;
46 boolean showJVSuffix = true;
48 boolean showText = true;
50 boolean showColourText = false;
52 boolean showBoxes = true;
54 boolean wrapAlignment = false;
56 boolean renderGaps = true;
58 boolean showSequenceFeatures = false;
60 boolean showAnnotation = true;
62 boolean upperCasebold = false;
70 Font font = new Font("SansSerif", Font.PLAIN, 10);
72 boolean validCharWidth = true;
78 NJTree currentTree = null;
80 boolean scaleAboveWrapped = true;
82 boolean scaleLeftWrapped = true;
84 boolean scaleRightWrapped = true;
86 // The following vector holds the features which are
87 // currently visible, in the correct order or rendering
88 public Hashtable featuresDisplayed;
90 boolean showHiddenMarkers = true;
92 public jalview.bin.JalviewLite applet;
94 Hashtable sequenceColours;
98 Stack historyList = new Stack();
100 Stack redoList = new Stack();
102 public void finalize()
110 public AlignViewport(AlignmentI al, JalviewLite applet)
112 calculator = new jalview.workers.AlignCalcManager();
113 this.applet = applet;
115 // we always pad gaps
116 this.setPadGaps(true);
118 this.endRes = al.getWidth() - 1;
120 this.endSeq = al.getHeight() - 1;
123 // get the width and height scaling factors if they were specified
124 String param = applet.getParameter("widthScale");
129 widthScale = new Float(param).floatValue();
130 } catch (Exception e)
133 if (widthScale <= 1.0)
136 .println("Invalid alignment character width scaling factor ("
137 + widthScale + "). Ignoring.");
143 .println("Alignment character width scaling factor is now "
147 param = applet.getParameter("heightScale");
152 heightScale = new Float(param).floatValue();
153 } catch (Exception e)
156 if (heightScale <= 1.0)
159 .println("Invalid alignment character height scaling factor ("
160 + heightScale + "). Ignoring.");
166 .println("Alignment character height scaling factor is now "
173 MAC = new jalview.util.Platform().isAMac();
177 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
179 showAnnotation = applet.getDefaultParameter("showAnnotation",
182 showConservation = applet.getDefaultParameter("showConservation",
185 showQuality = applet.getDefaultParameter("showQuality", showQuality);
187 showConsensus = applet.getDefaultParameter("showConsensus",
190 showUnconserved = applet.getDefaultParameter("showUnconserved",
193 String param = applet.getParameter("upperCase");
196 if (param.equalsIgnoreCase("bold"))
198 upperCasebold = true;
201 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
203 followHighlight = applet.getDefaultParameter("automaticScrolling",
205 followSelection = followHighlight;
207 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
210 normaliseSequenceLogo = applet.getDefaultParameter(
211 "normaliseSequenceLogo", applet.getDefaultParameter(
212 "normaliseLogo", normaliseSequenceLogo));
214 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
217 showGroupConservation = applet.getDefaultParameter(
218 "showGroupConservation", showGroupConservation);
220 showConsensusHistogram = applet.getDefaultParameter(
221 "showConsensusHistogram", showConsensusHistogram);
227 String colour = applet.getParameter("defaultColour");
231 colour = applet.getParameter("userDefinedColour");
234 colour = "User Defined";
240 globalColourScheme = ColourSchemeProperty.getColour(alignment,
242 if (globalColourScheme != null)
244 globalColourScheme.setConsensus(hconsensus);
248 if (applet.getParameter("userDefinedColour") != null)
250 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
251 .getParameter("userDefinedColour"));
254 initAutoAnnotation();
258 public void showSequenceFeatures(boolean b)
260 showSequenceFeatures = b;
263 public boolean getShowSequenceFeatures()
265 return showSequenceFeatures;
269 * get the consensus sequence as displayed under the PID consensus annotation
272 * @return consensus sequence as a new sequence object
274 public SequenceI getConsensusSeq()
276 if (consensus == null)
278 updateConsensus(null);
280 if (consensus == null)
284 StringBuffer seqs = new StringBuffer();
285 for (int i = 0; i < consensus.annotations.length; i++)
287 if (consensus.annotations[i] != null)
289 if (consensus.annotations[i].description.charAt(0) == '[')
291 seqs.append(consensus.annotations[i].description.charAt(1));
295 seqs.append(consensus.annotations[i].displayCharacter);
299 SequenceI sq = new Sequence("Consensus", seqs.toString());
300 sq.setDescription("Percentage Identity Consensus "
301 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
305 public int getStartRes()
310 public int getEndRes()
315 public int getStartSeq()
320 public void setStartRes(int res)
325 public void setStartSeq(int seq)
330 public void setEndRes(int res)
332 if (res > alignment.getWidth() - 1)
334 // log.System.out.println(" Corrected res from " + res + " to maximum " +
335 // (alignment.getWidth()-1));
336 res = alignment.getWidth() - 1;
345 public void setEndSeq(int seq)
347 if (seq > alignment.getHeight())
349 seq = alignment.getHeight();
358 public int getEndSeq()
363 java.awt.Frame nullFrame;
365 protected FeatureSettings featureSettings = null;
367 private float heightScale = 1, widthScale = 1;
369 public void setFont(Font f)
372 if (nullFrame == null)
374 nullFrame = new java.awt.Frame();
375 nullFrame.addNotify();
378 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
379 setCharHeight((int) (heightScale * fm.getHeight()));
380 charWidth = (int) (widthScale * fm.charWidth('M'));
384 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
385 fm = nullFrame.getGraphics().getFontMetrics(f2);
386 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
390 public Font getFont()
395 public int getCharWidth()
400 public void setCharHeight(int h)
405 public int getCharHeight()
410 public void setWrappedWidth(int w)
412 this.wrappedWidth = w;
415 public int getwrappedWidth()
420 public AlignmentI getAlignment()
425 public void setAlignment(AlignmentI align)
427 this.alignment = align;
430 public void setWrapAlignment(boolean state)
432 wrapAlignment = state;
435 public void setShowText(boolean state)
440 public void setRenderGaps(boolean state)
445 public boolean getColourText()
447 return showColourText;
450 public void setColourText(boolean state)
452 showColourText = state;
455 public void setShowBoxes(boolean state)
460 public boolean getWrapAlignment()
462 return wrapAlignment;
465 public boolean getShowText()
470 public boolean getShowBoxes()
475 public char getGapCharacter()
477 return getAlignment().getGapCharacter();
480 public void setGapCharacter(char gap)
482 if (getAlignment() != null)
484 getAlignment().setGapCharacter(gap);
488 public void setThreshold(int thresh)
493 public int getThreshold()
498 public void setIncrement(int inc)
503 public int getIncrement()
508 public void resetSeqLimits(int height)
510 setEndSeq(height / getCharHeight());
513 public void setCurrentTree(NJTree tree)
518 public NJTree getCurrentTree()
523 public boolean getShowJVSuffix()
528 public void setShowJVSuffix(boolean b)
533 public boolean getShowAnnotation()
535 return showAnnotation;
538 public void setShowAnnotation(boolean b)
543 public boolean getScaleAboveWrapped()
545 return scaleAboveWrapped;
548 public boolean getScaleLeftWrapped()
550 return scaleLeftWrapped;
553 public boolean getScaleRightWrapped()
555 return scaleRightWrapped;
558 public void setScaleAboveWrapped(boolean b)
560 scaleAboveWrapped = b;
563 public void setScaleLeftWrapped(boolean b)
565 scaleLeftWrapped = b;
568 public void setScaleRightWrapped(boolean b)
570 scaleRightWrapped = b;
573 public void setIgnoreGapsConsensus(boolean b)
575 ignoreGapsInConsensusCalculation = b;
576 updateConsensus(null);
577 if (globalColourScheme != null)
579 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
580 ignoreGapsInConsensusCalculation);
585 public boolean getShowHiddenMarkers()
587 return showHiddenMarkers;
590 public void setShowHiddenMarkers(boolean show)
592 showHiddenMarkers = show;
595 public Color getSequenceColour(SequenceI seq)
597 if (sequenceColours == null || !sequenceColours.containsKey(seq))
603 return (Color) sequenceColours.get(seq);
607 public void setSequenceColour(SequenceI seq, Color col)
609 if (sequenceColours == null)
611 sequenceColours = new Hashtable();
616 sequenceColours.remove(seq);
620 sequenceColours.put(seq, col);
624 boolean centreColumnLabels;
626 public boolean getCentreColumnLabels()
628 return centreColumnLabels;
631 public void updateSequenceIdColours()
634 for (SequenceGroup sg : alignment.getGroups())
636 if (sg.idColour != null)
638 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
640 this.setSequenceColour(s, sg.idColour);
646 public boolean followHighlight = true;
648 public boolean getFollowHighlight()
650 return followHighlight;
653 public boolean followSelection = true;
656 * @return true if view selection should always follow the selections
657 * broadcast by other selection sources
659 public boolean getFollowSelection()
661 return followSelection;
664 public void sendSelection()
666 jalview.structure.StructureSelectionManager
667 .getStructureSelectionManager(applet).sendSelection(
668 new SequenceGroup(getSelectionGroup()),
669 new ColumnSelection(getColumnSelection()), this);
673 * synthesize a column selection if none exists so it covers the given
674 * selection group. if wholewidth is false, no column selection is made if the
675 * selection group covers the whole alignment width.
680 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
684 && (sgs = sg.getStartRes()) >= 0
685 && sg.getStartRes() <= (sge = sg.getEndRes())
686 && (colSel == null || colSel.getSelected() == null || colSel
687 .getSelected().size() == 0))
689 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
696 colSel = new ColumnSelection();
698 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
700 colSel.addElement(cspos);
706 public boolean hasHiddenColumns()
708 return hasHiddenColumns;
711 public boolean isNormaliseSequenceLogo()
713 return normaliseSequenceLogo;
716 public void setNormaliseSequenceLogo(boolean state)
718 normaliseSequenceLogo = state;
723 * @return true if alignment characters should be displayed
725 public boolean isValidCharWidth()
727 return validCharWidth;