4 import java.awt.Graphics2D.*;
\r
5 import java.awt.image.*;
\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 protected boolean showScores = true;
\r
15 protected int maxIdLength = -1;
\r
16 protected String maxIdStr = null;
\r
17 BufferedImage image;
\r
20 boolean fastPaint = false;
\r
22 public IdCanvas(AlignViewport av)
\r
24 setLayout(new BorderLayout());
\r
26 PaintRefresher.Register(this);
\r
29 public void drawIdString(Graphics2D gg,SequenceI s,int i, int starty, int ypos) {
\r
30 int charHeight = av.getCharHeight();
\r
33 if (av.getSelectionGroup()!=null && av.getSelectionGroup().sequences.contains(s)) {
\r
34 gg.setColor(Color.lightGray);
\r
35 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
36 gg.setColor(Color.white);
\r
38 gg.setColor(s.getColor());
\r
39 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
40 gg.setColor(Color.black);
\r
43 String string = s.getName();
\r
44 if(av.getShowFullId())
\r
45 string = s.getDisplayId();
\r
47 gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight- (charHeight/5));
\r
51 public void fastPaint(int vertical)
\r
54 { repaint(); return;}
\r
56 gg.copyArea( 0,0, getWidth(), imgHeight, 0, -vertical*av.charHeight );
\r
58 int ss=av.startSeq, es=av.endSeq, transY = 0;
\r
59 if(vertical>0) // scroll down
\r
61 transY = imgHeight - vertical*av.charHeight;
\r
69 gg.translate(0, transY);
\r
73 gg.translate( 0, -transY );
\r
80 public void paintComponent(Graphics g)
\r
82 g.setColor(Color.white);
\r
83 g.fillRect(0, 0, getWidth(), getHeight());
\r
87 g.drawImage(image, 0, 0, this);
\r
92 imgHeight = getHeight();
\r
93 imgHeight -= imgHeight % av.charHeight;
\r
94 image = new BufferedImage(getWidth(), imgHeight, BufferedImage.TYPE_INT_RGB);
\r
95 gg = (Graphics2D) image.getGraphics();
\r
96 //Fill in the background
\r
97 gg.setColor(Color.white);
\r
98 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
99 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
100 RenderingHints.VALUE_ANTIALIAS_ON);
\r
101 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
102 av.getFont().getSize());
\r
103 gg.setFont(italic);
\r
105 drawIds( av.getStartSeq(), av.endSeq);
\r
107 g.drawImage(image, 0, 0, this);
\r
110 void drawIds(int starty, int endy)
\r
113 Color currentColor = Color.white;
\r
114 Color currentTextColor = Color.black;
\r
116 if (av.getWrapAlignment())
\r
118 // Draw the rest of the panels
\r
119 int chunkHeight = (av.alignment.getHeight() + 2)*av.charHeight;
\r
120 int row = av.getStartRes() / av.chunkWidth ;
\r
121 for(int ypos=2*av.charHeight;
\r
122 ypos <= getHeight() && row*av.chunkWidth<av.alignment.getWidth();
\r
123 ypos += chunkHeight, row++ )
\r
125 for (int i = starty; i < av.alignment.getHeight(); i++)
\r
127 SequenceI s = av.alignment.getSequenceAt(i);
\r
128 drawIdString(gg, s, i, 0, ypos);
\r
136 //Now draw the id strings
\r
137 for (int i = starty; i < endy; i++)
\r
139 // Selected sequence colours
\r
141 if (av.getSelectionGroup()!= null
\r
142 && av.getSelectionGroup().sequences.contains(av.alignment.getSequenceAt(i)))
\r
144 // if(av.alignment.findGroup(al.getSequenceAt(i)).getEndRes()==
\r
145 currentColor = Color.lightGray;
\r
146 currentTextColor = Color.black;
\r
150 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
151 currentTextColor = Color.black;
\r
154 gg.setColor(currentColor);
\r
157 AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
161 gg.setColor(currentTextColor);
\r
162 String string = av.alignment.getSequenceAt(i).getName();
\r
163 if(av.getShowFullId())
\r
164 string = av.alignment.getSequenceAt(i).getDisplayId();
\r
165 gg.drawString(string, 0,
\r
166 AlignmentUtil.getPixelHeight(starty, i, av.charHeight) +
\r
167 av.charHeight - (av.charHeight / 5));
\r
171 gg.setColor(Color.white);
\r
172 gg.fillRect(getWidth()-4,0,4,getHeight());
\r