From 893f1fefbcf73ae49776c667b110483ba26ee376 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 27 Sep 2005 14:16:59 +0000 Subject: [PATCH] Show labels in wrapped view --- src/jalview/gui/AlignmentPanel.java | 45 ++++++++++++++++++++++++--------- src/jalview/gui/AnnotationLabels.java | 30 +++++++++++++++------- src/jalview/gui/AnnotationPanel.java | 6 ++--- src/jalview/gui/IdCanvas.java | 22 ++++++++++++---- 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index ac87ebe..d1187ac 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -690,7 +690,7 @@ public class AlignmentPanel extends GAlignmentPanel if (av.showAnnotation && (endSeq == av.alignment.getHeight())) { pg.translate(-idWidth, (endSeq - startSeq) * av.charHeight +3); - alabels.drawComponent((Graphics2D) pg); + alabels.drawComponent((Graphics2D) pg, idWidth); pg.translate(idWidth, 0); annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + 1); @@ -716,8 +716,12 @@ public class AlignmentPanel extends GAlignmentPanel { int annotationHeight = 0; + AnnotationLabels labels = null; if (av.showAnnotation) + { annotationHeight = annotationPanel.adjustPanelHeight(); + labels = new AnnotationLabels(av); + } int hgap = av.charHeight; if (av.scaleAboveWrapped) @@ -749,22 +753,39 @@ public class AlignmentPanel extends GAlignmentPanel pg.setClip(0, pi * pheight, pwidth, pheight); int ypos = hgap; + Font italic = new Font(av.getFont().getName(), Font.ITALIC, + av.getFont().getSize()); + pg.setFont(italic); + do { - for (int i = 0; i < av.alignment.getHeight(); i++) - { - SequenceI s = av.alignment.getSequenceAt(i); - String string = s.getName(); + for (int i = 0; i < av.alignment.getHeight(); i++) + { + SequenceI s = av.alignment.getSequenceAt(i); + String string = s.getName(); - if (av.getShowFullId()) - { - string = s.getDisplayId(); - } + if (av.getShowFullId()) + { + string = s.getDisplayId(); + } - pg.drawString(string, 0, - ((i * av.charHeight) + ypos + av.charHeight) - - (av.charHeight / 5)); + pg.drawString(string, 0, + ( (i * av.charHeight) + ypos + av.charHeight) - + (av.charHeight / 5)); + } + if (labels != null) + { + pg.translate(0, + ypos + + (av.getAlignment().getHeight() * av.charHeight)); + + pg.setFont(av.getFont()); + labels.drawComponent( pg, idWidth ); + pg.setFont(italic); + pg.translate(0, + -ypos - + (av.getAlignment().getHeight() * av.charHeight)); } ypos += cHeight; diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 7c8850d..8561e64 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -44,12 +44,14 @@ public class AnnotationLabels extends JPanel implements MouseListener, boolean active = false; Image image; AlignmentPanel ap; + AlignViewport av; boolean resizing = false; int oldY; int mouseX; int selectedRow = 0; int scrollOffset = 0; + /** * Creates a new AnnotationLabels object. * @@ -58,6 +60,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, public AnnotationLabels(AlignmentPanel ap) { this.ap = ap; + av = ap.av; java.net.URL url = getClass().getResource("/images/idwidth.gif"); Image temp = null; @@ -88,6 +91,11 @@ public class AnnotationLabels extends JPanel implements MouseListener, addMouseMotionListener(this); } + public AnnotationLabels(AlignViewport av) + { + this.av = av; + } + /** * DOCUMENT ME! * @@ -346,13 +354,19 @@ public class AnnotationLabels extends JPanel implements MouseListener, * * @param g1 DOCUMENT ME! */ - public void paintComponent(Graphics g1) + public void paintComponent(Graphics g) { - Graphics2D g = (Graphics2D) g1; - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + + int width = getWidth(); + if(width==0) + width = ap.calculateIdWidth().width + 4; + + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - drawComponent(g); + drawComponent(g2, width); + } /** @@ -360,7 +374,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * * @param g DOCUMENT ME! */ - public void drawComponent(Graphics2D g) + public void drawComponent(Graphics g, int width) { FontMetrics fm = g.getFontMetrics(g.getFont()); g.setColor(Color.white); @@ -369,12 +383,10 @@ public class AnnotationLabels extends JPanel implements MouseListener, g.translate(0, scrollOffset); g.setColor(Color.black); - AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); int y = g.getFont().getSize(); int x = 0; - int width = getWidth(); - if(width==0) - width = ap.calculateIdWidth().width + 4; + if (aa != null) { diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 9bbcc24..d97c80f 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -614,13 +614,13 @@ public class AnnotationPanel extends JPanel implements MouseListener, * @param startRes DOCUMENT ME! * @param endRes DOCUMENT ME! */ - public void drawComponent(Graphics2D g, int startRes, int endRes) + public void drawComponent(Graphics g, int startRes, int endRes) { + g.setFont(av.getFont()); + if (fm == null) fm = g.getFontMetrics(); - if(fm==null) - fm = g.getFontMetrics(); g.setColor(Color.white); g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight()); diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 2951c14..7d283ba 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -192,12 +192,7 @@ public class IdCanvas extends JPanel //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); drawIds(av.getStartSeq(), av.endSeq); @@ -212,17 +207,25 @@ public class IdCanvas extends JPanel */ void drawIds(int starty, int endy) { + Font italic = new Font(av.getFont().getName(), Font.ITALIC, + av.getFont().getSize()); + gg.setFont(italic); + gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + Color currentColor = Color.white; Color currentTextColor = Color.black; if (av.getWrapAlignment()) { int annotationHeight = 0; + AnnotationLabels labels = null; if(av.showAnnotation) { AnnotationPanel ap = new AnnotationPanel(av); annotationHeight = ap.adjustPanelHeight(); + labels = new AnnotationLabels(av); } int hgap = av.charHeight; @@ -245,6 +248,15 @@ public class IdCanvas extends JPanel SequenceI s = av.alignment.getSequenceAt(i); drawIdString(gg, s, i, 0, ypos); } + + if(labels!=null) + { + gg.setFont(av.getFont()); + gg.translate(0, ypos+(av.getAlignment().getHeight() * av.charHeight)); + labels.drawComponent(gg, getWidth()); + gg.translate(0, -ypos-(av.getAlignment().getHeight() * av.charHeight)); + gg.setFont(italic); + } } } else -- 1.7.10.2