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
21 public IdCanvas(AlignViewport av)
\r
23 setLayout(new BorderLayout());
\r
25 PaintRefresher.Register(this);
\r
28 public void drawIdString(Graphics2D gg,SequenceI s,int i, int starty, int ypos) {
\r
29 int charHeight = av.getCharHeight();
\r
32 if (av.getSelectionGroup()!=null && av.getSelectionGroup().sequences.contains(s)) {
\r
33 gg.setColor(Color.lightGray);
\r
34 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
35 gg.setColor(Color.white);
\r
37 gg.setColor(s.getColor());
\r
38 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
39 gg.setColor(Color.black);
\r
42 String string = s.getName();
\r
43 if(av.getShowFullId())
\r
44 string = s.getDisplayId();
\r
46 gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight- (charHeight/5));
\r
50 public void fastPaint(int vertical)
\r
58 gg.copyArea( 0,0, getWidth(), imgHeight, 0, -vertical*av.charHeight );
\r
60 int ss=av.startSeq, es=av.endSeq, transY = 0;
\r
61 if(vertical>0) // scroll down
\r
63 transY = imgHeight - vertical*av.charHeight;
\r
71 gg.translate(0, transY);
\r
75 gg.translate( 0, -transY );
\r
78 getGraphics().drawImage(image, 0, 0, this);
\r
81 public void paintComponent(Graphics g)
\r
83 imgHeight = getHeight();
\r
84 imgHeight -= imgHeight % av.charHeight;
\r
85 image = new BufferedImage(getWidth(), imgHeight, BufferedImage.TYPE_INT_RGB);
\r
86 gg = (Graphics2D) image.getGraphics();
\r
87 //Fill in the background
\r
88 gg.setColor(Color.white);
\r
89 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
90 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
91 RenderingHints.VALUE_ANTIALIAS_ON);
\r
92 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
93 av.getFont().getSize());
\r
97 g.setColor(Color.white);
\r
98 g.fillRect(0,0,getWidth(),getHeight());
\r
100 drawIds( av.getStartSeq(), av.endSeq);
\r
102 g.drawImage(image, 0, 0, this);
\r
105 void drawIds(int starty, int endy)
\r
108 Color currentColor = Color.white;
\r
109 Color currentTextColor = Color.black;
\r
111 if (av.getWrapAlignment())
\r
113 // Draw the rest of the panels
\r
114 int chunkHeight = (av.alignment.getHeight() + 2)*av.charHeight;
\r
115 int row = av.getStartRes() / av.chunkWidth ;
\r
116 for(int ypos=2*av.charHeight;
\r
117 ypos <= getHeight() && row*av.chunkWidth<av.alignment.getWidth();
\r
118 ypos += chunkHeight, row++ )
\r
120 for (int i = starty; i < av.alignment.getHeight(); i++)
\r
122 SequenceI s = av.alignment.getSequenceAt(i);
\r
123 drawIdString(gg, s, i, 0, ypos);
\r
131 //Now draw the id strings
\r
132 for (int i = starty; i < endy; i++)
\r
134 // Selected sequence colours
\r
136 if (av.getSelectionGroup()!= null
\r
137 && av.getSelectionGroup().sequences.contains(av.alignment.getSequenceAt(i)))
\r
139 // if(av.alignment.findGroup(al.getSequenceAt(i)).getEndRes()==
\r
140 currentColor = Color.lightGray;
\r
141 currentTextColor = Color.black;
\r
145 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
146 currentTextColor = Color.black;
\r
149 gg.setColor(currentColor);
\r
152 AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
156 gg.setColor(currentTextColor);
\r
157 String string = av.alignment.getSequenceAt(i).getName();
\r
158 if(av.getShowFullId())
\r
159 string = av.alignment.getSequenceAt(i).getDisplayId();
\r
160 gg.drawString(string, 0,
\r
161 AlignmentUtil.getPixelHeight(starty, i, av.charHeight) +
\r
162 av.charHeight - (av.charHeight / 5));
\r
166 gg.setColor(Color.white);
\r
167 gg.fillRect(getWidth()-4,0,4,getHeight());
\r