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;
57 private AnnotationColumnChooser annotationColumnSelectionState;
59 java.awt.Frame nullFrame;
61 protected FeatureSettings featureSettings = null;
63 private float heightScale = 1, widthScale = 1;
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 = Float.valueOf(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 = Float.valueOf(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(this, alignment,
208 if (residueShading != null)
210 residueShading.setConsensus(consensusProfiles);
214 if (applet.getParameter("userDefinedColour") != null)
216 residueShading = new ResidueShader(new UserColourScheme(
217 applet.getParameter("userDefinedColour")));
220 initAutoAnnotation();
227 public void setFont(Font f, boolean setGrid)
230 if (nullFrame == null)
232 nullFrame = new java.awt.Frame();
233 nullFrame.addNotify();
238 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
239 setCharHeight((int) (heightScale * fm.getHeight()));
240 setCharWidth((int) (widthScale * fm.charWidth('M')));
243 if (isUpperCasebold())
245 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
246 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
248 (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
252 public Font getFont()
257 public void resetSeqLimits(int height)
259 ranges.setEndSeq(height / getCharHeight());
262 boolean centreColumnLabels;
264 public boolean getCentreColumnLabels()
266 return centreColumnLabels;
269 public boolean followSelection = true;
272 * @return true if view selection should always follow the selections
273 * broadcast by other selection sources
275 public boolean getFollowSelection()
277 return followSelection;
281 public void sendSelection()
283 getStructureSelectionManager().sendSelection(
284 new SequenceGroup(getSelectionGroup()),
285 new ColumnSelection(getColumnSelection()),
286 new HiddenColumns(getAlignment().getHiddenColumns()), this);
290 * Returns an instance of the StructureSelectionManager scoped to this applet
296 public StructureSelectionManager getStructureSelectionManager()
298 return jalview.structure.StructureSelectionManager
299 .getStructureSelectionManager(applet);
304 * @return true if alignment characters should be displayed
307 public boolean isValidCharWidth()
309 return validCharWidth;
312 public AnnotationColumnChooser getAnnotationColumnSelectionState()
314 return annotationColumnSelectionState;
317 public void setAnnotationColumnSelectionState(
318 AnnotationColumnChooser annotationColumnSelectionState)
320 this.annotationColumnSelectionState = annotationColumnSelectionState;
324 public void mirrorCommand(CommandI command, boolean undo,
325 StructureSelectionManager ssm, VamsasSource source)
327 // TODO refactor so this can be pulled up to superclass or controller
329 * Do nothing unless we are a 'complement' of the source. May replace this
330 * with direct calls not via SSM.
332 if (source instanceof AlignViewportI
333 && ((AlignViewportI) source).getCodingComplement() == this)
342 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
344 if (mappedCommand != null)
346 mappedCommand.doCommand(null);
347 firePropertyChange("alignment", null, getAlignment().getSequences());
349 // ap.scalePanelHolder.repaint();
355 public VamsasSource getVamsasSource()
361 * If this viewport has a (Protein/cDNA) complement, then scroll the
362 * complementary alignment to match this one.
364 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
366 if (complementPanel == null)
372 * Populate a SearchResults object with the mapped location to scroll to. If
373 * there is no complement, or it is not following highlights, or no mapping
374 * is found, the result will be empty.
376 SearchResultsI sr = new SearchResults();
377 int seqOffset = findComplementScrollTarget(sr);
380 complementPanel.setToScrollComplementPanel(false);
381 complementPanel.scrollToCentre(sr, seqOffset);
382 complementPanel.setToScrollComplementPanel(true);
387 * Applies the supplied feature settings descriptor to currently known features.
388 * This supports an 'initial configuration' of feature colouring based on a
389 * preset or user favourite. This may then be modified in the usual way using
390 * the Feature Settings dialogue. NOT IMPLEMENTED FOR APPLET
392 * @param featureSettings
395 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
397 // TODO implement for applet
401 * Merges the supplied feature settings descriptor with existing feature styles.
402 * This supports an 'initial configuration' of feature colouring based on a
403 * preset or user favourite. This may then be modified in the usual way using
404 * the Feature Settings dialogue. NOT IMPLEMENTED FOR APPLET
406 * @param featureSettings
409 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
411 // TODO Auto-generated method stub