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
24 import java.awt.event.*;
\r
25 import java.awt.image.*;
\r
26 import javax.swing.*;
\r
28 import jalview.jbgui.*;
\r
32 * Base class for web service client thread and gui
\r
35 * @version $Revision$
\r
37 public class WebserviceInfo extends GWebserviceInfo
\r
40 /** Job is Queued */
\r
41 public static final int STATE_QUEUING = 0;
\r
43 /** Job is Running */
\r
44 public static final int STATE_RUNNING = 1;
\r
46 /** Job has finished with no errors */
\r
47 public static final int STATE_STOPPED_OK = 2;
\r
49 /** Job has been cancelled with no errors */
\r
50 public static final int STATE_CANCELLED_OK = 3;
\r
52 /** job has stopped because of some error */
\r
53 public static final int STATE_STOPPED_ERROR = 4;
\r
55 /** job has failed because of some unavoidable service interruption */
\r
56 public static final int STATE_STOPPED_SERVERERROR = 5;
\r
57 int currentStatus = STATE_QUEUING;
\r
61 jalview.ws.WSClientI thisService;
\r
62 boolean serviceIsCancellable;
\r
63 JInternalFrame frame;
\r
64 JTabbedPane subjobs=null;
\r
65 java.util.Vector jobPanes = null;
\r
67 public synchronized int addJobPane() {
\r
68 JScrollPane jobpane = new JScrollPane();
\r
69 JTextArea progressText = new JTextArea();
\r
70 progressText.setFont(new java.awt.Font("Verdana", 0, 10));
\r
71 progressText.setBorder(null);
\r
72 progressText.setEditable(false);
\r
73 progressText.setText("WS Job");
\r
74 progressText.setLineWrap(true);
\r
75 progressText.setWrapStyleWord(true);
\r
76 jobpane.setName("JobPane");
\r
77 jobpane.getViewport().add(progressText, null);
\r
78 jobpane.setBorder(null);
\r
79 if (jobPanes==null) {
\r
80 jobPanes = new Vector();
\r
82 int newpane = jobPanes.size();
\r
83 jobPanes.add(jobpane);
\r
86 this.add(jobpane, BorderLayout.CENTER);
\r
89 // revert to a tabbed pane.
\r
90 JScrollPane firstpane;
\r
91 this.remove(firstpane=(JScrollPane) jobPanes.get(0));
\r
92 subjobs=new JTabbedPane();
\r
93 this.add(subjobs, BorderLayout.CENTER);
\r
94 subjobs.add(firstpane);
\r
95 subjobs.setTitleAt(0, firstpane.getName());
\r
97 subjobs.add(jobpane);
\r
99 return newpane; // index for accessor methods below
\r
102 * Creates a new WebserviceInfo object.
\r
104 * @param title short name and job type
\r
105 * @param info reference or other human readable description
\r
107 public WebserviceInfo(String title, String info)
\r
109 init(title, info, 520, 500);
\r
113 * Creates a new WebserviceInfo object.
\r
115 * @param title DOCUMENT ME!
\r
116 * @param info DOCUMENT ME!
\r
117 * @param width DOCUMENT ME!
\r
118 * @param height DOCUMENT ME!
\r
120 public WebserviceInfo(String title, String info, int width, int height)
\r
122 init(title, info, width, height);
\r
128 * @return DOCUMENT ME!
\r
130 public jalview.ws.WSClientI getthisService()
\r
132 return thisService;
\r
138 * @param newservice DOCUMENT ME!
\r
140 public void setthisService(jalview.ws.WSClientI newservice)
\r
142 thisService = newservice;
\r
143 serviceIsCancellable = newservice.isCancellable();
\r
149 * @param title DOCUMENT ME!
\r
150 * @param info DOCUMENT ME!
\r
151 * @param width DOCUMENT ME!
\r
152 * @param height DOCUMENT ME!
\r
154 void init(String title, String info, int width, int height)
\r
156 frame = new JInternalFrame();
\r
157 frame.setContentPane(this);
\r
158 Desktop.addInternalFrame(frame, title, width, height);
\r
159 frame.setClosable(false);
\r
161 this.title = title;
\r
164 java.net.URL url = getClass().getResource("/images/logo.gif");
\r
165 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
167 MediaTracker mt = new MediaTracker(this);
\r
168 mt.addImage(image, 0);
\r
174 catch (Exception ex)
\r
178 AnimatedPanel ap = new AnimatedPanel();
\r
179 titlePanel.add(ap, BorderLayout.CENTER);
\r
181 Thread thread = new Thread(ap);
\r
188 * @param status integer status from state constants
\r
190 public void setStatus(int status)
\r
192 currentStatus = status;
\r
195 * subjob status indicator
\r
199 public void setStatus(int jobpane, int status) {
\r
200 if (jobpane<0 || jobpane>=jobPanes.size()) {
\r
201 throw new Error("setStatus called for non-existent job pane."+jobpane);
\r
204 case STATE_QUEUING:
\r
205 setProgressText(jobpane, "QUEUED");
\r
207 case STATE_RUNNING:
\r
208 setProgressText(jobpane, "RUNNING");
\r
210 case STATE_STOPPED_OK:
\r
211 setProgressText(jobpane, "FINISHED");
\r
213 case STATE_CANCELLED_OK:
\r
214 setProgressText(jobpane, "CANCELLED");
\r
216 case STATE_STOPPED_ERROR:
\r
217 setProgressText(jobpane, "BROKEN");
\r
219 case STATE_STOPPED_SERVERERROR:
\r
220 setProgressText(jobpane, "ALERT");
\r
223 setProgressText(jobpane, "UNKNOWN STATE");
\r
229 * @return DOCUMENT ME!
\r
231 public String getInfoText()
\r
233 return infoText.getText();
\r
239 * @param text DOCUMENT ME!
\r
241 public void setInfoText(String text)
\r
243 infoText.setText(text);
\r
249 * @param text DOCUMENT ME!
\r
251 public void appendInfoText(String text)
\r
253 infoText.append(text);
\r
258 * @return DOCUMENT ME!
\r
260 public String getProgressText(int which)
\r
262 if (jobPanes == null)
\r
264 return ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
\r
265 getComponent(0)).getText();
\r
270 * @param text DOCUMENT ME!
\r
272 public void setProgressText(int which, String text)
\r
274 if (jobPanes == null)
\r
276 ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
\r
277 getComponent(0)).setText(text);
\r
283 * @param text DOCUMENT ME!
\r
285 public void appendProgressText(int which, String text)
\r
287 if (jobPanes == null)
\r
289 ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
\r
290 getComponent(0)).append(text);
\r
293 * setProgressText(0, text)
\r
295 public void setProgressText(String text)
\r
297 setProgressText(0, text);
\r
300 * appendProgressText(0, text)
\r
302 public void appendProgressText(String text)
\r
304 appendProgressText(0, text);
\r
307 * getProgressText(0)
\r
309 public String getProgressText()
\r
311 return getProgressText(0);
\r
314 * get the tab title for a subjob
\r
318 public String getProgressName(int which) {
\r
319 if (jobPanes==null)
\r
322 return subjobs.getTitleAt(which);
\r
324 return ((JScrollPane) jobPanes.get(which)).getViewport().getComponent(0).getName();
\r
327 * set the tab title for a subjob
\r
328 * @param name String
\r
331 public void setProgressName(String name, int which) {
\r
333 subjobs.setTitleAt(which, name);
\r
335 ((JScrollPane) jobPanes.get(which)).getViewport().getComponent(0).setName(name);
\r
339 * Gui action for cancelling the current job, if possible.
\r
341 * @param e DOCUMENT ME!
\r
343 protected void cancel_actionPerformed(ActionEvent e)
\r
345 if (!serviceIsCancellable)
\r
347 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
348 "This job cannot be cancelled.\nJust close the window.", "Cancel job",
\r
349 JOptionPane.WARNING_MESSAGE);
\r
353 frame.setClosable(true);
\r
354 thisService.cancelJob();
\r
358 public void setResultsReady()
\r
360 frame.setClosable(true);
\r
361 buttonPanel.remove(cancel);
\r
362 buttonPanel.add(showResultsNewFrame);
\r
363 buttonPanel.add(mergeResults);
\r
364 buttonPanel.setLayout(new GridLayout(2,1,5,5));
\r
365 buttonPanel.validate();
\r
370 class AnimatedPanel extends JPanel implements Runnable
\r
372 long startTime = 0;
\r
373 BufferedImage offscreen;
\r
377 startTime = System.currentTimeMillis();
\r
378 Graphics2D g = null;
\r
380 while (currentStatus < STATE_STOPPED_OK)
\r
386 int units = (int) ( (System.currentTimeMillis() - startTime) /
\r
390 startTime = System.currentTimeMillis();
\r
392 if (offscreen == null || offscreen.getWidth(this) != getWidth()
\r
393 || offscreen.getHeight(this) != getHeight())
\r
395 offscreen = new BufferedImage(getWidth(), getHeight(),
\r
396 BufferedImage.TYPE_INT_ARGB);
\r
397 g = (Graphics2D) offscreen.getGraphics();
\r
400 g.setColor(Color.white);
\r
401 g.fillRect(0, 0, getWidth(), getHeight());
\r
403 g.setFont(new Font("Arial", Font.BOLD, 12));
\r
404 g.setColor(Color.black);
\r
406 switch (currentStatus)
\r
408 case STATE_QUEUING:
\r
409 g.drawString(title.concat(" - queuing"), 60, 30);
\r
413 case STATE_RUNNING:
\r
414 g.drawString(title.concat(" - running"), 60, 30);
\r
418 case STATE_STOPPED_OK:
\r
419 g.drawString(title.concat(" - complete"), 60, 30);
\r
423 case STATE_CANCELLED_OK:
\r
424 g.drawString(title.concat(" - job cancelled!"), 60, 30);
\r
428 case STATE_STOPPED_ERROR:
\r
429 g.drawString(title.concat(" - job error!"), 60, 30);
\r
433 case STATE_STOPPED_SERVERERROR:
\r
434 g.drawString(title.concat(" - Server Error! (try later)"),
\r
442 if (currentStatus >= STATE_STOPPED_OK)
\r
447 g.rotate(Math.toRadians(angle), 28, 28);
\r
448 g.drawImage(image, 10, 10, this);
\r
449 g.rotate( -Math.toRadians(angle), 28, 28);
\r
455 catch (Exception ex)
\r
460 cancel.setEnabled(false);
\r
463 public void paintComponent(Graphics g1)
\r
465 g1.drawImage(offscreen, 0,0,this);
\r