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.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 implements
50 boolean cursorMode = false;
52 Font font = new Font("SansSerif", Font.PLAIN, 10);
54 boolean validCharWidth = true;
56 TreeModel currentTree = null;
58 public jalview.bin.JalviewLite applet;
62 private AnnotationColumnChooser annotationColumnSelectionState;
65 public void finalize()
73 public AlignViewport(AlignmentI al, JalviewLite applet)
76 calculator = new jalview.workers.AlignCalcManager();
80 this.setPadGaps(true);
84 // get the width and height scaling factors if they were specified
85 String param = applet.getParameter("widthScale");
90 widthScale = new Float(param).floatValue();
94 if (widthScale <= 1.0)
97 .println("Invalid alignment character width scaling factor ("
98 + widthScale + "). Ignoring.");
101 if (JalviewLite.debug)
104 .println("Alignment character width scaling factor is now "
108 param = applet.getParameter("heightScale");
113 heightScale = new Float(param).floatValue();
114 } catch (Exception e)
117 if (heightScale <= 1.0)
120 .println("Invalid alignment character height scaling factor ("
121 + heightScale + "). Ignoring.");
124 if (JalviewLite.debug)
127 .println("Alignment character height scaling factor is now "
134 MAC = new jalview.util.Platform().isAMac();
138 setShowJVSuffix(applet.getDefaultParameter("showFullId",
141 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
142 isShowAnnotation()));
144 showConservation = applet.getDefaultParameter("showConservation",
147 showQuality = applet.getDefaultParameter("showQuality", showQuality);
149 showConsensus = applet.getDefaultParameter("showConsensus",
152 showOccupancy = applet.getDefaultParameter("showOccupancy",
155 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
156 getShowUnconserved()));
158 setScaleProteinAsCdna(applet.getDefaultParameter(
159 "scaleProteinAsCdna", isScaleProteinAsCdna()));
161 String param = applet.getParameter("upperCase");
164 if (param.equalsIgnoreCase("bold"))
166 setUpperCasebold(true);
169 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
171 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
172 isFollowHighlight()));
173 followSelection = isFollowHighlight();
175 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
178 normaliseSequenceLogo = applet.getDefaultParameter(
179 "normaliseSequenceLogo", applet.getDefaultParameter(
180 "normaliseLogo", normaliseSequenceLogo));
182 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
185 showGroupConservation = applet.getDefaultParameter(
186 "showGroupConservation", showGroupConservation);
188 showConsensusHistogram = applet.getDefaultParameter(
189 "showConsensusHistogram", showConsensusHistogram);
195 String colour = al.isNucleotide() ? applet
196 .getParameter("defaultColourNuc") : applet
197 .getParameter("defaultColourProt");
200 colour = applet.getParameter("defaultColour");
204 colour = applet.getParameter("userDefinedColour");
207 colour = "User Defined";
213 residueShading = new ResidueShader(
214 ColourSchemeProperty.getColourScheme(alignment, colour));
215 if (residueShading != null)
217 residueShading.setConsensus(hconsensus);
221 if (applet.getParameter("userDefinedColour") != null)
223 residueShading = new ResidueShader(
224 new UserColourScheme(
225 applet.getParameter("userDefinedColour")));
228 initAutoAnnotation();
233 * get the consensus sequence as displayed under the PID consensus annotation
236 * @return consensus sequence as a new sequence object
238 public SequenceI getConsensusSeq()
240 if (consensus == null)
242 updateConsensus(null);
244 if (consensus == null)
248 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
249 for (int i = 0; i < consensus.annotations.length; i++)
251 if (consensus.annotations[i] != null)
253 if (consensus.annotations[i].description.charAt(0) == '[')
255 seqs.append(consensus.annotations[i].description.charAt(1));
259 seqs.append(consensus.annotations[i].displayCharacter);
263 SequenceI sq = new Sequence("Consensus", seqs.toString());
264 sq.setDescription("Percentage Identity Consensus "
265 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
269 java.awt.Frame nullFrame;
271 protected FeatureSettings featureSettings = null;
273 private float heightScale = 1, widthScale = 1;
279 public void setFont(Font f, boolean setGrid)
282 if (nullFrame == null)
284 nullFrame = new java.awt.Frame();
285 nullFrame.addNotify();
290 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
291 setCharHeight((int) (heightScale * fm.getHeight()));
292 setCharWidth((int) (widthScale * fm.charWidth('M')));
295 if (isUpperCasebold())
297 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
298 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
299 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
303 public Font getFont()
308 public void resetSeqLimits(int height)
310 ranges.setEndSeq(height / getCharHeight());
313 public void setCurrentTree(TreeModel tree)
318 public TreeModel getCurrentTree()
323 boolean centreColumnLabels;
325 public boolean getCentreColumnLabels()
327 return centreColumnLabels;
330 public boolean followSelection = true;
333 * @return true if view selection should always follow the selections
334 * broadcast by other selection sources
336 public boolean getFollowSelection()
338 return followSelection;
342 public void sendSelection()
344 getStructureSelectionManager().sendSelection(
345 new SequenceGroup(getSelectionGroup()),
346 new ColumnSelection(getColumnSelection()),
347 new HiddenColumns(getAlignment().getHiddenColumns()), this);
351 * Returns an instance of the StructureSelectionManager scoped to this applet
357 public StructureSelectionManager getStructureSelectionManager()
359 return jalview.structure.StructureSelectionManager
360 .getStructureSelectionManager(applet);
364 public boolean isNormaliseSequenceLogo()
366 return normaliseSequenceLogo;
369 public void setNormaliseSequenceLogo(boolean state)
371 normaliseSequenceLogo = state;
376 * @return true if alignment characters should be displayed
379 public boolean isValidCharWidth()
381 return validCharWidth;
384 public AnnotationColumnChooser getAnnotationColumnSelectionState()
386 return annotationColumnSelectionState;
389 public void setAnnotationColumnSelectionState(
390 AnnotationColumnChooser annotationColumnSelectionState)
392 this.annotationColumnSelectionState = annotationColumnSelectionState;
396 public void mirrorCommand(CommandI command, boolean undo,
397 StructureSelectionManager ssm, VamsasSource source)
399 // TODO refactor so this can be pulled up to superclass or controller
401 * Do nothing unless we are a 'complement' of the source. May replace this
402 * with direct calls not via SSM.
404 if (source instanceof AlignViewportI
405 && ((AlignViewportI) source).getCodingComplement() == this)
414 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
416 if (mappedCommand != null)
418 mappedCommand.doCommand(null);
419 firePropertyChange("alignment", null, getAlignment().getSequences());
421 // ap.scalePanelHolder.repaint();
427 public VamsasSource getVamsasSource()
433 * If this viewport has a (Protein/cDNA) complement, then scroll the
434 * complementary alignment to match this one.
436 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
438 if (complementPanel == null)
444 * Populate a SearchResults object with the mapped location to scroll to. If
445 * there is no complement, or it is not following highlights, or no mapping
446 * is found, the result will be empty.
448 SearchResultsI sr = new SearchResults();
449 int seqOffset = findComplementScrollTarget(sr);
452 complementPanel.setToScrollComplementPanel(false);
453 complementPanel.scrollToCentre(sr, seqOffset);
454 complementPanel.setToScrollComplementPanel(true);
459 * Applies the supplied feature settings descriptor to currently known
460 * features. This supports an 'initial configuration' of feature colouring
461 * based on a preset or user favourite. This may then be modified in the usual
462 * way using the Feature Settings dialogue.
464 * @param featureSettings
467 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
469 // TODO implement for applet