X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=8548c426fde26194e0b873c2c0ffc4d16dcf3590;hb=5dd663636925f44c6f964fa32fed2f584223b295;hp=ed00d3379d6c59bec106afe6b8878f4a64c18a68;hpb=9c5d69ef1e102b1eac18ec13c362522f40c9000d;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index ed00d33..8548c42 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) 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 @@ -27,10 +27,10 @@ import jalview.schemes.*; import java.awt.*; import java.awt.event.*; import java.awt.print.*; - import java.io.*; - import javax.swing.*; +import java.beans.*; + /** @@ -81,67 +81,55 @@ public class AlignmentPanel extends GAlignmentPanel annotationPanel = new AnnotationPanel(this); alabels = new AnnotationLabels(this); - annotationSpaceFillerHolder.setPreferredSize(annotationPanel. - getPreferredSize()); - annotationScroller.setPreferredSize(annotationPanel.getPreferredSize()); 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); - annotationPanel.adjustPanelHeight(); - annotationSpaceFillerHolder.setPreferredSize(annotationPanel. - getPreferredSize()); - annotationScroller.setPreferredSize(annotationPanel. - getPreferredSize()); setAnnotationVisible(av.getShowAnnotation()); hscroll.addAdjustmentListener(this); vscroll.addAdjustmentListener(this); - af.addKeyListener(new KeyAdapter() + final AlignmentPanel ap = this; + av.addPropertyChangeListener(new PropertyChangeListener() { - public void keyPressed(KeyEvent evt) + public void propertyChange(PropertyChangeEvent evt) { - switch (evt.getKeyCode()) + if (evt.getPropertyName().equals("alignment")) { - case 27: // escape key - av.setSelectionGroup(null); - repaint(); - - break; + PaintRefresher.Refresh(ap, + av.getSequenceSetId(), + true, + true); + alignmentChanged(); + } + } + }); - case KeyEvent.VK_DOWN: - alignFrame.moveSelectedSequences(false); + adjustAnnotationHeight(); - break; + } - case KeyEvent.VK_UP: - alignFrame.moveSelectedSequences(true); + public void alignmentChanged() + { + av.alignmentChanged(this); - break; + if (overviewPanel != null) + overviewPanel.updateOverviewImage(); - case KeyEvent.VK_BACK_SPACE: - case KeyEvent.VK_DELETE: - alignFrame.cut_actionPerformed(null); - break; + alignFrame.updateEditMenuBar(); - case KeyEvent.VK_P: - seqPanel.seqCanvas.increaseAARatio(); - break; - case KeyEvent.VK_L: - seqPanel.seqCanvas.decreaseAARation(); - break; - } - } - }); + repaint(); } + + /** * DOCUMENT ME! */ @@ -165,19 +153,6 @@ public class AlignmentPanel extends GAlignmentPanel idPanel.idCanvas.setPreferredSize(d); hscrollFillerPanel.setPreferredSize(d); - if (av.getWrapAlignment()) - { - int max = av.alignment.getWidth() / - seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); - vscroll.setMaximum(max); - vscroll.setUnitIncrement(1); - vscroll.setVisibleAmount(1); - } - else - { - setScrollValues(av.getStartRes(), av.getStartSeq()); - } - if (overviewPanel != null) overviewPanel.setBoxPosition(); @@ -193,7 +168,9 @@ public class AlignmentPanel extends GAlignmentPanel { Container c = new Container(); - FontMetrics fm = c.getFontMetrics(av.font); + FontMetrics fm = c.getFontMetrics( + new Font(av.font.getName(), Font.ITALIC, av.font.getSize())); + AlignmentI al = av.getAlignment(); int i = 0; @@ -242,26 +219,43 @@ public class AlignmentPanel extends GAlignmentPanel * * @param results DOCUMENT ME! */ - public void highlightSearchResults(int[] results) + public void highlightSearchResults(SearchResults results) { seqPanel.seqCanvas.highlightSearchResults(results); // do we need to scroll the panel? if (results != null) { - SequenceI seq = av.alignment.getSequenceAt(results[0]); - int start = seq.findIndex(results[1]) - 1; - int end = seq.findIndex(results[2]) - 1; + SequenceI seq = results.getResultSequence(0); + int seqIndex = av.alignment.findIndex(seq); + int start = seq.findIndex(results.getResultStart(0)) - 1; + int end = seq.findIndex(results.getResultEnd(0)) - 1; - if ( (av.getStartRes() > start) || (av.getEndRes() < end) || - ( (av.getStartSeq() > results[0]) || - (av.getEndSeq() < results[0]))) + if(!av.wrapAlignment) + { + if ( (av.getStartRes() > end) || (av.getEndRes() < start) || + ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex))) + { + setScrollValues(start, seqIndex); + } + } + else { - setScrollValues(start, results[0]); + scrollToWrappedVisible(start); } } } + void scrollToWrappedVisible(int res) + { + 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; + } + } + /** * DOCUMENT ME! * @@ -297,6 +291,31 @@ public class AlignmentPanel extends GAlignmentPanel repaint(); } + public void adjustAnnotationHeight() + { + if (alignFrame.getHeight() == 0) + { + System.out.println("NEEDS FIXING"); + } + + int height = annotationPanel.adjustPanelHeight(); + + if (height > alignFrame.getHeight() / 2) + { + height = alignFrame.getHeight() / 2; + } + + annotationScroller.setPreferredSize( + new Dimension(annotationScroller.getWidth(), + height)); + + annotationSpaceFillerHolder.setPreferredSize(new Dimension( + annotationSpaceFillerHolder.getWidth(), + height)); + + repaint(); + } + /** * DOCUMENT ME! * @@ -363,7 +382,7 @@ public class AlignmentPanel extends GAlignmentPanel */ public boolean scrollRight(boolean right) { - if (right) + if (!right) { if (hscroll.getValue() < 1) { @@ -397,30 +416,36 @@ public class AlignmentPanel extends GAlignmentPanel */ public void setScrollValues(int x, int y) { - av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - - 1); + + int width = av.alignment.getWidth(); + int height = av.alignment.getHeight(); + + if(av.hasHiddenColumns) + width = av.getColumnSelection().findColumnPosition(width); + + av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) -1); hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; - if (hextent > av.alignment.getWidth()) + if (hextent > width) { - hextent = av.alignment.getWidth(); + hextent = width; } - if (vextent > av.alignment.getHeight()) + if (vextent > height) { - vextent = av.alignment.getHeight(); + vextent = height; } - if ( (hextent + x) > av.getAlignment().getWidth()) + if ( (hextent + x) > width) { - x = av.getAlignment().getWidth() - hextent; + x = width - hextent; } - if ( (vextent + y) > av.getAlignment().getHeight()) + if ( (vextent + y) > height) { - y = av.getAlignment().getHeight() - vextent; + y = height - vextent; } if (y < 0) @@ -433,8 +458,8 @@ public class AlignmentPanel extends GAlignmentPanel x = 0; } - hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth()); - vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight()); + hscroll.setValues(x, hextent, 0, width); + vscroll.setValues(y, vextent, 0, height); } /** @@ -462,10 +487,26 @@ public class AlignmentPanel extends GAlignmentPanel if (av.getWrapAlignment()) { - int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel. - seqCanvas.getWidth()); - av.setStartRes(vscroll.getValue() * rowSize); - av.setEndRes( (vscroll.getValue() + 1) * rowSize); + if(offy>-1) + { + int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel. + seqCanvas.getWidth()); + av.setStartRes(offy * rowSize); + av.setEndRes( (offy + 1) * rowSize); + } + else + { + //This is only called if file loaded is a jar file that + //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()); + } + }); + } } else { @@ -480,28 +521,33 @@ public class AlignmentPanel extends GAlignmentPanel overviewPanel.setBoxPosition(); } - int xShift = av.getStartRes() - oldX; - int yShift = av.getStartSeq() - oldY; + int scrollX = av.startRes - oldX; + int scrollY = av.startSeq - oldY; - if ( (xShift != 0 && yShift != 0) || - (Math.abs(xShift) > av.getEndRes() - av.getStartRes() - || Math.abs(yShift) > av.getEndSeq() - av.getStartSeq()) - || av.getWrapAlignment() - || !fastPaint) + if (av.getWrapAlignment() || !fastPaint) { - // Either no shift at all, or shift greater than visible amount repaint(); } else { - idPanel.idCanvas.fastPaint(yShift); - seqPanel.seqCanvas.fastPaint(xShift, yShift); - - scalePanel.repaint(); - - if (av.getShowAnnotation()) + // 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(scrollX0) + { + int max = maxwidth / + seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas. + getWidth()) + + 1; + vscroll.setMaximum(max); + vscroll.setUnitIncrement(1); + vscroll.setVisibleAmount(1); + } } else { setScrollValues(av.getStartRes(), av.getStartSeq()); } - - if( this.getVisibleRect().getBounds() == g.getClipBounds() ) - { - if (overviewPanel != null) + if( this.getVisibleRect().getBounds() == g.getClipBounds() + && overviewPanel != null) overviewPanel.updateOverviewImage(); - } } /** @@ -585,7 +639,7 @@ public class AlignmentPanel extends GAlignmentPanel public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException { - int idWidth = calculateIdWidth().width + 4; + int idWidth = getVisibleIdWidth(); FontMetrics fm = getFontMetrics(av.getFont()); int scaleHeight = av.charHeight + fm.getDescent(); @@ -657,18 +711,21 @@ public class AlignmentPanel extends GAlignmentPanel Color currentColor = null; Color currentTextColor = null; + pg.setFont(idPanel.idCanvas.idfont); + + SequenceI seq; for (int i = startSeq; i < endSeq; i++) { + seq = av.getAlignment().getSequenceAt(i); if ( (av.getSelectionGroup() != null) && - av.getSelectionGroup().sequences.contains( - av.getAlignment().getSequenceAt(i))) + av.getSelectionGroup().getSequences(null).contains(seq)) { currentColor = Color.gray; currentTextColor = Color.black; } else { - currentColor = av.getAlignment().getSequenceAt(i).getColor(); + currentColor = av.getSequenceColour(seq); currentTextColor = Color.black; } @@ -678,24 +735,32 @@ public class AlignmentPanel extends GAlignmentPanel pg.setColor(currentTextColor); - String string = av.getAlignment().getSequenceAt(i).getDisplayId - ( av.getShowJVSuffix()); + int xPos = 0; + if (av.rightAlignIds) + { + fm = pg.getFontMetrics(); + xPos = idWidth - fm.stringWidth( + seq.getDisplayId(av.getShowJVSuffix()) + ) - 4; + } - pg.drawString(string, 0, + pg.drawString(seq.getDisplayId( av.getShowJVSuffix()), + xPos, ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) - (av.getCharHeight() / 5)); } + pg.setFont(av.getFont()); + // draw main sequence panel pg.translate(idWidth, 0); - seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, - startRes, startSeq, 0); + seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0); if (av.showAnnotation && (endSeq == av.alignment.getHeight())) { - pg.translate( -idWidth, (endSeq - startSeq) * av.charHeight + 3); + pg.translate( -idWidth-3, (endSeq - startSeq) * av.charHeight + 3); alabels.drawComponent( (Graphics2D) pg, idWidth); - pg.translate(idWidth, 0); + pg.translate(idWidth+3, 0); annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes + 1); } @@ -736,12 +801,17 @@ public class AlignmentPanel extends GAlignmentPanel + hgap + annotationHeight; - int idWidth = calculateIdWidth().width + 4; + int idWidth = getVisibleIdWidth(); + + int maxwidth = av.alignment.getWidth(); + if (av.hasHiddenColumns) + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - idWidth); - int totalHeight = cHeight * (av.alignment.getWidth() / resWidth + 1); + int totalHeight = cHeight * (maxwidth / resWidth + 1); pg.setColor(Color.white); pg.fillRect(0, 0, pwidth, pheight); @@ -756,31 +826,35 @@ 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()); - - pg.drawString(string, 0, + int xPos = 0; + if (av.rightAlignIds) + { + FontMetrics fm = pg.getFontMetrics(); + xPos = idWidth - fm.stringWidth( string ) - 4; + } + pg.drawString(string, xPos, ( (i * av.charHeight) + ypos + av.charHeight) - (av.charHeight / 5)); } if (labels != null) { - pg.translate(0, + pg.translate(-3, ypos + (av.getAlignment().getHeight() * av.charHeight)); pg.setFont(av.getFont()); labels.drawComponent(pg, idWidth); - pg.setFont(italic); - pg.translate(0, + pg.translate(+3, -ypos - (av.getAlignment().getHeight() * av.charHeight)); } @@ -804,21 +878,42 @@ public class AlignmentPanel extends GAlignmentPanel } } + int getVisibleIdWidth() + { + return + idPanel.getWidth() > 0 ? idPanel.getWidth() : + calculateIdWidth().width + 4; + } + void makeAlignmentImage(int type, File file) { + int maxwidth = av.alignment.getWidth(); + if (av.hasHiddenColumns) + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth); + int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; - int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth); + int width = getVisibleIdWidth() + (maxwidth * av.charWidth); if (av.getWrapAlignment()) { height = getWrappedHeight(); - width = seqPanel.getWidth() + idPanel.getWidth(); + if (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true")) + { + width = alignFrame.getWidth() - 22; + } + else + width = seqPanel.getWidth() + getVisibleIdWidth(); + } else if (av.getShowAnnotation()) { height += annotationPanel.adjustPanelHeight() + 3; } + try + { + jalview.util.ImageMaker im; if(type==jalview.util.ImageMaker.PNG) im = new jalview.util.ImageMaker(this, @@ -831,20 +926,22 @@ public class AlignmentPanel extends GAlignmentPanel "Create EPS file from alignment", width, height, file, alignFrame.getTitle() ); - try - { if (av.getWrapAlignment()) { if(im.getGraphics()!=null) + { printWrappedAlignment(im.getGraphics(), width, height, 0); + im.writeImage(); + } } else { if(im.getGraphics()!=null) + { printUnwrapped(im.getGraphics(), width, height, 0); + im.writeImage(); + } } - - im.writeImage(); } catch (OutOfMemoryError err) { @@ -887,7 +984,7 @@ public class AlignmentPanel extends GAlignmentPanel { ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS ////////////////////////////////////////////// - int idWidth = calculateIdWidth().width + 4; + int idWidth = getVisibleIdWidth(); FontMetrics fm = getFontMetrics(av.getFont()); int scaleHeight = av.charHeight + fm.getDescent(); @@ -897,45 +994,106 @@ public class AlignmentPanel extends GAlignmentPanel { try { + int s, sSize = av.alignment.getHeight(), + res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy; + StringBuffer text = new StringBuffer(); PrintWriter out = new PrintWriter(new FileWriter(imgMapFile)); out.println(jalview.io.HTMLOutput.getImageMapHTML()); out.println("" + ""); - for (int s = 0; s < av.alignment.getHeight(); s++) + for (s = 0; s < sSize; s++) { + sy = s * av.charHeight + scaleHeight; + SequenceI seq = av.alignment.getSequenceAt(s); + SequenceFeature [] features = seq.getDatasetSequence().getSequenceFeatures(); SequenceGroup[] groups = av.alignment.findAllGroups(seq); - for (int i = 0; i < groups.length; i++) + for(res =0; resres) + text.append("
" + groups[g].getName() + ""); + } - out.println( - "" + groups[i].getName() + - "')\"; onMouseOut=\"toolTip()\"; " - + " href=\"#\">"); + + alIndex + " " + triplet ); + } + fSize = features.length; + for (f = 0; f < fSize; f++) + { + + if ( (features[f].getBegin() <= seq.findPosition(res)) && + (features[f].getEnd() >= seq.findPosition(res))) + { + if (features[f].getType().equals("disulfide bond")) + { + if (features[f].getBegin() == seq.findPosition(res) + || features[f].getEnd() == seq.findPosition(res)) + { + text.append("
disulfide bond " + features[f].getBegin() + ":" + + features[f].getEnd()); + } + } + else + { + 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") + ")"); + } + } + } + + } + } + if(text.length()>1) + { + text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">"); + out.println(text.toString()); + } } } - } - out.println("
"); out.close(); @@ -950,9 +1108,18 @@ public class AlignmentPanel extends GAlignmentPanel int getWrappedHeight() { + 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")) + { + seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth(); + } int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth( - seqPanel.seqCanvas.getWidth()); + seqPanelWidth + ); int hgap = av.charHeight; if (av.scaleAboveWrapped) @@ -968,7 +1135,12 @@ public class AlignmentPanel extends GAlignmentPanel + hgap + annotationHeight; - int height = ( (av.alignment.getWidth() / chunkWidth) + 1) * cHeight; + int maxwidth = av.alignment.getWidth(); + if (av.hasHiddenColumns) + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + + + int height = ( (maxwidth / chunkWidth) + 1) * cHeight; return height; }