Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.appletgui

File AlignViewport.java

 

Coverage histogram

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

Code metrics

50
98
18
1
422
290
46
0.47
5.44
18
2.56

Classes

Class Line # Actions
AlignViewport 44 98 46
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

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