2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.jbgui.*;
\r
24 import java.awt.event.*;
\r
25 import java.awt.image.*;
\r
27 import javax.swing.*;
\r
31 * Base class for web service client thread and gui
\r
34 * @version $Revision$
\r
36 public class WebserviceInfo extends GWebserviceInfo
\r
38 /** Job is Queued */
\r
39 public static final int STATE_QUEUING = 0;
\r
41 /** Job is Running */
\r
42 public static final int STATE_RUNNING = 1;
\r
44 /** Job has finished with no errors */
\r
45 public static final int STATE_STOPPED_OK = 2;
\r
47 /** Job has been cancelled with no errors */
\r
48 public static final int STATE_CANCELLED_OK = 3;
\r
50 /** job has stopped because of some error */
\r
51 public static final int STATE_STOPPED_ERROR = 4;
\r
53 /** job has failed because of some unavoidable service interruption */
\r
54 public static final int STATE_STOPPED_SERVERERROR = 5;
\r
55 int currentStatus = STATE_QUEUING;
\r
59 jalview.ws.WSClientI thisService;
\r
60 boolean serviceIsCancellable;
\r
61 JInternalFrame frame;
\r
64 * Creates a new WebserviceInfo object.
\r
66 * @param title short name and job type
\r
67 * @param info reference or other human readable description
\r
69 public WebserviceInfo(String title, String info)
\r
71 init(title, info, 520, 500);
\r
75 * Creates a new WebserviceInfo object.
\r
77 * @param title DOCUMENT ME!
\r
78 * @param info DOCUMENT ME!
\r
79 * @param width DOCUMENT ME!
\r
80 * @param height DOCUMENT ME!
\r
82 public WebserviceInfo(String title, String info, int width, int height)
\r
84 init(title, info, width, height);
\r
90 * @return DOCUMENT ME!
\r
92 public jalview.ws.WSClientI getthisService()
\r
100 * @param newservice DOCUMENT ME!
\r
102 public void setthisService(jalview.ws.WSClientI newservice)
\r
104 thisService = newservice;
\r
105 serviceIsCancellable = newservice.isCancellable();
\r
111 * @param title DOCUMENT ME!
\r
112 * @param info DOCUMENT ME!
\r
113 * @param width DOCUMENT ME!
\r
114 * @param height DOCUMENT ME!
\r
116 void init(String title, String info, int width, int height)
\r
118 frame = new JInternalFrame();
\r
119 frame.setContentPane(this);
\r
120 Desktop.addInternalFrame(frame, title, width, height);
\r
121 frame.setClosable(false);
\r
123 this.title = title;
\r
126 java.net.URL url = getClass().getResource("/images/logo.gif");
\r
127 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
129 MediaTracker mt = new MediaTracker(this);
\r
130 mt.addImage(image, 0);
\r
136 catch (Exception ex)
\r
140 AnimatedPanel ap = new AnimatedPanel();
\r
141 titlePanel.add(ap, BorderLayout.CENTER);
\r
143 Thread thread = new Thread(ap);
\r
150 * @param status integer status from state constants
\r
152 public void setStatus(int status)
\r
154 currentStatus = status;
\r
160 * @return DOCUMENT ME!
\r
162 public String getInfoText()
\r
164 return infoText.getText();
\r
170 * @param text DOCUMENT ME!
\r
172 public void setInfoText(String text)
\r
174 infoText.setText(text);
\r
180 * @param text DOCUMENT ME!
\r
182 public void appendInfoText(String text)
\r
184 infoText.append(text);
\r
190 * @return DOCUMENT ME!
\r
192 public String getProgressText()
\r
194 return progressText.getText();
\r
200 * @param text DOCUMENT ME!
\r
202 public void setProgressText(String text)
\r
204 progressText.setText(text);
\r
210 * @param text DOCUMENT ME!
\r
212 public void appendProgressText(String text)
\r
214 progressText.append(text);
\r
218 * Gui action for cancelling the current job, if possible.
\r
220 * @param e DOCUMENT ME!
\r
222 protected void cancel_actionPerformed(ActionEvent e)
\r
224 if (!serviceIsCancellable)
\r
226 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
227 "This job cannot be cancelled.\nJust close the window.", "Cancel job",
\r
228 JOptionPane.WARNING_MESSAGE);
\r
232 frame.setClosable(true);
\r
233 thisService.cancelJob();
\r
237 public void setResultsReady()
\r
239 frame.setClosable(true);
\r
240 buttonPanel.remove(cancel);
\r
241 buttonPanel.add(showResultsNewFrame);
\r
242 buttonPanel.add(mergeResults);
\r
243 buttonPanel.setLayout(new GridLayout(2,1,5,5));
\r
244 buttonPanel.validate();
\r
249 class AnimatedPanel extends JPanel implements Runnable
\r
251 long startTime = 0;
\r
252 BufferedImage offscreen;
\r
256 startTime = System.currentTimeMillis();
\r
257 Graphics2D g = null;
\r
259 while (currentStatus < STATE_STOPPED_OK)
\r
265 int units = (int) ( (System.currentTimeMillis() - startTime) /
\r
269 startTime = System.currentTimeMillis();
\r
271 if (offscreen == null || offscreen.getWidth(this) != getWidth()
\r
272 || offscreen.getHeight(this) != getHeight())
\r
274 offscreen = new BufferedImage(getWidth(), getHeight(),
\r
275 BufferedImage.TYPE_INT_ARGB);
\r
276 g = (Graphics2D) offscreen.getGraphics();
\r
279 g.setColor(Color.white);
\r
280 g.fillRect(0, 0, getWidth(), getHeight());
\r
282 g.setFont(new Font("Arial", Font.BOLD, 12));
\r
283 g.setColor(Color.black);
\r
285 switch (currentStatus)
\r
287 case STATE_QUEUING:
\r
288 g.drawString(title.concat(" - queuing"), 60, 30);
\r
292 case STATE_RUNNING:
\r
293 g.drawString(title.concat(" - running"), 60, 30);
\r
297 case STATE_STOPPED_OK:
\r
298 g.drawString(title.concat(" - complete"), 60, 30);
\r
302 case STATE_CANCELLED_OK:
\r
303 g.drawString(title.concat(" - job cancelled!"), 60, 30);
\r
307 case STATE_STOPPED_ERROR:
\r
308 g.drawString(title.concat(" - job error!"), 60, 30);
\r
312 case STATE_STOPPED_SERVERERROR:
\r
313 g.drawString(title.concat(" - Server Error! (try later)"),
\r
321 if (currentStatus >= STATE_STOPPED_OK)
\r
326 g.rotate(Math.toRadians(angle), 28, 28);
\r
327 g.drawImage(image, 10, 10, this);
\r
328 g.rotate( -Math.toRadians(angle), 28, 28);
\r
334 catch (Exception ex)
\r
339 cancel.setEnabled(false);
\r
342 public void paintComponent(Graphics g1)
\r
344 g1.drawImage(offscreen, 0,0,this);
\r