X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FRotatableCanvas.java;h=458d971171eca664caf1b3662ab23ca35855e834;hb=df9eac352d5fc1252e6377fec7cfc29fd841c932;hp=fbbf269ea8948444d720b44ae3cf47a6144f1d0d;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/gui/RotatableCanvas.java b/src/jalview/gui/RotatableCanvas.java index fbbf269..458d971 100755 --- a/src/jalview/gui/RotatableCanvas.java +++ b/src/jalview/gui/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 @@ -22,8 +22,6 @@ import jalview.datamodel.*; import jalview.math.*; -import jalview.util.*; - import java.awt.*; import java.awt.event.*; @@ -40,8 +38,6 @@ import javax.swing.*; */ public class RotatableCanvas extends JPanel implements MouseListener, MouseMotionListener, KeyListener -//RubberbandListener, -//SequenceSelectionListener { RotatableMatrix idmat = new RotatableMatrix(3, 3); RotatableMatrix objmat = new RotatableMatrix(3, 3); @@ -76,17 +72,29 @@ public class RotatableCanvas extends JPanel implements MouseListener, int recty2; float scalefactor = 1; AlignViewport av; + boolean showLabels = false; + Color bgColour = Color.black; // Controller controller; - public RotatableCanvas(AlignViewport av, Vector points, int npoint) + public RotatableCanvas(AlignViewport av) + { + this.av = av; + } + + public void showLabels(boolean b) + { + showLabels = b; + repaint(); + } + + public void setPoints(Vector points, int npoint) { this.points = points; this.npoint = npoint; - this.av = av; ToolTipManager.sharedInstance().registerComponent(this); ToolTipManager.sharedInstance().setInitialDelay(0); ToolTipManager.sharedInstance().setDismissDelay(10000); - PaintRefresher.Register(this, av.alignment); + PaintRefresher.Register(this, av.getSequenceSetId()); prefsize = getPreferredSize(); orig = new float[npoint][3]; @@ -129,31 +137,12 @@ public class RotatableCanvas extends JPanel implements MouseListener, scale = findScale(); - // System.out.println("Scale factor = " + scale); addMouseListener(this); - addKeyListener(this); - // if (getParent() != null) { - // getParent().addKeyListener(this); - //} addMouseMotionListener(this); - // Add rubberband - // rubberband = new RubberbandRectangle(this); - // rubberband.setActive(true); - // rubberband.addListener(this); } - /* public boolean handleSequenceSelectionEvent(SequenceSelectionEvent evt) { - redrawneeded = true; - repaint(); - return true; - } - - public void removeNotify() { - controller.removeListener(this); - super.removeNotify(); - }*/ public void initAxes() { for (int i = 0; i < 3; i++) @@ -311,31 +300,45 @@ public class RotatableCanvas extends JPanel implements MouseListener, * * @param g DOCUMENT ME! */ - public void paintComponent(Graphics g) + public void paintComponent(Graphics g1) { + + Graphics2D g = (Graphics2D) g1; + + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + if(points==null) + { + g.setFont(new Font("Verdana", Font.PLAIN, 18)); + g.drawString("Calculating PCA....", 20, getHeight()/2); + } + else + { //Only create the image at the beginning - - if ((img == null) || (prefsize.width != getWidth()) || - (prefsize.height != getHeight())) + if ( (img == null) || (prefsize.width != getWidth()) || + (prefsize.height != getHeight())) { - prefsize.width = getWidth(); - prefsize.height = getHeight(); + prefsize.width = getWidth(); + prefsize.height = getHeight(); - scale = findScale(); + scale = findScale(); - // System.out.println("New scale = " + scale); - img = createImage(getWidth(), getHeight()); - ig = img.getGraphics(); + // System.out.println("New scale = " + scale); + img = createImage(getWidth(), getHeight()); + ig = img.getGraphics(); } - drawBackground(ig, Color.black); + + drawBackground(ig, bgColour); drawScene(ig); if (drawAxes == true) { - drawAxes(ig); + drawAxes(ig); } g.drawImage(img, 0, 0, this); + } } /** @@ -345,6 +348,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ public void drawAxes(Graphics g) { + g.setColor(Color.yellow); for (int i = 0; i < 3; i++) @@ -372,9 +376,14 @@ public class RotatableCanvas extends JPanel implements MouseListener, * * @param g DOCUMENT ME! */ - public void drawScene(Graphics g) + public void drawScene(Graphics g1) { - boolean darker = false; + + Graphics2D g = (Graphics2D) g1; + + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + int halfwidth = getWidth() / 2; int halfheight = getHeight() / 2; @@ -399,7 +408,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, if (av.getSelectionGroup() != null) { - if (av.getSelectionGroup().sequences.contains( + if (av.getSelectionGroup().getSequences(false).contains( ((SequencePoint) points.elementAt(i)).sequence)) { g.setColor(Color.gray); @@ -412,7 +421,13 @@ public class RotatableCanvas extends JPanel implements MouseListener, } 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 @@ -468,8 +483,6 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ public void keyPressed(KeyEvent evt) { - requestFocus(); - if (evt.getKeyCode() == KeyEvent.VK_UP) { scalefactor = (float) (scalefactor * 1.1); @@ -493,24 +506,6 @@ public class RotatableCanvas extends JPanel implements MouseListener, repaint(); } - /** - * DOCUMENT ME! - */ - public void printPoints() - { - for (int i = 0; i < npoint; i++) - { - SequencePoint sp = (SequencePoint) points.elementAt(i); - Format.print(System.out, "%5d ", i); - - for (int j = 0; j < 3; j++) - { - Format.print(System.out, "%13.3f ", sp.coord[j]); - } - - System.out.println(); - } - } /** * DOCUMENT ME! @@ -580,13 +575,13 @@ public class RotatableCanvas extends JPanel implements MouseListener, if (av.getSelectionGroup() != null) { av.getSelectionGroup().addOrRemove(found, true); - PaintRefresher.Refresh(this, av.alignment); + PaintRefresher.Refresh(this, av.getSequenceSetId()); } else { av.setSelectionGroup(new SequenceGroup()); av.getSelectionGroup().addOrRemove(found, true); - av.getSelectionGroup().setEndRes(av.alignment.getWidth()); + av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1); } } @@ -671,8 +666,6 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ public void rectSelect(int x1, int y1, int x2, int y2) { - boolean changedSel = false; - for (int i = 0; i < npoint; i++) { SequencePoint sp = (SequencePoint) points.elementAt(i); @@ -685,9 +678,8 @@ public class RotatableCanvas extends JPanel implements MouseListener, { 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, true); } }