selection removed, now SelectionGroup does same job as id select and residue select
[jalview.git] / src / jalview / gui / IdCanvas.java
1 package jalview.gui;\r
2 \r
3 import java.awt.*;\r
4 import java.awt.Graphics2D.*;\r
5 \r
6 import javax.swing.*;\r
7 import jalview.datamodel.*;\r
8 import jalview.analysis.*;\r
9 public class IdCanvas extends JPanel\r
10 {\r
11   protected AlignViewport av;\r
12 \r
13   protected boolean showScores  = true;\r
14 \r
15   protected int     maxIdLength = -1;\r
16   protected String  maxIdStr    = null;\r
17 \r
18   public IdCanvas(AlignViewport av)\r
19   {\r
20     setLayout(new BorderLayout());\r
21     this.av         = av;\r
22     PaintRefresher.Register(this);\r
23   }\r
24 \r
25   public void drawIdString(Graphics gg,SequenceI s,int i, int starty, int ypos) {\r
26       int charHeight = av.getCharHeight();\r
27 \r
28 \r
29       if (av.getSelectionGroup()!=null && av.getSelectionGroup().sequences.contains(s)) {\r
30           gg.setColor(Color.lightGray);\r
31           gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);\r
32           gg.setColor(Color.white);\r
33       } else {\r
34           gg.setColor(s.getColor());\r
35           gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);\r
36           gg.setColor(Color.black);\r
37       }\r
38 \r
39       String string = s.getName() + "/" + s.getStart() + "-" + s.getEnd();\r
40 \r
41       gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight-   (charHeight/5));\r
42 \r
43   }\r
44 \r
45   public void paintComponent(Graphics gg) {\r
46     AlignmentI al         = av.alignment;\r
47     int        charHeight = av.charHeight;\r
48     gg.setFont(av.getFont());\r
49 \r
50     //Fill in the background\r
51     gg.setColor(Color.white);\r
52     gg.fillRect(0,0,getWidth(),getHeight());\r
53 \r
54     Color currentColor     = Color.white;\r
55     Color currentTextColor = Color.black;\r
56 \r
57     //Which ids are we printing\r
58     int starty = av.getStartSeq();\r
59     int endy   = av.endSeq;\r
60 \r
61     if (av.getWrapAlignment())\r
62     {\r
63           // Draw the rest of the panels\r
64           int chunkHeight =  (al.getHeight() + 2)*av.charHeight;\r
65           int row = av.getStartRes() / av.chunkWidth ;\r
66           for(int ypos=2*av.charHeight;\r
67               ypos <= getHeight() && row*av.chunkWidth<al.getWidth();\r
68               ypos += chunkHeight, row++ )\r
69           {\r
70             for (int i = starty; i < av.alignment.getHeight(); i++)\r
71             {\r
72               SequenceI s = al.getSequenceAt(i);\r
73               drawIdString(gg, s, i, 0, ypos);\r
74             }\r
75           }\r
76 \r
77 \r
78     } else\r
79     {\r
80 \r
81       //Now draw the id strings\r
82       for (int i = starty; i < endy; i++)\r
83       {\r
84         // Selected sequence colours\r
85 \r
86         if (av.getSelectionGroup()!= null && av.getSelectionGroup().sequences.contains(al.getSequenceAt(i)))\r
87         {\r
88        //   if(av.alignment.findGroup(al.getSequenceAt(i)).getEndRes()==\r
89           currentColor = Color.lightGray;\r
90           currentTextColor = Color.black;\r
91         }\r
92         else\r
93         {\r
94           currentColor = al.getSequenceAt(i).getColor();\r
95           currentTextColor = Color.black;\r
96         }\r
97 \r
98         gg.setColor(currentColor);\r
99 \r
100         gg.fillRect(0,\r
101                     AlignmentUtil.getPixelHeight(starty, i, charHeight),\r
102                     getWidth(),\r
103                     charHeight);\r
104 \r
105         gg.setColor(currentTextColor);\r
106         String string = al.getSequenceAt(i).getDisplayId();\r
107         gg.drawString(string, 0,\r
108                       AlignmentUtil.getPixelHeight(starty, i, charHeight) +\r
109                       charHeight - (charHeight / 5));\r
110       }\r
111     }\r
112 \r
113   }\r
114 \r
115 \r
116   public Dimension getLabelWidth()\r
117   {\r
118     if(getGraphics()==null)\r
119       return null;\r
120 \r
121    FontMetrics fm = this.getGraphics().getFontMetrics(av.font);\r
122    AlignmentI al = av.getAlignment();\r
123 \r
124    int i   = 0;\r
125    int idWidth = 0;\r
126 \r
127    while (i < al.getHeight() && al.getSequenceAt(i) != null)\r
128    {\r
129      SequenceI s   = al.getSequenceAt(i);\r
130      String str   = s.getDisplayId();\r
131      if (fm.stringWidth(str) > idWidth)\r
132        idWidth = fm.stringWidth(str);\r
133      i++;\r
134    }\r
135 \r
136    return new Dimension(idWidth + 10,getHeight());\r
137  }\r
138 \r
139  public Dimension getPreferredSize()\r
140  {\r
141    return getLabelWidth();\r
142  }\r
143 \r
144 \r
145 }\r