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