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.TreeModel;
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.Annotation;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.HiddenColumns;
32 import jalview.datamodel.SearchResults;
33 import jalview.datamodel.SearchResultsI;
34 import jalview.datamodel.Sequence;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.renderer.ResidueShader;
38 import jalview.schemes.ColourSchemeProperty;
39 import jalview.schemes.UserColourScheme;
40 import jalview.structure.SelectionSource;
41 import jalview.structure.StructureSelectionManager;
42 import jalview.structure.VamsasSource;
43 import jalview.viewmodel.AlignmentViewport;
46 import java.awt.FontMetrics;
48 public class AlignViewport extends AlignmentViewport
49 implements SelectionSource
51 boolean cursorMode = false;
53 Font font = new Font("SansSerif", Font.PLAIN, 10);
55 boolean validCharWidth = true;
57 TreeModel currentTree = null;
59 public jalview.bin.JalviewLite applet;
63 private AnnotationColumnChooser annotationColumnSelectionState;
65 public AlignViewport(AlignmentI al, JalviewLite applet)
68 calculator = new jalview.workers.AlignCalcManager();
72 this.setPadGaps(true);
76 // get the width and height scaling factors if they were specified
77 String param = applet.getParameter("widthScale");
82 widthScale = new Float(param).floatValue();
86 if (widthScale <= 1.0)
89 "Invalid alignment character width scaling factor ("
90 + widthScale + "). Ignoring.");
93 if (JalviewLite.debug)
96 "Alignment character width scaling factor is now "
100 param = applet.getParameter("heightScale");
105 heightScale = new Float(param).floatValue();
106 } catch (Exception e)
109 if (heightScale <= 1.0)
112 "Invalid alignment character height scaling factor ("
113 + heightScale + "). Ignoring.");
116 if (JalviewLite.debug)
119 "Alignment character height scaling factor is now "
126 MAC = new jalview.util.Platform().isAMac();
131 applet.getDefaultParameter("showFullId", getShowJVSuffix()));
133 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
134 isShowAnnotation()));
136 showConservation = applet.getDefaultParameter("showConservation",
139 showQuality = applet.getDefaultParameter("showQuality", showQuality);
141 showConsensus = applet.getDefaultParameter("showConsensus",
144 showOccupancy = applet.getDefaultParameter("showOccupancy",
147 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
148 getShowUnconserved()));
150 setScaleProteinAsCdna(applet.getDefaultParameter("scaleProteinAsCdna",
151 isScaleProteinAsCdna()));
153 String param = applet.getParameter("upperCase");
156 if (param.equalsIgnoreCase("bold"))
158 setUpperCasebold(true);
161 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
163 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
164 isFollowHighlight()));
165 followSelection = isFollowHighlight();
167 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
170 normaliseSequenceLogo = applet.getDefaultParameter(
171 "normaliseSequenceLogo", applet.getDefaultParameter(
172 "normaliseLogo", normaliseSequenceLogo));
174 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
177 showGroupConservation = applet.getDefaultParameter(
178 "showGroupConservation", showGroupConservation);
180 showConsensusHistogram = applet.getDefaultParameter(
181 "showConsensusHistogram", showConsensusHistogram);
187 String colour = al.isNucleotide()
188 ? applet.getParameter("defaultColourNuc")
189 : applet.getParameter("defaultColourProt");
192 colour = applet.getParameter("defaultColour");
196 colour = applet.getParameter("userDefinedColour");
199 colour = "User Defined";
205 residueShading = new ResidueShader(
206 ColourSchemeProperty.getColourScheme(alignment, colour));
207 if (residueShading != null)
209 residueShading.setConsensus(hconsensus);
213 if (applet.getParameter("userDefinedColour") != null)
215 residueShading = new ResidueShader(new UserColourScheme(
216 applet.getParameter("userDefinedColour")));
219 initAutoAnnotation();
223 java.awt.Frame nullFrame;
225 protected FeatureSettings featureSettings = null;
227 private float heightScale = 1, widthScale = 1;
233 public void setFont(Font f, boolean setGrid)
236 if (nullFrame == null)
238 nullFrame = new java.awt.Frame();
239 nullFrame.addNotify();
244 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
245 setCharHeight((int) (heightScale * fm.getHeight()));
246 setCharWidth((int) (widthScale * fm.charWidth('M')));
249 if (isUpperCasebold())
251 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
252 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
254 (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
258 public Font getFont()
263 public void resetSeqLimits(int height)
265 ranges.setEndSeq(height / getCharHeight());
268 public void setCurrentTree(TreeModel tree)
273 public TreeModel getCurrentTree()
278 boolean centreColumnLabels;
280 public boolean getCentreColumnLabels()
282 return centreColumnLabels;
285 public boolean followSelection = true;
288 * @return true if view selection should always follow the selections
289 * broadcast by other selection sources
291 public boolean getFollowSelection()
293 return followSelection;
297 public void sendSelection()
299 getStructureSelectionManager().sendSelection(
300 new SequenceGroup(getSelectionGroup()),
301 new ColumnSelection(getColumnSelection()),
302 new HiddenColumns(getAlignment().getHiddenColumns()), this);
306 * Returns an instance of the StructureSelectionManager scoped to this applet
312 public StructureSelectionManager getStructureSelectionManager()
314 return jalview.structure.StructureSelectionManager
315 .getStructureSelectionManager(applet);
319 public boolean isNormaliseSequenceLogo()
321 return normaliseSequenceLogo;
324 public void setNormaliseSequenceLogo(boolean state)
326 normaliseSequenceLogo = state;
331 * @return true if alignment characters should be displayed
334 public boolean isValidCharWidth()
336 return validCharWidth;
339 public AnnotationColumnChooser getAnnotationColumnSelectionState()
341 return annotationColumnSelectionState;
344 public void setAnnotationColumnSelectionState(
345 AnnotationColumnChooser annotationColumnSelectionState)
347 this.annotationColumnSelectionState = annotationColumnSelectionState;
351 public void mirrorCommand(CommandI command, boolean undo,
352 StructureSelectionManager ssm, VamsasSource source)
354 // TODO refactor so this can be pulled up to superclass or controller
356 * Do nothing unless we are a 'complement' of the source. May replace this
357 * with direct calls not via SSM.
359 if (source instanceof AlignViewportI
360 && ((AlignViewportI) source).getCodingComplement() == this)
369 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
371 if (mappedCommand != null)
373 mappedCommand.doCommand(null);
374 firePropertyChange("alignment", null, getAlignment().getSequences());
376 // ap.scalePanelHolder.repaint();
382 public VamsasSource getVamsasSource()
388 * If this viewport has a (Protein/cDNA) complement, then scroll the
389 * complementary alignment to match this one.
391 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
393 if (complementPanel == null)
399 * Populate a SearchResults object with the mapped location to scroll to. If
400 * there is no complement, or it is not following highlights, or no mapping
401 * is found, the result will be empty.
403 SearchResultsI sr = new SearchResults();
404 int seqOffset = findComplementScrollTarget(sr);
407 complementPanel.setToScrollComplementPanel(false);
408 complementPanel.scrollToCentre(sr, seqOffset);
409 complementPanel.setToScrollComplementPanel(true);
414 * Applies the supplied feature settings descriptor to currently known
415 * features. This supports an 'initial configuration' of feature colouring
416 * based on a preset or user favourite. This may then be modified in the usual
417 * way using the Feature Settings dialogue.
419 * @param featureSettings
422 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
424 // TODO implement for applet