From: amwaterhouse Date: Mon, 29 Aug 2005 10:18:50 +0000 (+0000) Subject: Edit and annotate wrapped alignment X-Git-Tag: Release_2_05~12 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4f8907121d304b0f9b499578578c3381b815db9d;p=jalview.git Edit and annotate wrapped alignment --- diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 841f929..6c2c07b 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -129,7 +129,7 @@ public class SeqCanvas extends JComponent if (value != -1) { - int x = LABEL_WEST - fm.stringWidth(value + ""); + int x = LABEL_WEST - fm.stringWidth(String.valueOf(value))-av.charWidth/2; g.drawString(value + "", x, (ypos + (i * av.charHeight)) - (av.charHeight / 5)); } @@ -171,7 +171,7 @@ public class SeqCanvas extends JComponent if (value != -1) { - g.drawString(value + "", 0, + g.drawString(String.valueOf(value), av.charWidth/2, (ypos + (i * av.charHeight)) - (av.charHeight / 5)); } } @@ -324,17 +324,32 @@ public class SeqCanvas extends JComponent if (av.scaleRightWrapped) { - LABEL_EAST = fm.stringWidth(av.alignment.getWidth() + "000"); + LABEL_EAST = fm.stringWidth(getMask()+"0"); } if (av.scaleLeftWrapped) { - LABEL_WEST = fm.stringWidth(av.alignment.getWidth() + ""); + LABEL_WEST = fm.stringWidth(getMask()); } return (cwidth - LABEL_EAST - LABEL_WEST) / av.charWidth; } + + /** + * Generates a string of zeroes. + * @return String + */ + String getMask() + { + String mask = "0"; + for (int i = av.alignment.getWidth(); i > 0; i /= 10) + { + mask += "0"; + } + return mask; + } + /** * DOCUMENT ME! * @@ -346,6 +361,7 @@ public class SeqCanvas extends JComponent public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes) { + AlignmentI al = av.getAlignment(); FontMetrics fm = getFontMetrics(av.getFont()); @@ -354,14 +370,14 @@ public class SeqCanvas extends JComponent if (av.scaleRightWrapped) { - LABEL_EAST = fm.stringWidth(al.getWidth() + "000"); + LABEL_EAST = fm.stringWidth(getMask()+"0"); } int LABEL_WEST = 0; if (av.scaleLeftWrapped) { - LABEL_WEST = fm.stringWidth(al.getWidth() + "0"); + LABEL_WEST = fm.stringWidth(getMask()); } int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth; @@ -383,9 +399,9 @@ public class SeqCanvas extends JComponent if (av.scaleRightWrapped) { - g.translate(canvasWidth - LABEL_EAST + av.charWidth, 0); + g.translate(canvasWidth - LABEL_EAST, 0); drawEastScale(g, startRes, endx, ypos); - g.translate(-(canvasWidth - LABEL_EAST + av.charWidth), 0); + g.translate(-(canvasWidth - LABEL_EAST), 0); } g.translate(LABEL_WEST, 0); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index bc8f200..41174d4 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -95,21 +95,11 @@ public class SeqPanel extends JPanel { public void mouseMoved(MouseEvent evt) { - if (av.getWrapAlignment()) - { - return; - } - doMouseMoved(evt); } public void mouseDragged(MouseEvent evt) { - if (av.getWrapAlignment()) - { - return; - } - if (editingSeqs) { doMouseDragged(evt); @@ -155,10 +145,6 @@ public class SeqPanel extends JPanel public void mouseReleased(MouseEvent evt) { mouseWheelPressed = false; - if (av.getWrapAlignment()) - { - return; - } if (editingSeqs) { @@ -177,10 +163,6 @@ public class SeqPanel extends JPanel mouseWheelPressed = true; return; } - if (av.getWrapAlignment()) - { - return; - } if (evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) @@ -201,26 +183,63 @@ public class SeqPanel extends JPanel public void mouseExited(MouseEvent evt) { - if (av.getWrapAlignment() || editingSeqs) - { - return; - } - doMouseExitedDefineMode(evt); } public void mouseEntered(MouseEvent evt) { - if (av.getWrapAlignment() || editingSeqs) - { - return; - } - doMouseEnteredDefineMode(evt); } }); } + int findRes(MouseEvent evt) + { + int res = 0; + int x = evt.getX(); + + if (av.wrapAlignment) + { + int y = evt.getY(); + y -= (2 * av.charHeight); + x -= seqCanvas.LABEL_WEST; + + int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; + int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth()); + int block = y/chunkHeight; + block += av.getStartRes()/cwidth; + + res = block*cwidth + x / av.getCharWidth(); + } + else + { + res = (x / av.getCharWidth()) + av.getStartRes(); + } + + return res; + + } + + 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()); + } + else + { + seq = (y / av.getCharHeight()) + av.getStartSeq(); + } + + return seq; + } + + /** * DOCUMENT ME! * @@ -249,17 +268,11 @@ public class SeqPanel extends JPanel */ public void doMousePressed(MouseEvent evt) { - ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence", - av.alignment, HistoryItem.EDIT)); + ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence", + av.alignment, HistoryItem.EDIT)); - int seq; - int res; - - int x = evt.getX(); - int y = evt.getY(); - - res = (x / av.getCharWidth()) + av.getStartRes(); - seq = (y / av.getCharHeight()) + av.getStartSeq(); + int seq = findSeq(evt); + int res = findRes(evt); if ((seq < av.getAlignment().getHeight()) && (res < av.getAlignment().getSequenceAt(seq).getLength())) @@ -286,39 +299,17 @@ public class SeqPanel extends JPanel */ public void doMouseMoved(MouseEvent evt) { - int res = 0; - int seq = 0; - int x = evt.getX(); - int y = evt.getY(); - - if (av.wrapAlignment) - { - y -= (2 * av.charHeight); + int res = findRes(evt); + int seq = findSeq(evt); - int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; - - res = (int) ((y / chunkHeight) * (getWidth() / av.charWidth)) + - (x / av.getCharWidth()) + av.getStartRes(); - - y %= chunkHeight; - seq = (y / av.getCharHeight()) + av.getStartSeq(); - } - else - { - res = (x / av.getCharWidth()) + av.getStartRes(); - seq = (y / av.getCharHeight()) + av.getStartSeq(); - } - - if (seq >= av.getAlignment().getHeight()) - { + if(res<0 || seq<0 || seq >= av.getAlignment().getHeight()) return; - } - SequenceI sequence = av.getAlignment().getSequenceAt(seq); + SequenceI sequence = av.getAlignment().getSequenceAt(seq); - if (res > sequence.getLength()) - { - return; + if (res > sequence.getLength()) + { + return; } Object obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + @@ -381,7 +372,7 @@ public class SeqPanel extends JPanel public void doMouseDragged(MouseEvent evt) { // If we're dragging we're editing - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + int res = findRes(evt); if (res < 0) { @@ -679,9 +670,9 @@ public class SeqPanel extends JPanel */ public void doMousePressedDefineMode(MouseEvent evt) { - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - int seq = (evt.getY() / av.getCharHeight()) + av.getStartSeq(); - oldSeq = seq; + int res = findRes(evt); + int seq = findSeq(evt); + oldSeq = seq; SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq); @@ -827,11 +818,11 @@ public class SeqPanel extends JPanel */ public void doMouseDraggedDefineMode(MouseEvent evt) { - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - int y = (evt.getY() / av.getCharHeight()) + av.getStartSeq(); + int res = findRes(evt); + int y = findSeq(evt); - if (stretchGroup == null) - { + if (stretchGroup == null) + { return; } @@ -855,7 +846,7 @@ public class SeqPanel extends JPanel { res = av.getStartRes(); } - else if (res > av.getEndRes()) + else if (res > av.getEndRes() && !av.getWrapAlignment()) { res = av.getEndRes(); }