X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FWebserviceInfo.java;h=b30837ff45d97c0de80f53f6863aea4f9a8daa86;hb=08bde8d252a69d4d6a3b2497f759bd5d6f154a3f;hp=df18a628bcb42822ce6f677d9ec13bdac9683c25;hpb=ab9e5bf849afd2f41102db0bf9893de1df0512f6;p=jalview.git diff --git a/src/jalview/gui/WebserviceInfo.java b/src/jalview/gui/WebserviceInfo.java index df18a62..b30837f 100755 --- a/src/jalview/gui/WebserviceInfo.java +++ b/src/jalview/gui/WebserviceInfo.java @@ -26,15 +26,15 @@ import java.awt.image.*; import javax.swing.*; import jalview.jbgui.*; +import jalview.ws.WSClientI; /** * Base class for web service client thread and gui - * + * * @author $author$ * @version $Revision$ */ -public class WebserviceInfo - extends GWebserviceInfo +public class WebserviceInfo extends GWebserviceInfo { /** Job is Queued */ @@ -54,17 +54,29 @@ public class WebserviceInfo /** job has failed because of some unavoidable service interruption */ public static final int STATE_STOPPED_SERVERERROR = 5; + int currentStatus = STATE_QUEUING; + Image image; + int angle = 0; + String title = ""; + jalview.ws.WSClientI thisService; + boolean serviceIsCancellable; + JInternalFrame frame; + JTabbedPane subjobs = null; + java.util.Vector jobPanes = null; + private boolean serviceCanMergeResults = false; + private boolean viewResultsImmediatly = true; + // tabbed or not public synchronized int addJobPane() { @@ -109,9 +121,11 @@ public class WebserviceInfo /** * Creates a new WebserviceInfo object. - * - * @param title short name and job type - * @param info reference or other human readable description + * + * @param title + * short name and job type + * @param info + * reference or other human readable description */ public WebserviceInfo(String title, String info) { @@ -120,11 +134,15 @@ public class WebserviceInfo /** * Creates a new WebserviceInfo object. - * - * @param title DOCUMENT ME! - * @param info DOCUMENT ME! - * @param width DOCUMENT ME! - * @param height DOCUMENT ME! + * + * @param title + * DOCUMENT ME! + * @param info + * DOCUMENT ME! + * @param width + * DOCUMENT ME! + * @param height + * DOCUMENT ME! */ public WebserviceInfo(String title, String info, int width, int height) { @@ -133,7 +151,7 @@ public class WebserviceInfo /** * DOCUMENT ME! - * + * * @return DOCUMENT ME! */ public jalview.ws.WSClientI getthisService() @@ -142,9 +160,11 @@ public class WebserviceInfo } /** - * DOCUMENT ME! - * - * @param newservice DOCUMENT ME! + * Update state of GUI based on client capabilities (like whether the job is + * cancellable, whether the 'merge results' button is shown. + * + * @param newservice + * service client to query for capabilities */ public void setthisService(jalview.ws.WSClientI newservice) { @@ -152,15 +172,37 @@ public class WebserviceInfo serviceIsCancellable = newservice.isCancellable(); frame.setClosable(!serviceIsCancellable); serviceCanMergeResults = newservice.canMergeResults(); + rebuildButtonPanel(); + } + + private void rebuildButtonPanel() + { + if (buttonPanel != null) + { + buttonPanel.removeAll(); + if (serviceIsCancellable) + { + buttonPanel.add(cancel); + frame.setClosable(false); + } + else + { + frame.setClosable(true); + } + } } /** * DOCUMENT ME! - * - * @param title DOCUMENT ME! - * @param info DOCUMENT ME! - * @param width DOCUMENT ME! - * @param height DOCUMENT ME! + * + * @param title + * DOCUMENT ME! + * @param info + * DOCUMENT ME! + * @param width + * DOCUMENT ME! + * @param height + * DOCUMENT ME! */ void init(String title, String info, int width, int height) { @@ -181,8 +223,7 @@ public class WebserviceInfo try { mt.waitForID(0); - } - catch (Exception ex) + } catch (Exception ex) { } @@ -191,12 +232,29 @@ public class WebserviceInfo Thread thread = new Thread(ap); thread.start(); + final WebserviceInfo thisinfo = this; + frame + .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + { + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + // System.out.println("Shutting down webservice client"); + WSClientI service = thisinfo.getthisService(); + if (service != null) + { + service.cancelJob(); + } + }; + }); + } /** * DOCUMENT ME! - * - * @param status integer status from state constants + * + * @param status + * integer status from state constants */ public void setStatus(int status) { @@ -205,6 +263,7 @@ public class WebserviceInfo /** * subjob status indicator + * * @param jobpane * @param status */ @@ -212,36 +271,37 @@ public class WebserviceInfo { if (jobpane < 0 || jobpane >= jobPanes.size()) { - throw new Error("setStatus called for non-existent job pane." + jobpane); + throw new Error("setStatus called for non-existent job pane." + + jobpane); } switch (status) { - case STATE_QUEUING: - setProgressName(jobpane + " - QUEUED", jobpane); - break; - case STATE_RUNNING: - setProgressName(jobpane + " - RUNNING", jobpane); - break; - case STATE_STOPPED_OK: - setProgressName(jobpane + " - FINISHED", jobpane); - break; - case STATE_CANCELLED_OK: - setProgressName(jobpane + " - CANCELLED", jobpane); - break; - case STATE_STOPPED_ERROR: - setProgressName(jobpane + " - BROKEN", jobpane); - break; - case STATE_STOPPED_SERVERERROR: - setProgressName(jobpane + " - ALERT", jobpane); - break; - default: - setProgressName(jobpane + " - UNKNOWN STATE", jobpane); + case STATE_QUEUING: + setProgressName(jobpane + " - QUEUED", jobpane); + break; + case STATE_RUNNING: + setProgressName(jobpane + " - RUNNING", jobpane); + break; + case STATE_STOPPED_OK: + setProgressName(jobpane + " - FINISHED", jobpane); + break; + case STATE_CANCELLED_OK: + setProgressName(jobpane + " - CANCELLED", jobpane); + break; + case STATE_STOPPED_ERROR: + setProgressName(jobpane + " - BROKEN", jobpane); + break; + case STATE_STOPPED_SERVERERROR: + setProgressName(jobpane + " - ALERT", jobpane); + break; + default: + setProgressName(jobpane + " - UNKNOWN STATE", jobpane); } } /** * DOCUMENT ME! - * + * * @return DOCUMENT ME! */ public String getInfoText() @@ -251,8 +311,9 @@ public class WebserviceInfo /** * DOCUMENT ME! - * - * @param text DOCUMENT ME! + * + * @param text + * DOCUMENT ME! */ public void setInfoText(String text) { @@ -261,8 +322,9 @@ public class WebserviceInfo /** * DOCUMENT ME! - * - * @param text DOCUMENT ME! + * + * @param text + * DOCUMENT ME! */ public void appendInfoText(String text) { @@ -271,7 +333,7 @@ public class WebserviceInfo /** * DOCUMENT ME! - * + * * @return DOCUMENT ME! */ public String getProgressText(int which) @@ -280,14 +342,15 @@ public class WebserviceInfo { addJobPane(); } - return ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport(). - getComponent(0)).getText(); + return ((JTextArea) ((JScrollPane) jobPanes.get(which)).getViewport() + .getComponent(0)).getText(); } /** * DOCUMENT ME! - * - * @param text DOCUMENT ME! + * + * @param text + * DOCUMENT ME! */ public void setProgressText(int which, String text) { @@ -295,14 +358,15 @@ public class WebserviceInfo { addJobPane(); } - ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport(). - getComponent(0)).setText(text); + ((JTextArea) ((JScrollPane) jobPanes.get(which)).getViewport() + .getComponent(0)).setText(text); } /** * DOCUMENT ME! - * - * @param text DOCUMENT ME! + * + * @param text + * DOCUMENT ME! */ public void appendProgressText(int which, String text) { @@ -310,8 +374,8 @@ public class WebserviceInfo { addJobPane(); } - ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport(). - getComponent(0)).append(text); + ((JTextArea) ((JScrollPane) jobPanes.get(which)).getViewport() + .getComponent(0)).append(text); } /** @@ -340,7 +404,9 @@ public class WebserviceInfo /** * get the tab title for a subjob - * @param which int + * + * @param which + * int * @return String */ public String getProgressName(int which) @@ -355,15 +421,18 @@ public class WebserviceInfo } else { - return ( (JScrollPane) jobPanes.get(which)).getViewport().getComponent(0). - getName(); + return ((JScrollPane) jobPanes.get(which)).getViewport() + .getComponent(0).getName(); } } /** * set the tab title for a subjob - * @param name String - * @param which int + * + * @param name + * String + * @param which + * int */ public void setProgressName(String name, int which) { @@ -380,17 +449,21 @@ public class WebserviceInfo /** * Gui action for cancelling the current job, if possible. - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ protected void cancel_actionPerformed(ActionEvent e) { if (!serviceIsCancellable) { + // JBPNote : TODO: We should REALLY just tell the WSClientI to cancel + // anyhow - it has to stop threads and clean up + // JBPNote : TODO: Instead of a warning, we should have an optional 'Are + // you sure?' prompt JOptionPane.showInternalMessageDialog(Desktop.desktop, - "This job cannot be cancelled.\nJust close the window.", - "Cancel job", - JOptionPane.WARNING_MESSAGE); + "This job cannot be cancelled.\nJust close the window.", + "Cancel job", JOptionPane.WARNING_MESSAGE); } else { @@ -422,7 +495,8 @@ public class WebserviceInfo } /** - * called when job has finished but no result objects can be passed back to user + * called when job has finished but no result objects can be passed back to + * user */ public void setFinishedNoResults() { @@ -432,10 +506,10 @@ public class WebserviceInfo validate(); } - class AnimatedPanel - extends JPanel implements Runnable + class AnimatedPanel extends JPanel implements Runnable { long startTime = 0; + BufferedImage offscreen; public void run() @@ -448,8 +522,7 @@ public class WebserviceInfo { Thread.sleep(50); - int units = (int) ( (System.currentTimeMillis() - startTime) / - 10f); + int units = (int) ((System.currentTimeMillis() - startTime) / 10f); angle += units; angle %= 360; startTime = System.currentTimeMillis(); @@ -460,8 +533,7 @@ public class WebserviceInfo } repaint(); - } - catch (Exception ex) + } catch (Exception ex) { } } @@ -472,10 +544,10 @@ public class WebserviceInfo void drawPanel() { if (offscreen == null || offscreen.getWidth(this) != getWidth() - || offscreen.getHeight(this) != getHeight()) + || offscreen.getHeight(this) != getHeight()) { offscreen = new BufferedImage(getWidth(), getHeight(), - BufferedImage.TYPE_INT_ARGB); + BufferedImage.TYPE_INT_ARGB); } Graphics2D g = (Graphics2D) offscreen.getGraphics(); @@ -488,44 +560,42 @@ public class WebserviceInfo switch (currentStatus) { - case STATE_QUEUING: - g.drawString(title.concat(" - queuing"), 60, 30); + 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; } if (image != null) { g.rotate(Math.toRadians(angle), 28, 28); g.drawImage(image, 10, 10, this); - g.rotate( -Math.toRadians(angle), 28, 28); + g.rotate(-Math.toRadians(angle), 28, 28); } }