SequenceFeature display added
[jalview.git] / src / jalview / gui / AlignViewport.java
1 package jalview.gui;\r
2 \r
3 import java.awt.*;\r
4 import jalview.io.*;\r
5 import jalview.analysis.NJTree;\r
6 import jalview.datamodel.*;\r
7 import jalview.schemes.*;\r
8 import java.util.*;\r
9 \r
10 public class AlignViewport\r
11 {\r
12   int startRes;\r
13   int endRes;\r
14 \r
15   int startSeq;\r
16   int endSeq;\r
17 \r
18   boolean showScores=false;\r
19   boolean showText=true;\r
20   boolean showColourText=false;\r
21   boolean showBoxes=true;\r
22   boolean wrapAlignment=false;\r
23   boolean renderGaps = true;\r
24   boolean showSequenceFeatures = true;\r
25 \r
26   ColourSchemeI globalColourScheme = null;\r
27   boolean conservationColourSelected = false;\r
28 \r
29   SequenceGroup rubberbandGroup = null;\r
30 \r
31   RendererI renderer = new SequenceRenderer(this);\r
32 \r
33   int             charHeight;\r
34   int             charWidth;\r
35   int             chunkWidth;\r
36   int             chunkHeight;\r
37 \r
38   Font            font = new Font("SansSerif",Font.PLAIN,10);\r
39   AlignmentI      alignment;\r
40 \r
41   Selection       sel    = new Selection(this);\r
42   ColumnSelection colSel = new ColumnSelection();\r
43 \r
44   OutputGenerator og;\r
45 \r
46   String visibleConsensus;\r
47 \r
48   int threshold;\r
49   int increment;\r
50 \r
51   NJTree currentTree = null;\r
52 \r
53   int window   = 50;\r
54   int baseline = 30;\r
55 \r
56   Vector kmers;\r
57 \r
58   public AlignViewport(AlignmentI da,\r
59                        boolean showScores,\r
60                        boolean showText,\r
61                        boolean showBoxes,\r
62                        boolean wrapAlignment) {\r
63     this(0,da.getWidth()-1,0,da.getHeight()-1,showScores,\r
64          showText,\r
65          showBoxes,\r
66          wrapAlignment);\r
67 \r
68     setAlignment(da);\r
69   }\r
70 \r
71   public AlignViewport(int startRes, int endRes,\r
72                        int startSeq, int endSeq,\r
73                        boolean showScores,\r
74                        boolean showText,\r
75                        boolean showBoxes,\r
76                        boolean wrapAlignment) {\r
77 \r
78     this.startRes = startRes;\r
79     this.endRes   = endRes;\r
80     this.startSeq = startSeq;\r
81     this.endSeq   = endSeq;\r
82 \r
83     this.showScores    = showScores;\r
84     this.showText      = showText;\r
85     this.showBoxes     = showBoxes;\r
86     this.wrapAlignment = wrapAlignment;\r
87 \r
88    // og  = new AlignmentOutputGenerator(this);\r
89 \r
90     setFont( font );\r
91  }\r
92 \r
93  public void showSequenceFeatures(boolean b)\r
94  {\r
95    showSequenceFeatures = b;\r
96  }\r
97 \r
98   public String getVisibleConsensus()\r
99   {\r
100     return visibleConsensus;\r
101   }\r
102 \r
103   Vector consensus = new Vector();\r
104   public Vector getConsensus(boolean recalculate)\r
105   {\r
106     if(recalculate || consensus.size()<1)\r
107     {\r
108       consensus = alignment.getAAFrequency();\r
109       StringBuffer sb = new StringBuffer();\r
110       Hashtable hash = null;\r
111       for (int i = 0; i < consensus.size(); i++)\r
112       {\r
113         hash = (Hashtable) consensus.elementAt(i);\r
114         sb.append(hash.get("maxResidue").toString().charAt(0));\r
115       }\r
116       visibleConsensus = sb.toString();\r
117     }\r
118 \r
119 \r
120     return consensus;\r
121   }\r
122 \r
123   public SequenceGroup getRubberbandGroup()\r
124   {\r
125     return rubberbandGroup;\r
126   }\r
127 \r
128   public void setRubberbandGroup(SequenceGroup sg)\r
129   {\r
130     rubberbandGroup = sg;\r
131   }\r
132 \r
133  public boolean getConservationSelected()\r
134  {\r
135    return conservationColourSelected;\r
136  }\r
137 \r
138  public void setConservationSelected(boolean b)\r
139  {\r
140    conservationColourSelected = b;\r
141  }\r
142 \r
143   public int getStartRes() {\r
144     return startRes;\r
145   }\r
146 \r
147   public int getEndRes() {\r
148     return endRes;\r
149   }\r
150 \r
151   public int getStartSeq() {\r
152     return startSeq;\r
153   }\r
154 \r
155   public void setGlobalColourScheme(ColourSchemeI cs)\r
156   {\r
157      globalColourScheme = cs;\r
158   }\r
159 \r
160   public ColourSchemeI getGlobalColourScheme()\r
161   {\r
162     return globalColourScheme;\r
163   }\r
164 \r
165 \r
166   public void setStartRes(int res) {\r
167     this.startRes = res;\r
168   }\r
169   public void setStartSeq(int seq) {\r
170     this.startSeq = seq;\r
171   }\r
172   public void setEndRes(int res) {\r
173     if (res > alignment.getWidth()-1) {\r
174       System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));\r
175        res = alignment.getWidth() -1;\r
176     }\r
177     if (res < 0) {\r
178       res = 0;\r
179     }\r
180     this.endRes = res;\r
181   }\r
182   public void setEndSeq(int seq) {\r
183     if (seq > alignment.getHeight()) {\r
184       seq = alignment.getHeight();\r
185     }\r
186     if (seq < 0) {\r
187       seq = 0;\r
188     }\r
189     this.endSeq = seq;\r
190   }\r
191   public int getEndSeq() {\r
192     return endSeq;\r
193   }\r
194 \r
195   public void setFont(Font f) {\r
196     font = f;\r
197     javax.swing.JFrame temp = new javax.swing.JFrame();\r
198     temp.addNotify();\r
199     java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);\r
200     setCharHeight(fm.getHeight());\r
201     setCharWidth(fm.charWidth('M'));\r
202   }\r
203 \r
204   public Font getFont() {\r
205     return font;\r
206   }\r
207   public void setCharWidth(int w) {\r
208     this.charWidth = w;\r
209   }\r
210   public int getCharWidth() {\r
211     return charWidth;\r
212   }\r
213   public void setCharHeight(int h) {\r
214     this.charHeight = h;\r
215   }\r
216   public int getCharHeight() {\r
217     return charHeight;\r
218   }\r
219   public void setChunkWidth(int w) {\r
220     this.chunkWidth = w;\r
221   }\r
222   public int getChunkWidth() {\r
223     return chunkWidth;\r
224   }\r
225   public void setChunkHeight(int h) {\r
226     this.chunkHeight = h;\r
227   }\r
228   public int getChunkHeight() {\r
229     return chunkHeight;\r
230   }\r
231   public AlignmentI getAlignment() {\r
232     return alignment;\r
233   }\r
234   public void setAlignment(AlignmentI align) {\r
235     this.alignment = align;\r
236   }\r
237   public void setShowScores(boolean state) {\r
238     showScores = state;\r
239   }\r
240   public void setWrapAlignment(boolean state) {\r
241     wrapAlignment = state;\r
242   }\r
243   public void setShowText(boolean state) {\r
244     showText = state;\r
245   }\r
246 \r
247   public void setRenderGaps(boolean state){\r
248     renderGaps = state;\r
249     if(renderer instanceof SequenceRenderer)\r
250     {\r
251       SequenceRenderer sr = (SequenceRenderer)renderer;\r
252       sr.renderGaps(state);\r
253     }\r
254   }\r
255 \r
256 \r
257   public boolean getColourText()\r
258   {\r
259     return showColourText;\r
260   }\r
261 \r
262   public void setColourText(boolean state)\r
263   {\r
264     showColourText = state;\r
265   }\r
266 \r
267   public void setShowBoxes(boolean state) {\r
268     showBoxes = state;\r
269   }\r
270   public boolean getShowScores() {\r
271     return showScores;\r
272   }\r
273   public boolean getWrapAlignment() {\r
274       return wrapAlignment;\r
275   }\r
276   public boolean getShowText() {\r
277     return showText;\r
278   }\r
279   public boolean getShowBoxes() {\r
280     return showBoxes;\r
281   }\r
282 \r
283   public char getGapCharacter() {\r
284     return getAlignment().getGapCharacter();\r
285   }\r
286   public void setGapCharacter(char gap) {\r
287     if (getAlignment() != null) {\r
288       getAlignment().setGapCharacter(gap);\r
289     }\r
290   }\r
291   public void setThreshold(int thresh) {\r
292     threshold = thresh;\r
293   }\r
294   public int getThreshold() {\r
295     return threshold;\r
296   }\r
297   public void setIncrement(int inc) {\r
298     increment = inc;\r
299   }\r
300   public int getIncrement() {\r
301     return increment;\r
302   }\r
303   public int getIndex(int y) {\r
304     int y1     = 0;\r
305     int starty = getStartSeq();\r
306     int endy   = getEndSeq();\r
307 \r
308     for (int i = starty; i <= endy; i++) {\r
309       if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {\r
310         int y2 = y1 + getCharHeight();\r
311 \r
312         if (y>=y1 && y <=y2) {\r
313           return i;\r
314         }\r
315         y1  = y2;\r
316       } else {\r
317         return -1;\r
318       }\r
319     }\r
320     return -1;\r
321   }\r
322   public Selection getSelection() {\r
323     return sel;\r
324   }\r
325   public ColumnSelection getColumnSelection() {\r
326     return colSel;\r
327   }\r
328   public OutputGenerator getOutputGenerator() {\r
329     return og;\r
330   }\r
331   public void resetSeqLimits(int height) {\r
332     setStartSeq(0);\r
333     setEndSeq(height/getCharHeight());\r
334   }\r
335   public void setCurrentTree(NJTree tree) {\r
336       currentTree = tree;\r
337   }\r
338   public NJTree getCurrentTree() {\r
339     return currentTree;\r
340   }\r
341 \r
342     public void setRenderer(RendererI rend) {\r
343         this.renderer = rend;\r
344     }\r
345 \r
346     public RendererI getRenderer() {\r
347         return renderer;\r
348     }\r
349     public int getPIDWindow() {\r
350         return window;\r
351     }\r
352     public void setPIDWindow(int window) {\r
353         this.window = window;\r
354     }\r
355 \r
356     public int getPIDBaseline() {\r
357         return baseline;\r
358     }\r
359     public void setPIDBaseline(int baseline) {\r
360         this.baseline = baseline;\r
361     }\r
362 \r
363     public void setKmers(Vector kmers) {\r
364         this.kmers = kmers;\r
365     }\r
366 \r
367     public Vector getKmers() {\r
368         return this.kmers;\r
369     }\r
370 \r
371 \r
372 }\r