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;
23 import jalview.analysis.NJTree;
24 import jalview.api.AlignViewportI;
25 import jalview.bin.JalviewLite;
26 import jalview.commands.CommandI;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.Sequence;
30 import jalview.datamodel.SequenceGroup;
31 import jalview.datamodel.SequenceI;
32 import jalview.schemes.ColourSchemeProperty;
33 import jalview.schemes.UserColourScheme;
34 import jalview.structure.CommandListener;
35 import jalview.structure.SelectionSource;
36 import jalview.structure.StructureSelectionManager;
37 import jalview.structure.VamsasSource;
38 import jalview.viewmodel.AlignmentViewport;
42 public class AlignViewport extends AlignmentViewport implements
43 AlignViewportI, SelectionSource, VamsasSource, CommandListener
53 boolean cursorMode = false;
55 Font font = new Font("SansSerif", Font.PLAIN, 10);
57 boolean validCharWidth = true;
59 NJTree currentTree = null;
61 public jalview.bin.JalviewLite applet;
65 private AnnotationColumnChooser annotationColumnSelectionState;
67 public void finalize()
75 public AlignViewport(AlignmentI al, JalviewLite applet)
78 calculator = new jalview.workers.AlignCalcManager();
82 this.setPadGaps(true);
84 this.endRes = al.getWidth() - 1;
86 this.endSeq = al.getHeight() - 1;
89 // get the width and height scaling factors if they were specified
90 String param = applet.getParameter("widthScale");
95 widthScale = new Float(param).floatValue();
99 if (widthScale <= 1.0)
102 .println("Invalid alignment character width scaling factor ("
103 + widthScale + "). Ignoring.");
109 .println("Alignment character width scaling factor is now "
113 param = applet.getParameter("heightScale");
118 heightScale = new Float(param).floatValue();
119 } catch (Exception e)
122 if (heightScale <= 1.0)
125 .println("Invalid alignment character height scaling factor ("
126 + heightScale + "). Ignoring.");
132 .println("Alignment character height scaling factor is now "
139 MAC = new jalview.util.Platform().isAMac();
143 setShowJVSuffix(applet.getDefaultParameter("showFullId",
146 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
147 isShowAnnotation()));
149 showConservation = applet.getDefaultParameter("showConservation",
152 showQuality = applet.getDefaultParameter("showQuality", showQuality);
154 showConsensus = applet.getDefaultParameter("showConsensus",
157 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
158 getShowUnconserved()));
160 String param = applet.getParameter("upperCase");
163 if (param.equalsIgnoreCase("bold"))
165 setUpperCasebold(true);
168 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
170 followHighlight = applet.getDefaultParameter("automaticScrolling",
172 followSelection = followHighlight;
174 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
177 normaliseSequenceLogo = applet.getDefaultParameter(
178 "normaliseSequenceLogo", applet.getDefaultParameter(
179 "normaliseLogo", normaliseSequenceLogo));
181 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
184 showGroupConservation = applet.getDefaultParameter(
185 "showGroupConservation", showGroupConservation);
187 showConsensusHistogram = applet.getDefaultParameter(
188 "showConsensusHistogram", showConsensusHistogram);
194 String colour = applet.getParameter("defaultColour");
198 colour = applet.getParameter("userDefinedColour");
201 colour = "User Defined";
207 globalColourScheme = ColourSchemeProperty.getColour(alignment,
209 if (globalColourScheme != null)
211 globalColourScheme.setConsensus(hconsensus);
215 if (applet.getParameter("userDefinedColour") != null)
217 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
218 .getParameter("userDefinedColour"));
221 initAutoAnnotation();
226 * get the consensus sequence as displayed under the PID consensus annotation
229 * @return consensus sequence as a new sequence object
231 public SequenceI getConsensusSeq()
233 if (consensus == null)
235 updateConsensus(null);
237 if (consensus == null)
241 StringBuffer seqs = new StringBuffer();
242 for (int i = 0; i < consensus.annotations.length; i++)
244 if (consensus.annotations[i] != null)
246 if (consensus.annotations[i].description.charAt(0) == '[')
248 seqs.append(consensus.annotations[i].description.charAt(1));
252 seqs.append(consensus.annotations[i].displayCharacter);
256 SequenceI sq = new Sequence("Consensus", seqs.toString());
257 sq.setDescription("Percentage Identity Consensus "
258 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
262 public int getStartRes()
267 public int getEndRes()
272 public int getStartSeq()
277 public void setStartRes(int res)
282 public void setStartSeq(int seq)
287 public void setEndRes(int res)
289 if (res > alignment.getWidth() - 1)
291 // log.System.out.println(" Corrected res from " + res + " to maximum " +
292 // (alignment.getWidth()-1));
293 res = alignment.getWidth() - 1;
302 public void setEndSeq(int seq)
304 if (seq > alignment.getHeight())
306 seq = alignment.getHeight();
315 public int getEndSeq()
320 java.awt.Frame nullFrame;
322 protected FeatureSettings featureSettings = null;
324 private float heightScale = 1, widthScale = 1;
326 public void setFont(Font f)
329 if (nullFrame == null)
331 nullFrame = new java.awt.Frame();
332 nullFrame.addNotify();
335 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
336 setCharHeight((int) (heightScale * fm.getHeight()));
337 setCharWidth((int) (widthScale * fm.charWidth('M')));
339 if (isUpperCasebold())
341 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
342 fm = nullFrame.getGraphics().getFontMetrics(f2);
343 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
347 public Font getFont()
353 public void resetSeqLimits(int height)
355 setEndSeq(height / getCharHeight());
358 public void setCurrentTree(NJTree tree)
363 public NJTree getCurrentTree()
369 boolean centreColumnLabels;
371 public boolean getCentreColumnLabels()
373 return centreColumnLabels;
376 public boolean followHighlight = true;
378 public boolean getFollowHighlight()
380 return followHighlight;
383 public boolean followSelection = true;
386 * @return true if view selection should always follow the selections
387 * broadcast by other selection sources
389 public boolean getFollowSelection()
391 return followSelection;
394 public void sendSelection()
396 getStructureSelectionManager().sendSelection(
397 new SequenceGroup(getSelectionGroup()),
398 new ColumnSelection(getColumnSelection()), this);
402 * Returns an instance of the StructureSelectionManager scoped to this applet
408 public StructureSelectionManager getStructureSelectionManager()
410 return jalview.structure.StructureSelectionManager
411 .getStructureSelectionManager(applet);
415 * synthesize a column selection if none exists so it covers the given
416 * selection group. if wholewidth is false, no column selection is made if the
417 * selection group covers the whole alignment width.
422 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
426 && (sgs = sg.getStartRes()) >= 0
427 && sg.getStartRes() <= (sge = sg.getEndRes())
428 && (colSel == null || colSel.getSelected() == null || colSel
429 .getSelected().size() == 0))
431 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
438 colSel = new ColumnSelection();
440 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
442 colSel.addElement(cspos);
447 public boolean isNormaliseSequenceLogo()
449 return normaliseSequenceLogo;
452 public void setNormaliseSequenceLogo(boolean state)
454 normaliseSequenceLogo = state;
459 * @return true if alignment characters should be displayed
461 public boolean isValidCharWidth()
463 return validCharWidth;
466 public AnnotationColumnChooser getAnnotationColumnSelectionState()
468 return annotationColumnSelectionState;
471 public void setAnnotationColumnSelectionState(
472 AnnotationColumnChooser annotationColumnSelectionState)
474 this.annotationColumnSelectionState = annotationColumnSelectionState;
478 public void mirrorCommand(CommandI command, boolean undo,
479 StructureSelectionManager ssm, VamsasSource source)
481 // TODO refactor so this can be pulled up to superclass or controller
483 * Do nothing unless we are a 'complement' of the source. May replace this
484 * with direct calls not via SSM.
486 if (source instanceof AlignViewportI
487 && ((AlignViewportI) source).getCodingComplement() == this)
496 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
498 if (mappedCommand != null)
500 mappedCommand.doCommand(null);
501 firePropertyChange("alignment", null, getAlignment().getSequences());
503 // ap.scalePanelHolder.repaint();
509 public VamsasSource getVamsasSource()