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