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