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;
46 public class AlignViewport extends AlignmentViewport implements
49 boolean cursorMode = false;
51 Font font = new Font("SansSerif", Font.PLAIN, 10);
53 boolean validCharWidth = true;
55 TreeModel currentTree = null;
57 public jalview.bin.JalviewLite applet;
61 private AnnotationColumnChooser annotationColumnSelectionState;
64 public void finalize()
72 public AlignViewport(AlignmentI al, JalviewLite applet)
75 calculator = new jalview.workers.AlignCalcManager();
79 this.setPadGaps(true);
83 // get the width and height scaling factors if they were specified
84 String param = applet.getParameter("widthScale");
89 widthScale = new Float(param).floatValue();
93 if (widthScale <= 1.0)
96 .println("Invalid alignment character width scaling factor ("
97 + widthScale + "). Ignoring.");
100 if (JalviewLite.debug)
103 .println("Alignment character width scaling factor is now "
107 param = applet.getParameter("heightScale");
112 heightScale = new Float(param).floatValue();
113 } catch (Exception e)
116 if (heightScale <= 1.0)
119 .println("Invalid alignment character height scaling factor ("
120 + heightScale + "). Ignoring.");
123 if (JalviewLite.debug)
126 .println("Alignment character height scaling factor is now "
133 MAC = new jalview.util.Platform().isAMac();
137 setShowJVSuffix(applet.getDefaultParameter("showFullId",
140 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
141 isShowAnnotation()));
143 showConservation = applet.getDefaultParameter("showConservation",
146 showQuality = applet.getDefaultParameter("showQuality", showQuality);
148 showConsensus = applet.getDefaultParameter("showConsensus",
151 showOccupancy = applet.getDefaultParameter("showOccupancy",
154 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
155 getShowUnconserved()));
157 setScaleProteinAsCdna(applet.getDefaultParameter(
158 "scaleProteinAsCdna", isScaleProteinAsCdna()));
160 String param = applet.getParameter("upperCase");
163 if (param.equalsIgnoreCase("bold"))
165 setUpperCasebold(true);
168 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
170 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
171 isFollowHighlight()));
172 followSelection = isFollowHighlight();
174 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
177 normaliseSequenceLogo = applet.getDefaultParameter(
178 "normaliseSequenceLogo", applet.getDefaultParameter(
179 "normaliseLogo", normaliseSequenceLogo));
181 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
184 showGroupConservation = applet.getDefaultParameter(
185 "showGroupConservation", showGroupConservation);
187 showConsensusHistogram = applet.getDefaultParameter(
188 "showConsensusHistogram", showConsensusHistogram);
194 String colour = al.isNucleotide() ? applet
195 .getParameter("defaultColourNuc") : applet
196 .getParameter("defaultColourProt");
199 colour = applet.getParameter("defaultColour");
203 colour = applet.getParameter("userDefinedColour");
206 colour = "User Defined";
212 residueShading = new ResidueShader(
213 ColourSchemeProperty.getColourScheme(alignment, colour));
214 if (residueShading != null)
216 residueShading.setConsensus(hconsensus);
220 if (applet.getParameter("userDefinedColour") != null)
222 residueShading = new ResidueShader(
223 new UserColourScheme(
224 applet.getParameter("userDefinedColour")));
227 initAutoAnnotation();
232 * get the consensus sequence as displayed under the PID consensus annotation
235 * @return consensus sequence as a new sequence object
237 public SequenceI getConsensusSeq()
239 if (consensus == null)
241 updateConsensus(null);
243 if (consensus == null)
247 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
248 for (int i = 0; i < consensus.annotations.length; i++)
250 if (consensus.annotations[i] != null)
252 if (consensus.annotations[i].description.charAt(0) == '[')
254 seqs.append(consensus.annotations[i].description.charAt(1));
258 seqs.append(consensus.annotations[i].displayCharacter);
262 SequenceI sq = new Sequence("Consensus", seqs.toString());
263 sq.setDescription("Percentage Identity Consensus "
264 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
268 java.awt.Frame nullFrame;
270 protected FeatureSettings featureSettings = null;
272 private float heightScale = 1, widthScale = 1;
274 public void setFont(Font f)
277 if (nullFrame == null)
279 nullFrame = new java.awt.Frame();
280 nullFrame.addNotify();
283 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
284 setCharHeight((int) (heightScale * fm.getHeight()));
285 setCharWidth((int) (widthScale * fm.charWidth('M')));
287 if (isUpperCasebold())
289 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
290 fm = nullFrame.getGraphics().getFontMetrics(f2);
291 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
295 public Font getFont()
300 public void resetSeqLimits(int height)
302 ranges.setEndSeq(height / getCharHeight());
305 public void setCurrentTree(TreeModel tree)
310 public TreeModel getCurrentTree()
315 boolean centreColumnLabels;
317 public boolean getCentreColumnLabels()
319 return centreColumnLabels;
322 public boolean followSelection = true;
325 * @return true if view selection should always follow the selections
326 * broadcast by other selection sources
328 public boolean getFollowSelection()
330 return followSelection;
334 public void sendSelection()
336 getStructureSelectionManager().sendSelection(
337 new SequenceGroup(getSelectionGroup()),
338 new ColumnSelection(getColumnSelection()),
339 new HiddenColumns(getAlignment().getHiddenColumns()), this);
343 * Returns an instance of the StructureSelectionManager scoped to this applet
349 public StructureSelectionManager getStructureSelectionManager()
351 return jalview.structure.StructureSelectionManager
352 .getStructureSelectionManager(applet);
356 public boolean isNormaliseSequenceLogo()
358 return normaliseSequenceLogo;
361 public void setNormaliseSequenceLogo(boolean state)
363 normaliseSequenceLogo = state;
368 * @return true if alignment characters should be displayed
371 public boolean isValidCharWidth()
373 return validCharWidth;
376 public AnnotationColumnChooser getAnnotationColumnSelectionState()
378 return annotationColumnSelectionState;
381 public void setAnnotationColumnSelectionState(
382 AnnotationColumnChooser annotationColumnSelectionState)
384 this.annotationColumnSelectionState = annotationColumnSelectionState;
388 public void mirrorCommand(CommandI command, boolean undo,
389 StructureSelectionManager ssm, VamsasSource source)
391 // TODO refactor so this can be pulled up to superclass or controller
393 * Do nothing unless we are a 'complement' of the source. May replace this
394 * with direct calls not via SSM.
396 if (source instanceof AlignViewportI
397 && ((AlignViewportI) source).getCodingComplement() == this)
406 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
408 if (mappedCommand != null)
410 mappedCommand.doCommand(null);
411 firePropertyChange("alignment", null, getAlignment().getSequences());
413 // ap.scalePanelHolder.repaint();
419 public VamsasSource getVamsasSource()
425 * If this viewport has a (Protein/cDNA) complement, then scroll the
426 * complementary alignment to match this one.
428 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
430 if (complementPanel == null)
436 * Populate a SearchResults object with the mapped location to scroll to. If
437 * there is no complement, or it is not following highlights, or no mapping
438 * is found, the result will be empty.
440 SearchResultsI sr = new SearchResults();
441 int seqOffset = findComplementScrollTarget(sr);
444 complementPanel.setFollowingComplementScroll(true);
445 complementPanel.scrollToCentre(sr, seqOffset);
450 * Applies the supplied feature settings descriptor to currently known
451 * features. This supports an 'initial configuration' of feature colouring
452 * based on a preset or user favourite. This may then be modified in the usual
453 * way using the Feature Settings dialogue.
455 * @param featureSettings
458 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
460 // TODO implement for applet