2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
\r
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3
\r
10 * of the License, or (at your option) any later version.
\r
12 * Jalview is distributed in the hope that it will be useful, but
\r
13 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
15 * PURPOSE. See the GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
\r
21 package jalview.appletgui;
\r
23 import jalview.analysis.NJTree;
\r
24 import jalview.api.AlignViewportI;
\r
25 import jalview.bin.JalviewLite;
\r
26 import jalview.commands.CommandI;
\r
27 import jalview.datamodel.AlignmentI;
\r
28 import jalview.datamodel.ColumnSelection;
\r
29 import jalview.datamodel.SearchResults;
\r
30 import jalview.datamodel.Sequence;
\r
31 import jalview.datamodel.SequenceGroup;
\r
32 import jalview.datamodel.SequenceI;
\r
33 import jalview.schemes.ColourSchemeProperty;
\r
34 import jalview.schemes.UserColourScheme;
\r
35 import jalview.structure.CommandListener;
\r
36 import jalview.structure.SelectionSource;
\r
37 import jalview.structure.StructureSelectionManager;
\r
38 import jalview.structure.VamsasSource;
\r
39 import jalview.util.Platform;
\r
40 import jalview.viewmodel.AlignmentViewport;
\r
41 import jalview.workers.AlignCalcManager;
\r
43 import java.awt.Font;
\r
45 public class AlignViewport extends AlignmentViewport implements
\r
46 SelectionSource, VamsasSource, CommandListener
\r
48 boolean cursorMode = false;
\r
50 Font font = new Font("SansSerif", Font.PLAIN, 10);
\r
52 boolean validCharWidth = true;
\r
54 NJTree currentTree = null;
\r
56 public JalviewLite applet;
\r
58 boolean MAC = false;
\r
60 private AnnotationColumnChooser annotationColumnSelectionState;
\r
62 public void finalize()
\r
70 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
73 calculator = new AlignCalcManager();
\r
74 this.applet = applet;
\r
76 // we always pad gaps
\r
77 this.setPadGaps(true);
\r
79 this.endRes = al.getWidth() - 1;
\r
81 this.endSeq = al.getHeight() - 1;
\r
84 // get the width and height scaling factors if they were specified
\r
85 String param = applet.getParameter("widthScale");
\r
90 widthScale = new Float(param).floatValue();
\r
91 } catch (Exception e)
\r
94 if (widthScale <= 1.0)
\r
97 .println("Invalid alignment character width scaling factor ("
\r
98 + widthScale + "). Ignoring.");
\r
101 if (JalviewLite.debug)
\r
104 .println("Alignment character width scaling factor is now "
\r
108 param = applet.getParameter("heightScale");
\r
113 heightScale = new Float(param).floatValue();
\r
114 } catch (Exception e)
\r
117 if (heightScale <= 1.0)
\r
120 .println("Invalid alignment character height scaling factor ("
\r
121 + heightScale + "). Ignoring.");
\r
124 if (JalviewLite.debug)
\r
127 .println("Alignment character height scaling factor is now "
\r
134 MAC = Platform.isAMac();
\r
136 if (applet != null)
\r
138 setShowJVSuffix(applet.getDefaultParameter("showFullId",
\r
139 getShowJVSuffix()));
\r
141 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
\r
142 isShowAnnotation()));
\r
144 showConservation = applet.getDefaultParameter("showConservation",
\r
147 showQuality = applet.getDefaultParameter("showQuality", showQuality);
\r
149 showConsensus = applet.getDefaultParameter("showConsensus",
\r
152 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
\r
153 getShowUnconserved()));
\r
155 setScaleProteinAsCdna(applet.getDefaultParameter(
\r
156 "scaleProteinAsCdna", isScaleProteinAsCdna()));
\r
158 String param = applet.getParameter("upperCase");
\r
161 if (param.equalsIgnoreCase("bold"))
\r
163 setUpperCasebold(true);
\r
166 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
\r
168 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
\r
169 isFollowHighlight()));
\r
170 followSelection = isFollowHighlight();
\r
172 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
\r
175 normaliseSequenceLogo = applet.getDefaultParameter(
\r
176 "normaliseSequenceLogo", applet.getDefaultParameter(
\r
177 "normaliseLogo", normaliseSequenceLogo));
\r
179 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
\r
180 showGroupConsensus);
\r
182 showGroupConservation = applet.getDefaultParameter(
\r
183 "showGroupConservation", showGroupConservation);
\r
185 showConsensusHistogram = applet.getDefaultParameter(
\r
186 "showConsensusHistogram", showConsensusHistogram);
\r
190 if (applet != null)
\r
192 String colour = applet.getParameter("defaultColour");
\r
194 if (colour == null)
\r
196 colour = applet.getParameter("userDefinedColour");
\r
197 if (colour != null)
\r
199 colour = "User Defined";
\r
203 if (colour != null)
\r
205 globalColourScheme = ColourSchemeProperty.getColour(alignment,
\r
207 if (globalColourScheme != null)
\r
209 globalColourScheme.setConsensus(hconsensus);
\r
213 if (applet.getParameter("userDefinedColour") != null)
\r
215 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
\r
216 .getParameter("userDefinedColour"));
\r
219 initAutoAnnotation();
\r
224 * get the consensus sequence as displayed under the PID consensus annotation
\r
227 * @return consensus sequence as a new sequence object
\r
229 public SequenceI getConsensusSeq()
\r
231 if (consensus == null)
\r
233 updateConsensus(null);
\r
235 if (consensus == null)
\r
239 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
\r
240 for (int i = 0; i < consensus.annotations.length; i++)
\r
242 if (consensus.annotations[i] != null)
\r
244 if (consensus.annotations[i].description.charAt(0) == '[')
\r
246 seqs.append(consensus.annotations[i].description.charAt(1));
\r
250 seqs.append(consensus.annotations[i].displayCharacter);
\r
254 SequenceI sq = new Sequence("Consensus", seqs.toString());
\r
255 sq.setDescription("Percentage Identity Consensus "
\r
256 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
\r
260 java.awt.Frame nullFrame;
\r
262 protected FeatureSettings featureSettings = null;
\r
264 private float heightScale = 1, widthScale = 1;
\r
266 public void setFont(Font f)
\r
269 if (nullFrame == null)
\r
271 nullFrame = new java.awt.Frame();
\r
272 nullFrame.addNotify();
\r
275 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
\r
276 setCharHeight((int) (heightScale * fm.getHeight()));
\r
277 setCharWidth((int) (widthScale * fm.charWidth('M')));
\r
279 if (isUpperCasebold())
\r
281 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
\r
282 fm = nullFrame.getGraphics().getFontMetrics(f2);
\r
283 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
\r
287 public Font getFont()
\r
293 public void resetSeqLimits(int height)
\r
295 setEndSeq(height / getCharHeight());
\r
298 public void setCurrentTree(NJTree tree)
\r
300 currentTree = tree;
\r
303 public NJTree getCurrentTree()
\r
305 return currentTree;
\r
309 boolean centreColumnLabels;
\r
311 public boolean getCentreColumnLabels()
\r
313 return centreColumnLabels;
\r
316 public boolean followSelection = true;
\r
319 * @return true if view selection should always follow the selections
\r
320 * broadcast by other selection sources
\r
322 public boolean getFollowSelection()
\r
324 return followSelection;
\r
327 public void sendSelection()
\r
329 getStructureSelectionManager().sendSelection(
\r
330 new SequenceGroup(getSelectionGroup()),
\r
331 new ColumnSelection(getColumnSelection()), this);
\r
335 * Returns an instance of the StructureSelectionManager scoped to this applet
\r
341 public StructureSelectionManager getStructureSelectionManager()
\r
343 return StructureSelectionManager.getStructureSelectionManager(applet);
\r
347 * synthesize a column selection if none exists so it covers the given
\r
348 * selection group. if wholewidth is false, no column selection is made if the
\r
349 * selection group covers the whole alignment width.
\r
352 * @param wholewidth
\r
354 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
\r
358 && (sgs = sg.getStartRes()) >= 0
\r
359 && sg.getStartRes() <= (sge = sg.getEndRes())
\r
360 && (colSel == null || colSel.getSelected() == null || colSel
\r
361 .getSelected().size() == 0))
\r
363 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
\r
368 if (colSel == null)
\r
370 colSel = new ColumnSelection();
\r
372 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
\r
374 colSel.addElement(cspos);
\r
379 public boolean isNormaliseSequenceLogo()
\r
381 return normaliseSequenceLogo;
\r
384 public void setNormaliseSequenceLogo(boolean state)
\r
386 normaliseSequenceLogo = state;
\r
391 * @return true if alignment characters should be displayed
\r
393 public boolean isValidCharWidth()
\r
395 return validCharWidth;
\r
398 public AnnotationColumnChooser getAnnotationColumnSelectionState()
\r
400 return annotationColumnSelectionState;
\r
403 public void setAnnotationColumnSelectionState(
\r
404 AnnotationColumnChooser annotationColumnSelectionState)
\r
406 this.annotationColumnSelectionState = annotationColumnSelectionState;
\r
410 public void mirrorCommand(CommandI command, boolean undo,
\r
411 StructureSelectionManager ssm, VamsasSource source)
\r
413 // TODO refactor so this can be pulled up to superclass or controller
\r
415 * Do nothing unless we are a 'complement' of the source. May replace this
\r
416 * with direct calls not via SSM.
\r
418 if (source instanceof AlignViewportI
\r
419 && ((AlignViewportI) source).getCodingComplement() == this)
\r
428 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
\r
429 getGapCharacter());
\r
430 if (mappedCommand != null)
\r
432 mappedCommand.doCommand(null);
\r
433 firePropertyChange("alignment", null, getAlignment().getSequences());
\r
435 // ap.scalePanelHolder.repaint();
\r
441 public VamsasSource getVamsasSource()
\r
447 * If this viewport has a (Protein/cDNA) complement, then scroll the
\r
448 * complementary alignment to match this one.
\r
450 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
\r
452 if (complementPanel == null)
\r
458 * Populate a SearchResults object with the mapped location to scroll to. If
\r
459 * there is no complement, or it is not following highlights, or no mapping
\r
460 * is found, the result will be empty.
\r
462 SearchResults sr = new SearchResults();
\r
463 int seqOffset = findComplementScrollTarget(sr);
\r
466 complementPanel.setFollowingComplementScroll(true);
\r
467 complementPanel.scrollToCentre(sr, seqOffset);
\r