From ce728f87f1f43be3041ef02f7f2cc2e39314711a Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 22 Sep 2005 13:23:07 +0000 Subject: [PATCH] Wrap alignment with annotations --- src/jalview/gui/AlignViewport.java | 30 ++---------- src/jalview/gui/AlignmentPanel.java | 84 ++++++++++++++++++++++++---------- src/jalview/gui/AnnotationPanel.java | 10 +++- src/jalview/gui/IdCanvas.java | 20 +++++++- src/jalview/gui/IdPanel.java | 16 +++++-- src/jalview/gui/SeqCanvas.java | 46 +++++++++++++++---- src/jalview/gui/SeqPanel.java | 46 +++++++++++++++---- src/jalview/io/HTMLOutput.java | 4 +- 8 files changed, 181 insertions(+), 75 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 6627941..3420993 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -61,8 +61,7 @@ public class AlignViewport SequenceGroup selectionGroup; int charHeight; int charWidth; - int chunkWidth; - int chunkHeight; + int wrappedWidth; Font font = new Font("SansSerif", Font.PLAIN, 10); AlignmentI alignment; ColumnSelection colSel = new ColumnSelection(); @@ -630,9 +629,9 @@ public class AlignViewport * * @param w DOCUMENT ME! */ - public void setChunkWidth(int w) + public void setWrappedWidth(int w) { - this.chunkWidth = w; + this.wrappedWidth = w; } /** @@ -640,30 +639,11 @@ public class AlignViewport * * @return DOCUMENT ME! */ - public int getChunkWidth() + public int getWrappedWidth() { - return chunkWidth; + return wrappedWidth; } - /** - * DOCUMENT ME! - * - * @param h DOCUMENT ME! - */ - public void setChunkHeight(int h) - { - this.chunkHeight = h; - } - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getChunkHeight() - { - return chunkHeight; - } /** * DOCUMENT ME! diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index f6e6114..8f5c74c 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -47,7 +47,7 @@ import javax.swing.*; public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener, Printable { - AlignViewport av; + public AlignViewport av; OverviewPanel overviewPanel; SeqPanel seqPanel; IdPanel idPanel; @@ -134,6 +134,7 @@ public class AlignmentPanel extends GAlignmentPanel }); } + /** * DOCUMENT ME! */ @@ -625,7 +626,7 @@ public class AlignmentPanel extends GAlignmentPanel if (av.showAnnotation) { - pagesHigh += annotationPanel.getHeight(); + pagesHigh += annotationPanel.adjustPanelHeight()+3; } pagesHigh /= pheight; @@ -685,7 +686,7 @@ public class AlignmentPanel extends GAlignmentPanel if (av.showAnnotation && (endSeq == av.alignment.getHeight())) { - pg.translate(-idWidth, (endSeq - startSeq) * av.charHeight); + pg.translate(-idWidth, (endSeq - startSeq) * av.charHeight +3); alabels.drawComponent((Graphics2D) pg); pg.translate(idWidth, 0); annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + @@ -710,17 +711,32 @@ public class AlignmentPanel extends GAlignmentPanel public int printWrappedAlignment(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException { - int idWidth = calculateIdWidth().width + 4; + + int annotationHeight = 0; + if (av.showAnnotation) + annotationHeight = annotationPanel.adjustPanelHeight(); + + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; + + + int idWidth = calculateIdWidth().width + 4; int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - idWidth); - int totalHeight = totalHeight = (av.alignment.getHeight() + 2) * ((av.alignment.getWidth() / resWidth) + - 1) * av.charHeight; + + int totalHeight = cHeight * (av.alignment.getWidth() / resWidth +1); pg.setColor(Color.white); pg.fillRect(0, 0, pwidth, pheight); pg.setFont(av.getFont()); + //////////////// // Draw the ids pg.setColor(Color.black); @@ -729,7 +745,7 @@ public class AlignmentPanel extends GAlignmentPanel pg.setClip(0, pi * pheight, pwidth, pheight); - int ypos = 2 * av.charHeight; + int ypos = hgap; do { @@ -748,7 +764,7 @@ public class AlignmentPanel extends GAlignmentPanel (av.charHeight / 5)); } - ypos += ((av.alignment.getHeight() + 2) * av.charHeight); + ypos += cHeight; } while (ypos < totalHeight); @@ -759,8 +775,9 @@ public class AlignmentPanel extends GAlignmentPanel if ((pi * pheight) < totalHeight) { return Printable.PAGE_EXISTS; + } - else + else { return Printable.NO_SUCH_PAGE; } @@ -824,23 +841,22 @@ public class AlignmentPanel extends GAlignmentPanel chooser.getSelectedFile().getParent()); } + int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth); + if (av.getWrapAlignment()) { - height = ( (av.alignment.getWidth() / av.getChunkWidth()) + 1) * - av.chunkHeight; + height = getWrappedHeight(); width = seqPanel.getWidth() + idPanel.getWidth(); - } - - - if (av.getShowAnnotation()) + else if (av.getShowAnnotation()) { - height += annotationPanel.getPreferredSize().height; + height += annotationPanel.adjustPanelHeight()+3; } + try { FileOutputStream out = new FileOutputStream(epsFile); @@ -948,6 +964,32 @@ public class AlignmentPanel extends GAlignmentPanel } + int getWrappedHeight() + { + + int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth( + seqPanel.seqCanvas.getWidth()); + + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + + int annotationHeight = 0; + if (av.showAnnotation) + { + annotationHeight = annotationPanel.adjustPanelHeight(); + } + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; + + + int height = ( (av.alignment.getWidth() / chunkWidth) + 1) * cHeight; + + return height; + } + /** * DOCUMENT ME! */ @@ -986,16 +1028,12 @@ public class AlignmentPanel extends GAlignmentPanel if (av.getWrapAlignment()) { - height = ( (av.alignment.getWidth() / av.getChunkWidth()) + 1) * - av.chunkHeight; + height = getWrappedHeight(); width = seqPanel.getWidth() + idPanel.getWidth(); - } - - - if (av.getShowAnnotation()) + else if (av.getShowAnnotation()) { - height += annotationPanel.getPreferredSize().height; + height += annotationPanel.adjustPanelHeight()+3; } try diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index bc14d66..9bbcc24 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -76,6 +76,12 @@ public class AnnotationPanel extends JPanel implements MouseListener, ap.annotationScroller.getVerticalScrollBar().addAdjustmentListener(this); } + public AnnotationPanel(AlignViewport av) + { + this.av = av; + } + + /** * DOCUMENT ME! * @@ -89,7 +95,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, /** * DOCUMENT ME! */ - public void adjustPanelHeight() + public int adjustPanelHeight() { // setHeight of panels image = null; @@ -136,6 +142,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, } this.setPreferredSize(new Dimension(1, height)); + + return height; } /** diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 9581ccc..2951c14 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -217,12 +217,28 @@ public class IdCanvas extends JPanel if (av.getWrapAlignment()) { + int annotationHeight = 0; + + if(av.showAnnotation) + { + AnnotationPanel ap = new AnnotationPanel(av); + annotationHeight = ap.adjustPanelHeight(); + } + + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; + int rowSize = av.getEndRes() - av.getStartRes(); // Draw the rest of the panels - for (int ypos = 2 * av.charHeight, row = av.startRes; + for (int ypos = hgap, row = av.startRes; (ypos <= getHeight()) && (row < av.alignment.getWidth()); - ypos += av.chunkHeight, row += rowSize) + ypos += cHeight, row += rowSize) { for (int i = starty; i < av.alignment.getHeight(); i++) { diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 201516f..011502b 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -70,6 +70,16 @@ public class IdPanel extends JPanel implements MouseListener, { } + int getWrappedY(int y) + { + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + + return y - hgap; + } + + /** * DOCUMENT ME! * @@ -83,7 +93,7 @@ public class IdPanel extends JPanel implements MouseListener, if (av.getWrapAlignment()) { - y -= (2 * av.charHeight); + y = getWrappedY(y); } int seq = av.getIndex(y); @@ -125,7 +135,7 @@ public class IdPanel extends JPanel implements MouseListener, if (av.getWrapAlignment()) { - y -= (2 * av.charHeight); + y = getWrappedY(y); } //DEFAULT LINK IS FIRST IN THE LINK LIST @@ -205,7 +215,7 @@ public class IdPanel extends JPanel implements MouseListener, if (av.getWrapAlignment()) { - y -= (2 * av.charHeight); + y = getWrappedY(y); } int seq = av.getIndex(y); diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 1ed5e50..303aac6 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -43,8 +43,6 @@ public class SeqCanvas extends JComponent AlignViewport av; boolean displaySearch = false; int[] searchResults = null; - int chunkHeight; - int chunkWidth; boolean fastPaint = false; int LABEL_WEST; int LABEL_EAST; @@ -294,11 +292,6 @@ public class SeqCanvas extends JComponent gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); - chunkWidth = getWrappedCanvasWidth(getWidth()); - chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; - - av.setChunkHeight(chunkHeight); - av.setChunkWidth(chunkWidth); if (av.getWrapAlignment()) { @@ -385,13 +378,21 @@ public class SeqCanvas extends JComponent LABEL_WEST = fm.stringWidth(getMask()); } + int hgap = av.charHeight; + if(av.scaleAboveWrapped) + hgap += av.charHeight; + int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth; - int cHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; + int cHeight = av.getAlignment().getHeight() * av.charHeight; + + av.setWrappedWidth(cWidth); av.endRes = av.startRes + cWidth; + int endx = (startRes + cWidth) - 1; - int ypos = 2 * av.charHeight; + int ypos = hgap; + while ((ypos <= canvasHeight) && (startRes < av.alignment.getWidth())) { @@ -437,10 +438,23 @@ public class SeqCanvas extends JComponent drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos); + + if(av.showAnnotation) + { + g.translate(0, cHeight + ypos + 3); + if(annotations==null) + annotations = new AnnotationPanel(av); + + annotations.drawComponent( (Graphics2D) g, startRes, endx + 1); + g.translate(0, -cHeight - ypos); + } g.setClip(clip); g.translate(-LABEL_WEST, 0); - ypos += cHeight; + ypos += cHeight+getAnnotationHeight()+hgap; + if(av.showAnnotation) + ypos -= 3; + startRes += cWidth; endx = (startRes + cWidth) - 1; @@ -451,6 +465,18 @@ public class SeqCanvas extends JComponent } } + AnnotationPanel annotations; + int getAnnotationHeight() + { + if(!av.showAnnotation) + return 0; + + if(annotations==null) + annotations = new AnnotationPanel(av); + + return annotations.adjustPanelHeight(); + } + /** * DOCUMENT ME! * diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 8146be0..8486ac1 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -212,16 +212,26 @@ public class SeqPanel extends JPanel if (av.wrapAlignment) { + + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + seqCanvas.getAnnotationHeight(); + int y = evt.getY(); - y -= (2 * av.charHeight); + y -= hgap; x -= seqCanvas.LABEL_WEST; - int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; + int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth()); - wrappedBlock = y/chunkHeight; - wrappedBlock += av.getStartRes()/cwidth; - res = wrappedBlock*cwidth + x / av.getCharWidth(); + wrappedBlock = y / cHeight; + wrappedBlock += av.getStartRes() / cwidth; + + res = wrappedBlock * cwidth + x / av.getCharWidth(); + } else { @@ -234,14 +244,22 @@ public class SeqPanel extends JPanel int findSeq(MouseEvent evt) { + int seq = 0; int y = evt.getY(); if (av.wrapAlignment) { - y -= (2 * av.charHeight); - int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; - seq = ( (y % chunkHeight) / av.getCharHeight()); + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + seqCanvas.getAnnotationHeight(); + + y -= hgap; + + seq = ( (y % cHeight) / av.getCharHeight()); } else { @@ -602,8 +620,18 @@ public class SeqPanel extends JPanel startWrapBlock=wrappedBlock; - if(seq<0 || res<0) + if(av.wrapAlignment && seq>av.alignment.getHeight()) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + "Cannot edit annotations in wrapped view.", + "Wrapped view - no edit", + JOptionPane.WARNING_MESSAGE); return; + } + + if(seq<0 || res<0) + return; + SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq); diff --git a/src/jalview/io/HTMLOutput.java b/src/jalview/io/HTMLOutput.java index e4dc83e..08eacd6 100755 --- a/src/jalview/io/HTMLOutput.java +++ b/src/jalview/io/HTMLOutput.java @@ -205,9 +205,9 @@ public class HTMLOutput "\n"); for (int startRes = 0; startRes < al.getWidth(); - startRes += av.getChunkWidth()) + startRes += av.getWrappedWidth()) { - int endRes = startRes + av.getChunkWidth(); + int endRes = startRes + av.getWrappedWidth(); if (endRes > al.getWidth()) { -- 1.7.10.2