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