trimmed down
[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 = true;\r
24   boolean showSequenceFeatures = true;\r
25 \r
26   ColourSchemeI globalColourScheme = null;\r
27   boolean conservationColourSelected = false;\r
28 \r
29   SequenceGroup rubberbandGroup = null;\r
30 \r
31   RendererI renderer = new SequenceRenderer(this);\r
32 \r
33   int             charHeight;\r
34   int             charWidth;\r
35   int             chunkWidth;\r
36   int             chunkHeight;\r
37 \r
38   Font            font = new Font("SansSerif",Font.PLAIN,10);\r
39   AlignmentI      alignment;\r
40 \r
41   Selection       sel    = new Selection(this);\r
42   ColumnSelection colSel = new ColumnSelection();\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 \r
52   public AlignViewport(AlignmentI da,\r
53                        boolean showScores,\r
54                        boolean showText,\r
55                        boolean showBoxes,\r
56                        boolean wrapAlignment) {\r
57     this(0,da.getWidth()-1,0,da.getHeight()-1,showScores,\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 showScores,\r
68                        boolean showText,\r
69                        boolean showBoxes,\r
70                        boolean wrapAlignment) {\r
71 \r
72     this.startRes = startRes;\r
73     this.endRes   = endRes;\r
74     this.startSeq = startSeq;\r
75     this.endSeq   = endSeq;\r
76 \r
77     this.showScores    = showScores;\r
78     this.showText      = showText;\r
79     this.showBoxes     = showBoxes;\r
80     this.wrapAlignment = wrapAlignment;\r
81 \r
82    // og  = new AlignmentOutputGenerator(this);\r
83 \r
84     setFont( font );\r
85  }\r
86 \r
87  public void showSequenceFeatures(boolean b)\r
88  {\r
89    showSequenceFeatures = b;\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   public SequenceGroup getRubberbandGroup()\r
118   {\r
119     return rubberbandGroup;\r
120   }\r
121 \r
122   public void setRubberbandGroup(SequenceGroup sg)\r
123   {\r
124     rubberbandGroup = sg;\r
125   }\r
126 \r
127  public boolean getConservationSelected()\r
128  {\r
129    return conservationColourSelected;\r
130  }\r
131 \r
132  public void setConservationSelected(boolean b)\r
133  {\r
134    conservationColourSelected = b;\r
135  }\r
136 \r
137   public int getStartRes() {\r
138     return startRes;\r
139   }\r
140 \r
141   public int getEndRes() {\r
142     return endRes;\r
143   }\r
144 \r
145   public int getStartSeq() {\r
146     return startSeq;\r
147   }\r
148 \r
149   public void setGlobalColourScheme(ColourSchemeI cs)\r
150   {\r
151      globalColourScheme = cs;\r
152   }\r
153 \r
154   public ColourSchemeI getGlobalColourScheme()\r
155   {\r
156     return globalColourScheme;\r
157   }\r
158 \r
159 \r
160   public void setStartRes(int res) {\r
161     this.startRes = res;\r
162   }\r
163   public void setStartSeq(int seq) {\r
164     this.startSeq = seq;\r
165   }\r
166   public void setEndRes(int res) {\r
167     if (res > alignment.getWidth()-1) {\r
168       System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));\r
169        res = alignment.getWidth() -1;\r
170     }\r
171     if (res < 0) {\r
172       res = 0;\r
173     }\r
174     this.endRes = res;\r
175   }\r
176   public void setEndSeq(int seq) {\r
177     if (seq > alignment.getHeight()) {\r
178       seq = alignment.getHeight();\r
179     }\r
180     if (seq < 0) {\r
181       seq = 0;\r
182     }\r
183     this.endSeq = seq;\r
184   }\r
185   public int getEndSeq() {\r
186     return endSeq;\r
187   }\r
188 \r
189   public void setFont(Font f) {\r
190     font = f;\r
191     javax.swing.JFrame temp = new javax.swing.JFrame();\r
192     temp.addNotify();\r
193     java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);\r
194     setCharHeight(fm.getHeight());\r
195     setCharWidth(fm.charWidth('M'));\r
196   }\r
197 \r
198   public Font getFont() {\r
199     return font;\r
200   }\r
201   public void setCharWidth(int w) {\r
202     this.charWidth = w;\r
203   }\r
204   public int getCharWidth() {\r
205     return charWidth;\r
206   }\r
207   public void setCharHeight(int h) {\r
208     this.charHeight = h;\r
209   }\r
210   public int getCharHeight() {\r
211     return charHeight;\r
212   }\r
213   public void setChunkWidth(int w) {\r
214     this.chunkWidth = w;\r
215   }\r
216   public int getChunkWidth() {\r
217     return chunkWidth;\r
218   }\r
219   public void setChunkHeight(int h) {\r
220     this.chunkHeight = h;\r
221   }\r
222   public int getChunkHeight() {\r
223     return chunkHeight;\r
224   }\r
225   public AlignmentI getAlignment() {\r
226     return alignment;\r
227   }\r
228   public void setAlignment(AlignmentI align) {\r
229     this.alignment = align;\r
230   }\r
231   public void setShowScores(boolean state) {\r
232     showScores = state;\r
233   }\r
234   public void setWrapAlignment(boolean state) {\r
235     wrapAlignment = state;\r
236   }\r
237   public void setShowText(boolean state) {\r
238     showText = state;\r
239   }\r
240 \r
241   public void setRenderGaps(boolean state){\r
242     renderGaps = state;\r
243     if(renderer instanceof SequenceRenderer)\r
244     {\r
245       SequenceRenderer sr = (SequenceRenderer)renderer;\r
246       sr.renderGaps(state);\r
247     }\r
248   }\r
249 \r
250 \r
251   public boolean getColourText()\r
252   {\r
253     return showColourText;\r
254   }\r
255 \r
256   public void setColourText(boolean state)\r
257   {\r
258     showColourText = state;\r
259   }\r
260 \r
261   public void setShowBoxes(boolean state) {\r
262     showBoxes = state;\r
263   }\r
264   public boolean getShowScores() {\r
265     return showScores;\r
266   }\r
267   public boolean getWrapAlignment() {\r
268       return wrapAlignment;\r
269   }\r
270   public boolean getShowText() {\r
271     return showText;\r
272   }\r
273   public boolean getShowBoxes() {\r
274     return showBoxes;\r
275   }\r
276 \r
277   public char getGapCharacter() {\r
278     return getAlignment().getGapCharacter();\r
279   }\r
280   public void setGapCharacter(char gap) {\r
281     if (getAlignment() != null) {\r
282       getAlignment().setGapCharacter(gap);\r
283     }\r
284   }\r
285   public void setThreshold(int thresh) {\r
286     threshold = thresh;\r
287   }\r
288   public int getThreshold() {\r
289     return threshold;\r
290   }\r
291   public void setIncrement(int inc) {\r
292     increment = inc;\r
293   }\r
294   public int getIncrement() {\r
295     return increment;\r
296   }\r
297   public int getIndex(int y) {\r
298     int y1     = 0;\r
299     int starty = getStartSeq();\r
300     int endy   = getEndSeq();\r
301 \r
302     for (int i = starty; i <= endy; i++) {\r
303       if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) {\r
304         int y2 = y1 + getCharHeight();\r
305 \r
306         if (y>=y1 && y <=y2) {\r
307           return i;\r
308         }\r
309         y1  = y2;\r
310       } else {\r
311         return -1;\r
312       }\r
313     }\r
314     return -1;\r
315   }\r
316   public Selection getSelection() {\r
317     return sel;\r
318   }\r
319   public ColumnSelection getColumnSelection() {\r
320     return colSel;\r
321   }\r
322 \r
323   public void resetSeqLimits(int height) {\r
324     setStartSeq(0);\r
325     setEndSeq(height/getCharHeight());\r
326   }\r
327   public void setCurrentTree(NJTree tree) {\r
328       currentTree = tree;\r
329   }\r
330   public NJTree getCurrentTree() {\r
331     return currentTree;\r
332   }\r
333 \r
334     public void setRenderer(RendererI rend) {\r
335         this.renderer = rend;\r
336     }\r
337 \r
338     public RendererI getRenderer() {\r
339         return renderer;\r
340     }\r
341 \r
342 }\r