4 import java.awt.Graphics2D.*;
\r
6 import javax.swing.*;
\r
7 import jalview.datamodel.*;
\r
8 import jalview.analysis.*;
\r
9 public class IdCanvas extends JPanel
\r
11 protected AlignViewport av;
\r
13 public boolean paintFlag = false;
\r
14 protected boolean showScores = true;
\r
16 protected int maxIdLength = -1;
\r
17 protected String maxIdStr = null;
\r
19 public IdCanvas(AlignViewport av)
\r
21 setLayout(new BorderLayout());
\r
23 PaintRefresher.Register(this);
\r
26 public void drawIdString(Graphics gg,SequenceI ds,int i, int starty, int ypos) {
\r
27 int charHeight = av.getCharHeight();
\r
29 if (av.getSelection().contains(ds)) {
\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
34 gg.setColor(ds.getColor());
\r
35 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
36 gg.setColor(Color.black);
\r
39 String string = ds.getName() + "/" + ds.getStart() + "-" + ds.getEnd();
\r
41 gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight- (charHeight/5));
\r
45 public void paintComponent(Graphics gg) {
\r
46 AlignmentI da = av.getAlignment();
\r
47 int charHeight = av.getCharHeight();
\r
48 gg.setFont(av.getFont());
\r
50 //Fill in the background
\r
51 gg.setColor(Color.white);
\r
52 gg.fillRect(0,0,getWidth(),getHeight());
\r
54 Color currentColor = Color.white;
\r
55 Color currentTextColor = Color.black;
\r
57 //Which ids are we printing
\r
58 int starty = av.getStartSeq();
\r
59 int endy = av.endSeq;
\r
61 if (av.getWrapAlignment())
\r
63 // Draw the rest of the panels
\r
64 int chunkHeight = (da.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<da.getWidth();
\r
68 ypos += chunkHeight, row++ )
\r
70 for (int i = starty; i < endy; i++)
\r
72 SequenceI s = da.getSequenceAt(i);
\r
73 drawIdString(gg, s, i, 0, ypos);
\r
81 //Now draw the id strings
\r
82 for (int i = starty; i < endy; i++)
\r
84 // Selected sequence colours
\r
85 if (av.getSelection().contains(da.getSequenceAt(i)))
\r
87 currentColor = Color.lightGray;
\r
88 currentTextColor = Color.black;
\r
92 currentColor = da.getSequenceAt(i).getColor();
\r
93 currentTextColor = Color.black;
\r
96 gg.setColor(currentColor);
\r
99 AlignmentUtil.getPixelHeight(starty, i, charHeight),
\r
103 gg.setColor(currentTextColor);
\r
104 String string = da.getSequenceAt(i).getDisplayId();
\r
105 gg.drawString(string, 0,
\r
106 AlignmentUtil.getPixelHeight(starty, i, charHeight) +
\r
107 charHeight - (charHeight / 5));
\r
114 public Dimension getLabelWidth()
\r
116 if(getGraphics()==null)
\r
119 FontMetrics fm = this.getGraphics().getFontMetrics(av.font);
\r
120 AlignmentI al = av.getAlignment();
\r
125 while (i < al.getHeight() && al.getSequenceAt(i) != null)
\r
127 SequenceI s = al.getSequenceAt(i);
\r
128 String str = s.getDisplayId();
\r
129 if (fm.stringWidth(str) > idWidth)
\r
130 idWidth = fm.stringWidth(str);
\r
134 return new Dimension(idWidth + 10,getHeight());
\r
137 public Dimension getPreferredSize()
\r
139 return getLabelWidth();
\r