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
117 if (av.getWrapAlignment())
\r
120 int rowSize = av.getEndRes() - av.getStartRes();
\r
121 // Draw the rest of the panels
\r
123 for(int ypos=2*av.charHeight, row=av.getEndRes()-rowSize;
\r
124 ypos <= getHeight() && row<av.alignment.getWidth();
\r
125 ypos += av.chunkHeight, row+=rowSize )
\r
127 for (int i = starty; i < av.alignment.getHeight(); i++)
\r
129 SequenceI s = av.alignment.getSequenceAt(i);
\r
130 drawIdString(gg, s, i, 0, ypos);
\r
138 //Now draw the id strings
\r
139 for (int i = starty; i < endy; i++)
\r
141 // Selected sequence colours
\r
143 if (av.getSelectionGroup()!= null
\r
144 && av.getSelectionGroup().sequences.contains(av.alignment.getSequenceAt(i)))
\r
146 // if(av.alignment.findGroup(al.getSequenceAt(i)).getEndRes()==
\r
147 currentColor = Color.lightGray;
\r
148 currentTextColor = Color.black;
\r
152 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
153 currentTextColor = Color.black;
\r
156 gg.setColor(currentColor);
\r
159 AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
163 gg.setColor(currentTextColor);
\r
164 String string = av.alignment.getSequenceAt(i).getName();
\r
165 if(av.getShowFullId())
\r
166 string = av.alignment.getSequenceAt(i).getDisplayId();
\r
167 gg.drawString(string, 0,
\r
168 AlignmentUtil.getPixelHeight(starty, i, av.charHeight) +
\r
169 av.charHeight - (av.charHeight / 5));
\r
173 gg.setColor(Color.white);
\r
174 gg.fillRect(getWidth()-4,0,4,getHeight());
\r