/*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
-*/\r
-\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
package jalview.gui;\r
\r
+import jalview.jbgui.*;\r
+\r
import java.awt.*;\r
import java.awt.event.*;\r
+\r
import javax.swing.*;\r
-import jalview.jbgui.GWebserviceInfo;\r
\r
+\r
+/**\r
+ * Base class for web service client thread and gui\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
public class WebserviceInfo extends GWebserviceInfo\r
{\r
+ /** Job is Queued */\r
+ public static final int STATE_QUEUING = 0;\r
+\r
+ /** Job is Running */\r
+ public static final int STATE_RUNNING = 1;\r
+\r
+ /** Job has finished with no errors */\r
+ public static final int STATE_STOPPED_OK = 2;\r
+\r
+ /** Job has been cancelled with no errors */\r
+ public static final int STATE_CANCELLED_OK = 3;\r
\r
- public static final int STATE_QUEUING = 0;\r
- public static final int STATE_RUNNING = 1;\r
- public static final int STATE_STOPPED_OK = 2;\r
- public static final int STATE_CANCELLED_OK = 3;\r
- public static final int STATE_STOPPED_ERROR = 4;\r
- public static final int STATE_STOPPED_SERVERERROR = 5;\r
- int currentStatus = STATE_QUEUING;\r
- Image image;\r
- int angle = 0;\r
-\r
- String title="";\r
- jalview.ws.WSClientI thisService;\r
- boolean serviceIsCancellable;\r
- public jalview.ws.WSClientI getthisService() {\r
- return thisService;\r
- }\r
- public void setthisService(jalview.ws.WSClientI newservice) {\r
- thisService = newservice;\r
- serviceIsCancellable = newservice.isCancellable();\r
- }\r
-\r
- public WebserviceInfo(String title, String info)\r
- {\r
- init(title, info, 520, 500);\r
- }\r
-\r
- public WebserviceInfo(String title, String info, int width, int height)\r
- {\r
- init(title, info, width, height);\r
- }\r
-\r
- void init(String title, String info, int width, int height)\r
- {\r
- JInternalFrame frame = new JInternalFrame();\r
- frame.setContentPane(this);\r
- Desktop.addInternalFrame(frame, title, width, height);\r
-\r
- this.title = title;\r
- setInfoText(info);\r
- java.net.URL url = getClass().getResource("/images/logo.gif");\r
- image = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
- MediaTracker mt = new MediaTracker(this);\r
- mt.addImage(image, 0);\r
- try\r
+ /** job has stopped because of some error */\r
+ public static final int STATE_STOPPED_ERROR = 4;\r
+\r
+ /** job has failed because of some unavoidable service interruption */\r
+ public static final int STATE_STOPPED_SERVERERROR = 5;\r
+ int currentStatus = STATE_QUEUING;\r
+ Image image;\r
+ int angle = 0;\r
+ String title = "";\r
+ jalview.ws.WSClientI thisService;\r
+ boolean serviceIsCancellable;\r
+\r
+ /**\r
+ * Creates a new WebserviceInfo object.\r
+ *\r
+ * @param title short name and job type\r
+ * @param info reference or other human readable description\r
+ */\r
+ public WebserviceInfo(String title, String info)\r
{\r
- mt.waitForID(0);\r
+ init(title, info, 520, 500);\r
}\r
- catch (Exception ex)\r
- {}\r
\r
+ /**\r
+ * Creates a new WebserviceInfo object.\r
+ *\r
+ * @param title DOCUMENT ME!\r
+ * @param info DOCUMENT ME!\r
+ * @param width DOCUMENT ME!\r
+ * @param height DOCUMENT ME!\r
+ */\r
+ public WebserviceInfo(String title, String info, int width, int height)\r
+ {\r
+ init(title, info, width, height);\r
+ }\r
\r
- AnimatedPanel ap = new AnimatedPanel();\r
- titlePanel.add(ap, BorderLayout.CENTER);\r
- Thread thread = new Thread(ap);\r
- thread.start();\r
- }\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public jalview.ws.WSClientI getthisService()\r
+ {\r
+ return thisService;\r
+ }\r
\r
- public void setStatus(int status)\r
- {\r
- currentStatus = status;\r
- }\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param newservice DOCUMENT ME!\r
+ */\r
+ public void setthisService(jalview.ws.WSClientI newservice)\r
+ {\r
+ thisService = newservice;\r
+ serviceIsCancellable = newservice.isCancellable();\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param title DOCUMENT ME!\r
+ * @param info DOCUMENT ME!\r
+ * @param width DOCUMENT ME!\r
+ * @param height DOCUMENT ME!\r
+ */\r
+ void init(String title, String info, int width, int height)\r
+ {\r
+ JInternalFrame frame = new JInternalFrame();\r
+ frame.setContentPane(this);\r
+ Desktop.addInternalFrame(frame, title, width, height);\r
+\r
+ this.title = title;\r
+ setInfoText(info);\r
\r
- public String getInfoText()\r
- { return infoText.getText(); }\r
+ java.net.URL url = getClass().getResource("/images/logo.gif");\r
+ image = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
\r
- public void setInfoText(String text)\r
- { infoText.setText(text); }\r
+ MediaTracker mt = new MediaTracker(this);\r
+ mt.addImage(image, 0);\r
\r
- public void appendInfoText(String text)\r
- { infoText.append(text); }\r
+ try\r
+ {\r
+ mt.waitForID(0);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
\r
- public String getProgressText()\r
- { return progressText.getText(); }\r
+ AnimatedPanel ap = new AnimatedPanel();\r
+ titlePanel.add(ap, BorderLayout.CENTER);\r
\r
- public void setProgressText(String text)\r
- { progressText.setText(text); }\r
+ Thread thread = new Thread(ap);\r
+ thread.start();\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param status integer status from state constants\r
+ */\r
+ public void setStatus(int status)\r
+ {\r
+ currentStatus = status;\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public String getInfoText()\r
+ {\r
+ return infoText.getText();\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param text DOCUMENT ME!\r
+ */\r
+ public void setInfoText(String text)\r
+ {\r
+ infoText.setText(text);\r
+ }\r
\r
- public void appendProgressText(String text)\r
- { progressText.append(text); }\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param text DOCUMENT ME!\r
+ */\r
+ public void appendInfoText(String text)\r
+ {\r
+ infoText.append(text);\r
+ }\r
\r
- protected void cancel_actionPerformed(ActionEvent e)\r
- {\r
- if (!serviceIsCancellable)\r
- JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
- "This job cannot be cancelled." ,\r
- "Cancel job"\r
- ,JOptionPane.WARNING_MESSAGE);\r
- else\r
- thisService.cancelJob();\r
- }\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public String getProgressText()\r
+ {\r
+ return progressText.getText();\r
+ }\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param text DOCUMENT ME!\r
+ */\r
+ public void setProgressText(String text)\r
+ {\r
+ progressText.setText(text);\r
+ }\r
\r
- class AnimatedPanel extends JPanel implements Runnable\r
- {\r
- long startTime=0;\r
- public void run()\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param text DOCUMENT ME!\r
+ */\r
+ public void appendProgressText(String text)\r
{\r
- startTime = System.currentTimeMillis();\r
- while(currentStatus<STATE_STOPPED_OK)\r
- try\r
- {\r
- Thread.sleep(50);\r
-\r
- int units = (int)((System.currentTimeMillis()-startTime)/10f);\r
- angle += units;\r
- angle %= 360;\r
- startTime = System.currentTimeMillis();\r
- repaint();\r
-\r
- }\r
- catch (Exception ex)\r
- {}\r
- angle = 0;\r
- cancel.setEnabled(false);\r
+ progressText.append(text);\r
+ }\r
\r
+ /**\r
+ * Gui action for cancelling the current job, if possible.\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void cancel_actionPerformed(ActionEvent e)\r
+ {\r
+ if (!serviceIsCancellable)\r
+ {\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+ "This job cannot be cancelled.\nJust close the window.", "Cancel job",\r
+ JOptionPane.WARNING_MESSAGE);\r
+ }\r
+ else\r
+ {\r
+ thisService.cancelJob();\r
+ }\r
}\r
\r
- synchronized public void paintComponent(Graphics g1)\r
+ class AnimatedPanel extends JPanel implements Runnable\r
{\r
- Graphics2D g = (Graphics2D) g1;\r
- g.setColor(Color.white);\r
- g.fillRect(0, 0, getWidth(), getHeight());\r
- if (image != null)\r
- {\r
- g.rotate(Math.toRadians(angle), 28, 28);\r
- g.drawImage(image, 10, 10, this);\r
- g.rotate( -Math.toRadians(angle), 28, 28);\r
- }\r
- g.setFont(new Font("Arial", Font.BOLD, 12));\r
- g.setColor(Color.black);\r
- switch(currentStatus)\r
- {\r
- case STATE_QUEUING:\r
- g.drawString(title.concat(" - queuing"), 60, 30);\r
- break;\r
- case STATE_RUNNING:\r
- g.drawString(title.concat(" - running"), 60, 30);\r
- break;\r
- case STATE_STOPPED_OK:\r
- g.drawString(title.concat(" - complete"), 60, 30);\r
- break;\r
-\r
- case STATE_CANCELLED_OK:\r
- g.drawString(title.concat(" - job cancelled!"), 60, 30);\r
- break;\r
-\r
- case STATE_STOPPED_ERROR:\r
- g.drawString(title.concat(" - job error!"), 60, 30);\r
- break;\r
- case STATE_STOPPED_SERVERERROR:\r
- g.drawString(title.concat(" - Server Error! (try later)"), 60, 30);\r
- break;\r
- }\r
+ long startTime = 0;\r
+\r
+ public void run()\r
+ {\r
+ startTime = System.currentTimeMillis();\r
+\r
+ while (currentStatus < STATE_STOPPED_OK)\r
+ {\r
+ try\r
+ {\r
+ Thread.sleep(50);\r
+\r
+ int units = (int) ((System.currentTimeMillis() - startTime) / 10f);\r
+ angle += units;\r
+ angle %= 360;\r
+ startTime = System.currentTimeMillis();\r
+ repaint();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
+ }\r
+\r
+ angle = 0;\r
+ cancel.setEnabled(false);\r
+ }\r
+\r
+ synchronized public void paintComponent(Graphics g1)\r
+ {\r
+ Graphics2D g = (Graphics2D) g1;\r
+ g.setColor(Color.white);\r
+ g.fillRect(0, 0, getWidth(), getHeight());\r
+\r
+ if (image != null)\r
+ {\r
+ g.rotate(Math.toRadians(angle), 28, 28);\r
+ g.drawImage(image, 10, 10, this);\r
+ g.rotate(-Math.toRadians(angle), 28, 28);\r
+ }\r
+\r
+ g.setFont(new Font("Arial", Font.BOLD, 12));\r
+ g.setColor(Color.black);\r
+\r
+ switch (currentStatus)\r
+ {\r
+ case STATE_QUEUING:\r
+ g.drawString(title.concat(" - queuing"), 60, 30);\r
+\r
+ break;\r
+\r
+ case STATE_RUNNING:\r
+ g.drawString(title.concat(" - running"), 60, 30);\r
+\r
+ break;\r
+\r
+ case STATE_STOPPED_OK:\r
+ g.drawString(title.concat(" - complete"), 60, 30);\r
+\r
+ break;\r
+\r
+ case STATE_CANCELLED_OK:\r
+ g.drawString(title.concat(" - job cancelled!"), 60, 30);\r
+\r
+ break;\r
+\r
+ case STATE_STOPPED_ERROR:\r
+ g.drawString(title.concat(" - job error!"), 60, 30);\r
+\r
+ break;\r
+\r
+ case STATE_STOPPED_SERVERERROR:\r
+ g.drawString(title.concat(" - Server Error! (try later)"), 60,\r
+ 30);\r
\r
+ break;\r
+ }\r
+ }\r
}\r
- }\r
}\r