2 * Copyright (C) $$Year-Rel$$ The Jalview Authors
3 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
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.api.AlignViewportI;
24 import jalview.api.FeatureSettingsModelI;
25 import jalview.bin.JalviewLite;
26 import jalview.commands.CommandI;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.HiddenColumns;
30 import jalview.datamodel.SearchResults;
31 import jalview.datamodel.SearchResultsI;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.renderer.ResidueShader;
34 import jalview.schemes.ColourSchemeProperty;
35 import jalview.schemes.UserColourScheme;
36 import jalview.structure.SelectionSource;
37 import jalview.structure.StructureSelectionManager;
38 import jalview.structure.VamsasSource;
39 import jalview.viewmodel.AlignmentViewport;
42 import java.awt.FontMetrics;
44 public class AlignViewport extends AlignmentViewport
45 implements SelectionSource
47 boolean cursorMode = false;
49 Font font = new Font("SansSerif", Font.PLAIN, 10);
51 boolean validCharWidth = true;
53 public jalview.bin.JalviewLite applet;
55 private AnnotationColumnChooser annotationColumnSelectionState;
57 java.awt.Frame nullFrame;
59 protected FeatureSettings featureSettings = null;
61 private float heightScale = 1, widthScale = 1;
63 public AlignViewport(AlignmentI al, JalviewLite applet)
66 calculator = new jalview.workers.AlignCalcManager2();
70 this.setPadGaps(true);
74 // get the width and height scaling factors if they were specified
75 String param = applet.getParameter("widthScale");
80 widthScale = Float.valueOf(param).floatValue();
84 if (widthScale <= 1.0)
87 "Invalid alignment character width scaling factor ("
88 + widthScale + "). Ignoring.");
91 if (JalviewLite.debug)
94 "Alignment character width scaling factor is now "
98 param = applet.getParameter("heightScale");
103 heightScale = Float.valueOf(param).floatValue();
104 } catch (Exception e)
107 if (heightScale <= 1.0)
110 "Invalid alignment character height scaling factor ("
111 + heightScale + "). Ignoring.");
114 if (JalviewLite.debug)
117 "Alignment character height scaling factor is now "
127 applet.getDefaultParameter("showFullId", getShowJVSuffix()));
129 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
130 isShowAnnotation()));
132 showConservation = applet.getDefaultParameter("showConservation",
135 showQuality = applet.getDefaultParameter("showQuality", showQuality);
137 showConsensus = applet.getDefaultParameter("showConsensus",
140 showOccupancy = applet.getDefaultParameter("showOccupancy",
143 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
144 getShowUnconserved()));
146 setScaleProteinAsCdna(applet.getDefaultParameter("scaleProteinAsCdna",
147 isScaleProteinAsCdna()));
149 String param = applet.getParameter("upperCase");
152 if (param.equalsIgnoreCase("bold"))
154 setUpperCasebold(true);
157 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
159 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
160 isFollowHighlight()));
161 followSelection = isFollowHighlight();
163 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
166 normaliseSequenceLogo = applet.getDefaultParameter(
167 "normaliseSequenceLogo", applet.getDefaultParameter(
168 "normaliseLogo", normaliseSequenceLogo));
170 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
173 showGroupConservation = applet.getDefaultParameter(
174 "showGroupConservation", showGroupConservation);
176 showConsensusHistogram = applet.getDefaultParameter(
177 "showConsensusHistogram", showConsensusHistogram);
183 String colour = al.isNucleotide()
184 ? applet.getParameter("defaultColourNuc")
185 : applet.getParameter("defaultColourProt");
188 colour = applet.getParameter("defaultColour");
192 colour = applet.getParameter("userDefinedColour");
195 colour = "User Defined";
201 residueShading = new ResidueShader(ColourSchemeProperty
202 .getColourScheme(this, alignment, colour));
203 if (residueShading != null)
205 residueShading.setConsensus(consensusProfiles);
209 if (applet.getParameter("userDefinedColour") != null)
211 residueShading = new ResidueShader(new UserColourScheme(
212 applet.getParameter("userDefinedColour")));
215 initAutoAnnotation();
222 public void setFont(Font f, boolean setGrid)
225 if (nullFrame == null)
227 nullFrame = new java.awt.Frame();
228 nullFrame.addNotify();
233 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
234 setCharHeight((int) (heightScale * fm.getHeight()));
235 setCharWidth((int) (widthScale * fm.charWidth('M')));
238 if (isUpperCasebold())
240 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
241 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
243 (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
247 public Font getFont()
252 public void resetSeqLimits(int height)
254 ranges.setEndSeq(height / getCharHeight() - 1); // BH 2019.04.18
257 boolean centreColumnLabels;
259 public boolean getCentreColumnLabels()
261 return centreColumnLabels;
264 public boolean followSelection = true;
267 * @return true if view selection should always follow the selections
268 * broadcast by other selection sources
270 public boolean getFollowSelection()
272 return followSelection;
276 public void sendSelection()
278 getStructureSelectionManager().sendSelection(
279 new SequenceGroup(getSelectionGroup()),
280 new ColumnSelection(getColumnSelection()),
281 new HiddenColumns(getAlignment().getHiddenColumns()), this);
285 * Returns an instance of the StructureSelectionManager scoped to this applet
291 public StructureSelectionManager getStructureSelectionManager()
293 return jalview.structure.StructureSelectionManager
294 .getStructureSelectionManager(applet);
299 * @return true if alignment characters should be displayed
302 public boolean isValidCharWidth()
304 return validCharWidth;
307 public AnnotationColumnChooser getAnnotationColumnSelectionState()
309 return annotationColumnSelectionState;
312 public void setAnnotationColumnSelectionState(
313 AnnotationColumnChooser annotationColumnSelectionState)
315 this.annotationColumnSelectionState = annotationColumnSelectionState;
319 public void mirrorCommand(CommandI command, boolean undo,
320 StructureSelectionManager ssm, VamsasSource source)
322 // TODO refactor so this can be pulled up to superclass or controller
324 * Do nothing unless we are a 'complement' of the source. May replace this
325 * with direct calls not via SSM.
327 if (source instanceof AlignViewportI
328 && ((AlignViewportI) source).getCodingComplement() == this)
337 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
339 if (mappedCommand != null)
341 mappedCommand.doCommand(null);
344 // ap.scalePanelHolder.repaint();
350 public VamsasSource getVamsasSource()
356 * If this viewport has a (Protein/cDNA) complement, then scroll the
357 * complementary alignment to match this one.
359 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
361 if (complementPanel == null)
367 * Populate a SearchResults object with the mapped location to scroll to. If
368 * there is no complement, or it is not following highlights, or no mapping
369 * is found, the result will be empty.
371 SearchResultsI sr = new SearchResults();
372 int seqOffset = findComplementScrollTarget(sr);
375 complementPanel.setToScrollComplementPanel(false);
376 complementPanel.scrollToCentre(sr, seqOffset);
377 complementPanel.setToScrollComplementPanel(true);
382 * Applies the supplied feature settings descriptor to currently known
383 * features. This supports an 'initial configuration' of feature colouring
384 * based on a preset or user favourite. This may then be modified in the usual
385 * way using the Feature Settings dialogue. NOT IMPLEMENTED FOR APPLET
387 * @param featureSettings
390 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
392 // TODO implement for applet
396 * Merges the supplied feature settings descriptor with existing feature
397 * styles. This supports an 'initial configuration' of feature colouring based
398 * on a preset or user favourite. This may then be modified in the usual way
399 * using the Feature Settings dialogue. NOT IMPLEMENTED FOR APPLET
401 * @param featureSettings
404 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
406 // TODO Auto-generated method stub