resetSeqLimits altered
[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 showFullId = 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 = false;\r
25 \r
26   boolean colourAppliesToAllGroups = true;\r
27   ColourSchemeI globalColourScheme = null;\r
28   boolean conservationColourSelected = false;\r
29   boolean abovePIDThreshold = false;\r
30 \r
31   SequenceGroup selectionGroup = new SequenceGroup();\r
32 \r
33   RendererI renderer = new SequenceRenderer(this);\r
34 \r
35   int             charHeight;\r
36   int             charWidth;\r
37   int             chunkWidth;\r
38   int             chunkHeight;\r
39 \r
40   Font            font = new Font("SansSerif",Font.PLAIN,10);\r
41   AlignmentI      alignment;\r
42 \r
43   ColumnSelection colSel = new ColumnSelection();\r
44 \r
45   String visibleConsensus;\r
46 \r
47   int threshold;\r
48   int increment;\r
49 \r
50   NJTree currentTree = null;\r
51 \r
52 \r
53   public AlignViewport(AlignmentI da,\r
54                        boolean showText,\r
55                        boolean showBoxes,\r
56                        boolean wrapAlignment) {\r
57     this(0,da.getWidth()-1,0,da.getHeight()-1,\r
58          showText,\r
59          showBoxes,\r
60          wrapAlignment);\r
61 \r
62     setAlignment(da);\r
63   }\r
64 \r
65   public AlignViewport(int startRes, int endRes,\r
66                        int startSeq, int endSeq,\r
67                        boolean showText,\r
68                        boolean showBoxes,\r
69                        boolean wrapAlignment) {\r
70 \r
71     this.startRes = startRes;\r
72     this.endRes   = endRes;\r
73     this.startSeq = startSeq;\r
74     this.endSeq   = endSeq;\r
75     this.showText      = showText;\r
76     this.showBoxes     = showBoxes;\r
77     this.wrapAlignment = wrapAlignment;\r
78 \r
79     setFont( font );\r
80  }\r
81 \r
82  public void showSequenceFeatures(boolean b)\r
83  {\r
84    showSequenceFeatures = b;\r
85  }\r
86 \r
87   public String getVisibleConsensus()\r
88   {\r
89     return visibleConsensus;\r
90   }\r
91 \r
92   Vector consensus = new Vector();\r
93   public Vector getConsensus(boolean recalculate)\r
94   {\r
95     if(recalculate || consensus.size()<1)\r
96     {\r
97       consensus = alignment.getAAFrequency();\r
98       StringBuffer sb = new StringBuffer();\r
99       Hashtable hash = null;\r
100       for (int i = 0; i < consensus.size(); i++)\r
101       {\r
102         hash = (Hashtable) consensus.elementAt(i);\r
103         sb.append(hash.get("maxResidue").toString().charAt(0));\r
104       }\r
105       visibleConsensus = sb.toString();\r
106     }\r
107 \r
108 \r
109     return consensus;\r
110   }\r
111 \r
112   public SequenceGroup getSelectionGroup()\r
113   {\r
114     return selectionGroup;\r
115   }\r
116 \r
117   public void setSelectionGroup(SequenceGroup sg)\r
118   {\r
119     selectionGroup = sg;\r
120   }\r
121 \r
122 \r
123  public boolean getConservationSelected()\r
124  {\r
125    return conservationColourSelected;\r
126  }\r
127 \r
128  public void setConservationSelected(boolean b)\r
129  {\r
130    conservationColourSelected = b;\r
131  }\r
132 \r
133  public boolean getAbovePIDThreshold()\r
134  {\r
135    return abovePIDThreshold;\r
136  }\r
137 \r
138  public void setAbovePIDThreshold(boolean b)\r
139  {\r
140    abovePIDThreshold = 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 \r
238   public void setWrapAlignment(boolean state) {\r
239     wrapAlignment = state;\r
240   }\r
241   public void setShowText(boolean state) {\r
242     showText = state;\r
243   }\r
244 \r
245   public void setRenderGaps(boolean state){\r
246     renderGaps = state;\r
247     if(renderer instanceof SequenceRenderer)\r
248     {\r
249       SequenceRenderer sr = (SequenceRenderer)renderer;\r
250       sr.renderGaps(state);\r
251     }\r
252   }\r
253 \r
254 \r
255   public boolean getColourText()\r
256   {\r
257     return showColourText;\r
258   }\r
259 \r
260   public void setColourText(boolean state)\r
261   {\r
262     showColourText = state;\r
263   }\r
264 \r
265   public void setShowBoxes(boolean state) {\r
266     showBoxes = state;\r
267   }\r
268 \r
269   public boolean getWrapAlignment() {\r
270       return wrapAlignment;\r
271   }\r
272   public boolean getShowText() {\r
273     return showText;\r
274   }\r
275   public boolean getShowBoxes() {\r
276     return showBoxes;\r
277   }\r
278 \r
279   public char getGapCharacter() {\r
280     return getAlignment().getGapCharacter();\r
281   }\r
282   public void setGapCharacter(char gap) {\r
283     if (getAlignment() != null) {\r
284       getAlignment().setGapCharacter(gap);\r
285     }\r
286   }\r
287   public void setThreshold(int thresh) {\r
288     threshold = thresh;\r
289   }\r
290   public int getThreshold() {\r
291     return threshold;\r
292   }\r
293   public void setIncrement(int inc) {\r
294     increment = inc;\r
295   }\r
296   public int getIncrement() {\r
297     return increment;\r
298   }\r
299   public int getIndex(int y) {\r
300     int y1     = 0;\r
301     int starty = getStartSeq();\r
302     int endy   = getEndSeq();\r
303 \r
304     for (int i = starty; i <= endy; i++) {\r
305       if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {\r
306         int y2 = y1 + getCharHeight();\r
307 \r
308         if (y>=y1 && y <=y2) {\r
309           return i;\r
310         }\r
311         y1  = y2;\r
312       } else {\r
313         return -1;\r
314       }\r
315     }\r
316     return -1;\r
317   }\r
318 \r
319   public ColumnSelection getColumnSelection() {\r
320     return colSel;\r
321   }\r
322 \r
323   public void resetSeqLimits(int height) {\r
324     setEndSeq(height/getCharHeight());\r
325   }\r
326   public void setCurrentTree(NJTree tree) {\r
327       currentTree = tree;\r
328   }\r
329   public NJTree getCurrentTree() {\r
330     return currentTree;\r
331   }\r
332 \r
333     public void setRenderer(RendererI rend) {\r
334         this.renderer = rend;\r
335     }\r
336 \r
337     public RendererI getRenderer() {\r
338         return renderer;\r
339     }\r
340 \r
341   public void setColourAppliesToAllGroups(boolean b)\r
342   {   colourAppliesToAllGroups = b; }\r
343 \r
344   public boolean getColourAppliesToAllGroups()\r
345   {return colourAppliesToAllGroups; }\r
346 \r
347   public boolean getShowFullId()\r
348   {\r
349     return showFullId;\r
350   }\r
351 \r
352   public void setShowFullId(boolean b)\r
353   {\r
354     showFullId = b;\r
355   }\r
356 }\r