X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=b11838ce2473dbee03b7add60370998a907b96ec;hb=ea7870f9bf9ae81876afbe3fdd4d9bd9022b4014;hp=ed00d3379d6c59bec106afe6b8878f4a64c18a68;hpb=9c5d69ef1e102b1eac18ec13c362522f40c9000d;p=jalview.git
diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java
index ed00d33..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) 2005 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 jalview.datamodel.*;
+import jalview.jbgui.*;
+import jalview.schemes.*;
/**
* DOCUMENT ME!
@@ -39,8 +36,8 @@ import javax.swing.*;
* @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;
@@ -81,65 +78,48 @@ 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);
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);
+ fontChanged();
+ adjustAnnotationHeight();
- break;
+ }
- case KeyEvent.VK_UP:
- alignFrame.moveSelectedSequences(true);
+ public void alignmentChanged()
+ {
+ av.alignmentChanged(this);
- break;
+ alignFrame.updateEditMenuBar();
- case KeyEvent.VK_BACK_SPACE:
- case KeyEvent.VK_DELETE:
- alignFrame.cut_actionPerformed(null);
- break;
+ paintAlignment(true);
- case KeyEvent.VK_P:
- seqPanel.seqCanvas.increaseAARatio();
- break;
- case KeyEvent.VK_L:
- seqPanel.seqCanvas.decreaseAARation();
- break;
- }
- }
- });
}
/**
@@ -165,21 +145,10 @@ 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();
+ }
repaint();
}
@@ -193,7 +162,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,24 +213,44 @@ 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)
{
- setScrollValues(start, results[0]);
+ if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
+ ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
+ {
+ setScrollValues(start, seqIndex);
+ }
+ }
+ else
+ {
+ scrollToWrappedVisible(start);
}
}
+
+ paintAlignment(true);
+ }
+
+ 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;
+ }
}
/**
@@ -297,6 +288,37 @@ public class AlignmentPanel extends GAlignmentPanel
repaint();
}
+ public void adjustAnnotationHeight()
+ {
+ if (alignFrame.getHeight() == 0)
+ {
+ System.out.println("NEEDS FIXING");
+ }
+
+ 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));
+
+
+ annotationSpaceFillerHolder.setPreferredSize(new Dimension(
+ annotationSpaceFillerHolder.getWidth(),
+ height));
+
+ repaint();
+ }
+
/**
* DOCUMENT ME!
*
@@ -363,7 +385,7 @@ public class AlignmentPanel extends GAlignmentPanel
*/
public boolean scrollRight(boolean right)
{
- if (right)
+ if (!right)
{
if (hscroll.getValue() < 1)
{
@@ -397,30 +419,38 @@ 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 +463,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 +492,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 +526,53 @@ 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);
+ // 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.startRes - av.endRes)
+ {
+ scrollX = av.startRes - av.endRes;
+ }
+
+ if (scrollX != 0 || scrollY != 0)
+ {
+ idPanel.idCanvas.fastPaint(scrollY);
+ seqPanel.seqCanvas.fastPaint(scrollX,
+ scrollY);
+ scalePanel.repaint();
+
+ if (av.getShowAnnotation())
+ {
+ annotationPanel.fastPaint(scrollX);
+ }
+ }
+ }
+ }
+
+ public void paintAlignment(boolean updateOverview)
+ {
+ repaint();
- scalePanel.repaint();
+ if(updateOverview)
+ {
+ jalview.structure.StructureSelectionManager.getStructureSelectionManager()
+ .sequenceColoursChanged(this);
- if (av.getShowAnnotation())
+ if (overviewPanel != null)
{
- annotationPanel.fastPaint(xShift);
+ overviewPanel.updateOverviewImage();
}
}
}
@@ -522,23 +593,30 @@ public class AlignmentPanel extends GAlignmentPanel
if (av.getWrapAlignment())
{
- int max = av.alignment.getWidth() /
- seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()) +1;
- vscroll.setMaximum(max);
- vscroll.setUnitIncrement(1);
- vscroll.setVisibleAmount(1);
+ 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 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)
- overviewPanel.updateOverviewImage();
- }
}
/**
@@ -585,7 +663,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 +735,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 +759,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);
}
@@ -730,18 +819,26 @@ public class AlignmentPanel extends GAlignmentPanel
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 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 +853,33 @@ 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,
+ String string = s.getDisplayId(av.getShowJVSuffix());
+ 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,47 +903,83 @@ public class AlignmentPanel extends GAlignmentPanel
}
}
+ int getVisibleIdWidth()
+ {
+ return
+ idPanel.getWidth() > 0 ? idPanel.getWidth() :
+ calculateIdWidth().width + 4;
+ }
+
void makeAlignmentImage(int type, File file)
{
- int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
- int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth);
+ int maxwidth = av.alignment.getWidth();
+ if (av.hasHiddenColumns)
+ {
+ maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
+ }
+
+ int height = ( (av.alignment.getHeight() + 1) * av.charHeight)
+ + scalePanel.getHeight();
+ 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()
+ - vscroll.getPreferredSize().width
+ - alignFrame.getInsets().left
+ - alignFrame.getInsets().right;
+ }
+ else
+ {
+ width = seqPanel.getWidth() + getVisibleIdWidth();
+ }
+
}
else if (av.getShowAnnotation())
{
height += annotationPanel.adjustPanelHeight() + 3;
}
- 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() );
-
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());
+ }
+
if (av.getWrapAlignment())
{
- if(im.getGraphics()!=null)
+ if (im.getGraphics() != null)
+ {
printWrappedAlignment(im.getGraphics(), width, height, 0);
+ im.writeImage();
+ }
}
else
{
- if(im.getGraphics()!=null)
+ if (im.getGraphics() != null)
+ {
printUnwrapped(im.getGraphics(), width, height, 0);
+ im.writeImage();
+ }
}
-
- im.writeImage();
}
catch (OutOfMemoryError err)
{
@@ -867,6 +1002,7 @@ public class AlignmentPanel extends GAlignmentPanel
ex.printStackTrace();
}
}
+
/**
* DOCUMENT ME!
*/
@@ -887,7 +1023,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 +1033,121 @@ 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("
"
+ "