X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FRotatableCanvas.java;h=724b9fbdda3c4f2c2659037fab782b860772cd55;hb=452198e86b03d40c83d0492ab04ab2f6d52e8f5e;hp=460a99f85f678a531fdef1dd262fa94572017f00;hpb=930a6609bc99bfb0827fc5d0d16666787aaba575;p=jalview.git diff --git a/src/jalview/gui/RotatableCanvas.java b/src/jalview/gui/RotatableCanvas.java index 460a99f..724b9fb 100755 --- a/src/jalview/gui/RotatableCanvas.java +++ b/src/jalview/gui/RotatableCanvas.java @@ -40,8 +40,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,13 +74,25 @@ 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); @@ -129,31 +139,13 @@ 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 +303,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 +351,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 +379,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; @@ -412,7 +424,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 +486,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 +509,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!