X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdCanvas.java;h=0fe986a5b590d7501e76a06e12d1e4bab3b8ca85;hb=1b032d3acf34d0c4166c84366f89e29ff4c784eb;hp=a05c6c0120e280c5862c95c106781f7ec3f95323;hpb=df9b85c1cf39894039018499fe802406cc37f209;p=jalview.git diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index a05c6c0..0fe986a 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -43,6 +43,7 @@ public class IdCanvas extends JPanel int imgHeight = 0; boolean fastPaint = false; java.util.Vector searchResults; + FontMetrics fm; /** * Creates a new IdCanvas object. @@ -53,7 +54,7 @@ public class IdCanvas extends JPanel { setLayout(new BorderLayout()); this.av = av; - PaintRefresher.Register(this, av.alignment); + PaintRefresher.Register(this, av.getSequenceSetId()); } /** @@ -65,9 +66,10 @@ public class IdCanvas extends JPanel * @param starty DOCUMENT ME! * @param ypos DOCUMENT ME! */ - public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty, - int ypos) + public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty, int ypos) { + int xPos = 0; + int panelWidth = getWidth(); int charHeight = av.charHeight; if ((searchResults != null) && searchResults.contains(s)) @@ -87,15 +89,26 @@ public class IdCanvas extends JPanel } else { - gg.setColor(s.getColor()); + gg.setColor(av.getSequenceColour(s)); gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(), charHeight); gg.setColor(Color.black); } + if (av.rightAlignIds) + { + xPos = panelWidth - fm.stringWidth( + s.getDisplayId(av.getShowJVSuffix()) + ) - 4; + } gg.drawString( s.getDisplayId(av.getShowJVSuffix()), - 0, (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5)); + xPos, (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5)); + + if (av.hasHiddenRows && av.showHiddenMarkers) + drawMarker(i, starty, ypos); + + } /** @@ -169,6 +182,8 @@ public class IdCanvas extends JPanel return; } + int oldHeight = imgHeight; + imgHeight = getHeight(); imgHeight -= (imgHeight % av.charHeight); @@ -177,15 +192,18 @@ public class IdCanvas extends JPanel return; } - image = new BufferedImage(getWidth(), imgHeight, - BufferedImage.TYPE_INT_RGB); + if(oldHeight!=imgHeight || image.getWidth(this)!=getWidth()) + { + 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); - drawIds(av.getStartSeq(), av.endSeq); g.drawImage(image, 0, 0, this); @@ -203,6 +221,7 @@ public class IdCanvas extends JPanel av.getFont().getSize()); gg.setFont(italic); + fm = gg.getFontMetrics(); if (av.antiAlias) gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, @@ -249,7 +268,7 @@ public class IdCanvas extends JPanel { if (av.hasHiddenRows) { - setHiddenFont(i, starty); + setHiddenFont(i); } else gg.setFont(italic); @@ -264,35 +283,47 @@ public class IdCanvas extends JPanel labels.drawComponent(gg, getWidth()); gg.translate(0, -ypos-(alheight * av.charHeight)); } + + } } else { + //Now draw the id strings + int panelWidth = getWidth(); + int xPos = 0; + + SequenceI sequence; //Now draw the id strings for (int i = starty; i < endy; i++) { + sequence = av.alignment.getSequenceAt(i); + + if(sequence==null) + continue; + if (av.hasHiddenRows) { - setHiddenFont(i, starty); + setHiddenFont(i); } // Selected sequence colours if ( (searchResults != null) && - searchResults.contains(av.alignment.getSequenceAt(i))) + searchResults.contains(sequence)) { currentColor = Color.black; currentTextColor = Color.white; } else if ( (av.getSelectionGroup() != null) && av.getSelectionGroup().getSequences(false).contains( - av.alignment.getSequenceAt(i))) + sequence)) { currentColor = Color.lightGray; currentTextColor = Color.black; } else { - currentColor = av.alignment.getSequenceAt(i).getColor(); + currentColor = av.getSequenceColour(sequence); currentTextColor = Color.black; } @@ -303,39 +334,95 @@ public class IdCanvas extends JPanel gg.setColor(currentTextColor); - String string = av.alignment.getSequenceAt(i).getDisplayId( av.getShowJVSuffix()); + String string = sequence.getDisplayId( av.getShowJVSuffix()); + - gg.drawString(string, 0, + if(av.rightAlignIds) + { + xPos = panelWidth - fm.stringWidth(string) - 4; + } + + gg.drawString(string, xPos, (((i - starty) * av.charHeight) + av.charHeight) - (av.charHeight / 5)); + + if(av.hasHiddenRows && av.showHiddenMarkers) + drawMarker(i, starty, 0); + } } } - void setHiddenFont(int i, int starty) + void drawMarker(int i, int starty, int yoffset) { - Font italic = new Font(av.getFont().getName(), Font.ITALIC, - av.getFont().getSize()); - Font bold = new Font(av.getFont().getName(), Font.BOLD, - av.getFont().getSize()); - int tmp, hiddenIndex = starty; - tmp = av.adjustForHiddenSeqs(i); + SequenceI [] hseqs = av.alignment.getHiddenSequences().hiddenSequences; + //Use this method here instead of calling hiddenSeq adjust + //3 times. + int hSize = hseqs.length; - if (av.adjustForHiddenSeqs(i - 1) == tmp - 1) - { - hiddenIndex = tmp; - } + int hiddenIndex = i; + int lastIndex = i - 1; + int nextIndex = i + 1; - if (hiddenIndex != tmp) + for(int j=0; j lastIndex + 1); + boolean above = (nextIndex > hiddenIndex+1); + + + gg.setColor(Color.blue); + if(below) + { + gg.fillPolygon(new int[] + {getWidth()- av.charHeight, + getWidth()- av.charHeight, + getWidth()}, + new int[] + { + (i - starty) * av.charHeight +yoffset, + (i - starty) * av.charHeight +yoffset+ av.charHeight / 4, + (i - starty) * av.charHeight+yoffset + }, 3); + } + if(above) + { + gg.fillPolygon(new int[] + {getWidth()- av.charHeight, + getWidth()- av.charHeight, + getWidth() }, + new int[] + { + (i - starty+1) * av.charHeight +yoffset, + (i - starty+1) * av.charHeight +yoffset- av.charHeight / 4, + (i - starty+1) * av.charHeight +yoffset + }, 3); + + } + } + + void setHiddenFont(int i) + { + Font italic = new Font(av.getFont().getName(), Font.ITALIC, + av.getFont().getSize()); + Font bold = new Font(av.getFont().getName(), Font.BOLD, + av.getFont().getSize()); + - if (av.alignment.getSequenceAt(i).getHiddenSequences() != null) + if (av.alignment.getSequenceAt(i)!=null + && av.alignment.getSequenceAt(i).getHiddenSequences() != null) gg.setFont(bold); else gg.setFont(italic);