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