Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.appletgui

File AlignViewport.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

50
96
16
1
409
280
44
0.46
6
16
2.75

Classes

Class Line # Actions
AlignViewport 44 96 44
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Copyright (C) $$Year-Rel$$ The Jalview Authors
3    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.appletgui;
22   
23    import jalview.api.AlignViewportI;
24    import jalview.api.FeatureSettingsModelI;
25    import jalview.bin.JalviewLite;
26    import jalview.commands.CommandI;
27    import jalview.datamodel.AlignmentI;
28    import jalview.datamodel.ColumnSelection;
29    import jalview.datamodel.HiddenColumns;
30    import jalview.datamodel.SearchResults;
31    import jalview.datamodel.SearchResultsI;
32    import jalview.datamodel.SequenceGroup;
33    import jalview.renderer.ResidueShader;
34    import jalview.schemes.ColourSchemeProperty;
35    import jalview.schemes.UserColourScheme;
36    import jalview.structure.SelectionSource;
37    import jalview.structure.StructureSelectionManager;
38    import jalview.structure.VamsasSource;
39    import jalview.viewmodel.AlignmentViewport;
40   
41    import java.awt.Font;
42    import java.awt.FontMetrics;
43   
 
44    public class AlignViewport extends AlignmentViewport<AlignmentPanel>
45    implements SelectionSource
46    {
47    boolean cursorMode = false;
48   
49    Font font = new Font("SansSerif", Font.PLAIN, 10);
50   
51    boolean validCharWidth = true;
52   
53    public jalview.bin.JalviewLite applet;
54   
55    private AnnotationColumnChooser annotationColumnSelectionState;
56   
57    java.awt.Frame nullFrame;
58   
59    protected FeatureSettings featureSettings = null;
60   
61    private float heightScale = 1, widthScale = 1;
62   
 
63  0 toggle public AlignViewport(AlignmentI al, JalviewLite applet)
64    {
65  0 super(al);
66  0 calculator = new jalview.workers.AlignCalcManager2();
67  0 this.applet = applet;
68   
69    // we always pad gaps
70  0 this.setPadGaps(true);
71   
72  0 if (applet != null)
73    {
74    // get the width and height scaling factors if they were specified
75  0 String param = applet.getParameter("widthScale");
76  0 if (param != null)
77    {
78  0 try
79    {
80  0 widthScale = Float.valueOf(param).floatValue();
81    } catch (Exception e)
82    {
83    }
84  0 if (widthScale <= 1.0)
85    {
86  0 jalview.bin.Console.errPrintln(
87    "Invalid alignment character width scaling factor ("
88    + widthScale + "). Ignoring.");
89  0 widthScale = 1;
90    }
91  0 if (JalviewLite.debug)
92    {
93  0 jalview.bin.Console.errPrintln(
94    "Alignment character width scaling factor is now "
95    + widthScale);
96    }
97    }
98  0 param = applet.getParameter("heightScale");
99  0 if (param != null)
100    {
101  0 try
102    {
103  0 heightScale = Float.valueOf(param).floatValue();
104    } catch (Exception e)
105    {
106    }
107  0 if (heightScale <= 1.0)
108    {
109  0 jalview.bin.Console.errPrintln(
110    "Invalid alignment character height scaling factor ("
111    + heightScale + "). Ignoring.");
112  0 heightScale = 1;
113    }
114  0 if (JalviewLite.debug)
115    {
116  0 jalview.bin.Console.errPrintln(
117    "Alignment character height scaling factor is now "
118    + heightScale);
119    }
120    }
121    }
122  0 setFont(font, true);
123   
124  0 if (applet != null)
125    {
126  0 setShowJVSuffix(
127    applet.getDefaultParameter("showFullId", getShowJVSuffix()));
128   
129  0 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
130    isShowAnnotation()));
131   
132  0 showConservation = applet.getDefaultParameter("showConservation",
133    showConservation);
134   
135  0 showQuality = applet.getDefaultParameter("showQuality", showQuality);
136   
137  0 showConsensus = applet.getDefaultParameter("showConsensus",
138    showConsensus);
139   
140  0 showOccupancy = applet.getDefaultParameter("showOccupancy",
141    showOccupancy);
142   
143  0 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
144    getShowUnconserved()));
145   
146  0 setScaleProteinAsCdna(applet.getDefaultParameter("scaleProteinAsCdna",
147    isScaleProteinAsCdna()));
148   
149  0 String param = applet.getParameter("upperCase");
150  0 if (param != null)
151    {
152  0 if (param.equalsIgnoreCase("bold"))
153    {
154  0 setUpperCasebold(true);
155    }
156    }
157  0 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
158   
159  0 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
160    isFollowHighlight()));
161  0 followSelection = isFollowHighlight();
162   
163  0 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
164    showSequenceLogo);
165   
166  0 normaliseSequenceLogo = applet.getDefaultParameter(
167    "normaliseSequenceLogo", applet.getDefaultParameter(
168    "normaliseLogo", normaliseSequenceLogo));
169   
170  0 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
171    showGroupConsensus);
172   
173  0 showGroupConservation = applet.getDefaultParameter(
174    "showGroupConservation", showGroupConservation);
175   
176  0 showConsensusHistogram = applet.getDefaultParameter(
177    "showConsensusHistogram", showConsensusHistogram);
178   
179    }
180   
181  0 if (applet != null)
182    {
183  0 String colour = al.isNucleotide()
184    ? applet.getParameter("defaultColourNuc")
185    : applet.getParameter("defaultColourProt");
186  0 if (colour == null)
187    {
188  0 colour = applet.getParameter("defaultColour");
189    }
190  0 if (colour == null)
191    {
192  0 colour = applet.getParameter("userDefinedColour");
193  0 if (colour != null)
194    {
195  0 colour = "User Defined";
196    }
197    }
198   
199  0 if (colour != null)
200    {
201  0 residueShading = new ResidueShader(ColourSchemeProperty
202    .getColourScheme(this, alignment, colour));
203  0 if (residueShading != null)
204    {
205  0 residueShading.setConsensus(consensusProfiles);
206    }
207    }
208   
209  0 if (applet.getParameter("userDefinedColour") != null)
210    {
211  0 residueShading = new ResidueShader(new UserColourScheme(
212    applet.getParameter("userDefinedColour")));
213    }
214    }
215  0 initAutoAnnotation();
216    }
217   
218    /**
219    * {@inheritDoc}
220    */
 
221  0 toggle @Override
222    public void setFont(Font f, boolean setGrid)
223    {
224  0 font = f;
225  0 if (nullFrame == null)
226    {
227  0 nullFrame = new java.awt.Frame();
228  0 nullFrame.addNotify();
229    }
230   
231  0 if (setGrid)
232    {
233  0 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
234  0 setCharHeight((int) (heightScale * fm.getHeight()));
235  0 setCharWidth((int) (widthScale * fm.charWidth('M')));
236    }
237   
238  0 if (isUpperCasebold())
239    {
240  0 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
241  0 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
242  0 setCharWidth(
243    (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
244    }
245    }
246   
 
247  0 toggle public Font getFont()
248    {
249  0 return font;
250    }
251   
 
252  0 toggle public void resetSeqLimits(int height)
253    {
254  0 ranges.setEndSeq(height / getCharHeight() - 1); // BH 2019.04.18
255    }
256   
257    boolean centreColumnLabels;
258   
 
259  0 toggle public boolean getCentreColumnLabels()
260    {
261  0 return centreColumnLabels;
262    }
263   
264    public boolean followSelection = true;
265   
266    /**
267    * @return true if view selection should always follow the selections
268    * broadcast by other selection sources
269    */
 
270  0 toggle public boolean getFollowSelection()
271    {
272  0 return followSelection;
273    }
274   
 
275  0 toggle @Override
276    public void sendSelection()
277    {
278  0 getStructureSelectionManager().sendSelection(
279    new SequenceGroup(getSelectionGroup()),
280    new ColumnSelection(getColumnSelection()),
281    new HiddenColumns(getAlignment().getHiddenColumns()), this);
282    }
283   
284    /**
285    * Returns an instance of the StructureSelectionManager scoped to this applet
286    * instance.
287    *
288    * @return
289    */
 
290  0 toggle @Override
291    public StructureSelectionManager getStructureSelectionManager()
292    {
293  0 return jalview.structure.StructureSelectionManager
294    .getStructureSelectionManager(applet);
295    }
296   
297    /**
298    *
299    * @return true if alignment characters should be displayed
300    */
 
301  0 toggle @Override
302    public boolean isValidCharWidth()
303    {
304  0 return validCharWidth;
305    }
306   
 
307  0 toggle public AnnotationColumnChooser getAnnotationColumnSelectionState()
308    {
309  0 return annotationColumnSelectionState;
310    }
311   
 
312  0 toggle public void setAnnotationColumnSelectionState(
313    AnnotationColumnChooser annotationColumnSelectionState)
314    {
315  0 this.annotationColumnSelectionState = annotationColumnSelectionState;
316    }
317   
 
318  0 toggle @Override
319    public void mirrorCommand(CommandI command, boolean undo,
320    StructureSelectionManager ssm, VamsasSource source)
321    {
322    // TODO refactor so this can be pulled up to superclass or controller
323    /*
324    * Do nothing unless we are a 'complement' of the source. May replace this
325    * with direct calls not via SSM.
326    */
327  0 if (source instanceof AlignViewportI
328    && ((AlignViewportI) source).getCodingComplement() == this)
329    {
330    // ok to continue;
331    }
332    else
333    {
334  0 return;
335    }
336   
337  0 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
338    getGapCharacter());
339  0 if (mappedCommand != null)
340    {
341  0 mappedCommand.doCommand(null);
342  0 notifyAlignment();
343   
344    // ap.scalePanelHolder.repaint();
345    // ap.repaint();
346    }
347    }
348   
 
349  0 toggle @Override
350    public VamsasSource getVamsasSource()
351    {
352  0 return this;
353    }
354   
355    /**
356    * If this viewport has a (Protein/cDNA) complement, then scroll the
357    * complementary alignment to match this one.
358    */
 
359  0 toggle public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
360    {
361  0 if (complementPanel == null)
362    {
363  0 return;
364    }
365   
366    /*
367    * Populate a SearchResults object with the mapped location to scroll to. If
368    * there is no complement, or it is not following highlights, or no mapping
369    * is found, the result will be empty.
370    */
371  0 SearchResultsI sr = new SearchResults();
372  0 int seqOffset = findComplementScrollTarget(sr);
373  0 if (!sr.isEmpty())
374    {
375  0 complementPanel.setToScrollComplementPanel(false);
376  0 complementPanel.scrollToCentre(sr, seqOffset);
377  0 complementPanel.setToScrollComplementPanel(true);
378    }
379    }
380   
381    /**
382    * Applies the supplied feature settings descriptor to currently known
383    * features. This supports an 'initial configuration' of feature colouring
384    * based on a preset or user favourite. This may then be modified in the usual
385    * way using the Feature Settings dialogue. NOT IMPLEMENTED FOR APPLET
386    *
387    * @param featureSettings
388    */
 
389  0 toggle @Override
390    public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
391    {
392    // TODO implement for applet
393    }
394   
395    /**
396    * Merges the supplied feature settings descriptor with existing feature
397    * styles. This supports an 'initial configuration' of feature colouring based
398    * on a preset or user favourite. This may then be modified in the usual way
399    * using the Feature Settings dialogue. NOT IMPLEMENTED FOR APPLET
400    *
401    * @param featureSettings
402    */
 
403  0 toggle @Override
404    public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
405    {
406    // TODO Auto-generated method stub
407   
408    }
409    }