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