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();
149 * @param title DOCUMENT ME!
150 * @param info DOCUMENT ME!
151 * @param width DOCUMENT ME!
152 * @param height DOCUMENT ME!
154 void init(String title, String info, int width, int height)
156 frame = new JInternalFrame();
157 frame.setContentPane(this);
158 Desktop.addInternalFrame(frame, title, width, height);
159 frame.setClosable(false);
164 java.net.URL url = getClass().getResource("/images/logo.gif");
165 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
167 MediaTracker mt = new MediaTracker(this);
168 mt.addImage(image, 0);
178 AnimatedPanel ap = new AnimatedPanel();
179 titlePanel.add(ap, BorderLayout.CENTER);
181 Thread thread = new Thread(ap);
188 * @param status integer status from state constants
190 public void setStatus(int status)
192 currentStatus = status;
195 * subjob status indicator
199 public void setStatus(int jobpane, int status) {
200 if (jobpane<0 || jobpane>=jobPanes.size()) {
201 throw new Error("setStatus called for non-existent job pane."+jobpane);
205 setProgressName(jobpane+" - QUEUED", jobpane);
208 setProgressName(jobpane+" - RUNNING", jobpane);
210 case STATE_STOPPED_OK:
211 setProgressName(jobpane+" - FINISHED", jobpane);
213 case STATE_CANCELLED_OK:
214 setProgressName(jobpane+" - CANCELLED", jobpane);
216 case STATE_STOPPED_ERROR:
217 setProgressName(jobpane+" - BROKEN",jobpane);
219 case STATE_STOPPED_SERVERERROR:
220 setProgressName(jobpane+" - ALERT", jobpane);
223 setProgressName(jobpane+" - UNKNOWN STATE", jobpane);
229 * @return DOCUMENT ME!
231 public String getInfoText()
233 return infoText.getText();
239 * @param text DOCUMENT ME!
241 public void setInfoText(String text)
243 infoText.setText(text);
249 * @param text DOCUMENT ME!
251 public void appendInfoText(String text)
253 infoText.append(text);
258 * @return DOCUMENT ME!
260 public String getProgressText(int which)
262 if (jobPanes == null)
264 return ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
265 getComponent(0)).getText();
270 * @param text DOCUMENT ME!
272 public void setProgressText(int which, String text)
274 if (jobPanes == null)
276 ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
277 getComponent(0)).setText(text);
283 * @param text DOCUMENT ME!
285 public void appendProgressText(int which, String text)
287 if (jobPanes == null)
289 ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
290 getComponent(0)).append(text);
293 * setProgressText(0, text)
295 public void setProgressText(String text)
297 setProgressText(0, text);
300 * appendProgressText(0, text)
302 public void appendProgressText(String text)
304 appendProgressText(0, text);
309 public String getProgressText()
311 return getProgressText(0);
314 * get the tab title for a subjob
318 public String getProgressName(int which) {
322 return subjobs.getTitleAt(which);
324 return ((JScrollPane) jobPanes.get(which)).getViewport().getComponent(0).getName();
327 * set the tab title for a subjob
331 public void setProgressName(String name, int which) {
333 subjobs.setTitleAt(which, name);
334 subjobs.revalidate();
337 JScrollPane c=(JScrollPane) jobPanes.get(which);
338 c.getViewport().getComponent(0).setName(name);
343 * Gui action for cancelling the current job, if possible.
345 * @param e DOCUMENT ME!
347 protected void cancel_actionPerformed(ActionEvent e)
349 if (!serviceIsCancellable)
351 JOptionPane.showInternalMessageDialog(Desktop.desktop,
352 "This job cannot be cancelled.\nJust close the window.", "Cancel job",
353 JOptionPane.WARNING_MESSAGE);
357 frame.setClosable(true);
358 thisService.cancelJob();
362 public void setResultsReady()
364 frame.setClosable(true);
365 buttonPanel.remove(cancel);
366 buttonPanel.add(showResultsNewFrame);
367 buttonPanel.add(mergeResults);
368 buttonPanel.setLayout(new GridLayout(2,1,5,5));
369 buttonPanel.validate();
374 class AnimatedPanel extends JPanel implements Runnable
377 BufferedImage offscreen;
381 startTime = System.currentTimeMillis();
384 while (currentStatus < STATE_STOPPED_OK)
390 int units = (int) ( (System.currentTimeMillis() - startTime) /
394 startTime = System.currentTimeMillis();
396 if (offscreen == null || offscreen.getWidth(this) != getWidth()
397 || offscreen.getHeight(this) != getHeight())
399 offscreen = new BufferedImage(getWidth(), getHeight(),
400 BufferedImage.TYPE_INT_ARGB);
401 g = (Graphics2D) offscreen.getGraphics();
404 g.setColor(Color.white);
405 g.fillRect(0, 0, getWidth(), getHeight());
407 g.setFont(new Font("Arial", Font.BOLD, 12));
408 g.setColor(Color.black);
410 switch (currentStatus)
413 g.drawString(title.concat(" - queuing"), 60, 30);
418 g.drawString(title.concat(" - running"), 60, 30);
422 case STATE_STOPPED_OK:
423 g.drawString(title.concat(" - complete"), 60, 30);
427 case STATE_CANCELLED_OK:
428 g.drawString(title.concat(" - job cancelled!"), 60, 30);
432 case STATE_STOPPED_ERROR:
433 g.drawString(title.concat(" - job error!"), 60, 30);
437 case STATE_STOPPED_SERVERERROR:
438 g.drawString(title.concat(" - Server Error! (try later)"),
446 if (currentStatus >= STATE_STOPPED_OK)
451 g.rotate(Math.toRadians(angle), 28, 28);
452 g.drawImage(image, 10, 10, this);
453 g.rotate( -Math.toRadians(angle), 28, 28);
464 cancel.setEnabled(false);
467 public void paintComponent(Graphics g1)
469 g1.drawImage(offscreen, 0,0,this);