From 7ee3b5a7f099858cdde2318c719121b39d9e466e Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 8 Apr 2005 15:03:36 +0000 Subject: [PATCH] scale above, left right added --- src/jalview/gui/AlignFrame.java | 25 +++++- src/jalview/gui/AlignViewport.java | 23 +++++ src/jalview/gui/AlignmentPanel.java | 16 ++-- src/jalview/gui/IdCanvas.java | 12 +-- src/jalview/gui/SeqCanvas.java | 159 ++++++++++++++++++++++++++++++----- 5 files changed, 201 insertions(+), 34 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 7b67e81..6170cf9 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -23,7 +23,7 @@ import java.awt.print.*; import javax.swing.*; import javax.swing.event.*; import java.util.*; -import java.awt.datatransfer.*; +import java.awt.datatransfer.*; public class AlignFrame extends GAlignFrame @@ -594,8 +594,31 @@ public class AlignFrame extends GAlignFrame { viewport.setWrapAlignment( wrapMenuItem.isSelected() ); alignPanel.setWrapAlignment( wrapMenuItem.isSelected() ); + scaleAbove.setVisible( wrapMenuItem.isSelected() ); + scaleLeft.setVisible( wrapMenuItem.isSelected() ); + scaleRight.setVisible( wrapMenuItem.isSelected() ); + alignPanel.RefreshPanels(); + } + + protected void scaleAbove_actionPerformed(ActionEvent e) + { + viewport.setScaleAboveWrapped(scaleAbove.isSelected()); + alignPanel.repaint(); } + protected void scaleLeft_actionPerformed(ActionEvent e) + { + viewport.setScaleLeftWrapped(scaleLeft.isSelected()); + alignPanel.repaint(); + } + + protected void scaleRight_actionPerformed(ActionEvent e) + { + viewport.setScaleRightWrapped(scaleRight.isSelected()); + alignPanel.repaint(); + } + + public void viewBoxesMenuItem_actionPerformed(ActionEvent e) { diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 43f6aff..d02eb01 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -48,6 +48,10 @@ public class AlignViewport NJTree currentTree = null; + boolean scaleAboveWrapped = false; + boolean scaleLeftWrapped = true; + boolean scaleRightWrapped = true; + public AlignViewport(AlignmentI al, boolean showText, @@ -444,4 +448,23 @@ public class AlignViewport showAnnotation = b; } + public boolean getScaleAboveWrapped() + { return scaleAboveWrapped;} + + public boolean getScaleLeftWrapped() + { return scaleLeftWrapped; } + + public boolean getScaleRightWrapped() + { return scaleRightWrapped; } + + public void setScaleAboveWrapped(boolean b) + { scaleAboveWrapped = b; } + + public void setScaleLeftWrapped(boolean b) + { scaleLeftWrapped = b; } + + public void setScaleRightWrapped(boolean b) + { scaleRightWrapped = b; } + + } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index c38b7dc..73cee2d 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -225,8 +225,13 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene annotationScroller.setVisible(!wrap); annotationSpaceFillerHolder.setVisible(!wrap); idSpaceFillerPanel1.setVisible(!wrap); - - RefreshPanels(); + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + RefreshPanels(); + } + }); } @@ -266,8 +271,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene if (av.getWrapAlignment()) { - int max = av.alignment.getWidth() / - (seqPanel.seqCanvas.getWidth() / av.charWidth) + 1; + int max = av.alignment.getWidth() / seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); vscroll.setValues(0, 1, 0, max); } else @@ -372,7 +376,9 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene int offy = vscroll.getValue(); if (av.getWrapAlignment()) { - av.setStartRes( vscroll.getValue() * av.getChunkWidth()); + int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + av.setStartRes( vscroll.getValue() * rowSize ); + av.setEndRes( (vscroll.getValue()+1) * rowSize ); } else { diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 959c83c..b693f98 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -113,14 +113,16 @@ public class IdCanvas extends JPanel Color currentColor = Color.white; Color currentTextColor = Color.black; + if (av.getWrapAlignment()) { + + int rowSize = av.getEndRes() - av.getStartRes(); // Draw the rest of the panels - int chunkHeight = (av.alignment.getHeight() + 2)*av.charHeight; - int row = av.getStartRes() / av.chunkWidth ; - for(int ypos=2*av.charHeight; - ypos <= getHeight() && row*av.chunkWidth startx) + { + if (jalview.util.Comparison.isGap(seq.getCharAt(index))) + { + index--; + continue; } + value = av.alignment.getSequenceAt(i).findPosition(index); + break; + } + if(value!=-1) + g.drawString(value + "", 0, ypos + i*av.charHeight - av.charHeight/5); } +} + + + + public void fastPaint(int horizontal, int vertical) { @@ -81,7 +141,8 @@ public void fastPaint(int horizontal, int vertical) gg.translate(transX, transY); - + gg.setColor(Color.white); + gg.fillRect(0,0, (er-sr)*av.charWidth, (es-ss)*av.charHeight); drawPanel(gg, sr, er, ss, es, sr, ss, 0); gg.translate( -transX, -transY); @@ -128,7 +189,7 @@ public void fastPaint(int horizontal, int vertical) gg.setColor(Color.white); gg.fillRect(0,0,imgWidth,imgHeight); - chunkWidth = getWidth()/av.charWidth; + chunkWidth = getWrappedCanvasWidth( getWidth() ); chunkHeight = (av.getAlignment().getHeight() + 2)*av.charHeight; av.setChunkHeight(chunkHeight); @@ -144,27 +205,68 @@ public void fastPaint(int horizontal, int vertical) } + public int getWrappedCanvasWidth(int cwidth) + { + FontMetrics fm = getFontMetrics(av.getFont()); + + int LABEL_EAST = 0; + if(av.scaleRightWrapped) + LABEL_EAST = fm.stringWidth( av.alignment.getWidth()+"000" ); + int LABEL_WEST = 0; + if(av.scaleLeftWrapped) + LABEL_WEST = fm.stringWidth( av.alignment.getWidth()+"0" ); + + return (cwidth - LABEL_EAST -LABEL_WEST)/av.charWidth; + } + public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes) { - AlignmentI da = av.getAlignment(); + AlignmentI al = av.getAlignment(); + + FontMetrics fm = getFontMetrics(av.getFont()); - int cWidth = canvasWidth/av.charWidth; + int LABEL_EAST = 0; + if(av.scaleRightWrapped) + LABEL_EAST = fm.stringWidth( al.getWidth()+"000" ); + int LABEL_WEST = 0; + if(av.scaleLeftWrapped) + LABEL_WEST = fm.stringWidth( al.getWidth()+"0" ); + + int cWidth = (canvasWidth - LABEL_EAST -LABEL_WEST)/av.charWidth; int cHeight = (av.getAlignment().getHeight() + 2)*av.charHeight; int endx = startRes+cWidth-1; - int ypos = 2*av.charHeight; + int ypos = 2*av.charHeight; + - while (ypos <= canvasHeight) + while (ypos <= canvasHeight && endx da.getWidth()) - endx = da.getWidth(); + if (endx > al.getWidth()) + endx = al.getWidth(); } } @@ -172,7 +274,7 @@ public void fastPaint(int horizontal, int vertical) public void drawPanel(Graphics g1,int x1,int x2, int y1, int y2,int startx, int starty,int offset) { - Graphics2D g = (Graphics2D)g1; + Graphics2D g = (Graphics2D)g1; g.setFont(av.getFont()); RendererI sr = av.getRenderer(); @@ -253,12 +355,26 @@ public void fastPaint(int horizontal, int vertical) sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight); ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth; + if (av.getWrapAlignment()) + { + if (sx < 0) + sx = 0; + + if (ex > getWidth()) + { + if (av.getWrapAlignment()) + ex = getWrappedCanvasWidth(getWidth()) * av.charWidth; + + } + } + else if(ex>getWidth()) + ex -= av.charWidth; + if (sx < getWidth() && ex > 0 && group.sequences.contains(av.alignment.getSequenceAt(i))) { - if (bottom == -1 && !group.sequences.contains(av.alignment.getSequenceAt(i + 1))) bottom = sy + av.charHeight ; @@ -366,9 +482,6 @@ public void fastPaint(int horizontal, int vertical) } - public int getChunkWidth() { - return chunkWidth; - } public void highlightSearchResults(int [] results) { -- 1.7.10.2