X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FRotatableCanvas.java;h=667653fcf8a5bb4c87532372a8a1f5941c68dac6;hb=2267a3de329c0fb4848c6e1a42ad2d52c658f759;hp=7d32b86e99927b10d84e5ecba749058fa26b4a8a;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/appletgui/RotatableCanvas.java b/src/jalview/appletgui/RotatableCanvas.java index 7d32b86..667653f 100755 --- a/src/jalview/appletgui/RotatableCanvas.java +++ b/src/jalview/appletgui/RotatableCanvas.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 @@ -32,12 +32,12 @@ public class RotatableCanvas extends Panel implements MouseListener, MouseMotionListener, KeyListener -//RubberbandListener, -//SequenceSelectionListener { RotatableMatrix idmat = new RotatableMatrix(3, 3); RotatableMatrix objmat = new RotatableMatrix(3, 3); RotatableMatrix rotmat = new RotatableMatrix(3, 3); + String tooltip; + int toolx, tooly; //RubberbandRectangle rubberband; @@ -82,17 +82,25 @@ public class RotatableCanvas float scalefactor = 1; AlignViewport av; -// Controller controller; + boolean showLabels = false; + public RotatableCanvas(AlignViewport av) + { + this.av = av; + } - public RotatableCanvas(AlignViewport av, - Vector points, int npoint) + public void showLabels(boolean b) + { + showLabels = b; + repaint(); + } + + public void setPoints(Vector points, int npoint) { this.points = points; this.npoint = npoint; - this.av = av; - PaintRefresher.Register(this); -// + PaintRefresher.Register(this, av.alignment); + prefsize = getPreferredSize(); orig = new float[npoint][3]; @@ -285,31 +293,50 @@ public class RotatableCanvas return getPreferredSize(); } + public void update(Graphics g) + { + paint(g); + } public void paint(Graphics g) { - //Only create the image at the beginning - - if ( (img == null) || (prefsize.width != getSize().width) || - (prefsize.height != getSize().height)) + if (points == null) + { + g.setFont(new Font("Verdana", Font.PLAIN, 18)); + g.drawString("Calculating PCA....", 20, getSize().height / 2); + } + else { - prefsize.width = getSize().width; - prefsize.height = getSize().height; - scale = findScale(); + //Only create the image at the beginning - + if ( (img == null) || (prefsize.width != getSize().width) || + (prefsize.height != getSize().height)) + { + prefsize.width = getSize().width; + prefsize.height = getSize().height; - // System.out.println("New scale = " + scale); - img = createImage(getSize().width, getSize().height); - ig = img.getGraphics(); + scale = findScale(); - } + // System.out.println("New scale = " + scale); + img = createImage(getSize().width, getSize().height); + ig = img.getGraphics(); - drawBackground(ig, Color.black); - drawScene(ig); - if (drawAxes == true) - { - drawAxes(ig); - } + } + + drawBackground(ig, Color.black); + drawScene(ig); + if (drawAxes == true) + { + drawAxes(ig); + } + + if(tooltip!=null) + { + ig.setColor(Color.red); + ig.drawString(tooltip, toolx, tooly); + } - g.drawImage(img, 0, 0, this); + g.drawImage(img, 0, 0, this); + } } public void drawAxes(Graphics g) @@ -332,7 +359,7 @@ public class RotatableCanvas public void drawScene(Graphics g) { - boolean darker = false; + //boolean darker = false; int halfwidth = getSize().width / 2; int halfheight = getSize().height / 2; @@ -344,18 +371,18 @@ public class RotatableCanvas int y = (int) ( (float) (sp.coord[1] - centre[1]) * scale) + halfheight; float z = sp.coord[1] - centre[2]; - if (sp.sequence.getColor() == Color.black) + if (av.getSequenceColour(sp.sequence) == Color.black) { g.setColor(Color.white); } else { - g.setColor(sp.sequence.getColor()); + g.setColor(av.getSequenceColour(sp.sequence)); } if (av.getSelectionGroup() != null) { - if (av.getSelectionGroup().sequences.contains( ( (SequencePoint) points. + if (av.getSelectionGroup().getSequences(false).contains( ( (SequencePoint) points. elementAt(i)).sequence)) { g.setColor(Color.gray); @@ -367,14 +394,14 @@ public class RotatableCanvas } g.fillRect(x - 3, y - 3, 6, 6); - g.setColor(Color.red); + if (showLabels) + { + g.setColor(Color.red); + g.drawString( ( (SequencePoint) points.elementAt(i)).sequence. + getName(), + x - 3, y - 4); + } } -// //Now the rectangle -// if (rectx2 != -1 && recty2 != -1) { -// g.setColor(Color.white); -// -// g.drawRect(rectx1,recty1,rectx2-rectx1,recty2-recty1); -// } } public Dimension minimumsize() @@ -395,7 +422,6 @@ public class RotatableCanvas public void keyPressed(KeyEvent evt) { - requestFocus(); if (evt.getKeyCode() == KeyEvent.VK_UP) { scalefactor = (float) (scalefactor * 1.1); @@ -470,41 +496,41 @@ public class RotatableCanvas { if (av.getSelectionGroup() != null) { - av.getSelectionGroup().addOrRemove(found); - PaintRefresher.Refresh(this); + av.getSelectionGroup().addOrRemove(found, true); + av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1); + PaintRefresher.Refresh(this, av.alignment); } else { av.setSelectionGroup(new SequenceGroup()); - av.getSelectionGroup().addOrRemove(found); - av.getSelectionGroup().setEndRes(av.alignment.getWidth()); + av.getSelectionGroup().addOrRemove(found, true); + av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1); } } repaint(); } - // private void fireSequenceSelectionEvent(Selection sel) { - // controller.handleSequenceSelectionEvent(new SequenceSelectionEvent(this,sel)); - //} public void mouseMoved(MouseEvent evt) { - // SequenceI found = findPoint(evt.getX(), evt.getY()); + SequenceI found = findPoint(evt.getX(), evt.getY()); + if(found==null) + tooltip = null; + else + { + tooltip = found.getName(); + toolx = evt.getX(); + tooly = evt.getY(); + } + repaint(); } public void mouseDragged(MouseEvent evt) { mx = evt.getX(); my = evt.getY(); - //Check if this is a rectangle drawing drag - if ( (evt.getModifiers() & InputEvent.BUTTON2_MASK) != 0) - { -// rectx2 = evt.getX(); -// recty2 = evt.getY(); - } - else - { + rotmat.setIdentity(); rotmat.rotate( (float) (my - omy), 'x'); @@ -534,13 +560,11 @@ public class RotatableCanvas omy = my; paint(this.getGraphics()); - } - } public void rectSelect(int x1, int y1, int x2, int y2) { - boolean changedSel = false; + //boolean changedSel = false; for (int i = 0; i < npoint; i++) { SequencePoint sp = (SequencePoint) points.elementAt(i); @@ -553,17 +577,13 @@ public class RotatableCanvas { if (av != null) { - if (!av.getSelectionGroup().sequences.contains(sp.sequence)) + if (!av.getSelectionGroup().getSequences(false).contains(sp.sequence)) { - changedSel = true; - av.getSelectionGroup().addSequence(sp.sequence); + av.getSelectionGroup().addSequence(sp.sequence, true); } } } } - // if (changedSel) { - // fireSequenceSelectionEvent(av.getSelection()); - // } } public SequenceI findPoint(int x, int y) @@ -595,26 +615,5 @@ public class RotatableCanvas return null; } } - /* public boolean handleRubberbandEvent(RubberbandEvent evt) { - System.out.println("Rubberband handler called in RotatableCanvas with " + - evt.getBounds()); - - Rubberband rb = (Rubberband)evt.getSource(); - - // Clear the current selection (instance variable) - //if ((rb.getModifiers() & Event.SHIFT_MASK) == 0) { - // clearSelection(); - //} - - if (rb.getComponent() == this) { - Rectangle bounds = evt.getBounds(); - rectSelect(bounds.x,bounds.y,bounds.x+bounds.width,bounds.y+bounds.height); - } - - redrawneeded = true; - paint(this.getGraphics()); - - return true; - }*/ }