X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdCanvas.java;h=71cc48344d6380a0038dc8e8337b0aaee04245dd;hb=3e6b14950a06bb87c147493e4dfff0c4491ea25b;hp=5959493fa0cbe6b739a33b9907378dddd310eabb;hpb=628a29c56cc280f434f3568f3bf79555e1c77726;p=jalview.git diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 5959493..71cc483 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,10 @@ public class IdCanvas extends JPanel int imgHeight = 0; boolean fastPaint = false; java.util.Vector searchResults; + FontMetrics fm; + AnnotationLabels labels = null; + AnnotationPanel ap; + Font idfont; /** * Creates a new IdCanvas object. @@ -53,7 +57,7 @@ public class IdCanvas extends JPanel { setLayout(new BorderLayout()); this.av = av; - PaintRefresher.Register(this, av.alignment); + PaintRefresher.Register(this, av.getSequenceSetId()); } /** @@ -67,6 +71,8 @@ public class IdCanvas extends JPanel */ 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)) @@ -77,7 +83,7 @@ public class IdCanvas extends JPanel gg.setColor(Color.white); } else if ((av.getSelectionGroup() != null) && - av.getSelectionGroup().getSequences(false).contains(s)) + av.getSelectionGroup().getSequences(null).contains(s)) { gg.setColor(Color.lightGray); gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(), @@ -86,15 +92,21 @@ 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); @@ -173,6 +185,8 @@ public class IdCanvas extends JPanel return; } + int oldHeight = imgHeight; + imgHeight = getHeight(); imgHeight -= (imgHeight % av.charHeight); @@ -181,15 +195,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,10 +220,14 @@ public class IdCanvas extends JPanel */ void drawIds(int starty, int endy) { - Font italic = new Font(av.getFont().getName(), Font.ITALIC, + if(av.seqNameItalics) + idfont = new Font(av.getFont().getName(), Font.ITALIC, av.getFont().getSize()); + else + idfont = av.getFont(); - gg.setFont(italic); + gg.setFont(idfont); + fm = gg.getFontMetrics(); if (av.antiAlias) gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, @@ -224,13 +245,16 @@ public class IdCanvas extends JPanel maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; int annotationHeight = 0; - AnnotationLabels labels = null; + if(av.showAnnotation) { - AnnotationPanel ap = new AnnotationPanel(av); + if (ap == null) + ap = new AnnotationPanel(av); + annotationHeight = ap.adjustPanelHeight(); - labels = new AnnotationLabels(av); + if (labels == null) + labels = new AnnotationLabels(av); } int hgap = av.charHeight; @@ -251,56 +275,65 @@ public class IdCanvas extends JPanel { for (int i = starty; i < alheight; i++) { + SequenceI s = av.alignment.getSequenceAt(i); if (av.hasHiddenRows) { - setHiddenFont(i); + setHiddenFont(s); } else - gg.setFont(italic); + gg.setFont(idfont); - SequenceI s = av.alignment.getSequenceAt(i); drawIdString(gg, s, i, 0, ypos); } - if(labels!=null) + if(labels!=null && av.showAnnotation) { gg.translate(0, ypos+(alheight * av.charHeight)); labels.drawComponent(gg, getWidth()); gg.translate(0, -ypos-(alheight * av.charHeight)); } - - } } else { + //No need to hang on to labels if we're not wrapped + labels = null; + //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); + setHiddenFont(sequence); } // 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))) + av.getSelectionGroup().getSequences(null).contains( + sequence)) { currentColor = Color.lightGray; currentTextColor = Color.black; } else { - currentColor = av.alignment.getSequenceAt(i).getColor(); + currentColor = av.getSequenceColour(sequence); currentTextColor = Color.black; } @@ -311,9 +344,15 @@ 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)); @@ -327,12 +366,32 @@ public class IdCanvas extends JPanel void drawMarker(int i, int starty, int yoffset) { - int hiddenIndex = av.adjustForHiddenSeqs(i); - int lastIndex = av.adjustForHiddenSeqs(i - 1); - int nextIndex = av.adjustForHiddenSeqs(i + 1); + + SequenceI [] hseqs = av.alignment.getHiddenSequences().hiddenSequences; + //Use this method here instead of calling hiddenSeq adjust + //3 times. + int hSize = hseqs.length; + + int hiddenIndex = i; + int lastIndex = i - 1; + int nextIndex = i + 1; + + for(int j=0; j lastIndex + 1); - boolean above = (nextIndex>hiddenIndex+1); + boolean above = (nextIndex > hiddenIndex+1); + gg.setColor(Color.blue); if(below) @@ -364,17 +423,17 @@ public class IdCanvas extends JPanel } } - void setHiddenFont(int i) + void setHiddenFont(SequenceI seq) { - 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.hiddenRepSequences!=null && + av.hiddenRepSequences.containsKey(seq)) gg.setFont(bold); else - gg.setFont(italic); + gg.setFont(idfont); } /**