X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdCanvas.java;h=b693f988d5fc9693764bb9936d087f57e1089d99;hb=1340920fd1b15c9bc8cd2284def7ec176a4989d5;hp=67fabf799cc3e350699318ff97252cd15f457dee;hpb=dad44a64adbed84c9bf40a49fc8fa01e9e6074f0;p=jalview.git diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 67fabf7..b693f98 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -1,24 +1,23 @@ package jalview.gui; import java.awt.*; +import java.awt.Graphics2D.*; +import java.awt.image.*; import javax.swing.*; import jalview.datamodel.*; import jalview.analysis.*; public class IdCanvas extends JPanel { - protected Image img; - protected Graphics gg; - - protected int imgWidth; - protected int imgHeight; - protected AlignViewport av; - public boolean paintFlag = false; protected boolean showScores = true; protected int maxIdLength = -1; protected String maxIdStr = null; + BufferedImage image; + Graphics2D gg; + int imgHeight=0; + boolean fastPaint = false; public IdCanvas(AlignViewport av) { @@ -27,197 +26,153 @@ public class IdCanvas extends JPanel PaintRefresher.Register(this); } - public void drawIdString(Graphics g,SequenceI ds,int i, int starty, int ypos) { + public void drawIdString(Graphics2D gg,SequenceI s,int i, int starty, int ypos) { int charHeight = av.getCharHeight(); - if (av.getSelection().contains(ds)) { - gg.setColor(Color.gray); + + if (av.getSelectionGroup()!=null && av.getSelectionGroup().sequences.contains(s)) { + gg.setColor(Color.lightGray); gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight); gg.setColor(Color.white); } else { - gg.setColor(ds.getColor()); + gg.setColor(s.getColor()); gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight); gg.setColor(Color.black); } - String string = ds.getName() + "/" + ds.getStart() + "-" + ds.getEnd(); + String string = s.getName(); + if(av.getShowFullId()) + string = s.getDisplayId(); gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight- (charHeight/5)); } - public void paintComponent(Graphics g) { - AlignmentI da = av.getAlignment(); - int charHeight = av.getCharHeight(); - Font f = av.getFont(); + public void fastPaint(int vertical) + { + if(gg==null) + { repaint(); return;} - if (img == null || - imgWidth != getWidth() || - imgHeight != getHeight() || - paintFlag == true) { + gg.copyArea( 0,0, getWidth(), imgHeight, 0, -vertical*av.charHeight ); - imgWidth = getWidth(); - imgHeight = getHeight(); + int ss=av.startSeq, es=av.endSeq, transY = 0; + if(vertical>0) // scroll down + { + transY = imgHeight - vertical*av.charHeight; + ss = es - vertical; + } + else if(vertical<0) + { + es = ss-vertical; + } - if (imgWidth <= 0 ) { - imgWidth = 700; - } - if (imgHeight <= 0 ) { - imgHeight = 500; - } + gg.translate(0, transY); - img = createImage(imgWidth,imgHeight); + drawIds(ss, es); - gg = img.getGraphics(); - gg.setColor(Color.white); - gg.fillRect(0,0,imgWidth,imgHeight); + gg.translate( 0, -transY ); - gg.setFont(f); - paintFlag = false; + fastPaint = true; + repaint(); + } - } + public void paintComponent(Graphics g) + { + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); + if (fastPaint) + { + g.drawImage(image, 0, 0, this); + fastPaint = false; + return; + } + imgHeight = getHeight(); + imgHeight -= imgHeight % av.charHeight; + image = new BufferedImage(getWidth(), imgHeight, BufferedImage.TYPE_INT_RGB); + gg = (Graphics2D) image.getGraphics(); //Fill in the background gg.setColor(Color.white); - gg.fillRect(0,0,imgWidth,imgHeight); + gg.fillRect(0, 0, getWidth(), imgHeight); + gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + Font italic = new Font(av.getFont().getName(), Font.ITALIC, + av.getFont().getSize()); + gg.setFont(italic); - Color currentColor = Color.white; - Color currentTextColor = Color.black; + drawIds( av.getStartSeq(), av.endSeq); - //Which ids are we printing - int starty = av.getStartSeq(); - int endy = av.getEndSeq(); + g.drawImage(image, 0, 0, this); + } + void drawIds(int starty, int endy) + { + + Color currentColor = Color.white; + Color currentTextColor = Color.black; if (av.getWrapAlignment()) { - starty = starty%av.getChunkHeight(); - - int ypos = 0; - int rowstart = starty; - - if (starty == 0) - ypos = 2*charHeight; - else if (starty == 1) - { - starty = 0; - ypos = charHeight; - } - - endy = starty + da.getHeight(); - - if (endy > da.getHeight()) { - endy = da.getHeight(); - } - - for (int i = starty; i < endy; i++) { - SequenceI s = da.getSequenceAt(i); - drawIdString(gg,s,i,starty,ypos); - } - if (rowstart == 0) { - ypos = ypos + av.getChunkHeight(); - } else if (rowstart == 1) { - ypos = ypos + av.getChunkHeight(); - } else { - ypos = ypos + av.getChunkHeight() - rowstart*charHeight; - } - - starty = 0; - - int chunkwidth = av.getChunkWidth(); - int startx = (int)(av.getEndSeq()/chunkwidth)*chunkwidth; - int endx = startx + chunkwidth; - - while (ypos <= getHeight() && endx < da.getWidth()) { + int rowSize = av.getEndRes() - av.getStartRes(); + // Draw the rest of the panels - for (int i = starty; i < endy; i++) { - SequenceI s = da.getSequenceAt(i); - drawIdString(gg,s,i,starty,ypos); - } + for(int ypos=2*av.charHeight, row=av.getEndRes(); + ypos <= getHeight() && row da.getWidth()) { - endx = da.getWidth(); - } - - starty = 0; - - if (endy > da.getHeight()) { - endy = da.getHeight(); - } - - } - } else { - - //Now draw the id strings - for (int i = starty; i < endy; i++) + } else { - // Selected sequence colours - if (av.getSelection().contains(da.getSequenceAt(i))) - { - currentColor = Color.gray; - currentTextColor = Color.black; - } - else + //Now draw the id strings + for (int i = starty; i < endy; i++) { - currentColor = da.getSequenceAt(i).getColor(); - currentTextColor = Color.black; - } - - gg.setColor(currentColor); + // Selected sequence colours + if (av.getSelectionGroup()!= null + && av.getSelectionGroup().sequences.contains(av.alignment.getSequenceAt(i))) + { + // if(av.alignment.findGroup(al.getSequenceAt(i)).getEndRes()== + currentColor = Color.lightGray; + currentTextColor = Color.black; + } + else + { + currentColor = av.alignment.getSequenceAt(i).getColor(); + currentTextColor = Color.black; + } + gg.setColor(currentColor); - gg.fillRect(0, - AlignmentUtil.getPixelHeight(starty,i,charHeight), + gg.fillRect(0, + AlignmentUtil.getPixelHeight(starty, i, av.charHeight), getWidth(), - charHeight); - - gg.setColor(currentTextColor); - - String string = da.getSequenceAt(i).getDisplayId(); + av.charHeight); + + gg.setColor(currentTextColor); + String string = av.alignment.getSequenceAt(i).getName(); + if(av.getShowFullId()) + string = av.alignment.getSequenceAt(i).getDisplayId(); + gg.drawString(string, 0, + AlignmentUtil.getPixelHeight(starty, i, av.charHeight) + + av.charHeight - (av.charHeight / 5)); + } - gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + charHeight- (charHeight/5)); - } + // add a border + gg.setColor(Color.white); + gg.fillRect(getWidth()-4,0,4,getHeight()); } - g.drawImage(img,0,0,this); } - - - public Dimension getLabelWidth() - { - - FontMetrics fm = this.getGraphics().getFontMetrics(av.font); - AlignmentI al = av.getAlignment(); - - int i = 0; - int idWidth = 0; - - while (i < al.getHeight() && al.getSequenceAt(i) != null) - { - SequenceI s = al.getSequenceAt(i); - String str = s.getDisplayId(); - if (fm.stringWidth(str) > idWidth) - idWidth = fm.stringWidth(str); - i++; - } - - return new Dimension(idWidth + 10,getHeight()); - } - - public Dimension getPreferredSize() - { - return getLabelWidth(); - } - - }