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.NJTree;
24 import jalview.api.AlignExportSettingI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.FeatureRenderer;
27 import jalview.bin.JalviewLite;
28 import jalview.commands.CommandI;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.SearchResults;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceGroup;
34 import jalview.datamodel.SequenceI;
35 import jalview.schemes.ColourSchemeProperty;
36 import jalview.schemes.UserColourScheme;
37 import jalview.structure.CommandListener;
38 import jalview.structure.SelectionSource;
39 import jalview.structure.StructureSelectionManager;
40 import jalview.structure.VamsasSource;
41 import jalview.viewmodel.AlignmentViewport;
45 public class AlignViewport extends AlignmentViewport implements
46 SelectionSource, VamsasSource, CommandListener
48 boolean cursorMode = false;
50 Font font = new Font("SansSerif", Font.PLAIN, 10);
52 boolean validCharWidth = true;
54 NJTree currentTree = null;
56 public jalview.bin.JalviewLite applet;
60 private AnnotationColumnChooser annotationColumnSelectionState;
62 private FeatureRenderer featureRenderer;
64 private AlignExportSettingI exportSettings;
66 public void finalize()
74 public AlignViewport(AlignmentI al, JalviewLite applet)
77 calculator = new jalview.workers.AlignCalcManager();
81 this.setPadGaps(true);
83 this.endRes = al.getWidth() - 1;
85 this.endSeq = al.getHeight() - 1;
88 // get the width and height scaling factors if they were specified
89 String param = applet.getParameter("widthScale");
94 widthScale = new Float(param).floatValue();
98 if (widthScale <= 1.0)
101 .println("Invalid alignment character width scaling factor ("
102 + widthScale + "). Ignoring.");
105 if (JalviewLite.debug)
108 .println("Alignment character width scaling factor is now "
112 param = applet.getParameter("heightScale");
117 heightScale = new Float(param).floatValue();
118 } catch (Exception e)
121 if (heightScale <= 1.0)
124 .println("Invalid alignment character height scaling factor ("
125 + heightScale + "). Ignoring.");
128 if (JalviewLite.debug)
131 .println("Alignment character height scaling factor is now "
138 MAC = new jalview.util.Platform().isAMac();
142 setShowJVSuffix(applet.getDefaultParameter("showFullId",
145 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
146 isShowAnnotation()));
148 showConservation = applet.getDefaultParameter("showConservation",
151 showQuality = applet.getDefaultParameter("showQuality", showQuality);
153 showConsensus = applet.getDefaultParameter("showConsensus",
156 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
157 getShowUnconserved()));
159 setScaleProteinAsCdna(applet.getDefaultParameter(
160 "scaleProteinAsCdna", isScaleProteinAsCdna()));
162 String param = applet.getParameter("upperCase");
165 if (param.equalsIgnoreCase("bold"))
167 setUpperCasebold(true);
170 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
172 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
173 isFollowHighlight()));
174 followSelection = isFollowHighlight();
176 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
179 normaliseSequenceLogo = applet.getDefaultParameter(
180 "normaliseSequenceLogo", applet.getDefaultParameter(
181 "normaliseLogo", normaliseSequenceLogo));
183 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
186 showGroupConservation = applet.getDefaultParameter(
187 "showGroupConservation", showGroupConservation);
189 showConsensusHistogram = applet.getDefaultParameter(
190 "showConsensusHistogram", showConsensusHistogram);
196 String colour = applet.getParameter("defaultColour");
200 colour = applet.getParameter("userDefinedColour");
203 colour = "User Defined";
209 globalColourScheme = ColourSchemeProperty.getColour(alignment,
211 if (globalColourScheme != null)
213 globalColourScheme.setConsensus(hconsensus);
217 if (applet.getParameter("userDefinedColour") != null)
219 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
220 .getParameter("userDefinedColour"));
223 initAutoAnnotation();
228 * get the consensus sequence as displayed under the PID consensus annotation
231 * @return consensus sequence as a new sequence object
233 public SequenceI getConsensusSeq()
235 if (consensus == null)
237 updateConsensus(null);
239 if (consensus == null)
243 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
244 for (int i = 0; i < consensus.annotations.length; i++)
246 if (consensus.annotations[i] != null)
248 if (consensus.annotations[i].description.charAt(0) == '[')
250 seqs.append(consensus.annotations[i].description.charAt(1));
254 seqs.append(consensus.annotations[i].displayCharacter);
258 SequenceI sq = new Sequence("Consensus", seqs.toString());
259 sq.setDescription("Percentage Identity Consensus "
260 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
264 java.awt.Frame nullFrame;
266 protected FeatureSettings featureSettings = null;
268 private float heightScale = 1, widthScale = 1;
270 public void setFont(Font f)
273 if (nullFrame == null)
275 nullFrame = new java.awt.Frame();
276 nullFrame.addNotify();
279 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
280 setCharHeight((int) (heightScale * fm.getHeight()));
281 setCharWidth((int) (widthScale * fm.charWidth('M')));
283 if (isUpperCasebold())
285 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
286 fm = nullFrame.getGraphics().getFontMetrics(f2);
287 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
291 public Font getFont()
297 public void resetSeqLimits(int height)
299 setEndSeq(height / getCharHeight());
302 public void setCurrentTree(NJTree tree)
307 public NJTree getCurrentTree()
313 boolean centreColumnLabels;
315 public boolean getCentreColumnLabels()
317 return centreColumnLabels;
320 public boolean followSelection = true;
323 * @return true if view selection should always follow the selections
324 * broadcast by other selection sources
326 public boolean getFollowSelection()
328 return followSelection;
331 public void sendSelection()
333 getStructureSelectionManager().sendSelection(
334 new SequenceGroup(getSelectionGroup()),
335 new ColumnSelection(getColumnSelection()), this);
339 * Returns an instance of the StructureSelectionManager scoped to this applet
345 public StructureSelectionManager getStructureSelectionManager()
347 return jalview.structure.StructureSelectionManager
348 .getStructureSelectionManager(applet);
352 * synthesize a column selection if none exists so it covers the given
353 * selection group. if wholewidth is false, no column selection is made if the
354 * selection group covers the whole alignment width.
359 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
363 && (sgs = sg.getStartRes()) >= 0
364 && sg.getStartRes() <= (sge = sg.getEndRes())
365 && (colSel == null || colSel.getSelected() == null || colSel
366 .getSelected().size() == 0))
368 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
375 colSel = new ColumnSelection();
377 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
379 colSel.addElement(cspos);
384 public boolean isNormaliseSequenceLogo()
386 return normaliseSequenceLogo;
389 public void setNormaliseSequenceLogo(boolean state)
391 normaliseSequenceLogo = state;
396 * @return true if alignment characters should be displayed
398 public boolean isValidCharWidth()
400 return validCharWidth;
403 public AnnotationColumnChooser getAnnotationColumnSelectionState()
405 return annotationColumnSelectionState;
408 public void setAnnotationColumnSelectionState(
409 AnnotationColumnChooser annotationColumnSelectionState)
411 this.annotationColumnSelectionState = annotationColumnSelectionState;
415 public void mirrorCommand(CommandI command, boolean undo,
416 StructureSelectionManager ssm, VamsasSource source)
418 // TODO refactor so this can be pulled up to superclass or controller
420 * Do nothing unless we are a 'complement' of the source. May replace this
421 * with direct calls not via SSM.
423 if (source instanceof AlignViewportI
424 && ((AlignViewportI) source).getCodingComplement() == this)
433 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
435 if (mappedCommand != null)
437 mappedCommand.doCommand(null);
438 firePropertyChange("alignment", null, getAlignment().getSequences());
440 // ap.scalePanelHolder.repaint();
446 public VamsasSource getVamsasSource()
452 * If this viewport has a (Protein/cDNA) complement, then scroll the
453 * complementary alignment to match this one.
455 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
457 if (complementPanel == null)
463 * Populate a SearchResults object with the mapped location to scroll to. If
464 * there is no complement, or it is not following highlights, or no mapping
465 * is found, the result will be empty.
467 SearchResults sr = new SearchResults();
468 int seqOffset = findComplementScrollTarget(sr);
471 complementPanel.setFollowingComplementScroll(true);
472 complementPanel.scrollToCentre(sr, seqOffset);