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;
23 import jalview.analysis.NJTree;
24 import jalview.api.AlignViewportI;
25 import jalview.api.FeatureSettingsModelI;
26 import jalview.bin.JalviewLite;
27 import jalview.commands.CommandI;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.SearchResults;
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;
44 public class AlignViewport extends AlignmentViewport implements
45 SelectionSource, VamsasSource, CommandListener
47 boolean cursorMode = false;
49 Font font = new Font("SansSerif", Font.PLAIN, 10);
51 boolean validCharWidth = true;
53 NJTree currentTree = null;
55 public jalview.bin.JalviewLite applet;
59 private AnnotationColumnChooser annotationColumnSelectionState;
62 public void finalize()
70 public AlignViewport(AlignmentI al, JalviewLite applet)
73 calculator = new jalview.workers.AlignCalcManager();
77 this.setPadGaps(true);
79 this.endRes = al.getWidth() - 1;
81 this.endSeq = al.getHeight() - 1;
84 // get the width and height scaling factors if they were specified
85 String param = applet.getParameter("widthScale");
90 widthScale = new Float(param).floatValue();
94 if (widthScale <= 1.0)
97 .println("Invalid alignment character width scaling factor ("
98 + widthScale + "). Ignoring.");
101 if (JalviewLite.debug)
104 .println("Alignment character width scaling factor is now "
108 param = applet.getParameter("heightScale");
113 heightScale = new Float(param).floatValue();
114 } catch (Exception e)
117 if (heightScale <= 1.0)
120 .println("Invalid alignment character height scaling factor ("
121 + heightScale + "). Ignoring.");
124 if (JalviewLite.debug)
127 .println("Alignment character height scaling factor is now "
134 MAC = new jalview.util.Platform().isAMac();
138 setShowJVSuffix(applet.getDefaultParameter("showFullId",
141 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
142 isShowAnnotation()));
144 showConservation = applet.getDefaultParameter("showConservation",
147 showQuality = applet.getDefaultParameter("showQuality", showQuality);
149 showConsensus = applet.getDefaultParameter("showConsensus",
152 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
153 getShowUnconserved()));
155 setScaleProteinAsCdna(applet.getDefaultParameter(
156 "scaleProteinAsCdna", isScaleProteinAsCdna()));
158 String param = applet.getParameter("upperCase");
161 if (param.equalsIgnoreCase("bold"))
163 setUpperCasebold(true);
166 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
168 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
169 isFollowHighlight()));
170 followSelection = isFollowHighlight();
172 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
175 normaliseSequenceLogo = applet.getDefaultParameter(
176 "normaliseSequenceLogo", applet.getDefaultParameter(
177 "normaliseLogo", normaliseSequenceLogo));
179 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
182 showGroupConservation = applet.getDefaultParameter(
183 "showGroupConservation", showGroupConservation);
185 showConsensusHistogram = applet.getDefaultParameter(
186 "showConsensusHistogram", showConsensusHistogram);
192 String colour = al.isNucleotide() ? applet
193 .getParameter("defaultColourNuc") : applet
194 .getParameter("defaultColourProt");
197 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 java.awt.Frame nullFrame;
267 protected FeatureSettings featureSettings = null;
269 private float heightScale = 1, widthScale = 1;
271 public void setFont(Font f)
274 if (nullFrame == null)
276 nullFrame = new java.awt.Frame();
277 nullFrame.addNotify();
280 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
281 setCharHeight((int) (heightScale * fm.getHeight()));
282 setCharWidth((int) (widthScale * fm.charWidth('M')));
284 if (isUpperCasebold())
286 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
287 fm = nullFrame.getGraphics().getFontMetrics(f2);
288 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
292 public Font getFont()
297 public void resetSeqLimits(int height)
299 setEndSeq(height / getCharHeight());
302 public void setCurrentTree(NJTree tree)
307 public NJTree getCurrentTree()
312 boolean centreColumnLabels;
314 public boolean getCentreColumnLabels()
316 return centreColumnLabels;
319 public boolean followSelection = true;
322 * @return true if view selection should always follow the selections
323 * broadcast by other selection sources
325 public boolean getFollowSelection()
327 return followSelection;
331 public void sendSelection()
333 getStructureSelectionManager().sendSelection(
334 new SequenceGroup(getSelectionGroup()),
335 new ColumnSelection(getColumnSelection()), this);
339 * Returns an instance of the StructureSelectionManager scoped to this applet
345 public StructureSelectionManager getStructureSelectionManager()
347 return jalview.structure.StructureSelectionManager
348 .getStructureSelectionManager(applet);
352 public boolean isNormaliseSequenceLogo()
354 return normaliseSequenceLogo;
357 public void setNormaliseSequenceLogo(boolean state)
359 normaliseSequenceLogo = state;
364 * @return true if alignment characters should be displayed
367 public boolean isValidCharWidth()
369 return validCharWidth;
372 public AnnotationColumnChooser getAnnotationColumnSelectionState()
374 return annotationColumnSelectionState;
377 public void setAnnotationColumnSelectionState(
378 AnnotationColumnChooser annotationColumnSelectionState)
380 this.annotationColumnSelectionState = annotationColumnSelectionState;
384 public void mirrorCommand(CommandI command, boolean undo,
385 StructureSelectionManager ssm, VamsasSource source)
387 // TODO refactor so this can be pulled up to superclass or controller
389 * Do nothing unless we are a 'complement' of the source. May replace this
390 * with direct calls not via SSM.
392 if (source instanceof AlignViewportI
393 && ((AlignViewportI) source).getCodingComplement() == this)
402 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
404 if (mappedCommand != null)
406 mappedCommand.doCommand(null);
407 firePropertyChange("alignment", null, getAlignment().getSequences());
409 // ap.scalePanelHolder.repaint();
415 public VamsasSource getVamsasSource()
421 * If this viewport has a (Protein/cDNA) complement, then scroll the
422 * complementary alignment to match this one.
424 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
426 if (complementPanel == null)
432 * Populate a SearchResults object with the mapped location to scroll to. If
433 * there is no complement, or it is not following highlights, or no mapping
434 * is found, the result will be empty.
436 SearchResults sr = new SearchResults();
437 int seqOffset = findComplementScrollTarget(sr);
440 complementPanel.setFollowingComplementScroll(true);
441 complementPanel.scrollToCentre(sr, seqOffset);
446 * Applies the supplied feature settings descriptor to currently known
447 * features. This supports an 'initial configuration' of feature colouring
448 * based on a preset or user favourite. This may then be modified in the usual
449 * way using the Feature Settings dialogue.
451 * @param featureSettings
454 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
456 // TODO implement for applet