X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=b11838ce2473dbee03b7add60370998a907b96ec;hb=fb1cdebe4a9d93839c81a2d3eb39e8da9cb83d64;hp=4047ac8c161129d066f63818a72e83fbd0360755;hpb=0452450533728e478ef8c893ea2cb3483c740fb3;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 4047ac8..b11838c 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2007 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 @@ -18,20 +18,17 @@ */ package jalview.gui; -import jalview.datamodel.*; - -import jalview.jbgui.*; - -import jalview.schemes.*; +import java.beans.*; +import java.io.*; import java.awt.*; import java.awt.event.*; import java.awt.print.*; -import java.io.*; import javax.swing.*; -import java.beans.*; - +import jalview.datamodel.*; +import jalview.jbgui.*; +import jalview.schemes.*; /** * DOCUMENT ME! @@ -39,8 +36,8 @@ import java.beans.*; * @author $author$ * @version $Revision$ */ -public class AlignmentPanel extends GAlignmentPanel - implements AdjustmentListener, Printable +public class AlignmentPanel + extends GAlignmentPanel implements AdjustmentListener, Printable { public AlignViewport av; OverviewPanel overviewPanel; @@ -84,10 +81,8 @@ public class AlignmentPanel extends GAlignmentPanel annotationScroller.setViewportView(annotationPanel); annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER); - fontChanged(); - scalePanelHolder.add(scalePanel, BorderLayout.CENTER); - seqPanelHolder.add(seqPanel, BorderLayout.CENTER); + seqPanelHolder.add(seqPanel, BorderLayout.CENTER); setScrollValues(0, 0); @@ -110,8 +105,9 @@ public class AlignmentPanel extends GAlignmentPanel alignmentChanged(); } } - }); + }); + fontChanged(); adjustAnnotationHeight(); } @@ -120,15 +116,11 @@ public class AlignmentPanel extends GAlignmentPanel { av.alignmentChanged(this); - if (overviewPanel != null) - overviewPanel.updateOverviewImage(); - alignFrame.updateEditMenuBar(); - repaint(); - } - + paintAlignment(true); + } /** * DOCUMENT ME! @@ -154,7 +146,9 @@ public class AlignmentPanel extends GAlignmentPanel hscrollFillerPanel.setPreferredSize(d); if (overviewPanel != null) + { overviewPanel.setBoxPosition(); + } repaint(); } @@ -169,7 +163,7 @@ public class AlignmentPanel extends GAlignmentPanel Container c = new Container(); FontMetrics fm = c.getFontMetrics( - new Font(av.font.getName(), Font.ITALIC, av.font.getSize())); + new Font(av.font.getName(), Font.ITALIC, av.font.getSize())); AlignmentI al = av.getAlignment(); @@ -231,10 +225,10 @@ public class AlignmentPanel extends GAlignmentPanel int start = seq.findIndex(results.getResultStart(0)) - 1; int end = seq.findIndex(results.getResultEnd(0)) - 1; - if(!av.wrapAlignment) + if (!av.wrapAlignment) { - if ( (av.getStartRes() > end) || (av.getEndRes() < start) || - ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex))) + if ( (av.getStartRes() > end) || (av.getEndRes() < start) || + ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex))) { setScrollValues(start, seqIndex); } @@ -244,12 +238,15 @@ public class AlignmentPanel extends GAlignmentPanel scrollToWrappedVisible(start); } } + + paintAlignment(true); } void scrollToWrappedVisible(int res) { - int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); - if( res<=av.getStartRes() || res>=(av.getStartRes()+cwidth) ) + int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas. + getWidth()); + if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth)) { vscroll.setValue(res / cwidth); av.startRes = vscroll.getValue() * cwidth; @@ -300,14 +297,20 @@ public class AlignmentPanel extends GAlignmentPanel int height = annotationPanel.adjustPanelHeight(); + if (hscroll.isVisible()) + { + height += hscroll.getPreferredSize().height; + } if (height > alignFrame.getHeight() / 2) { height = alignFrame.getHeight() / 2; } + hscroll.addNotify(); + annotationScroller.setPreferredSize( - new Dimension(annotationScroller.getWidth(), - height)); + new Dimension(annotationScroller.getWidth(), height)); + annotationSpaceFillerHolder.setPreferredSize(new Dimension( annotationSpaceFillerHolder.getWidth(), @@ -420,10 +423,12 @@ public class AlignmentPanel extends GAlignmentPanel int width = av.alignment.getWidth(); int height = av.alignment.getHeight(); - if(av.hasHiddenColumns) - width = av.getColumnSelection().findColumnPosition(width); + if (av.hasHiddenColumns) + { + width = av.getColumnSelection().findColumnPosition(width); + } - av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) -1); + av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1); hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; @@ -487,7 +492,7 @@ public class AlignmentPanel extends GAlignmentPanel if (av.getWrapAlignment()) { - if(offy>-1) + if (offy > -1) { int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel. seqCanvas.getWidth()); @@ -500,12 +505,12 @@ public class AlignmentPanel extends GAlignmentPanel //was wrapped when saved and user has wrap alignment true //as preference setting SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - setScrollValues(av.getStartRes(), av.getStartSeq()); - } - }); + { + public void run() + { + setScrollValues(av.getStartRes(), av.getStartSeq()); + } + }); } } else @@ -532,12 +537,16 @@ public class AlignmentPanel extends GAlignmentPanel { // Make sure we're not trying to draw a panel // larger than the visible window - if(scrollX>av.endRes-av.startRes) - scrollX = av.endRes-av.startRes; - else if(scrollX av.endRes - av.startRes) + { + scrollX = av.endRes - av.startRes; + } + else if (scrollX < av.startRes - av.endRes) + { scrollX = av.startRes - av.endRes; + } - if(scrollX!=0 || scrollY!=0) + if (scrollX != 0 || scrollY != 0) { idPanel.idCanvas.fastPaint(scrollY); seqPanel.seqCanvas.fastPaint(scrollX, @@ -552,6 +561,22 @@ public class AlignmentPanel extends GAlignmentPanel } } + public void paintAlignment(boolean updateOverview) + { + repaint(); + + if(updateOverview) + { + jalview.structure.StructureSelectionManager.getStructureSelectionManager() + .sequenceColoursChanged(this); + + if (overviewPanel != null) + { + overviewPanel.updateOverviewImage(); + } + } + } + /** * DOCUMENT ME! * @@ -571,10 +596,13 @@ public class AlignmentPanel extends GAlignmentPanel int maxwidth = av.alignment.getWidth(); if (av.hasHiddenColumns) + { maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + } - int canvasWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); - if(canvasWidth>0) + int canvasWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel. + seqCanvas.getWidth()); + if (canvasWidth > 0) { int max = maxwidth / seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas. @@ -589,10 +617,6 @@ public class AlignmentPanel extends GAlignmentPanel { setScrollValues(av.getStartRes(), av.getStartSeq()); } - - if( this.getVisibleRect().getBounds() == g.getClipBounds() - && overviewPanel != null) - overviewPanel.updateOverviewImage(); } /** @@ -711,9 +735,8 @@ public class AlignmentPanel extends GAlignmentPanel Color currentColor = null; Color currentTextColor = null; - pg.setFont(new Font(av.getFont().getName(), - Font.ITALIC, - av.getFont().getSize())); + pg.setFont(idPanel.idCanvas.idfont); + SequenceI seq; for (int i = startSeq; i < endSeq; i++) { @@ -745,7 +768,7 @@ public class AlignmentPanel extends GAlignmentPanel ) - 4; } - pg.drawString(seq.getDisplayId( av.getShowJVSuffix()), + pg.drawString(seq.getDisplayId(av.getShowJVSuffix()), xPos, ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) - (av.getCharHeight() / 5)); @@ -759,9 +782,9 @@ public class AlignmentPanel extends GAlignmentPanel if (av.showAnnotation && (endSeq == av.alignment.getHeight())) { - pg.translate( -idWidth-3, (endSeq - startSeq) * av.charHeight + 3); + pg.translate( -idWidth - 3, (endSeq - startSeq) * av.charHeight + 3); alabels.drawComponent( (Graphics2D) pg, idWidth); - pg.translate(idWidth+3, 0); + pg.translate(idWidth + 3, 0); annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes + 1); } @@ -796,7 +819,9 @@ public class AlignmentPanel extends GAlignmentPanel int hgap = av.charHeight; if (av.scaleAboveWrapped) + { hgap += av.charHeight; + } int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap @@ -806,8 +831,9 @@ public class AlignmentPanel extends GAlignmentPanel int maxwidth = av.alignment.getWidth(); if (av.hasHiddenColumns) + { maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; - + } int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - idWidth); @@ -827,21 +853,19 @@ 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++) { + pg.setFont(idPanel.idCanvas.idfont); SequenceI s = av.alignment.getSequenceAt(i); - String string = s.getDisplayId( av.getShowJVSuffix()); + String string = s.getDisplayId(av.getShowJVSuffix()); int xPos = 0; if (av.rightAlignIds) { - FontMetrics fm = getFontMetrics(italic); - xPos = idWidth - fm.stringWidth( string ) - 4; + FontMetrics fm = pg.getFontMetrics(); + xPos = idWidth - fm.stringWidth(string) - 4; } pg.drawString(string, xPos, ( (i * av.charHeight) + ypos + av.charHeight) - @@ -849,14 +873,13 @@ public class AlignmentPanel extends GAlignmentPanel } if (labels != null) { - pg.translate(-3, + pg.translate( -3, ypos + (av.getAlignment().getHeight() * av.charHeight)); pg.setFont(av.getFont()); labels.drawComponent(pg, idWidth); - pg.setFont(italic); - pg.translate(+3, + pg.translate( +3, -ypos - (av.getAlignment().getHeight() * av.charHeight)); } @@ -891,9 +914,12 @@ public class AlignmentPanel extends GAlignmentPanel { int maxwidth = av.alignment.getWidth(); if (av.hasHiddenColumns) + { maxwidth = av.getColumnSelection().findColumnPosition(maxwidth); + } - int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; + int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + + scalePanel.getHeight(); int width = getVisibleIdWidth() + (maxwidth * av.charWidth); if (av.getWrapAlignment()) @@ -902,10 +928,15 @@ public class AlignmentPanel extends GAlignmentPanel if (System.getProperty("java.awt.headless") != null && System.getProperty("java.awt.headless").equals("true")) { - width = alignFrame.getWidth() - 22; + width = alignFrame.getWidth() + - vscroll.getPreferredSize().width + - alignFrame.getInsets().left + - alignFrame.getInsets().right; } else + { width = seqPanel.getWidth() + getVisibleIdWidth(); + } } else if (av.getShowAnnotation()) @@ -916,21 +947,26 @@ public class AlignmentPanel extends GAlignmentPanel try { - jalview.util.ImageMaker im; - if(type==jalview.util.ImageMaker.PNG) - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.PNG, - "Create PNG image from alignment", - width, height, file, null); - else - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.EPS, - "Create EPS file from alignment", - width, height, file, alignFrame.getTitle() ); + jalview.util.ImageMaker im; + if (type == jalview.util.ImageMaker.PNG) + { + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.PNG, + "Create PNG image from alignment", + width, height, file, null); + } + else + { + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.EPS, + "Create EPS file from alignment", + width, height, file, + alignFrame.getTitle()); + } if (av.getWrapAlignment()) { - if(im.getGraphics()!=null) + if (im.getGraphics() != null) { printWrappedAlignment(im.getGraphics(), width, height, 0); im.writeImage(); @@ -938,7 +974,7 @@ public class AlignmentPanel extends GAlignmentPanel } else { - if(im.getGraphics()!=null) + if (im.getGraphics() != null) { printUnwrapped(im.getGraphics(), width, height, 0); im.writeImage(); @@ -966,6 +1002,7 @@ public class AlignmentPanel extends GAlignmentPanel ex.printStackTrace(); } } + /** * DOCUMENT ME! */ @@ -1010,92 +1047,107 @@ public class AlignmentPanel extends GAlignmentPanel sy = s * av.charHeight + scaleHeight; SequenceI seq = av.alignment.getSequenceAt(s); - SequenceFeature [] features = seq.getDatasetSequence().getSequenceFeatures(); + SequenceFeature[] features = seq.getDatasetSequence(). + getSequenceFeatures(); SequenceGroup[] groups = av.alignment.findAllGroups(seq); - for(res =0; resres) + if (groups[g].getStartRes() < res && groups[g].getEndRes() > res) + { text.append("
" + groups[g].getName() + ""); + } } if (features != null) { - if(text.length()<1) + if (text.length() < 1) { text.append("= seq.findPosition(res))) + if ( (features[f].getBegin() <= seq.findPosition(res)) && + (features[f].getEnd() >= seq.findPosition(res))) + { + if (features[f].getType().equals("disulfide bond")) { - if (features[f].getType().equals("disulfide bond")) + if (features[f].getBegin() == seq.findPosition(res) + || features[f].getEnd() == seq.findPosition(res)) { - if (features[f].getBegin() == seq.findPosition(res) - || features[f].getEnd() == seq.findPosition(res)) - { - text.append("
disulfide bond " + features[f].getBegin() + ":" + - features[f].getEnd()); - } + text.append("
disulfide bond " + features[f].getBegin() + + ":" + + features[f].getEnd()); } - else + } + else + { + text.append("
"); + text.append(features[f].getType()); + if (features[f].getDescription() != null && + !features[f]. + getType().equals(features[f].getDescription())) { - text.append("
"); - text.append(features[f].getType()); - if (features[f].getDescription() != null && !features[f].getType().equals(features[f].getDescription())) - text.append(" " + features[f].getDescription()); - - if (features[f].getValue("status") != null ) - { - text.append(" (" + features[f].getValue("status") + ")"); - } + text.append(" " + features[f].getDescription()); } - } + if (features[f].getValue("status") != null) + { + text.append(" (" + features[f].getValue("status") + ")"); + } + } } + } - if(text.length()>1) - { - text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">"); - out.println(text.toString()); - } + } + if (text.length() > 1) + { + text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">"); + out.println(text.toString()); } } + } out.println(""); out.close(); @@ -1112,20 +1164,25 @@ public class AlignmentPanel extends GAlignmentPanel { int seqPanelWidth = seqPanel.seqCanvas.getWidth(); - //If headless, seqPanel will have 0 width if (System.getProperty("java.awt.headless") != null - && System.getProperty("java.awt.headless").equals("true")) + && System.getProperty("java.awt.headless").equals("true")) { - seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth(); + seqPanelWidth = alignFrame.getWidth() + - getVisibleIdWidth() + - vscroll.getPreferredSize().width + - alignFrame.getInsets().left + - alignFrame.getInsets().right; } int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth( seqPanelWidth - ); + ); int hgap = av.charHeight; if (av.scaleAboveWrapped) + { hgap += av.charHeight; + } int annotationHeight = 0; if (av.showAnnotation) @@ -1139,76 +1196,12 @@ public class AlignmentPanel extends GAlignmentPanel int maxwidth = av.alignment.getWidth(); if (av.hasHiddenColumns) + { maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; - + } int height = ( (maxwidth / chunkWidth) + 1) * cHeight; return height; } - - /** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ - class Preview - extends JFrame - { - /** - * Creates a new Preview object. - * - * @param image DOCUMENT ME! - */ - public Preview(Image image) - { - setResizable(true); - setSize(image.getWidth(this), image.getHeight(this)); - setVisible(true); - getContentPane().setLayout(new BorderLayout()); - getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER); - validate(); - repaint(); - } - } - - /** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ - class PreviewPanel - extends JPanel - { - Image image; - - /** - * Creates a new PreviewPanel object. - * - * @param image DOCUMENT ME! - */ - public PreviewPanel(Image image) - { - this.image = image; - } - - /** - * DOCUMENT ME! - * - * @param g DOCUMENT ME! - */ - public void paintComponent(Graphics g) - { - if (image != null) - { - g.drawImage(image, 0, 0, this); - } - else - { - System.out.println("DEBUG:image is null"); - } - } - } }