Jalview Imported Sources
[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;\r
18   boolean showText;\r
19   boolean showColourText;\r
20   boolean showBoxes;\r
21   boolean wrapAlignment;\r
22 \r
23   boolean groupEdit    = false;\r
24 \r
25   RendererI renderer = new SequenceRenderer();\r
26 \r
27   int             charHeight;\r
28   double          charWidth;\r
29   int             chunkWidth;\r
30   int             chunkHeight;\r
31 \r
32   Color           backgroundColour;\r
33 \r
34   Font            font = new Font("SansSerif",Font.PLAIN,10);\r
35   AlignmentI      alignment;\r
36 \r
37   Selection       sel    = new Selection();\r
38   ColumnSelection colSel = new ColumnSelection();\r
39 \r
40   OutputGenerator og;\r
41 \r
42   String visibleConsensus;\r
43 \r
44   int threshold;\r
45   int increment;\r
46 \r
47   NJTree currentTree = null;\r
48 \r
49   int window   = 50;\r
50   int baseline = 30;\r
51 \r
52   Vector kmers;\r
53 \r
54   public AlignViewport(AlignmentI da,\r
55                        boolean showScores,\r
56                        boolean showText,\r
57                        boolean showBoxes,\r
58                        boolean wrapAlignment) {\r
59     this(0,da.getWidth()-1,0,da.getHeight()-1,showScores,\r
60          showText,\r
61          showBoxes,\r
62          wrapAlignment);\r
63 \r
64     setAlignment(da);\r
65   }\r
66 \r
67   public AlignViewport(int startRes, int endRes,\r
68                        int startSeq, int endSeq,\r
69                        boolean showScores,\r
70                        boolean showText,\r
71                        boolean showBoxes,\r
72                        boolean wrapAlignment) {\r
73 \r
74     this.startRes = startRes;\r
75     this.endRes   = endRes;\r
76     this.startSeq = startSeq;\r
77     this.endSeq   = endSeq;\r
78 \r
79     this.showScores    = showScores;\r
80     this.showText      = showText;\r
81     this.showBoxes     = showBoxes;\r
82     this.wrapAlignment = wrapAlignment;\r
83 \r
84    // og  = new AlignmentOutputGenerator(this);\r
85 \r
86     setFont( font );\r
87  }\r
88 \r
89   public AlignViewport(int startRes, int endRes,\r
90                        int startSeq, int endSeq,\r
91                        boolean showScores,\r
92                        boolean showText,\r
93                        boolean showBoxes,\r
94                        boolean wrapAlignment,\r
95                        Color backgroundColour) {\r
96     this(startRes,endRes,startSeq,endSeq,showScores,showText,showBoxes,wrapAlignment);\r
97 \r
98     this.backgroundColour = backgroundColour;\r
99   }\r
100 \r
101 \r
102   public String getVisibleConsensus()\r
103   {\r
104     return visibleConsensus;\r
105   }\r
106 \r
107   Vector consensus = new Vector();\r
108 \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 boolean getColourText()\r
224   {\r
225     return showColourText;\r
226   }\r
227 \r
228   public void setColourText(boolean state)\r
229   {\r
230     showColourText = state;\r
231   }\r
232 \r
233   public void setShowBoxes(boolean state) {\r
234     showBoxes = state;\r
235   }\r
236   public boolean getShowScores() {\r
237     return showScores;\r
238   }\r
239   public boolean getWrapAlignment() {\r
240       return wrapAlignment;\r
241   }\r
242   public boolean getShowText() {\r
243     return showText;\r
244   }\r
245   public boolean getShowBoxes() {\r
246     return showBoxes;\r
247   }\r
248  // public CommandParser getCommandLog() {\r
249  ///   return log;\r
250  // }\r
251   public boolean getGroupEdit() {\r
252     return groupEdit;\r
253   }\r
254   public void setGroupEdit(boolean state) {\r
255     groupEdit = state;\r
256   }\r
257   public String getGapCharacter() {\r
258     return getAlignment().getGapCharacter();\r
259   }\r
260   public void setGapCharacter(String gap) {\r
261     if (getAlignment() != null) {\r
262       getAlignment().setGapCharacter(gap);\r
263     }\r
264   }\r
265   public void setThreshold(int thresh) {\r
266     threshold = thresh;\r
267   }\r
268   public int getThreshold() {\r
269     return threshold;\r
270   }\r
271   public void setIncrement(int inc) {\r
272     increment = inc;\r
273   }\r
274   public int getIncrement() {\r
275     return increment;\r
276   }\r
277   public int getIndex(int y) {\r
278     int y1     = 0;\r
279     int starty = getStartSeq();\r
280     int endy   = getEndSeq();\r
281 \r
282     for (int i = starty; i <= endy; i++) {\r
283       if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {\r
284         int y2 = y1 + getCharHeight();\r
285 \r
286         if (y>=y1 && y <=y2) {\r
287           return i;\r
288         }\r
289         y1  = y2;\r
290       } else {\r
291         return -1;\r
292       }\r
293     }\r
294     return -1;\r
295   }\r
296   public Selection getSelection() {\r
297     return sel;\r
298   }\r
299   public ColumnSelection getColumnSelection() {\r
300     return colSel;\r
301   }\r
302   public OutputGenerator getOutputGenerator() {\r
303     return og;\r
304   }\r
305   public void resetSeqLimits(int height) {\r
306     setStartSeq(0);\r
307     setEndSeq(height/getCharHeight());\r
308   }\r
309   public void setCurrentTree(NJTree tree) {\r
310       currentTree = tree;\r
311   }\r
312   public NJTree getCurrentTree() {\r
313     return currentTree;\r
314   }\r
315 \r
316     public void setRenderer(RendererI rend) {\r
317         this.renderer = rend;\r
318     }\r
319 \r
320     public RendererI getRenderer() {\r
321         return renderer;\r
322     }\r
323     public int getPIDWindow() {\r
324         return window;\r
325     }\r
326     public void setPIDWindow(int window) {\r
327         this.window = window;\r
328     }\r
329 \r
330     public int getPIDBaseline() {\r
331         return baseline;\r
332     }\r
333     public void setPIDBaseline(int baseline) {\r
334         this.baseline = baseline;\r
335     }\r
336 \r
337     public void setKmers(Vector kmers) {\r
338         this.kmers = kmers;\r
339     }\r
340 \r
341     public Vector getKmers() {\r
342         return this.kmers;\r
343     }\r
344 \r
345 \r
346 }\r