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