X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdCanvas.java;h=4f5288d924d0b16068f09d7bc26c4ce9ac8f98be;hb=339c2de5fce77a1e1518df6df0c2d894352d6648;hp=67c3dca37b3d0036ae6e73bcad7406d9f5598bc1;hpb=51605ff0b3c81ba5894348745596b5038d905ffb;p=jalview.git diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 67c3dca..4f5288d 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -2,7 +2,7 @@ package jalview.gui; import java.awt.*; import java.awt.Graphics2D.*; - +import java.awt.image.*; import javax.swing.*; import jalview.datamodel.*; import jalview.analysis.*; @@ -10,11 +10,16 @@ public class IdCanvas extends JPanel { 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; + + java.util.Vector searchResults; public IdCanvas(AlignViewport av) { @@ -23,103 +28,126 @@ public class IdCanvas extends JPanel PaintRefresher.Register(this); } - public void drawIdString(Graphics gg,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(searchResults!=null && searchResults.contains(s)) + { + gg.setColor(Color.black); + gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight); + gg.setColor(Color.white); + } + else 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 gg) { - AlignmentI da = av.getAlignment(); - int charHeight = av.getCharHeight(); - gg.setFont(av.getFont()); + public void fastPaint(int vertical) + { + if(gg==null) + { repaint(); return;} - //Fill in the background - gg.setColor(Color.white); - gg.fillRect(0,0,getWidth(),getHeight()); + gg.copyArea( 0,0, getWidth(), imgHeight, 0, -vertical*av.charHeight ); - Color currentColor = Color.white; - Color currentTextColor = Color.black; + int ss=av.startSeq, es=av.endSeq, transY = 0; + if (vertical > 0) // scroll down + { + ss = es - vertical; + if(ss av.endSeq) + es = av.endSeq; + } - //Which ids are we printing - int starty = av.getStartSeq(); - int endy = av.getEndSeq(); - if (av.getWrapAlignment()) - { - starty = starty%av.getChunkHeight(); - int ypos = 0; - int rowstart = starty; + gg.translate(0, transY); - if (starty == 0) - ypos = 2*charHeight; - else if (starty == 1) - { - starty = 0; - ypos = charHeight; - } + drawIds(ss, es); - endy = starty + da.getHeight(); + gg.translate( 0, -transY ); - 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; - } + fastPaint = true; + repaint(); + } - starty = 0; + public void paintComponent(Graphics g) + { + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); - int chunkwidth = av.getChunkWidth(); - int startx = (int)(av.getEndSeq()/chunkwidth)*chunkwidth; - int endx = startx + chunkwidth; + if (fastPaint) + { + fastPaint = false; + g.drawImage(image, 0, 0, this); + return; + } + imgHeight = getHeight(); + imgHeight -= imgHeight % av.charHeight; - while (ypos <= getHeight() && endx < da.getWidth()) { + if (imgHeight<1) + return; - for (int i = starty; i < endy; i++) { - SequenceI s = da.getSequenceAt(i); - drawIdString(gg,s,i,starty,ypos); - } + 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, 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); - ypos += av.getChunkHeight(); - startx += chunkwidth; - endx = startx + chunkwidth; + drawIds( av.getStartSeq(), av.endSeq); - if (endx > da.getWidth()) { - endx = da.getWidth(); - } + g.drawImage(image, 0, 0, this); + } - starty = 0; + void drawIds(int starty, int endy) + { + Color currentColor = Color.white; + Color currentTextColor = Color.black; + + if (av.getWrapAlignment()) + { + + int rowSize = av.getEndRes() - av.getStartRes(); + // Draw the rest of the panels + + for(int ypos=2*av.charHeight, row=av.startRes; + ypos <= getHeight() && row da.getHeight()) { - endy = da.getHeight(); - } - } } else { @@ -127,60 +155,51 @@ public class IdCanvas extends JPanel for (int i = starty; i < endy; i++) { // Selected sequence colours - if (av.getSelection().contains(da.getSequenceAt(i))) + + if(searchResults!=null && searchResults.contains(av.alignment.getSequenceAt(i))) { - currentColor = Color.gray; + gg.setColor(Color.black); + currentColor = Color.black; + currentTextColor = Color.white; + } + else if (av.getSelectionGroup()!= null + && av.getSelectionGroup().sequences.contains(av.alignment.getSequenceAt(i))) + { + currentColor = Color.lightGray; currentTextColor = Color.black; } else { - currentColor = da.getSequenceAt(i).getColor(); + currentColor = av.alignment.getSequenceAt(i).getColor(); currentTextColor = Color.black; } gg.setColor(currentColor); gg.fillRect(0, - AlignmentUtil.getPixelHeight(starty, i, charHeight), + AlignmentUtil.getPixelHeight(starty, i, av.charHeight), getWidth(), - charHeight); + av.charHeight); gg.setColor(currentTextColor); - String string = da.getSequenceAt(i).getDisplayId(); + String string = av.alignment.getSequenceAt(i).getName(); + if(av.getShowFullId()) + string = av.alignment.getSequenceAt(i).getDisplayId(); gg.drawString(string, 0, - AlignmentUtil.getPixelHeight(starty, i, charHeight) + - charHeight - (charHeight / 5)); + AlignmentUtil.getPixelHeight(starty, i, av.charHeight) + + av.charHeight - (av.charHeight / 5)); } + + // add a border + gg.setColor(Color.white); + gg.fillRect(getWidth()-4,0,4,getHeight()); } } - - public Dimension getLabelWidth() + public void setHighlighted(java.util.Vector found) { - - 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(); - } - - + searchResults = found; + repaint(); + } }