2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import java.awt.event.*;
25 import java.awt.image.*;
28 import jalview.jbgui.*;
32 * Base class for web service client thread and gui
37 public class WebserviceInfo extends GWebserviceInfo
41 public static final int STATE_QUEUING = 0;
44 public static final int STATE_RUNNING = 1;
46 /** Job has finished with no errors */
47 public static final int STATE_STOPPED_OK = 2;
49 /** Job has been cancelled with no errors */
50 public static final int STATE_CANCELLED_OK = 3;
52 /** job has stopped because of some error */
53 public static final int STATE_STOPPED_ERROR = 4;
55 /** job has failed because of some unavoidable service interruption */
56 public static final int STATE_STOPPED_SERVERERROR = 5;
57 int currentStatus = STATE_QUEUING;
61 jalview.ws.WSClientI thisService;
62 boolean serviceIsCancellable;
64 JTabbedPane subjobs=null;
65 java.util.Vector jobPanes = null;
67 public synchronized int addJobPane() {
68 JScrollPane jobpane = new JScrollPane();
69 JTextArea progressText = new JTextArea();
70 progressText.setFont(new java.awt.Font("Verdana", 0, 10));
71 progressText.setBorder(null);
72 progressText.setEditable(false);
73 progressText.setText("WS Job");
74 progressText.setLineWrap(true);
75 progressText.setWrapStyleWord(true);
76 jobpane.setName("JobPane");
77 jobpane.getViewport().add(progressText, null);
78 jobpane.setBorder(null);
80 jobPanes = new Vector();
82 int newpane = jobPanes.size();
83 jobPanes.add(jobpane);
86 this.add(jobpane, BorderLayout.CENTER);
89 // revert to a tabbed pane.
90 JScrollPane firstpane;
91 this.remove(firstpane=(JScrollPane) jobPanes.get(0));
92 subjobs=new JTabbedPane();
93 this.add(subjobs, BorderLayout.CENTER);
94 subjobs.add(firstpane);
95 subjobs.setTitleAt(0, firstpane.getName());
99 return newpane; // index for accessor methods below
102 * Creates a new WebserviceInfo object.
104 * @param title short name and job type
105 * @param info reference or other human readable description
107 public WebserviceInfo(String title, String info)
109 init(title, info, 520, 500);
113 * Creates a new WebserviceInfo object.
115 * @param title DOCUMENT ME!
116 * @param info DOCUMENT ME!
117 * @param width DOCUMENT ME!
118 * @param height DOCUMENT ME!
120 public WebserviceInfo(String title, String info, int width, int height)
122 init(title, info, width, height);
128 * @return DOCUMENT ME!
130 public jalview.ws.WSClientI getthisService()
138 * @param newservice DOCUMENT ME!
140 public void setthisService(jalview.ws.WSClientI newservice)
142 thisService = newservice;
143 serviceIsCancellable = newservice.isCancellable();
144 frame.setClosable(!serviceIsCancellable);
150 * @param title DOCUMENT ME!
151 * @param info DOCUMENT ME!
152 * @param width DOCUMENT ME!
153 * @param height DOCUMENT ME!
155 void init(String title, String info, int width, int height)
157 frame = new JInternalFrame();
158 frame.setContentPane(this);
159 Desktop.addInternalFrame(frame, title, width, height);
160 frame.setClosable(false);
165 java.net.URL url = getClass().getResource("/images/logo.gif");
166 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
168 MediaTracker mt = new MediaTracker(this);
169 mt.addImage(image, 0);
179 AnimatedPanel ap = new AnimatedPanel();
180 titlePanel.add(ap, BorderLayout.CENTER);
182 Thread thread = new Thread(ap);
189 * @param status integer status from state constants
191 public void setStatus(int status)
193 currentStatus = status;
196 * subjob status indicator
200 public void setStatus(int jobpane, int status) {
201 if (jobpane<0 || jobpane>=jobPanes.size()) {
202 throw new Error("setStatus called for non-existent job pane."+jobpane);
206 setProgressName(jobpane+" - QUEUED", jobpane);
209 setProgressName(jobpane+" - RUNNING", jobpane);
211 case STATE_STOPPED_OK:
212 setProgressName(jobpane+" - FINISHED", jobpane);
214 case STATE_CANCELLED_OK:
215 setProgressName(jobpane+" - CANCELLED", jobpane);
217 case STATE_STOPPED_ERROR:
218 setProgressName(jobpane+" - BROKEN",jobpane);
220 case STATE_STOPPED_SERVERERROR:
221 setProgressName(jobpane+" - ALERT", jobpane);
224 setProgressName(jobpane+" - UNKNOWN STATE", jobpane);
230 * @return DOCUMENT ME!
232 public String getInfoText()
234 return infoText.getText();
240 * @param text DOCUMENT ME!
242 public void setInfoText(String text)
244 infoText.setText(text);
250 * @param text DOCUMENT ME!
252 public void appendInfoText(String text)
254 infoText.append(text);
259 * @return DOCUMENT ME!
261 public String getProgressText(int which)
263 if (jobPanes == null)
265 return ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
266 getComponent(0)).getText();
271 * @param text DOCUMENT ME!
273 public void setProgressText(int which, String text)
275 if (jobPanes == null)
277 ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
278 getComponent(0)).setText(text);
284 * @param text DOCUMENT ME!
286 public void appendProgressText(int which, String text)
288 if (jobPanes == null)
290 ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
291 getComponent(0)).append(text);
294 * setProgressText(0, text)
296 public void setProgressText(String text)
298 setProgressText(0, text);
301 * appendProgressText(0, text)
303 public void appendProgressText(String text)
305 appendProgressText(0, text);
310 public String getProgressText()
312 return getProgressText(0);
315 * get the tab title for a subjob
319 public String getProgressName(int which) {
323 return subjobs.getTitleAt(which);
325 return ((JScrollPane) jobPanes.get(which)).getViewport().getComponent(0).getName();
328 * set the tab title for a subjob
332 public void setProgressName(String name, int which) {
334 subjobs.setTitleAt(which, name);
335 subjobs.revalidate();
338 JScrollPane c=(JScrollPane) jobPanes.get(which);
339 c.getViewport().getComponent(0).setName(name);
344 * Gui action for cancelling the current job, if possible.
346 * @param e DOCUMENT ME!
348 protected void cancel_actionPerformed(ActionEvent e)
350 if (!serviceIsCancellable)
352 JOptionPane.showInternalMessageDialog(Desktop.desktop,
353 "This job cannot be cancelled.\nJust close the window.", "Cancel job",
354 JOptionPane.WARNING_MESSAGE);
358 thisService.cancelJob();
360 frame.setClosable(true);
363 public void setResultsReady()
365 frame.setClosable(true);
366 buttonPanel.remove(cancel);
367 buttonPanel.add(showResultsNewFrame);
368 buttonPanel.add(mergeResults);
369 buttonPanel.setLayout(new GridLayout(2,1,5,5));
370 buttonPanel.validate();
375 * called when job has finished but no result objects can be passed back to user
377 public void setFinishedNoResults()
379 frame.setClosable(true);
380 buttonPanel.remove(cancel);
381 buttonPanel.validate();
385 class AnimatedPanel extends JPanel implements Runnable
388 BufferedImage offscreen;
392 startTime = System.currentTimeMillis();
395 while (currentStatus < STATE_STOPPED_OK)
401 int units = (int) ( (System.currentTimeMillis() - startTime) /
405 startTime = System.currentTimeMillis();
407 if (offscreen == null || offscreen.getWidth(this) != getWidth()
408 || offscreen.getHeight(this) != getHeight())
410 offscreen = new BufferedImage(getWidth(), getHeight(),
411 BufferedImage.TYPE_INT_ARGB);
412 g = (Graphics2D) offscreen.getGraphics();
415 g.setColor(Color.white);
416 g.fillRect(0, 0, getWidth(), getHeight());
418 g.setFont(new Font("Arial", Font.BOLD, 12));
419 g.setColor(Color.black);
421 switch (currentStatus)
424 g.drawString(title.concat(" - queuing"), 60, 30);
429 g.drawString(title.concat(" - running"), 60, 30);
433 case STATE_STOPPED_OK:
434 g.drawString(title.concat(" - complete"), 60, 30);
438 case STATE_CANCELLED_OK:
439 g.drawString(title.concat(" - job cancelled!"), 60, 30);
443 case STATE_STOPPED_ERROR:
444 g.drawString(title.concat(" - job error!"), 60, 30);
448 case STATE_STOPPED_SERVERERROR:
449 g.drawString(title.concat(" - Server Error! (try later)"),
457 if (currentStatus >= STATE_STOPPED_OK)
462 g.rotate(Math.toRadians(angle), 28, 28);
463 g.drawImage(image, 10, 10, this);
464 g.rotate( -Math.toRadians(angle), 28, 28);
475 cancel.setEnabled(false);
478 public void paintComponent(Graphics g1)
480 g1.drawImage(offscreen, 0,0,this);