b88102e43b2b2ad0984f29e4b0d267d7d77dbec2
[jalview.git] / src / jalview / gui / WebserviceInfo.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.jbgui.GWebserviceInfo;
24 import jalview.util.MessageManager;
25 import jalview.ws.WSClientI;
26
27 import java.awt.BorderLayout;
28 import java.awt.Color;
29 import java.awt.Dimension;
30 import java.awt.Graphics;
31 import java.awt.Graphics2D;
32 import java.awt.GridLayout;
33 import java.awt.Image;
34 import java.awt.MediaTracker;
35 import java.awt.RenderingHints;
36 import java.awt.event.ActionEvent;
37 import java.awt.image.BufferedImage;
38 import java.util.Vector;
39
40 import javax.swing.JComponent;
41 import javax.swing.JEditorPane;
42 import javax.swing.JInternalFrame;
43 import javax.swing.JPanel;
44 import javax.swing.JScrollPane;
45 import javax.swing.JTabbedPane;
46 import javax.swing.JTextArea;
47 import javax.swing.event.HyperlinkEvent;
48 import javax.swing.event.HyperlinkListener;
49 import javax.swing.event.InternalFrameAdapter;
50 import javax.swing.event.InternalFrameEvent;
51 import javax.swing.text.html.HTMLEditorKit;
52 import javax.swing.text.html.StyleSheet;
53
54 /**
55  * Base class for web service client thread and gui TODO: create StAX parser to
56  * extract html body content reliably when preparing html formatted job statuses
57  * 
58  * @author $author$
59  * @version $Revision$
60  */
61 public class WebserviceInfo extends GWebserviceInfo
62         implements HyperlinkListener, IProgressIndicator
63 {
64
65   /** Job is Queued */
66   public static final int STATE_QUEUING = 0;
67
68   /** Job is Running */
69   public static final int STATE_RUNNING = 1;
70
71   /** Job has finished with no errors */
72   public static final int STATE_STOPPED_OK = 2;
73
74   /** Job has been cancelled with no errors */
75   public static final int STATE_CANCELLED_OK = 3;
76
77   /** job has stopped because of some error */
78   public static final int STATE_STOPPED_ERROR = 4;
79
80   /** job has failed because of some unavoidable service interruption */
81   public static final int STATE_STOPPED_SERVERERROR = 5;
82
83   int currentStatus = STATE_QUEUING;
84
85   Image image;
86
87   float angle = 0f;
88
89   String title = "";
90
91   jalview.ws.WSClientI thisService;
92
93   boolean serviceIsCancellable;
94
95   JInternalFrame frame;
96
97   private IProgressIndicator progressBar;
98
99   @Override
100   public void setVisible(boolean aFlag)
101   {
102     super.setVisible(aFlag);
103     frame.setVisible(aFlag);
104   }
105
106   JTabbedPane subjobs = null;
107
108   java.util.Vector jobPanes = null;
109
110   private boolean serviceCanMergeResults = false;
111
112   private boolean viewResultsImmediatly = true;
113
114   /**
115    * Get
116    * 
117    * @param flag
118    *          to indicate if results will be shown in a new window as soon as
119    *          they are available.
120    */
121   public boolean isViewResultsImmediatly()
122   {
123     return viewResultsImmediatly;
124   }
125
126   /**
127    * Set
128    * 
129    * @param flag
130    *          to indicate if results will be shown in a new window as soon as
131    *          they are available.
132    */
133   public void setViewResultsImmediatly(boolean viewResultsImmediatly)
134   {
135     this.viewResultsImmediatly = viewResultsImmediatly;
136   }
137
138   private StyleSheet getStyleSheet(HTMLEditorKit editorKit)
139   {
140
141     // Copied blatantly from
142     // http://www.velocityreviews.com/forums/t132265-string-into-htmldocument.html
143     StyleSheet myStyleSheet = new StyleSheet();
144
145     myStyleSheet.addStyleSheet(editorKit.getStyleSheet());
146
147     editorKit.setStyleSheet(myStyleSheet);
148
149     /*
150      * Set the style sheet rules here by reading them from the constants
151      * interface.
152      */
153     /*
154      * for (int ix=0; ix<CSS_RULES.length; ix++) {
155      * 
156      * myStyleSheet.addRule(CSS_RULES[ix]);
157      * 
158      * }
159      */
160     return myStyleSheet;
161
162   }
163
164   // tabbed or not
165   public synchronized int addJobPane()
166   {
167     JScrollPane jobpane = new JScrollPane();
168     JComponent _progressText;
169     if (renderAsHtml)
170     {
171       JEditorPane progressText = new JEditorPane("text/html", "");
172       progressText.addHyperlinkListener(this);
173       _progressText = progressText;
174       // progressText.setFont(new java.awt.Font("Verdana", 0, 10));
175       // progressText.setBorder(null);
176       progressText.setEditable(false);
177       /*
178        * HTMLEditorKit myEditorKit = new HTMLEditorKit();
179        * 
180        * StyleSheet myStyleSheet = getStyleSheet(myEditorKit);
181        * 
182        * HTMLDocument tipDocument = (HTMLDocument)
183        * (myEditorKit.createDefaultDocument());
184        * 
185        * progressText.setDocument(tipDocument);
186        */progressText.setText("<html><h1>WS Job</h1></html>");
187     }
188     else
189     {
190       JTextArea progressText = new JTextArea();
191       _progressText = progressText;
192
193       progressText.setFont(new java.awt.Font("Verdana", 0, 10));
194       progressText.setBorder(null);
195       progressText.setEditable(false);
196       progressText.setText("WS Job");
197       progressText.setLineWrap(true);
198       progressText.setWrapStyleWord(true);
199     }
200     jobpane.setName("JobPane");
201     jobpane.getViewport().add(_progressText, null);
202     jobpane.setBorder(null);
203     if (jobPanes == null)
204     {
205       jobPanes = new Vector();
206     }
207     int newpane = jobPanes.size();
208     jobPanes.add(jobpane);
209
210     if (newpane == 0)
211     {
212       this.add(jobpane, BorderLayout.CENTER);
213     }
214     else
215     {
216       if (newpane == 1)
217       {
218         // revert to a tabbed pane.
219         JScrollPane firstpane;
220         this.remove(firstpane = (JScrollPane) jobPanes.get(0));
221         subjobs = new JTabbedPane();
222         this.add(subjobs, BorderLayout.CENTER);
223         subjobs.add(firstpane);
224         subjobs.setTitleAt(0, firstpane.getName());
225       }
226       subjobs.add(jobpane);
227     }
228     return newpane; // index for accessor methods below
229   }
230
231   /**
232    * Creates a new WebserviceInfo object.
233    * 
234    * @param title
235    *          short name and job type
236    * @param info
237    *          reference or other human readable description
238    * @param makeVisible
239    *          true to display the webservices window immediatly (otherwise need
240    *          to call setVisible(true))
241    */
242   public WebserviceInfo(String title, String info, boolean makeVisible)
243   {
244     init(title, info, 520, 500, makeVisible);
245   }
246
247   /**
248    * Creates a new WebserviceInfo object.
249    * 
250    * @param title
251    *          DOCUMENT ME!
252    * @param info
253    *          DOCUMENT ME!
254    * @param width
255    *          DOCUMENT ME!
256    * @param height
257    *          DOCUMENT ME!
258    */
259   public WebserviceInfo(String title, String info, int width, int height,
260           boolean makeVisible)
261   {
262     // no references
263     init(title, info, width, height, makeVisible);
264   }
265
266   /**
267    * DOCUMENT ME!
268    * 
269    * @return DOCUMENT ME!
270    */
271   public jalview.ws.WSClientI getthisService()
272   {
273     return thisService;
274   }
275
276   /**
277    * Update state of GUI based on client capabilities (like whether the job is
278    * cancellable, whether the 'merge results' button is shown.
279    * 
280    * @param newservice
281    *          service client to query for capabilities
282    */
283   public void setthisService(jalview.ws.WSClientI newservice)
284   {
285     thisService = newservice;
286     serviceIsCancellable = newservice.isCancellable();
287     frame.setClosable(!serviceIsCancellable);
288     serviceCanMergeResults = newservice.canMergeResults();
289     rebuildButtonPanel();
290   }
291
292   private void rebuildButtonPanel()
293   {
294     if (buttonPanel != null)
295     {
296       buttonPanel.removeAll();
297       if (serviceIsCancellable)
298       {
299         buttonPanel.add(cancel);
300         frame.setClosable(false);
301       }
302       else
303       {
304         frame.setClosable(true);
305       }
306     }
307   }
308
309   /**
310    * DOCUMENT ME!
311    * 
312    * @param title
313    *          DOCUMENT ME!
314    * @param info
315    *          DOCUMENT ME!
316    * @param width
317    *          DOCUMENT ME!
318    * @param height
319    *          DOCUMENT ME!
320    */
321   void init(String title, String info, int width, int height,
322           boolean makeVisible)
323   {
324     frame = new JInternalFrame();
325     frame.setContentPane(this);
326     Desktop.addInternalFrame(frame, title, makeVisible, width, height, Desktop.FRAME_ALLOW_RESIZE, Desktop.FRAME_SET_MIN_SIZE_300);
327     frame.setClosable(false);
328
329     progressBar = new ProgressBar(statusPanel, statusBar);
330
331     this.title = title;
332     setInfoText(info);
333
334     java.net.URL url = getClass()
335             .getResource("/images/Jalview_Logo_small_with_border.png");
336     image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
337
338     MediaTracker mt = new MediaTracker(this);
339     mt.addImage(image, 0);
340
341     try
342     {
343       mt.waitForID(0);
344     } catch (Exception ex)
345     {
346     }
347
348     AnimatedPanel ap = new AnimatedPanel();
349     ap.setPreferredSize(new Dimension(60, 60));
350     titlePanel.add(ap, BorderLayout.WEST);
351     titlePanel.add(titleText, BorderLayout.CENTER);
352     setStatus(currentStatus);
353
354     Thread thread = new Thread(ap);
355     thread.start();
356     final WebserviceInfo thisinfo = this;
357     frame.addInternalFrameListener(
358             new InternalFrameAdapter()
359             {
360               @Override
361               public void internalFrameClosed(InternalFrameEvent evt)
362               {
363                 // System.out.println("Shutting down webservice client");
364                 WSClientI service = thisinfo.getthisService();
365                 if (service != null && service.isCancellable())
366                 {
367                   service.cancelJob();
368                 }
369               }
370             });
371     frame.validate();
372
373   }
374
375   /**
376    * DOCUMENT ME!
377    * 
378    * @param status
379    *          integer status from state constants
380    */
381   public void setStatus(int status)
382   {
383     currentStatus = status;
384
385     String message = null;
386     switch (currentStatus)
387     {
388     case STATE_QUEUING:
389       message = MessageManager.getString("label.state_queueing");
390       break;
391
392     case STATE_RUNNING:
393       message = MessageManager.getString("label.state_running");
394       break;
395
396     case STATE_STOPPED_OK:
397       message = MessageManager.getString("label.state_completed");
398       break;
399
400     case STATE_CANCELLED_OK:
401       message = MessageManager.getString("label.state_job_cancelled");
402       break;
403
404     case STATE_STOPPED_ERROR:
405       message = MessageManager.getString("label.state_job_error");
406       break;
407
408     case STATE_STOPPED_SERVERERROR:
409       message = MessageManager.getString("label.server_error_try_later");
410       break;
411     }
412     titleText.setText(title + (message == null ? "" : " - " + message));
413     titleText.repaint();
414   }
415
416   /**
417    * subjob status indicator
418    * 
419    * @param jobpane
420    * @param status
421    */
422   public void setStatus(int jobpane, int status)
423   {
424     if (jobpane < 0 || jobpane >= jobPanes.size())
425     {
426       throw new Error(MessageManager.formatMessage(
427               "error.setstatus_called_non_existent_job_pane", new String[]
428               { Integer.valueOf(jobpane).toString() }));
429     }
430     switch (status)
431     {
432     case STATE_QUEUING:
433       setProgressName(jobpane + " - QUEUED", jobpane);
434       break;
435     case STATE_RUNNING:
436       setProgressName(jobpane + " - RUNNING", jobpane);
437       break;
438     case STATE_STOPPED_OK:
439       setProgressName(jobpane + " - FINISHED", jobpane);
440       break;
441     case STATE_CANCELLED_OK:
442       setProgressName(jobpane + " - CANCELLED", jobpane);
443       break;
444     case STATE_STOPPED_ERROR:
445       setProgressName(jobpane + " - BROKEN", jobpane);
446       break;
447     case STATE_STOPPED_SERVERERROR:
448       setProgressName(jobpane + " - ALERT", jobpane);
449       break;
450     default:
451       setProgressName(jobpane + " - UNKNOWN STATE", jobpane);
452     }
453   }
454
455   /**
456    * DOCUMENT ME!
457    * 
458    * @return DOCUMENT ME!
459    */
460   public String getInfoText()
461   {
462     return infoText.getText();
463   }
464
465   /**
466    * DOCUMENT ME!
467    * 
468    * @param text
469    *          DOCUMENT ME!
470    */
471   public void setInfoText(String text)
472   {
473     infoText.setText(text);
474   }
475
476   /**
477    * DOCUMENT ME!
478    * 
479    * @param text
480    *          DOCUMENT ME!
481    */
482   public void appendInfoText(String text)
483   {
484     infoText.append(text);
485   }
486
487   /**
488    * DOCUMENT ME!
489    * 
490    * @return DOCUMENT ME!
491    */
492   public String getProgressText(int which)
493   {
494     if (jobPanes == null)
495     {
496       addJobPane();
497     }
498     if (renderAsHtml)
499     {
500       return ((JEditorPane) ((JScrollPane) jobPanes.get(which))
501               .getViewport().getComponent(0)).getText();
502     }
503     else
504     {
505       return ((JTextArea) ((JScrollPane) jobPanes.get(which)).getViewport()
506               .getComponent(0)).getText();
507     }
508   }
509
510   /**
511    * DOCUMENT ME!
512    * 
513    * @param text
514    *          DOCUMENT ME!
515    */
516   public void setProgressText(int which, String text)
517   {
518     if (jobPanes == null)
519     {
520       addJobPane();
521     }
522     if (renderAsHtml)
523     {
524       ((JEditorPane) ((JScrollPane) jobPanes.get(which)).getViewport()
525               .getComponent(0)).setText(ensureHtmlTagged(text));
526     }
527     else
528     {
529       ((JTextArea) ((JScrollPane) jobPanes.get(which)).getViewport()
530               .getComponent(0)).setText(text);
531     }
532   }
533
534   /**
535    * extract content from &lt;body&gt; content &lt;/body&gt;
536    * 
537    * @param text
538    * @param leaveFirst
539    *          - set to leave the initial html tag intact
540    * @param leaveLast
541    *          - set to leave the final html tag intact
542    * @return
543    */
544   private String getHtmlFragment(String text, boolean leaveFirst,
545           boolean leaveLast)
546   {
547     if (text == null)
548     {
549       return null;
550     }
551     String lowertxt = text.toLowerCase();
552     int htmlpos = leaveFirst ? -1 : lowertxt.indexOf("<body");
553
554     int htmlend = leaveLast ? -1 : lowertxt.indexOf("</body");
555     int htmlpose = lowertxt.indexOf(">", htmlpos),
556             htmlende = lowertxt.indexOf(">", htmlend);
557     if (htmlend == -1 && htmlpos == -1)
558     {
559       return text;
560     }
561     if (htmlend > -1)
562     {
563       return text.substring((htmlpos == -1 ? 0 : htmlpose + 1), htmlend);
564     }
565     return text.substring(htmlpos == -1 ? 0 : htmlpose + 1);
566   }
567
568   /**
569    * very simple routine for adding/ensuring html tags are present in text.
570    * 
571    * @param text
572    * @return properly html tag enclosed text
573    */
574   private String ensureHtmlTagged(String text)
575   {
576     if (text == null)
577     {
578       return "";
579     }
580     String lowertxt = text.toLowerCase();
581     int htmlpos = lowertxt.indexOf("<body");
582     int htmlend = lowertxt.indexOf("</body");
583     int doctype = lowertxt.indexOf("<!doctype");
584     int xmltype = lowertxt.indexOf("<?xml");
585     if (htmlend == -1)
586     {
587       text = text + "</body></html>";
588     }
589     if (htmlpos > -1)
590     {
591       if ((doctype > -1 && htmlpos > doctype)
592               || (xmltype > -1 && htmlpos > xmltype))
593       {
594         text = "<html><head></head><body>\n" + text.substring(htmlpos - 1);
595       }
596     }
597     else
598     {
599       text = "<html><head></head><body>\n" + text;
600     }
601     if (text.indexOf("<meta") > -1)
602     {
603       System.err
604               .println("HTML COntent: \n" + text + "<< END HTML CONTENT\n");
605
606     }
607     return text;
608   }
609
610   /**
611    * DOCUMENT ME!
612    * 
613    * @param text
614    *          DOCUMENT ME!
615    */
616   public void appendProgressText(int which, String text)
617   {
618     if (jobPanes == null)
619     {
620       addJobPane();
621     }
622     if (renderAsHtml)
623     {
624       String txt = getHtmlFragment(
625               ((JEditorPane) ((JScrollPane) jobPanes.get(which))
626                       .getViewport().getComponent(0)).getText(),
627               true, false);
628       ((JEditorPane) ((JScrollPane) jobPanes.get(which)).getViewport()
629               .getComponent(0))
630                       .setText(ensureHtmlTagged(
631                               txt + getHtmlFragment(text, false, true)));
632     }
633     else
634     {
635       ((JTextArea) ((JScrollPane) jobPanes.get(which)).getViewport()
636               .getComponent(0)).append(text);
637     }
638   }
639
640   /**
641    * setProgressText(0, text)
642    */
643   public void setProgressText(String text)
644   {
645     setProgressText(0, text);
646   }
647
648   /**
649    * appendProgressText(0, text)
650    */
651   public void appendProgressText(String text)
652   {
653     appendProgressText(0, text);
654   }
655
656   /**
657    * getProgressText(0)
658    */
659   public String getProgressText()
660   {
661     return getProgressText(0);
662   }
663
664   /**
665    * get the tab title for a subjob
666    * 
667    * @param which
668    *          int
669    * @return String
670    */
671   public String getProgressName(int which)
672   {
673     if (jobPanes == null)
674     {
675       addJobPane();
676     }
677     if (subjobs != null)
678     {
679       return subjobs.getTitleAt(which);
680     }
681     else
682     {
683       return ((JScrollPane) jobPanes.get(which)).getViewport()
684               .getComponent(0).getName();
685     }
686   }
687
688   /**
689    * set the tab title for a subjob
690    * 
691    * @param name
692    *          String
693    * @param which
694    *          int
695    */
696   public void setProgressName(String name, int which)
697   {
698     if (subjobs != null)
699     {
700       subjobs.setTitleAt(which, name);
701       subjobs.revalidate();
702       subjobs.repaint();
703     }
704     JScrollPane c = (JScrollPane) jobPanes.get(which);
705     c.getViewport().getComponent(0).setName(name);
706     c.repaint();
707   }
708
709   /**
710    * Gui action for cancelling the current job, if possible.
711    * 
712    * @param e
713    *          DOCUMENT ME!
714    */
715   @Override
716   protected void cancel_actionPerformed(ActionEvent e)
717   {
718     if (!serviceIsCancellable)
719     {
720       // JBPNote : TODO: We should REALLY just tell the WSClientI to cancel
721       // anyhow - it has to stop threads and clean up
722       // JBPNote : TODO: Instead of a warning, we should have an optional 'Are
723       // you sure?' prompt
724       warnUser(
725               MessageManager.getString(
726                       "warn.job_cannot_be_cancelled_close_window"),
727               MessageManager.getString("action.cancel_job"));
728     }
729     else
730     {
731       thisService.cancelJob();
732     }
733     frame.setClosable(true);
734   }
735
736   /**
737    * Spawns a thread that pops up a warning dialog box with the given message
738    * and title.
739    * 
740    * @param message
741    * @param title
742    */
743   public void warnUser(final String message, final String title)
744   {
745     javax.swing.SwingUtilities.invokeLater(new Runnable()
746     {
747       @Override
748       public void run()
749       {
750         JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), message,
751                 title, JvOptionPane.WARNING_MESSAGE);
752
753       }
754     });
755   }
756
757   /**
758    * Set up GUI for user to get at results - and possibly automatically display
759    * them if viewResultsImmediatly is set.
760    */
761   public void setResultsReady()
762   {
763     frame.setClosable(true);
764     buttonPanel.remove(cancel);
765     buttonPanel.add(showResultsNewFrame);
766     if (serviceCanMergeResults)
767     {
768       buttonPanel.add(mergeResults);
769       buttonPanel.setLayout(new GridLayout(2, 1, 5, 5));
770     }
771     buttonPanel.validate();
772     validate();
773     if (viewResultsImmediatly)
774     {
775       showResultsNewFrame.doClick();
776     }
777   }
778
779   /**
780    * called when job has finished but no result objects can be passed back to
781    * user
782    */
783   public void setFinishedNoResults()
784   {
785     frame.setClosable(true);
786     buttonPanel.remove(cancel);
787     buttonPanel.validate();
788     validate();
789   }
790
791   class AnimatedPanel extends JPanel implements Runnable
792   {
793     long startTime = 0;
794
795     BufferedImage offscreen;
796
797     @Override
798     public void run()
799     {
800       startTime = System.currentTimeMillis();
801
802       float invSpeed = 15f;
803       float factor = 1f;
804       while (currentStatus < STATE_STOPPED_OK)
805       {
806         if (currentStatus == STATE_QUEUING)
807         {
808           invSpeed = 25f;
809           factor = 1f;
810         }
811         else if (currentStatus == STATE_RUNNING)
812         {
813           invSpeed = 10f;
814           factor = (float) (0.5 + 1.5
815                   * (0.5 - (0.5 * Math.sin(3.14159 / 180 * (angle + 45)))));
816         }
817         try
818         {
819           Thread.sleep(50);
820
821           float delta = (System.currentTimeMillis() - startTime) / invSpeed;
822           angle += delta * factor;
823           angle %= 360;
824           startTime = System.currentTimeMillis();
825
826           if (currentStatus >= STATE_STOPPED_OK)
827           {
828             park();
829             angle = 0;
830           }
831
832           repaint();
833         } catch (Exception ex)
834         {
835         }
836       }
837
838       cancel.setEnabled(false);
839     }
840
841     public void park()
842     {
843       startTime = System.currentTimeMillis();
844
845       while (angle < 360)
846       {
847         float invSpeed = 5f;
848         float factor = 1f;
849         try
850         {
851           Thread.sleep(25);
852
853           float delta = (System.currentTimeMillis() - startTime) / invSpeed;
854           angle += delta * factor;
855           startTime = System.currentTimeMillis();
856
857           if (angle >= 360)
858           {
859             angle = 360;
860           }
861
862           repaint();
863         } catch (Exception ex)
864         {
865         }
866       }
867
868     }
869
870     void drawPanel()
871     {
872       if (offscreen == null || offscreen.getWidth(this) != getWidth()
873               || offscreen.getHeight(this) != getHeight())
874       {
875         offscreen = new BufferedImage(getWidth(), getHeight(),
876                 BufferedImage.TYPE_INT_RGB);
877       }
878
879       Graphics2D g = (Graphics2D) offscreen.getGraphics();
880
881       g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
882               RenderingHints.VALUE_ANTIALIAS_ON);
883       g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
884               RenderingHints.VALUE_INTERPOLATION_BICUBIC);
885       g.setRenderingHint(RenderingHints.KEY_RENDERING,
886               RenderingHints.VALUE_RENDER_QUALITY);
887
888       g.setColor(Color.white);
889       g.fillRect(0, 0, getWidth(), getHeight());
890
891       if (image != null)
892       {
893         int x = image.getWidth(this) / 2, y = image.getHeight(this) / 2;
894         g.rotate(3.14159 / 180 * (angle), x, y);
895         g.drawImage(image, 0, 0, this);
896         g.rotate(-3.14159 / 180 * (angle), x, y);
897       }
898     }
899
900     @Override
901         public void paintComponent(Graphics g1)
902     {
903       drawPanel();
904
905       g1.drawImage(offscreen, 0, 0, this);
906     }
907   }
908
909   boolean renderAsHtml = false;
910
911   public void setRenderAsHtml(boolean b)
912   {
913     renderAsHtml = b;
914   }
915
916   @Override
917 public void hyperlinkUpdate(HyperlinkEvent e)
918   {
919     Desktop.hyperlinkUpdate(e);
920   }
921
922   /*
923    * (non-Javadoc)
924    * 
925    * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
926    */
927   @Override
928   public void setProgressBar(String message, long id)
929   {
930     progressBar.setProgressBar(message, id);
931   }
932   
933   @Override
934   public void removeProgressBar(long id)
935   {
936     progressBar.removeProgressBar(id);
937   }
938
939   @Override
940   public void registerHandler(final long id,
941           final IProgressIndicatorHandler handler)
942   {
943     progressBar.registerHandler(id, handler);
944   }
945
946   /**
947    * 
948    * @return true if any progress bars are still active
949    */
950   @Override
951   public boolean operationInProgress()
952   {
953     return progressBar.operationInProgress();
954   }
955 }