4 import javax.swing.*;
\r
5 import jalview.datamodel.*;
\r
6 import jalview.analysis.*;
\r
7 public class IdCanvas extends JPanel
\r
10 protected Graphics gg;
\r
12 protected int imgWidth;
\r
13 protected int imgHeight;
\r
15 protected AlignViewport av;
\r
17 public boolean paintFlag = false;
\r
18 protected boolean showScores = true;
\r
20 protected int maxIdLength = -1;
\r
21 protected String maxIdStr = null;
\r
23 public IdCanvas(AlignViewport av)
\r
25 setLayout(new BorderLayout());
\r
27 PaintRefresher.Register(this);
\r
30 public void drawIdString(Graphics g,SequenceI ds,int i, int starty, int ypos) {
\r
31 int charHeight = av.getCharHeight();
\r
33 if (av.getSelection().contains(ds)) {
\r
34 gg.setColor(Color.gray);
\r
35 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
36 gg.setColor(Color.white);
\r
38 gg.setColor(ds.getColor());
\r
39 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
40 gg.setColor(Color.black);
\r
43 String string = ds.getName() + "/" + ds.getStart() + "-" + ds.getEnd();
\r
45 gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight/2);
\r
49 public void paintComponent(Graphics g) {
\r
50 AlignmentI da = av.getAlignment();
\r
51 int charWidth = (int)av.getCharWidth();
\r
52 int charHeight = av.getCharHeight();
\r
53 Font f = av.getFont();
\r
56 imgWidth != getWidth() ||
\r
57 imgHeight != getHeight() ||
\r
58 paintFlag == true) {
\r
60 imgWidth = getWidth();
\r
61 imgHeight = getHeight();
\r
63 if (imgWidth <= 0 ) {
\r
66 if (imgHeight <= 0 ) {
\r
70 img = createImage(imgWidth,imgHeight);
\r
72 gg = img.getGraphics();
\r
73 gg.setColor(Color.white);
\r
74 gg.fillRect(0,0,imgWidth,imgHeight);
\r
83 //Fill in the background
\r
84 gg.setColor(Color.white);
\r
85 gg.fillRect(0,0,imgWidth,imgHeight);
\r
87 Color currentColor = Color.white;
\r
88 Color currentTextColor = Color.black;
\r
90 //Which ids are we printing
\r
91 int starty = av.getStartSeq();
\r
92 int endy = av.getEndSeq();
\r
96 if (av.getWrapAlignment()) {
\r
97 starty = starty%av.getChunkHeight();
\r
100 int rowstart = starty;
\r
103 ypos = 2*charHeight;
\r
104 } else if (starty == 1) {
\r
109 endy = starty + da.getHeight();
\r
111 if (endy > da.getHeight()) {
\r
112 endy = da.getHeight();
\r
115 for (int i = starty; i < endy; i++) {
\r
116 SequenceI s = da.getSequenceAt(i);
\r
117 drawIdString(gg,s,i,starty,ypos);
\r
119 if (rowstart == 0) {
\r
120 ypos = ypos + av.getChunkHeight();
\r
121 } else if (rowstart == 1) {
\r
122 ypos = ypos + av.getChunkHeight();
\r
124 ypos = ypos + av.getChunkHeight() - rowstart*charHeight;
\r
129 int chunkwidth = av.getChunkWidth();
\r
130 int startx = (int)(av.getEndSeq()/chunkwidth)*chunkwidth;
\r
131 int endx = startx + chunkwidth;
\r
134 while (ypos <= getHeight() && endx < da.getWidth()) {
\r
136 for (int i = starty; i < endy; i++) {
\r
137 SequenceI s = da.getSequenceAt(i);
\r
138 drawIdString(gg,s,i,starty,ypos);
\r
141 ypos += av.getChunkHeight();
\r
142 startx += chunkwidth;
\r
143 endx = startx + chunkwidth;
\r
145 if (endx > da.getWidth()) {
\r
146 endx = da.getWidth();
\r
151 if (endy > da.getHeight()) {
\r
152 endy = da.getHeight();
\r
158 //Now draw the id strings
\r
159 for (int i = starty; i < endy; i++)
\r
162 // Selected sequence colours
\r
164 if (av.getSelection().contains(da.getSequenceAt(i))) {
\r
165 if (currentColor != Color.gray) {
\r
166 currentColor = Color.gray;
\r
167 currentTextColor = Color.black;
\r
170 else if (da.getSequenceAt(i).getColor() != null)
\r
172 currentColor = da.getSequenceAt(i).getColor();
\r
173 currentTextColor = Color.black;
\r
176 gg.setColor(currentColor);
\r
178 if (currentColor != Color.BLACK)
\r
181 AlignmentUtil.getPixelHeight(starty,i,charHeight),
\r
186 gg.setColor(currentTextColor);
\r
188 String string = da.getSequenceAt(i).getDisplayId();
\r
190 gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + charHeight- (charHeight/5));
\r
194 g.drawImage(img,0,0,this);
\r
198 public Dimension getLabelWidth()
\r
201 FontMetrics fm = this.getGraphics().getFontMetrics(av.font);
\r
202 AlignmentI al = av.getAlignment();
\r
207 while (i < al.getHeight() && al.getSequenceAt(i) != null)
\r
209 SequenceI s = al.getSequenceAt(i);
\r
210 String str = s.getDisplayId();
\r
211 if (fm.stringWidth(str) > idWidth)
\r
212 idWidth = fm.stringWidth(str);
\r
216 return new Dimension(idWidth + 10,getHeight());
\r
219 public Dimension getPreferredSize()
\r
221 return getLabelWidth();
\r