8c3f694de5f3661289f1b900c1d124c42ccd7163
[jalview.git] / src / jalview / schemes / ConservationColourScheme.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */\r
19 \r
20 package jalview.schemes;\r
21 import java.awt.*;\r
22 import jalview.analysis.*;\r
23 import java.util.Vector;\r
24 \r
25 public class ConservationColourScheme extends ResidueColourScheme {\r
26   public Conservation conserve;\r
27   public ColourSchemeI cs;\r
28   public int inc = 30;\r
29 \r
30   public ConservationColourScheme(Conservation cons, ColourSchemeI oldcs)\r
31   {\r
32     super();\r
33     conserve = cons;\r
34     cs = oldcs;\r
35   }\r
36 \r
37   public void setConsensus(Vector consensus)\r
38   {\r
39     this.consensus = consensus;\r
40     if(cs!=null)\r
41       cs.setConsensus(consensus);\r
42   }\r
43 \r
44    public Color findColour(String s, int i)\r
45    {\r
46      Color c = Color.white;\r
47      if (cs == null)\r
48        return c;\r
49 \r
50      char ch = conserve.getConsSequence().getSequence().charAt(i);\r
51      if (ch == '*' || ch == '+')\r
52      {\r
53        c = cs.findColour(s, i);\r
54      }\r
55      else\r
56      {\r
57        int tmp = 10;\r
58        int t = 0;\r
59        if (!jalview.util.Comparison.isGap(ch))\r
60          t = Integer.parseInt(ch + "");\r
61 \r
62        c = cs.findColour(s, i);\r
63 \r
64        while (tmp >= t)\r
65        {\r
66          c = lighter(c, inc);\r
67          tmp--;\r
68        }\r
69 \r
70      }\r
71 \r
72    return c;\r
73    }\r
74 \r
75 \r
76   public Color lighter(Color c, int inc) {\r
77     int red = c.getRed();\r
78     int blue = c.getBlue();\r
79     int green = c.getGreen();\r
80 \r
81     if (red < 255-inc) { red = red +inc;} else {red = 255;}\r
82     if (blue < 255-inc) { blue = blue +inc;} else {blue = 255;}\r
83     if (green < 255-inc) { green = green +inc;} else {green = 255;}\r
84 \r
85     return new Color(red,green,blue);\r
86   }\r
87 \r
88 }\r