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.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 public AlignViewport(AlignmentI al, JalviewLite applet)
62 calculator = new jalview.workers.AlignCalcManager();
66 this.setPadGaps(true);
70 // get the width and height scaling factors if they were specified
71 String param = applet.getParameter("widthScale");
76 widthScale = Float.valueOf(param).floatValue();
80 if (widthScale <= 1.0)
83 "Invalid alignment character width scaling factor ("
84 + widthScale + "). Ignoring.");
87 if (JalviewLite.debug)
90 "Alignment character width scaling factor is now "
94 param = applet.getParameter("heightScale");
99 heightScale = Float.valueOf(param).floatValue();
100 } catch (Exception e)
103 if (heightScale <= 1.0)
106 "Invalid alignment character height scaling factor ("
107 + heightScale + "). Ignoring.");
110 if (JalviewLite.debug)
113 "Alignment character height scaling factor is now "
120 MAC = new jalview.util.Platform().isAMac();
125 applet.getDefaultParameter("showFullId", getShowJVSuffix()));
127 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
128 isShowAnnotation()));
130 showConservation = applet.getDefaultParameter("showConservation",
133 showQuality = applet.getDefaultParameter("showQuality", showQuality);
135 showConsensus = applet.getDefaultParameter("showConsensus",
138 showOccupancy = applet.getDefaultParameter("showOccupancy",
141 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
142 getShowUnconserved()));
144 setScaleProteinAsCdna(applet.getDefaultParameter("scaleProteinAsCdna",
145 isScaleProteinAsCdna()));
147 String param = applet.getParameter("upperCase");
150 if (param.equalsIgnoreCase("bold"))
152 setUpperCasebold(true);
155 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
157 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
158 isFollowHighlight()));
159 followSelection = isFollowHighlight();
161 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
164 normaliseSequenceLogo = applet.getDefaultParameter(
165 "normaliseSequenceLogo", applet.getDefaultParameter(
166 "normaliseLogo", normaliseSequenceLogo));
168 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
171 showGroupConservation = applet.getDefaultParameter(
172 "showGroupConservation", showGroupConservation);
174 showConsensusHistogram = applet.getDefaultParameter(
175 "showConsensusHistogram", showConsensusHistogram);
181 String colour = al.isNucleotide()
182 ? applet.getParameter("defaultColourNuc")
183 : applet.getParameter("defaultColourProt");
186 colour = applet.getParameter("defaultColour");
190 colour = applet.getParameter("userDefinedColour");
193 colour = "User Defined";
199 residueShading = new ResidueShader(
200 ColourSchemeProperty.getColourScheme(this, alignment,
202 if (residueShading != null)
204 residueShading.setConsensus(hconsensus);
208 if (applet.getParameter("userDefinedColour") != null)
210 residueShading = new ResidueShader(new UserColourScheme(
211 applet.getParameter("userDefinedColour")));
214 initAutoAnnotation();
218 java.awt.Frame nullFrame;
220 protected FeatureSettings featureSettings = null;
222 private float heightScale = 1, widthScale = 1;
228 public void setFont(Font f, boolean setGrid)
231 if (nullFrame == null)
233 nullFrame = new java.awt.Frame();
234 nullFrame.addNotify();
239 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
240 setCharHeight((int) (heightScale * fm.getHeight()));
241 setCharWidth((int) (widthScale * fm.charWidth('M')));
244 if (isUpperCasebold())
246 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
247 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
249 (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
253 public Font getFont()
258 public void resetSeqLimits(int height)
260 ranges.setEndSeq(height / getCharHeight());
263 boolean centreColumnLabels;
265 public boolean getCentreColumnLabels()
267 return centreColumnLabels;
270 public boolean followSelection = true;
273 * @return true if view selection should always follow the selections
274 * broadcast by other selection sources
276 public boolean getFollowSelection()
278 return followSelection;
282 public void sendSelection()
284 getStructureSelectionManager().sendSelection(
285 new SequenceGroup(getSelectionGroup()),
286 new ColumnSelection(getColumnSelection()),
287 new HiddenColumns(getAlignment().getHiddenColumns()), this);
291 * Returns an instance of the StructureSelectionManager scoped to this applet
297 public StructureSelectionManager getStructureSelectionManager()
299 return jalview.structure.StructureSelectionManager
300 .getStructureSelectionManager(applet);
304 public boolean isNormaliseSequenceLogo()
306 return normaliseSequenceLogo;
309 public void setNormaliseSequenceLogo(boolean state)
311 normaliseSequenceLogo = state;
316 * @return true if alignment characters should be displayed
319 public boolean isValidCharWidth()
321 return validCharWidth;
324 public AnnotationColumnChooser getAnnotationColumnSelectionState()
326 return annotationColumnSelectionState;
329 public void setAnnotationColumnSelectionState(
330 AnnotationColumnChooser annotationColumnSelectionState)
332 this.annotationColumnSelectionState = annotationColumnSelectionState;
336 public void mirrorCommand(CommandI command, boolean undo,
337 StructureSelectionManager ssm, VamsasSource source)
339 // TODO refactor so this can be pulled up to superclass or controller
341 * Do nothing unless we are a 'complement' of the source. May replace this
342 * with direct calls not via SSM.
344 if (source instanceof AlignViewportI
345 && ((AlignViewportI) source).getCodingComplement() == this)
354 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
356 if (mappedCommand != null)
358 mappedCommand.doCommand(null);
359 firePropertyChange("alignment", null, getAlignment().getSequences());
361 // ap.scalePanelHolder.repaint();
367 public VamsasSource getVamsasSource()
373 * If this viewport has a (Protein/cDNA) complement, then scroll the
374 * complementary alignment to match this one.
376 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
378 if (complementPanel == null)
384 * Populate a SearchResults object with the mapped location to scroll to. If
385 * there is no complement, or it is not following highlights, or no mapping
386 * is found, the result will be empty.
388 SearchResultsI sr = new SearchResults();
389 int seqOffset = findComplementScrollTarget(sr);
392 complementPanel.setToScrollComplementPanel(false);
393 complementPanel.scrollToCentre(sr, seqOffset);
394 complementPanel.setToScrollComplementPanel(true);
399 * Applies the supplied feature settings descriptor to currently known
400 * features. This supports an 'initial configuration' of feature colouring
401 * based on a preset or user favourite. This may then be modified in the usual
402 * way using the Feature Settings dialogue.
404 * @param featureSettings
407 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
409 // TODO implement for applet