2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.AlignCalcManagerI;
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;
33 import jalview.workers.ConservationThread;
34 import jalview.workers.ConsensusThread;
36 public class AlignViewport extends AlignmentViewport implements AlignViewportI, SelectionSource, VamsasSource
46 boolean cursorMode = false;
48 boolean showJVSuffix = true;
50 boolean showText = true;
52 boolean showColourText = false;
54 boolean showBoxes = true;
56 boolean wrapAlignment = false;
58 boolean renderGaps = true;
60 boolean showSequenceFeatures = false;
62 boolean showAnnotation = true;
64 boolean upperCasebold = false;
66 boolean colourAppliesToAllGroups = true;
68 boolean conservationColourSelected = false;
70 boolean abovePIDThreshold = false;
78 Font font = new Font("SansSerif", Font.PLAIN, 10);
80 boolean validCharWidth = true;
86 NJTree currentTree = null;
88 boolean scaleAboveWrapped = true;
90 boolean scaleLeftWrapped = true;
92 boolean scaleRightWrapped = true;
94 // The following vector holds the features which are
95 // currently visible, in the correct order or rendering
96 public Hashtable featuresDisplayed;
99 boolean showHiddenMarkers = true;
101 public jalview.bin.JalviewLite applet;
103 Hashtable sequenceColours;
107 Stack historyList = new Stack();
109 Stack redoList = new Stack();
111 public void finalize() {
118 public AlignViewport(AlignmentI al, JalviewLite applet)
120 calculator = new jalview.workers.AlignCalcManager();
121 this.applet = applet;
123 // we always pad gaps
124 this.setPadGaps(true);
126 this.endRes = al.getWidth() - 1;
128 this.endSeq = al.getHeight() - 1;
131 // get the width and height scaling factors if they were specified
132 String param = applet.getParameter("widthScale");
137 widthScale = new Float(param).floatValue();
138 } catch (Exception e)
141 if (widthScale <= 1.0)
144 .println("Invalid alignment character width scaling factor ("
145 + widthScale + "). Ignoring.");
151 .println("Alignment character width scaling factor is now "
155 param = applet.getParameter("heightScale");
160 heightScale = new Float(param).floatValue();
161 } catch (Exception e)
164 if (heightScale <= 1.0)
167 .println("Invalid alignment character height scaling factor ("
168 + heightScale + "). Ignoring.");
174 .println("Alignment character height scaling factor is now "
181 MAC = new jalview.util.Platform().isAMac();
185 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
187 showAnnotation = applet.getDefaultParameter("showAnnotation", showAnnotation);
189 showConservation = applet.getDefaultParameter("showConservation", showConservation);
191 showQuality = applet.getDefaultParameter("showQuality", showQuality);
193 showConsensus = applet.getDefaultParameter("showConsensus", showConsensus);
195 showUnconserved = applet.getDefaultParameter("showUnconserved", showUnconserved);
197 String param = applet.getParameter("upperCase");
200 if (param.equalsIgnoreCase("bold"))
202 upperCasebold = true;
205 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
207 followHighlight = applet.getDefaultParameter("automaticScrolling",followHighlight);
208 followSelection = followHighlight;
210 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo", showSequenceLogo);
212 normaliseSequenceLogo = applet.getDefaultParameter("normaliseSequenceLogo", normaliseSequenceLogo);
214 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus", showGroupConsensus);
216 showGroupConservation = applet.getDefaultParameter("showGroupConservation", showGroupConservation);
218 showConsensusHistogram = applet.getDefaultParameter("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;
267 * get the consensus sequence as displayed under the PID consensus annotation
270 * @return consensus sequence as a new sequence object
272 public SequenceI getConsensusSeq()
274 if (consensus == null)
276 updateConsensus(null);
278 if (consensus == null)
282 StringBuffer seqs = new StringBuffer();
283 for (int i = 0; i < consensus.annotations.length; i++)
285 if (consensus.annotations[i] != null)
287 if (consensus.annotations[i].description.charAt(0) == '[')
289 seqs.append(consensus.annotations[i].description.charAt(1));
293 seqs.append(consensus.annotations[i].displayCharacter);
297 SequenceI sq = new Sequence("Consensus", seqs.toString());
298 sq.setDescription("Percentage Identity Consensus "
299 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
303 public boolean getConservationSelected()
305 return conservationColourSelected;
308 public void setConservationSelected(boolean b)
310 conservationColourSelected = b;
313 public boolean getAbovePIDThreshold()
315 return abovePIDThreshold;
318 public void setAbovePIDThreshold(boolean b)
320 abovePIDThreshold = b;
323 public int getStartRes()
328 public int getEndRes()
333 public int getStartSeq()
338 public void setStartRes(int res)
343 public void setStartSeq(int seq)
348 public void setEndRes(int res)
350 if (res > alignment.getWidth() - 1)
352 // log.System.out.println(" Corrected res from " + res + " to maximum " +
353 // (alignment.getWidth()-1));
354 res = alignment.getWidth() - 1;
363 public void setEndSeq(int seq)
365 if (seq > alignment.getHeight())
367 seq = alignment.getHeight();
376 public int getEndSeq()
381 java.awt.Frame nullFrame;
383 protected FeatureSettings featureSettings = null;
385 private float heightScale = 1, widthScale = 1;
387 public void setFont(Font f)
390 if (nullFrame == null)
392 nullFrame = new java.awt.Frame();
393 nullFrame.addNotify();
396 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
397 setCharHeight((int) (heightScale * fm.getHeight()));
398 charWidth = (int) (widthScale * fm.charWidth('M'));
402 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
403 fm = nullFrame.getGraphics().getFontMetrics(f2);
404 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
408 public Font getFont()
413 public int getCharWidth()
418 public void setCharHeight(int h)
423 public int getCharHeight()
428 public void setWrappedWidth(int w)
430 this.wrappedWidth = w;
433 public int getwrappedWidth()
438 public AlignmentI getAlignment()
443 public void setAlignment(AlignmentI align)
445 this.alignment = align;
448 public void setWrapAlignment(boolean state)
450 wrapAlignment = state;
453 public void setShowText(boolean state)
458 public void setRenderGaps(boolean state)
463 public boolean getColourText()
465 return showColourText;
468 public void setColourText(boolean state)
470 showColourText = state;
473 public void setShowBoxes(boolean state)
478 public boolean getWrapAlignment()
480 return wrapAlignment;
483 public boolean getShowText()
488 public boolean getShowBoxes()
493 public char getGapCharacter()
495 return getAlignment().getGapCharacter();
498 public void setGapCharacter(char gap)
500 if (getAlignment() != null)
502 getAlignment().setGapCharacter(gap);
506 public void setThreshold(int thresh)
511 public int getThreshold()
516 public void setIncrement(int inc)
521 public int getIncrement()
526 public void resetSeqLimits(int height)
528 setEndSeq(height / getCharHeight());
531 public void setCurrentTree(NJTree tree)
536 public NJTree getCurrentTree()
541 public void setColourAppliesToAllGroups(boolean b)
543 colourAppliesToAllGroups = b;
546 public boolean getColourAppliesToAllGroups()
548 return colourAppliesToAllGroups;
551 public boolean getShowJVSuffix()
556 public void setShowJVSuffix(boolean b)
561 public boolean getShowAnnotation()
563 return showAnnotation;
566 public void setShowAnnotation(boolean b)
571 public boolean getScaleAboveWrapped()
573 return scaleAboveWrapped;
576 public boolean getScaleLeftWrapped()
578 return scaleLeftWrapped;
581 public boolean getScaleRightWrapped()
583 return scaleRightWrapped;
586 public void setScaleAboveWrapped(boolean b)
588 scaleAboveWrapped = b;
591 public void setScaleLeftWrapped(boolean b)
593 scaleLeftWrapped = b;
596 public void setScaleRightWrapped(boolean b)
598 scaleRightWrapped = b;
601 public void setIgnoreGapsConsensus(boolean b)
603 ignoreGapsInConsensusCalculation = b;
604 updateConsensus(null);
605 if (globalColourScheme != null)
607 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
608 ignoreGapsInConsensusCalculation);
617 public boolean getShowHiddenMarkers()
619 return showHiddenMarkers;
622 public void setShowHiddenMarkers(boolean show)
624 showHiddenMarkers = show;
627 public Color getSequenceColour(SequenceI seq)
629 if (sequenceColours == null || !sequenceColours.containsKey(seq))
635 return (Color) sequenceColours.get(seq);
639 public void setSequenceColour(SequenceI seq, Color col)
641 if (sequenceColours == null)
643 sequenceColours = new Hashtable();
648 sequenceColours.remove(seq);
652 sequenceColours.put(seq, col);
656 boolean centreColumnLabels;
658 public boolean getCentreColumnLabels()
660 return centreColumnLabels;
663 public void updateSequenceIdColours()
665 Vector groups = alignment.getGroups();
666 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
668 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
669 if (sg.idColour != null)
671 Vector sqs = sg.getSequences(getHiddenRepSequences());
672 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
674 this.setSequenceColour((SequenceI) sqs.elementAt(s), sg.idColour);
680 public boolean followHighlight = true;
682 public boolean getFollowHighlight()
684 return followHighlight;
687 public boolean followSelection = true;
690 * @return true if view selection should always follow the selections
691 * broadcast by other selection sources
693 public boolean getFollowSelection()
695 return followSelection;
697 public void sendSelection()
699 jalview.structure.StructureSelectionManager
700 .getStructureSelectionManager(applet).sendSelection(
701 new SequenceGroup(getSelectionGroup()),
702 new ColumnSelection(getColumnSelection()), this);
709 * synthesize a column selection if none exists so it covers the given
710 * selection group. if wholewidth is false, no column selection is made if the
711 * selection group covers the whole alignment width.
716 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
720 && (sgs = sg.getStartRes()) >= 0
721 && sg.getStartRes() <= (sge = sg.getEndRes())
722 && (colSel == null || colSel.getSelected() == null || colSel
723 .getSelected().size() == 0))
725 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
732 colSel = new ColumnSelection();
734 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
736 colSel.addElement(cspos);
742 public boolean hasHiddenColumns()
744 return hasHiddenColumns;
747 public boolean isNormaliseSequenceLogo()
749 return normaliseSequenceLogo;
752 public void setNormaliseSequenceLogo(boolean state)
754 normaliseSequenceLogo = state;
759 * @return true if alignment characters should be displayed
761 public boolean isValidCharWidth()
763 return validCharWidth;