idwidth is calculated in alignpanel, not idcanvas
[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();\r
40       if(av.getShowFullId())\r
41         string = s.getDisplayId();\r
42 \r
43       gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight-   (charHeight/5));\r
44 \r
45   }\r
46 \r
47   public void paintComponent(Graphics gg) {\r
48     AlignmentI al         = av.alignment;\r
49     int        charHeight = av.charHeight;\r
50     Font italic = new Font(av.getFont().getName(), Font.ITALIC, av.getFont().getSize());\r
51 \r
52     gg.setFont(italic);\r
53 \r
54 \r
55     //Fill in the background\r
56     gg.setColor(Color.white);\r
57     gg.fillRect(0,0,getWidth(),getHeight());\r
58 \r
59     Color currentColor     = Color.white;\r
60     Color currentTextColor = Color.black;\r
61 \r
62     //Which ids are we printing\r
63     int starty = av.getStartSeq();\r
64     int endy   = av.endSeq;\r
65 \r
66     if (av.getWrapAlignment())\r
67     {\r
68           // Draw the rest of the panels\r
69           int chunkHeight =  (al.getHeight() + 2)*av.charHeight;\r
70           int row = av.getStartRes() / av.chunkWidth ;\r
71           for(int ypos=2*av.charHeight;\r
72               ypos <= getHeight() && row*av.chunkWidth<al.getWidth();\r
73               ypos += chunkHeight, row++ )\r
74           {\r
75             for (int i = starty; i < av.alignment.getHeight(); i++)\r
76             {\r
77               SequenceI s = al.getSequenceAt(i);\r
78               drawIdString(gg, s, i, 0, ypos);\r
79             }\r
80           }\r
81 \r
82 \r
83     } else\r
84     {\r
85 \r
86       //Now draw the id strings\r
87       for (int i = starty; i < endy; i++)\r
88       {\r
89         // Selected sequence colours\r
90 \r
91         if (av.getSelectionGroup()!= null && av.getSelectionGroup().sequences.contains(al.getSequenceAt(i)))\r
92         {\r
93        //   if(av.alignment.findGroup(al.getSequenceAt(i)).getEndRes()==\r
94           currentColor = Color.lightGray;\r
95           currentTextColor = Color.black;\r
96         }\r
97         else\r
98         {\r
99           currentColor = al.getSequenceAt(i).getColor();\r
100           currentTextColor = Color.black;\r
101         }\r
102 \r
103         gg.setColor(currentColor);\r
104 \r
105         gg.fillRect(0,\r
106                     AlignmentUtil.getPixelHeight(starty, i, charHeight),\r
107                     getWidth(),\r
108                     charHeight);\r
109 \r
110         gg.setColor(currentTextColor);\r
111         String string = al.getSequenceAt(i).getName();\r
112         if(av.getShowFullId())\r
113           string = al.getSequenceAt(i).getDisplayId();\r
114         gg.drawString(string, 0,\r
115                       AlignmentUtil.getPixelHeight(starty, i, charHeight) +\r
116                       charHeight - (charHeight / 5));\r
117       }\r
118     }\r
119 \r
120   }\r
121 }\r