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.Annotation;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.HiddenColumns;
31 import jalview.datamodel.SearchResults;
32 import jalview.datamodel.SearchResultsI;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
36 import jalview.renderer.ResidueShader;
37 import jalview.schemes.ColourSchemeProperty;
38 import jalview.schemes.UserColourScheme;
39 import jalview.structure.SelectionSource;
40 import jalview.structure.StructureSelectionManager;
41 import jalview.structure.VamsasSource;
42 import jalview.viewmodel.AlignmentViewport;
45 import java.awt.FontMetrics;
47 public class AlignViewport extends AlignmentViewport
48 implements SelectionSource
50 boolean cursorMode = false;
52 Font font = new Font("SansSerif", Font.PLAIN, 10);
54 boolean validCharWidth = true;
56 public jalview.bin.JalviewLite applet;
60 private AnnotationColumnChooser annotationColumnSelectionState;
62 public AlignViewport(AlignmentI al, JalviewLite applet)
65 calculator = new jalview.workers.AlignCalcManager();
69 this.setPadGaps(true);
73 // get the width and height scaling factors if they were specified
74 String param = applet.getParameter("widthScale");
79 widthScale = new Float(param).floatValue();
83 if (widthScale <= 1.0)
86 "Invalid alignment character width scaling factor ("
87 + widthScale + "). Ignoring.");
90 if (JalviewLite.debug)
93 "Alignment character width scaling factor is now "
97 param = applet.getParameter("heightScale");
102 heightScale = new Float(param).floatValue();
103 } catch (Exception e)
106 if (heightScale <= 1.0)
109 "Invalid alignment character height scaling factor ("
110 + heightScale + "). Ignoring.");
113 if (JalviewLite.debug)
116 "Alignment character height scaling factor is now "
123 MAC = new jalview.util.Platform().isAMac();
128 applet.getDefaultParameter("showFullId", getShowJVSuffix()));
130 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
131 isShowAnnotation()));
133 showConservation = applet.getDefaultParameter("showConservation",
136 showQuality = applet.getDefaultParameter("showQuality", showQuality);
138 showConsensus = applet.getDefaultParameter("showConsensus",
141 showOccupancy = applet.getDefaultParameter("showOccupancy",
144 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
145 getShowUnconserved()));
147 setScaleProteinAsCdna(applet.getDefaultParameter("scaleProteinAsCdna",
148 isScaleProteinAsCdna()));
150 String param = applet.getParameter("upperCase");
153 if (param.equalsIgnoreCase("bold"))
155 setUpperCasebold(true);
158 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
160 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
161 isFollowHighlight()));
162 followSelection = isFollowHighlight();
164 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
167 normaliseSequenceLogo = applet.getDefaultParameter(
168 "normaliseSequenceLogo", applet.getDefaultParameter(
169 "normaliseLogo", normaliseSequenceLogo));
171 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
174 showGroupConservation = applet.getDefaultParameter(
175 "showGroupConservation", showGroupConservation);
177 showConsensusHistogram = applet.getDefaultParameter(
178 "showConsensusHistogram", showConsensusHistogram);
184 String colour = al.isNucleotide()
185 ? applet.getParameter("defaultColourNuc")
186 : applet.getParameter("defaultColourProt");
189 colour = applet.getParameter("defaultColour");
193 colour = applet.getParameter("userDefinedColour");
196 colour = "User Defined";
202 residueShading = new ResidueShader(
203 ColourSchemeProperty.getColourScheme(alignment, colour));
204 if (residueShading != null)
206 residueShading.setConsensus(hconsensus);
210 if (applet.getParameter("userDefinedColour") != null)
212 residueShading = new ResidueShader(new UserColourScheme(
213 applet.getParameter("userDefinedColour")));
216 initAutoAnnotation();
220 java.awt.Frame nullFrame;
222 protected FeatureSettings featureSettings = null;
224 private float heightScale = 1, widthScale = 1;
230 public void setFont(Font f, boolean setGrid)
233 if (nullFrame == null)
235 nullFrame = new java.awt.Frame();
236 nullFrame.addNotify();
241 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
242 setCharHeight((int) (heightScale * fm.getHeight()));
243 setCharWidth((int) (widthScale * fm.charWidth('M')));
246 if (isUpperCasebold())
248 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
249 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
251 (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
255 public Font getFont()
260 public void resetSeqLimits(int height)
262 ranges.setEndSeq(height / getCharHeight());
265 boolean centreColumnLabels;
267 public boolean getCentreColumnLabels()
269 return centreColumnLabels;
272 public boolean followSelection = true;
275 * @return true if view selection should always follow the selections
276 * broadcast by other selection sources
278 public boolean getFollowSelection()
280 return followSelection;
284 public void sendSelection()
286 getStructureSelectionManager().sendSelection(
287 new SequenceGroup(getSelectionGroup()),
288 new ColumnSelection(getColumnSelection()),
289 new HiddenColumns(getAlignment().getHiddenColumns()), this);
293 * Returns an instance of the StructureSelectionManager scoped to this applet
299 public StructureSelectionManager getStructureSelectionManager()
301 return jalview.structure.StructureSelectionManager
302 .getStructureSelectionManager(applet);
306 public boolean isNormaliseSequenceLogo()
308 return normaliseSequenceLogo;
311 public void setNormaliseSequenceLogo(boolean state)
313 normaliseSequenceLogo = state;
318 * @return true if alignment characters should be displayed
321 public boolean isValidCharWidth()
323 return validCharWidth;
326 public AnnotationColumnChooser getAnnotationColumnSelectionState()
328 return annotationColumnSelectionState;
331 public void setAnnotationColumnSelectionState(
332 AnnotationColumnChooser annotationColumnSelectionState)
334 this.annotationColumnSelectionState = annotationColumnSelectionState;
338 public void mirrorCommand(CommandI command, boolean undo,
339 StructureSelectionManager ssm, VamsasSource source)
341 // TODO refactor so this can be pulled up to superclass or controller
343 * Do nothing unless we are a 'complement' of the source. May replace this
344 * with direct calls not via SSM.
346 if (source instanceof AlignViewportI
347 && ((AlignViewportI) source).getCodingComplement() == this)
356 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
358 if (mappedCommand != null)
360 mappedCommand.doCommand(null);
361 firePropertyChange("alignment", null, getAlignment().getSequences());
363 // ap.scalePanelHolder.repaint();
369 public VamsasSource getVamsasSource()
375 * If this viewport has a (Protein/cDNA) complement, then scroll the
376 * complementary alignment to match this one.
378 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
380 if (complementPanel == null)
386 * Populate a SearchResults object with the mapped location to scroll to. If
387 * there is no complement, or it is not following highlights, or no mapping
388 * is found, the result will be empty.
390 SearchResultsI sr = new SearchResults();
391 int seqOffset = findComplementScrollTarget(sr);
394 complementPanel.setToScrollComplementPanel(false);
395 complementPanel.scrollToCentre(sr, seqOffset);
396 complementPanel.setToScrollComplementPanel(true);
401 * Applies the supplied feature settings descriptor to currently known
402 * features. This supports an 'initial configuration' of feature colouring
403 * based on a preset or user favourite. This may then be modified in the usual
404 * way using the Feature Settings dialogue.
406 * @param featureSettings
409 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
411 // TODO implement for applet