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