From: amwaterhouse Date: Mon, 29 Aug 2005 10:32:05 +0000 (+0000) Subject: Edit and annotate wrapped alignment X-Git-Tag: Release_2_05~11 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=019042a9f87d94260b3060cdf45ab93ca714a46d;p=jalview.git Edit and annotate wrapped alignment --- diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 29616ef..3202fc4 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -36,7 +36,6 @@ public class SeqCanvas AlignViewport av; - boolean showScores = false; boolean displaySearch = false; int[] searchResults = null; @@ -97,7 +96,7 @@ public class SeqCanvas } 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); } @@ -126,7 +125,7 @@ public class SeqCanvas } if (value != -1) { - g.drawString(value + "", 0, + g.drawString(value + "", av.charWidth/2, ypos + i * av.charHeight - av.charHeight / 5); } } @@ -258,24 +257,39 @@ public class SeqCanvas int LABEL_WEST, LABEL_EAST; public int getWrappedCanvasWidth(int cwidth) { - FontMetrics fm = getFontMetrics(av.getFont()); + FontMetrics fm = getFontMetrics(av.getFont()); - LABEL_EAST = 0; - LABEL_WEST = 0; + LABEL_EAST = 0; + LABEL_WEST = 0; - if (av.scaleRightWrapped) - { - LABEL_EAST = fm.stringWidth(av.alignment.getWidth() + "000"); - } + if (av.scaleRightWrapped) + { + LABEL_EAST = fm.stringWidth(getMask()+"0"); + } - if (av.scaleLeftWrapped) - { - LABEL_WEST = fm.stringWidth(av.alignment.getWidth() + ""); - } + if (av.scaleLeftWrapped) + { + LABEL_WEST = fm.stringWidth(getMask()); + } - return (cwidth - LABEL_EAST - LABEL_WEST) / av.charWidth; + 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; + } + public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes) { @@ -283,15 +297,16 @@ public class SeqCanvas FontMetrics fm = getFontMetrics(av.getFont()); - int LABEL_EAST = 0; 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; @@ -313,9 +328,9 @@ public class SeqCanvas 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/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 53562cb..71f2d14 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -64,19 +64,11 @@ public class SeqPanel { public void mouseMoved(MouseEvent evt) { - if (av.getWrapAlignment()) - { - return; - } doMouseMoved(evt); } public void mouseDragged(MouseEvent evt) { - if (av.getWrapAlignment()) - { - return; - } if (editingSeqs) { doMouseDragged(evt); @@ -92,10 +84,6 @@ public class SeqPanel { public void mouseReleased(MouseEvent evt) { - if (av.getWrapAlignment()) - { - return; - } if (editingSeqs) { doMouseReleased(evt); @@ -109,10 +97,6 @@ public class SeqPanel public void mousePressed(MouseEvent evt) { - if (av.getWrapAlignment()) - { - return; - } if (evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) { if (evt.isAltDown() || evt.isControlDown()) @@ -131,7 +115,7 @@ public class SeqPanel public void mouseExited(MouseEvent evt) { - if (av.getWrapAlignment() || editingSeqs) + if (editingSeqs) { return; } @@ -141,7 +125,7 @@ public class SeqPanel public void mouseEntered(MouseEvent evt) { - if (av.getWrapAlignment() || editingSeqs) + if (editingSeqs) { return; } @@ -168,18 +152,60 @@ public class SeqPanel ap.repaint(); } + 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.getSize().width); + 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; + } + + public void doMousePressed(MouseEvent evt) { 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()) @@ -202,26 +228,8 @@ public class SeqPanel public void doMouseMoved(MouseEvent evt) { - int res = 0, seq = 0; - int x = evt.getX(); - int y = evt.getY(); - if (av.wrapAlignment) - { - y -= 2 * av.charHeight; - int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; - - res = (int) ( (y / chunkHeight) * (getSize().width / 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(); - } + int res = findRes(evt); + int seq = findSeq(evt); if (seq >= av.getAlignment().getHeight()) { @@ -284,7 +292,7 @@ public class SeqPanel { // If we're dragging we're editing - int res = evt.getX() / av.getCharWidth() + av.getStartRes(); + int res = findRes(evt); if (res < 0) { res = 0; @@ -556,8 +564,8 @@ public class SeqPanel int oldSeq = -1; public void doMousePressedDefineMode(MouseEvent evt) { - int res = evt.getX() / av.getCharWidth() + av.getStartRes(); - int seq = evt.getY() / av.getCharHeight() + av.getStartSeq(); + int res = findRes(evt); + int seq = findSeq(evt); oldSeq = seq; SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq); @@ -694,8 +702,8 @@ public class SeqPanel boolean remove = false; 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) { @@ -723,7 +731,7 @@ public class SeqPanel { res = av.getStartRes(); } - else if (res > av.getEndRes()) + else if (res > av.getEndRes() && !av.getWrapAlignment()) { res = av.getEndRes(); } @@ -795,11 +803,6 @@ public class SeqPanel public void doMouseExitedDefineMode(MouseEvent e) { - if (av.getWrapAlignment()) - { - return; - } - if (mouseDragging) { scrollThread = new ScrollThread(); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 41174d4..444b6bb 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -183,11 +183,21 @@ public class SeqPanel extends JPanel public void mouseExited(MouseEvent evt) { - doMouseExitedDefineMode(evt); + if (editingSeqs) + { + return; + } + + doMouseExitedDefineMode(evt); } public void mouseEntered(MouseEvent evt) { + if (editingSeqs) + { + return; + } + doMouseEnteredDefineMode(evt); } });