2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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;
25 import jalview.analysis.NJTree;
26 import jalview.api.AlignViewportI;
27 import jalview.bin.JalviewLite;
28 import jalview.commands.CommandI;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.schemes.ColourSchemeProperty;
35 import jalview.schemes.UserColourScheme;
36 import jalview.structure.CommandListener;
37 import jalview.structure.SelectionSource;
38 import jalview.structure.StructureSelectionManager;
39 import jalview.structure.VamsasSource;
40 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 setScaleProteinAsCdna(applet.getDefaultParameter(
161 "scaleProteinAsCdna", isScaleProteinAsCdna()));
163 String param = applet.getParameter("upperCase");
166 if (param.equalsIgnoreCase("bold"))
168 setUpperCasebold(true);
171 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
173 followHighlight = applet.getDefaultParameter("automaticScrolling",
175 followSelection = followHighlight;
177 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
180 normaliseSequenceLogo = applet.getDefaultParameter(
181 "normaliseSequenceLogo", applet.getDefaultParameter(
182 "normaliseLogo", normaliseSequenceLogo));
184 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
187 showGroupConservation = applet.getDefaultParameter(
188 "showGroupConservation", showGroupConservation);
190 showConsensusHistogram = applet.getDefaultParameter(
191 "showConsensusHistogram", showConsensusHistogram);
197 String colour = applet.getParameter("defaultColour");
201 colour = applet.getParameter("userDefinedColour");
204 colour = "User Defined";
210 globalColourScheme = ColourSchemeProperty.getColour(alignment,
212 if (globalColourScheme != null)
214 globalColourScheme.setConsensus(hconsensus);
218 if (applet.getParameter("userDefinedColour") != null)
220 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
221 .getParameter("userDefinedColour"));
224 initAutoAnnotation();
229 * get the consensus sequence as displayed under the PID consensus annotation
232 * @return consensus sequence as a new sequence object
234 public SequenceI getConsensusSeq()
236 if (consensus == null)
238 updateConsensus(null);
240 if (consensus == null)
244 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
245 for (int i = 0; i < consensus.annotations.length; i++)
247 if (consensus.annotations[i] != null)
249 if (consensus.annotations[i].description.charAt(0) == '[')
251 seqs.append(consensus.annotations[i].description.charAt(1));
255 seqs.append(consensus.annotations[i].displayCharacter);
259 SequenceI sq = new Sequence("Consensus", seqs.toString());
260 sq.setDescription("Percentage Identity Consensus "
261 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
265 public int getStartRes()
270 public int getEndRes()
275 public int getStartSeq()
280 public void setStartRes(int res)
285 public void setStartSeq(int seq)
290 public void setEndRes(int res)
292 if (res > alignment.getWidth() - 1)
294 // log.System.out.println(" Corrected res from " + res + " to maximum " +
295 // (alignment.getWidth()-1));
296 res = alignment.getWidth() - 1;
305 public void setEndSeq(int seq)
307 if (seq > alignment.getHeight())
309 seq = alignment.getHeight();
318 public int getEndSeq()
323 java.awt.Frame nullFrame;
325 protected FeatureSettings featureSettings = null;
327 private float heightScale = 1, widthScale = 1;
329 public void setFont(Font f)
332 if (nullFrame == null)
334 nullFrame = new java.awt.Frame();
335 nullFrame.addNotify();
338 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
339 setCharHeight((int) (heightScale * fm.getHeight()));
340 setCharWidth((int) (widthScale * fm.charWidth('M')));
342 if (isUpperCasebold())
344 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
345 fm = nullFrame.getGraphics().getFontMetrics(f2);
346 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
350 public Font getFont()
356 public void resetSeqLimits(int height)
358 setEndSeq(height / getCharHeight());
361 public void setCurrentTree(NJTree tree)
366 public NJTree getCurrentTree()
372 boolean centreColumnLabels;
374 public boolean getCentreColumnLabels()
376 return centreColumnLabels;
379 public boolean followHighlight = true;
381 public boolean getFollowHighlight()
383 return followHighlight;
386 public boolean followSelection = true;
389 * @return true if view selection should always follow the selections
390 * broadcast by other selection sources
392 public boolean getFollowSelection()
394 return followSelection;
397 public void sendSelection()
399 getStructureSelectionManager().sendSelection(
400 new SequenceGroup(getSelectionGroup()),
401 new ColumnSelection(getColumnSelection()), this);
405 * Returns an instance of the StructureSelectionManager scoped to this applet
411 public StructureSelectionManager getStructureSelectionManager()
413 return jalview.structure.StructureSelectionManager
414 .getStructureSelectionManager(applet);
418 * synthesize a column selection if none exists so it covers the given
419 * selection group. if wholewidth is false, no column selection is made if the
420 * selection group covers the whole alignment width.
425 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
429 && (sgs = sg.getStartRes()) >= 0
430 && sg.getStartRes() <= (sge = sg.getEndRes())
431 && (colSel == null || colSel.getSelected() == null || colSel
432 .getSelected().size() == 0))
434 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
441 colSel = new ColumnSelection();
443 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
445 colSel.addElement(cspos);
450 public boolean isNormaliseSequenceLogo()
452 return normaliseSequenceLogo;
455 public void setNormaliseSequenceLogo(boolean state)
457 normaliseSequenceLogo = state;
462 * @return true if alignment characters should be displayed
464 public boolean isValidCharWidth()
466 return validCharWidth;
469 public AnnotationColumnChooser getAnnotationColumnSelectionState()
471 return annotationColumnSelectionState;
474 public void setAnnotationColumnSelectionState(
475 AnnotationColumnChooser annotationColumnSelectionState)
477 this.annotationColumnSelectionState = annotationColumnSelectionState;
481 public void mirrorCommand(CommandI command, boolean undo,
482 StructureSelectionManager ssm, VamsasSource source)
484 // TODO refactor so this can be pulled up to superclass or controller
486 * Do nothing unless we are a 'complement' of the source. May replace this
487 * with direct calls not via SSM.
489 if (source instanceof AlignViewportI
490 && ((AlignViewportI) source).getCodingComplement() == this)
499 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
501 if (mappedCommand != null)
503 mappedCommand.doCommand(null);
504 firePropertyChange("alignment", null, getAlignment().getSequences());
506 // ap.scalePanelHolder.repaint();
512 public VamsasSource getVamsasSource()