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.AlignViewportI;
25 import jalview.bin.JalviewLite;
26 import jalview.commands.CommandI;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.SearchResults;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceGroup;
32 import jalview.datamodel.SequenceI;
33 import jalview.schemes.ColourSchemeProperty;
34 import jalview.schemes.UserColourScheme;
35 import jalview.structure.CommandListener;
36 import jalview.structure.SelectionSource;
37 import jalview.structure.StructureSelectionManager;
38 import jalview.structure.VamsasSource;
39 import jalview.util.Platform;
40 import jalview.viewmodel.AlignmentViewport;
41 import jalview.workers.AlignCalcManager;
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 JalviewLite applet;
60 private AnnotationColumnChooser annotationColumnSelectionState;
62 public void finalize()
70 public AlignViewport(AlignmentI al, JalviewLite applet)
73 calculator = new AlignCalcManager();
77 this.setPadGaps(true);
79 this.endRes = al.getWidth() - 1;
81 this.endSeq = al.getHeight() - 1;
84 // get the width and height scaling factors if they were specified
85 String param = applet.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.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 = 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 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
153 getShowUnconserved()));
155 setScaleProteinAsCdna(applet.getDefaultParameter(
156 "scaleProteinAsCdna", isScaleProteinAsCdna()));
158 String param = applet.upperCase;
161 if (param.equalsIgnoreCase("bold"))
163 setUpperCasebold(true);
166 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
168 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
169 isFollowHighlight()));
170 followSelection = isFollowHighlight();
172 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
175 normaliseSequenceLogo = applet.getDefaultParameter(
176 "normaliseSequenceLogo", applet.getDefaultParameter(
177 "normaliseLogo", normaliseSequenceLogo));
179 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
182 showGroupConservation = applet.getDefaultParameter(
183 "showGroupConservation", showGroupConservation);
185 showConsensusHistogram = applet.getDefaultParameter(
186 "showConsensusHistogram", showConsensusHistogram);
192 String colour = applet.defaultColour;
196 colour = applet.userDefinedColour;
199 colour = "User Defined";
205 globalColourScheme = ColourSchemeProperty.getColour(alignment,
207 if (globalColourScheme != null)
209 globalColourScheme.setConsensus(hconsensus);
213 if (applet.userDefinedColour != null)
215 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
219 initAutoAnnotation();
224 * get the consensus sequence as displayed under the PID consensus annotation
227 * @return consensus sequence as a new sequence object
229 public SequenceI getConsensusSeq()
231 if (consensus == null)
233 updateConsensus(null);
235 if (consensus == null)
239 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
240 for (int i = 0; i < consensus.annotations.length; i++)
242 if (consensus.annotations[i] != null)
244 if (consensus.annotations[i].description.charAt(0) == '[')
246 seqs.append(consensus.annotations[i].description.charAt(1));
250 seqs.append(consensus.annotations[i].displayCharacter);
254 SequenceI sq = new Sequence("Consensus", seqs.toString());
255 sq.setDescription("Percentage Identity Consensus "
256 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
260 awt2swing.Frame nullFrame;
262 protected FeatureSettings featureSettings = null;
264 private float heightScale = 1, widthScale = 1;
266 public void setFont(Font f)
269 if (nullFrame == null)
271 nullFrame = new awt2swing.Frame();
272 nullFrame.addNotify();
273 nullFrame.setFont(font);
276 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
277 setCharHeight((int) (heightScale * fm.getHeight()));
278 setCharWidth((int) (widthScale * fm.charWidth('M')));
280 if (isUpperCasebold())
282 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
283 fm = nullFrame.getGraphics().getFontMetrics(f2);
284 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
288 public Font getFont()
294 public void resetSeqLimits(int height)
296 setEndSeq(height / getCharHeight());
299 public void setCurrentTree(NJTree tree)
304 public NJTree getCurrentTree()
310 boolean centreColumnLabels;
312 public boolean getCentreColumnLabels()
314 return centreColumnLabels;
317 public boolean followSelection = true;
320 * @return true if view selection should always follow the selections
321 * broadcast by other selection sources
323 public boolean getFollowSelection()
325 return followSelection;
328 public void sendSelection()
330 getStructureSelectionManager().sendSelection(
331 new SequenceGroup(getSelectionGroup()),
332 new ColumnSelection(getColumnSelection()), this);
336 * Returns an instance of the StructureSelectionManager scoped to this applet
342 public StructureSelectionManager getStructureSelectionManager()
344 return StructureSelectionManager.getStructureSelectionManager(applet);
348 * synthesize a column selection if none exists so it covers the given
349 * selection group. if wholewidth is false, no column selection is made if the
350 * selection group covers the whole alignment width.
355 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
359 && (sgs = sg.getStartRes()) >= 0
360 && sg.getStartRes() <= (sge = sg.getEndRes())
361 && (colSel == null || colSel.getSelected() == null || colSel
362 .getSelected().size() == 0))
364 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
371 colSel = new ColumnSelection();
373 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
375 colSel.addElement(cspos);
380 public boolean isNormaliseSequenceLogo()
382 return normaliseSequenceLogo;
385 public void setNormaliseSequenceLogo(boolean state)
387 normaliseSequenceLogo = state;
392 * @return true if alignment characters should be displayed
394 public boolean isValidCharWidth()
396 return validCharWidth;
399 public AnnotationColumnChooser getAnnotationColumnSelectionState()
401 return annotationColumnSelectionState;
404 public void setAnnotationColumnSelectionState(
405 AnnotationColumnChooser annotationColumnSelectionState)
407 this.annotationColumnSelectionState = annotationColumnSelectionState;
411 public void mirrorCommand(CommandI command, boolean undo,
412 StructureSelectionManager ssm, VamsasSource source)
414 // TODO refactor so this can be pulled up to superclass or controller
416 * Do nothing unless we are a 'complement' of the source. May replace this
417 * with direct calls not via SSM.
419 if (source instanceof AlignViewportI
420 && ((AlignViewportI) source).getCodingComplement() == this)
429 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
431 if (mappedCommand != null)
433 mappedCommand.doCommand(null);
434 firePropertyChange("alignment", null, getAlignment().getSequences());
436 // ap.scalePanelHolder.repaint();
442 public VamsasSource getVamsasSource()
448 * If this viewport has a (Protein/cDNA) complement, then scroll the
449 * complementary alignment to match this one.
451 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
453 if (complementPanel == null)
459 * Populate a SearchResults object with the mapped location to scroll to. If
460 * there is no complement, or it is not following highlights, or no mapping
461 * is found, the result will be empty.
463 SearchResults sr = new SearchResults();
464 int seqOffset = findComplementScrollTarget(sr);
467 complementPanel.setFollowingComplementScroll(true);
468 complementPanel.scrollToCentre(sr, seqOffset);