JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / appletgui / AlignViewport.js
1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["jalview.structure.CommandListener", "$.SelectionSource", "$.VamsasSource", "jalview.viewmodel.AlignmentViewport", "java.awt.Font"], "jalview.appletgui.AlignViewport", ["awt2swing.Frame", "jalview.api.AlignViewportI", "jalview.bin.JalviewLite", "jalview.datamodel.ColumnSelection", "$.SearchResults", "$.Sequence", "$.SequenceGroup", "jalview.schemes.ColourSchemeProperty", "jalview.structure.StructureSelectionManager", "jalview.util.Platform", "jalview.workers.AlignCalcManager", "java.lang.Float", "$.StringBuilder"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.cursorMode = false;
5 this.font = null;
6 this.validCharWidth = true;
7 this.currentTree = null;
8 this.applet = null;
9 this.MAC = false;
10 this.annotationColumnSelectionState = null;
11 this.nullFrame = null;
12 this.featureSettings = null;
13 this.heightScale = 1;
14 this.widthScale = 1;
15 this.centreColumnLabels = false;
16 this.followSelection = true;
17 Clazz.instantialize (this, arguments);
18 }, jalview.appletgui, "AlignViewport", jalview.viewmodel.AlignmentViewport, [jalview.structure.SelectionSource, jalview.structure.VamsasSource, jalview.structure.CommandListener]);
19 Clazz.prepareFields (c$, function () {
20 this.font =  new java.awt.Font ("SansSerif", 0, 10);
21 });
22 Clazz.overrideMethod (c$, "finalize", 
23 function () {
24 this.applet = null;
25 this.quality = null;
26 this.alignment = null;
27 this.colSel = null;
28 });
29 Clazz.makeConstructor (c$, 
30 function (al, applet) {
31 Clazz.superConstructor (this, jalview.appletgui.AlignViewport);
32 this.calculator =  new jalview.workers.AlignCalcManager ();
33 this.applet = applet;
34 this.alignment = al;
35 this.setPadGaps (true);
36 this.startRes = 0;
37 this.endRes = al.getWidth () - 1;
38 this.startSeq = 0;
39 this.endSeq = al.getHeight () - 1;
40 if (applet != null) {
41 var param = applet.widthScale;
42 if (param != null) {
43 try {
44 this.widthScale =  new Float (param).floatValue ();
45 } catch (e) {
46 if (Clazz.exceptionOf (e, Exception)) {
47 } else {
48 throw e;
49 }
50 }
51 if (this.widthScale <= 1.0) {
52 System.err.println ("Invalid alignment character width scaling factor (" + this.widthScale + "). Ignoring.");
53 this.widthScale = 1;
54 }if (jalview.bin.JalviewLite.debug) {
55 System.err.println ("Alignment character width scaling factor is now " + this.widthScale);
56 }}param = applet.heightScale;
57 if (param != null) {
58 try {
59 this.heightScale =  new Float (param).floatValue ();
60 } catch (e) {
61 if (Clazz.exceptionOf (e, Exception)) {
62 } else {
63 throw e;
64 }
65 }
66 if (this.heightScale <= 1.0) {
67 System.err.println ("Invalid alignment character height scaling factor (" + this.heightScale + "). Ignoring.");
68 this.heightScale = 1;
69 }if (jalview.bin.JalviewLite.debug) {
70 System.err.println ("Alignment character height scaling factor is now " + this.heightScale);
71 }}}this.setFont (this.font);
72 this.MAC = jalview.util.Platform.isAMac ();
73 if (applet != null) {
74 this.setShowJVSuffix (applet.getDefaultParameter ("showFullId", this.getShowJVSuffix ()));
75 this.setShowAnnotation (applet.getDefaultParameter ("showAnnotation", this.isShowAnnotation ()));
76 this.showConservation = applet.getDefaultParameter ("showConservation", this.showConservation);
77 this.showQuality = applet.getDefaultParameter ("showQuality", this.showQuality);
78 this.showConsensus = applet.getDefaultParameter ("showConsensus", this.showConsensus);
79 this.setShowUnconserved (applet.getDefaultParameter ("showUnconserved", this.getShowUnconserved ()));
80 this.setScaleProteinAsCdna (applet.getDefaultParameter ("scaleProteinAsCdna", this.isScaleProteinAsCdna ()));
81 var param = applet.upperCase;
82 if (param != null) {
83 if (param.equalsIgnoreCase ("bold")) {
84 this.setUpperCasebold (true);
85 }}this.sortByTree = applet.getDefaultParameter ("sortByTree", this.sortByTree);
86 this.setFollowHighlight (applet.getDefaultParameter ("automaticScrolling", this.isFollowHighlight ()));
87 this.followSelection = this.isFollowHighlight ();
88 this.showSequenceLogo = applet.getDefaultParameter ("showSequenceLogo", this.showSequenceLogo);
89 this.normaliseSequenceLogo = applet.getDefaultParameter ("normaliseSequenceLogo", applet.getDefaultParameter ("normaliseLogo", this.normaliseSequenceLogo));
90 this.showGroupConsensus = applet.getDefaultParameter ("showGroupConsensus", this.showGroupConsensus);
91 this.showGroupConservation = applet.getDefaultParameter ("showGroupConservation", this.showGroupConservation);
92 this.showConsensusHistogram = applet.getDefaultParameter ("showConsensusHistogram", this.showConsensusHistogram);
93 }if (applet != null) {
94 var colour = applet.defaultColour;
95 if (colour == null) {
96 colour = applet.userDefinedColour;
97 if (colour != null) {
98 colour = "User Defined";
99 }}if (colour != null) {
100 this.globalColourScheme = jalview.schemes.ColourSchemeProperty.getColour (this.alignment, colour);
101 if (this.globalColourScheme != null) {
102 this.globalColourScheme.setConsensus (this.hconsensus);
103 }}if (applet.userDefinedColour != null) {
104 (this.globalColourScheme).parseAppletParameter (applet.userDefinedColour);
105 }}this.initAutoAnnotation ();
106 }, "jalview.datamodel.AlignmentI,jalview.bin.JalviewLite");
107 Clazz.defineMethod (c$, "getConsensusSeq", 
108 function () {
109 if (this.consensus == null) {
110 this.updateConsensus (null);
111 }if (this.consensus == null) {
112 return null;
113 }var seqs =  new StringBuilder (this.consensus.annotations.length);
114 for (var i = 0; i < this.consensus.annotations.length; i++) {
115 if (this.consensus.annotations[i] != null) {
116 if (this.consensus.annotations[i].description.charAt (0) == '[') {
117 seqs.append (this.consensus.annotations[i].description.charAt (1));
118 } else {
119 seqs.append (this.consensus.annotations[i].displayCharacter);
120 }}}
121 var sq =  new jalview.datamodel.Sequence ("Consensus", seqs.toString ());
122 sq.setDescription ("Percentage Identity Consensus " + ((this.ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
123 return sq;
124 });
125 Clazz.defineMethod (c$, "setFont", 
126 function (f) {
127 this.font = f;
128 if (this.nullFrame == null) {
129 this.nullFrame =  new awt2swing.Frame ();
130 this.nullFrame.addNotify ();
131 this.nullFrame.setFont (this.font);
132 }var fm = this.nullFrame.getGraphics ().getFontMetrics (this.font);
133 this.setCharHeight (Clazz.floatToInt (this.heightScale * fm.getHeight ()));
134 this.setCharWidth (Clazz.floatToInt (this.widthScale * fm.charWidth ('M')));
135 if (this.isUpperCasebold ()) {
136 var f2 =  new java.awt.Font (f.getName (), 1, f.getSize ());
137 fm = this.nullFrame.getGraphics ().getFontMetrics (f2);
138 this.setCharWidth (Clazz.floatToInt (this.widthScale * (Clazz.doubleToInt (fm.stringWidth ("MMMMMMMMMMM") / 10))));
139 }}, "java.awt.Font");
140 Clazz.defineMethod (c$, "getFont", 
141 function () {
142 return this.font;
143 });
144 Clazz.defineMethod (c$, "resetSeqLimits", 
145 function (height) {
146 this.setEndSeq (Clazz.doubleToInt (height / this.getCharHeight ()));
147 }, "~N");
148 Clazz.defineMethod (c$, "setCurrentTree", 
149 function (tree) {
150 this.currentTree = tree;
151 }, "jalview.analysis.NJTree");
152 Clazz.defineMethod (c$, "getCurrentTree", 
153 function () {
154 return this.currentTree;
155 });
156 Clazz.defineMethod (c$, "getCentreColumnLabels", 
157 function () {
158 return this.centreColumnLabels;
159 });
160 Clazz.defineMethod (c$, "getFollowSelection", 
161 function () {
162 return this.followSelection;
163 });
164 Clazz.overrideMethod (c$, "sendSelection", 
165 function () {
166 this.getStructureSelectionManager ().sendSelection ( new jalview.datamodel.SequenceGroup (this.getSelectionGroup ()),  new jalview.datamodel.ColumnSelection (this.getColumnSelection ()), this);
167 });
168 Clazz.overrideMethod (c$, "getStructureSelectionManager", 
169 function () {
170 return jalview.structure.StructureSelectionManager.getStructureSelectionManager (this.applet);
171 });
172 Clazz.defineMethod (c$, "expandColSelection", 
173 function (sg, wholewidth) {
174 var sgs;
175 var sge;
176 if (sg != null && (sgs = sg.getStartRes ()) >= 0 && sg.getStartRes () <= (sge = sg.getEndRes ()) && (this.colSel == null || this.colSel.getSelected () == null || this.colSel.getSelected ().size () == 0)) {
177 if (!wholewidth && this.alignment.getWidth () == (1 + sge - sgs)) {
178 return;
179 }if (this.colSel == null) {
180 this.colSel =  new jalview.datamodel.ColumnSelection ();
181 }for (var cspos = sg.getStartRes (); cspos <= sg.getEndRes (); cspos++) {
182 this.colSel.addElement (cspos);
183 }
184 }}, "jalview.datamodel.SequenceGroup,~B");
185 Clazz.overrideMethod (c$, "isNormaliseSequenceLogo", 
186 function () {
187 return this.normaliseSequenceLogo;
188 });
189 Clazz.defineMethod (c$, "setNormaliseSequenceLogo", 
190 function (state) {
191 this.normaliseSequenceLogo = state;
192 }, "~B");
193 Clazz.overrideMethod (c$, "isValidCharWidth", 
194 function () {
195 return this.validCharWidth;
196 });
197 Clazz.defineMethod (c$, "getAnnotationColumnSelectionState", 
198 function () {
199 return this.annotationColumnSelectionState;
200 });
201 Clazz.defineMethod (c$, "setAnnotationColumnSelectionState", 
202 function (annotationColumnSelectionState) {
203 this.annotationColumnSelectionState = annotationColumnSelectionState;
204 }, "jalview.appletgui.AnnotationColumnChooser");
205 Clazz.overrideMethod (c$, "mirrorCommand", 
206 function (command, undo, ssm, source) {
207 if (Clazz.instanceOf (source, jalview.api.AlignViewportI) && (source).getCodingComplement () === this) {
208 } else {
209 return;
210 }var mappedCommand = ssm.mapCommand (command, undo, this.getAlignment (), this.getGapCharacter ());
211 if (mappedCommand != null) {
212 mappedCommand.doCommand (null);
213 this.firePropertyChange ("alignment", null, this.getAlignment ().getSequences ());
214 }}, "jalview.commands.CommandI,~B,jalview.structure.StructureSelectionManager,jalview.structure.VamsasSource");
215 Clazz.overrideMethod (c$, "getVamsasSource", 
216 function () {
217 return this;
218 });
219 Clazz.defineMethod (c$, "scrollComplementaryAlignment", 
220 function (complementPanel) {
221 if (complementPanel == null) {
222 return;
223 }var sr =  new jalview.datamodel.SearchResults ();
224 var seqOffset = this.findComplementScrollTarget (sr);
225 if (!sr.isEmpty ()) {
226 complementPanel.setFollowingComplementScroll (true);
227 complementPanel.scrollToCentre (sr, seqOffset);
228 }}, "jalview.appletgui.AlignmentPanel");
229 });