From 129fc8c4f960f978baef88779939592e7b4227d2 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 10 May 2006 12:57:39 +0000 Subject: [PATCH] Draw an offscreen Image --- src/jalview/gui/WebserviceInfo.java | 99 ++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 43 deletions(-) diff --git a/src/jalview/gui/WebserviceInfo.java b/src/jalview/gui/WebserviceInfo.java index a260072..479cfc9 100755 --- a/src/jalview/gui/WebserviceInfo.java +++ b/src/jalview/gui/WebserviceInfo.java @@ -22,6 +22,7 @@ import jalview.jbgui.*; import java.awt.*; import java.awt.event.*; +import java.awt.image.*; import javax.swing.*; @@ -233,6 +234,7 @@ public class WebserviceInfo extends GWebserviceInfo class AnimatedPanel extends JPanel implements Runnable { long startTime = 0; + BufferedImage offscreen; public void run() { @@ -248,66 +250,77 @@ public class WebserviceInfo extends GWebserviceInfo angle += units; angle %= 360; startTime = System.currentTimeMillis(); - repaint(); - } - catch (Exception ex) - { - } - } - angle = 0; - cancel.setEnabled(false); - } + if (offscreen == null || offscreen.getWidth(this) != getWidth() + || offscreen.getHeight(this) != getHeight()) + { + offscreen = new BufferedImage(getWidth(), getHeight(), + BufferedImage.TYPE_INT_RGB); + } - synchronized public void paintComponent(Graphics g1) - { - Graphics2D g = (Graphics2D) g1; - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); + Graphics2D g = (Graphics2D) offscreen.getGraphics(); + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); - if (image != null) - { - g.rotate(Math.toRadians(angle), 28, 28); - g.drawImage(image, 10, 10, this); - g.rotate(-Math.toRadians(angle), 28, 28); - } + if (image != null) + { + g.rotate(Math.toRadians(angle), 28, 28); + g.drawImage(image, 10, 10, this); + g.rotate( -Math.toRadians(angle), 28, 28); + } - g.setFont(new Font("Arial", Font.BOLD, 12)); - g.setColor(Color.black); + g.setFont(new Font("Arial", Font.BOLD, 12)); + g.setColor(Color.black); - switch (currentStatus) - { - case STATE_QUEUING: - g.drawString(title.concat(" - queuing"), 60, 30); + switch (currentStatus) + { + case STATE_QUEUING: + g.drawString(title.concat(" - queuing"), 60, 30); - break; + break; - case STATE_RUNNING: - g.drawString(title.concat(" - running"), 60, 30); + case STATE_RUNNING: + g.drawString(title.concat(" - running"), 60, 30); - break; + break; - case STATE_STOPPED_OK: - g.drawString(title.concat(" - complete"), 60, 30); + case STATE_STOPPED_OK: + g.drawString(title.concat(" - complete"), 60, 30); - break; + break; - case STATE_CANCELLED_OK: - g.drawString(title.concat(" - job cancelled!"), 60, 30); + case STATE_CANCELLED_OK: + g.drawString(title.concat(" - job cancelled!"), 60, 30); - break; + break; - case STATE_STOPPED_ERROR: - g.drawString(title.concat(" - job error!"), 60, 30); + case STATE_STOPPED_ERROR: + g.drawString(title.concat(" - job error!"), 60, 30); - break; + break; - case STATE_STOPPED_SERVERERROR: - g.drawString(title.concat(" - Server Error! (try later)"), 60, - 30); + case STATE_STOPPED_SERVERERROR: + g.drawString(title.concat(" - Server Error! (try later)"), + 60, + 30); - break; + break; + } + + repaint(); + } + catch (Exception ex) + { + } } + + angle = 0; + cancel.setEnabled(false); + } + + public void paintComponent(Graphics g1) + { + g1.drawImage(offscreen, 0,0,this); } } } -- 1.7.10.2