4c572a2489515b4923f4c9c17e65e6958990ee47
[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.util.Platform;
26 import jalview.util.ChannelProperties;
27 import jalview.ws.WSClientI;
28
29 import java.awt.BorderLayout;
30 import java.awt.Color;
31 import java.awt.Dimension;
32 import java.awt.Graphics;
33 import java.awt.Graphics2D;
34 import java.awt.GridLayout;
35 import java.awt.Image;
36 import java.awt.MediaTracker;
37 import java.awt.RenderingHints;
38 import java.awt.event.ActionEvent;
39 import java.awt.image.BufferedImage;
40 import java.util.Locale;
41 import java.util.Vector;
42
43 import javax.swing.JComponent;
44 import javax.swing.JEditorPane;
45 import javax.swing.JInternalFrame;
46 import javax.swing.JPanel;
47 import javax.swing.JScrollPane;
48 import javax.swing.JTabbedPane;
49 import javax.swing.JTextArea;
50 import javax.swing.event.HyperlinkEvent;
51 import javax.swing.event.HyperlinkListener;
52 import javax.swing.event.InternalFrameAdapter;
53 import javax.swing.event.InternalFrameEvent;
54 import javax.swing.text.html.HTMLEditorKit;
55 import javax.swing.text.html.StyleSheet;
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     // no references
266     init(title, info, width, height, makeVisible);
267   }
268
269   /**
270    * DOCUMENT ME!
271    * 
272    * @return DOCUMENT ME!
273    */
274   public jalview.ws.WSClientI getthisService()
275   {
276     return thisService;
277   }
278
279   /**
280    * Update state of GUI based on client capabilities (like whether the job is
281    * cancellable, whether the 'merge results' button is shown.
282    * 
283    * @param newservice
284    *          service client to query for capabilities
285    */
286   public void setthisService(jalview.ws.WSClientI newservice)
287   {
288     thisService = newservice;
289     serviceIsCancellable = newservice.isCancellable();
290     frame.setClosable(!serviceIsCancellable);
291     serviceCanMergeResults = newservice.canMergeResults();
292     rebuildButtonPanel();
293   }
294
295   private void rebuildButtonPanel()
296   {
297     if (buttonPanel != null)
298     {
299       buttonPanel.removeAll();
300       if (serviceIsCancellable)
301       {
302         buttonPanel.add(cancel);
303         frame.setClosable(false);
304       }
305       else
306       {
307         frame.setClosable(true);
308       }
309     }
310   }
311
312   /**
313    * DOCUMENT ME!
314    * 
315    * @param title
316    *          DOCUMENT ME!
317    * @param info
318    *          DOCUMENT ME!
319    * @param width
320    *          DOCUMENT ME!
321    * @param height
322    *          DOCUMENT ME!
323    */
324   void init(String title, String info, int width, int height,
325           boolean makeVisible)
326   {
327     frame = new JInternalFrame();
328     frame.setContentPane(this);
329     Desktop.addInternalFrame(frame, title, makeVisible, width, height, Desktop.FRAME_ALLOW_RESIZE, Desktop.FRAME_SET_MIN_SIZE_300);
330     frame.setClosable(false);
331
332     progressBar = new ProgressBar(statusPanel, statusBar);
333
334     this.title = title;
335     setInfoText(info);
336
337     image = ChannelProperties.getImage("rotatable_logo.48");
338
339     MediaTracker mt = new MediaTracker(this);
340     mt.addImage(image, 0);
341
342     try
343     {
344       mt.waitForID(0);
345     } catch (Exception ex)
346     {
347     }
348
349     AnimatedPanel ap = new AnimatedPanel();
350     ap.setPreferredSize(new Dimension(60, 60));
351     titlePanel.add(ap, BorderLayout.WEST);
352     titlePanel.add(titleText, BorderLayout.CENTER);
353     setStatus(currentStatus);
354
355     if (!Platform.isJS())
356     {
357       // No animation for the moment//
358       Thread thread = new Thread(ap);
359       thread.start();
360     }
361     final WebserviceInfo thisinfo = this;
362     frame.addInternalFrameListener(
363             new InternalFrameAdapter()
364             {
365               @Override
366               public void internalFrameClosed(InternalFrameEvent evt)
367               {
368                 // System.out.println("Shutting down webservice client");
369                 WSClientI service = thisinfo.getthisService();
370                 if (service != null && service.isCancellable())
371                 {
372                   service.cancelJob();
373                 }
374               }
375             });
376     frame.validate();
377
378   }
379
380   /**
381    * DOCUMENT ME!
382    * 
383    * @param status
384    *          integer status from state constants
385    */
386   public void setStatus(int status)
387   {
388     currentStatus = status;
389
390     String message = null;
391     switch (currentStatus)
392     {
393     case STATE_QUEUING:
394       message = MessageManager.getString("label.state_queueing");
395       break;
396
397     case STATE_RUNNING:
398       message = MessageManager.getString("label.state_running");
399       break;
400
401     case STATE_STOPPED_OK:
402       message = MessageManager.getString("label.state_completed");
403       break;
404
405     case STATE_CANCELLED_OK:
406       message = MessageManager.getString("label.state_job_cancelled");
407       break;
408
409     case STATE_STOPPED_ERROR:
410       message = MessageManager.getString("label.state_job_error");
411       break;
412
413     case STATE_STOPPED_SERVERERROR:
414       message = MessageManager.getString("label.server_error_try_later");
415       break;
416     }
417     titleText.setText(title + (message == null ? "" : " - " + message));
418     titleText.repaint();
419   }
420
421   /**
422    * subjob status indicator
423    * 
424    * @param jobpane
425    * @param status
426    */
427   public void setStatus(int jobpane, int status)
428   {
429     if (jobpane < 0 || jobpane >= jobPanes.size())
430     {
431       throw new Error(MessageManager.formatMessage(
432               "error.setstatus_called_non_existent_job_pane", new String[]
433               { Integer.valueOf(jobpane).toString() }));
434     }
435     switch (status)
436     {
437     case STATE_QUEUING:
438       setProgressName(jobpane + " - QUEUED", jobpane);
439       break;
440     case STATE_RUNNING:
441       setProgressName(jobpane + " - RUNNING", jobpane);
442       break;
443     case STATE_STOPPED_OK:
444       setProgressName(jobpane + " - FINISHED", jobpane);
445       break;
446     case STATE_CANCELLED_OK:
447       setProgressName(jobpane + " - CANCELLED", jobpane);
448       break;
449     case STATE_STOPPED_ERROR:
450       setProgressName(jobpane + " - BROKEN", jobpane);
451       break;
452     case STATE_STOPPED_SERVERERROR:
453       setProgressName(jobpane + " - ALERT", jobpane);
454       break;
455     default:
456       setProgressName(jobpane + " - UNKNOWN STATE", jobpane);
457     }
458   }
459
460   /**
461    * DOCUMENT ME!
462    * 
463    * @return DOCUMENT ME!
464    */
465   public String getInfoText()
466   {
467     return infoText.getText();
468   }
469
470   /**
471    * DOCUMENT ME!
472    * 
473    * @param text
474    *          DOCUMENT ME!
475    */
476   public void setInfoText(String text)
477   {
478     infoText.setText(text);
479   }
480
481   /**
482    * DOCUMENT ME!
483    * 
484    * @param text
485    *          DOCUMENT ME!
486    */
487   public void appendInfoText(String text)
488   {
489     infoText.append(text);
490   }
491
492   /**
493    * DOCUMENT ME!
494    * 
495    * @return DOCUMENT ME!
496    */
497   public String getProgressText(int which)
498   {
499     if (jobPanes == null)
500     {
501       addJobPane();
502     }
503     if (renderAsHtml)
504     {
505       return ((JEditorPane) ((JScrollPane) jobPanes.get(which))
506               .getViewport().getComponent(0)).getText();
507     }
508     else
509     {
510       return ((JTextArea) ((JScrollPane) jobPanes.get(which)).getViewport()
511               .getComponent(0)).getText();
512     }
513   }
514
515   /**
516    * DOCUMENT ME!
517    * 
518    * @param text
519    *          DOCUMENT ME!
520    */
521   public void setProgressText(int which, String text)
522   {
523     if (jobPanes == null)
524     {
525       addJobPane();
526     }
527     if (renderAsHtml)
528     {
529       ((JEditorPane) ((JScrollPane) jobPanes.get(which)).getViewport()
530               .getComponent(0)).setText(ensureHtmlTagged(text));
531     }
532     else
533     {
534       ((JTextArea) ((JScrollPane) jobPanes.get(which)).getViewport()
535               .getComponent(0)).setText(text);
536     }
537   }
538
539   /**
540    * extract content from &lt;body&gt; content &lt;/body&gt;
541    * 
542    * @param text
543    * @param leaveFirst
544    *          - set to leave the initial html tag intact
545    * @param leaveLast
546    *          - set to leave the final html tag intact
547    * @return
548    */
549   private String getHtmlFragment(String text, boolean leaveFirst,
550           boolean leaveLast)
551   {
552     if (text == null)
553     {
554       return null;
555     }
556     String lowertxt = text.toLowerCase(Locale.ROOT);
557     int htmlpos = leaveFirst ? -1 : lowertxt.indexOf("<body");
558
559     int htmlend = leaveLast ? -1 : lowertxt.indexOf("</body");
560     int htmlpose = lowertxt.indexOf(">", htmlpos),
561             htmlende = lowertxt.indexOf(">", htmlend);
562     if (htmlend == -1 && htmlpos == -1)
563     {
564       return text;
565     }
566     if (htmlend > -1)
567     {
568       return text.substring((htmlpos == -1 ? 0 : htmlpose + 1), htmlend);
569     }
570     return text.substring(htmlpos == -1 ? 0 : htmlpose + 1);
571   }
572
573   /**
574    * very simple routine for adding/ensuring html tags are present in text.
575    * 
576    * @param text
577    * @return properly html tag enclosed text
578    */
579   private String ensureHtmlTagged(String text)
580   {
581     if (text == null)
582     {
583       return "";
584     }
585     String lowertxt = text.toLowerCase(Locale.ROOT);
586     int htmlpos = lowertxt.indexOf("<body");
587     int htmlend = lowertxt.indexOf("</body");
588     int doctype = lowertxt.indexOf("<!doctype");
589     int xmltype = lowertxt.indexOf("<?xml");
590     if (htmlend == -1)
591     {
592       text = text + "</body></html>";
593     }
594     if (htmlpos > -1)
595     {
596       if ((doctype > -1 && htmlpos > doctype)
597               || (xmltype > -1 && htmlpos > xmltype))
598       {
599         text = "<html><head></head><body>\n" + text.substring(htmlpos - 1);
600       }
601     }
602     else
603     {
604       text = "<html><head></head><body>\n" + text;
605     }
606     if (text.indexOf("<meta") > -1)
607     {
608       System.err
609               .println("HTML COntent: \n" + text + "<< END HTML CONTENT\n");
610
611     }
612     return text;
613   }
614
615   /**
616    * DOCUMENT ME!
617    * 
618    * @param text
619    *          DOCUMENT ME!
620    */
621   public void appendProgressText(int which, String text)
622   {
623     if (jobPanes == null)
624     {
625       addJobPane();
626     }
627     if (renderAsHtml)
628     {
629       String txt = getHtmlFragment(
630               ((JEditorPane) ((JScrollPane) jobPanes.get(which))
631                       .getViewport().getComponent(0)).getText(),
632               true, false);
633       ((JEditorPane) ((JScrollPane) jobPanes.get(which)).getViewport()
634               .getComponent(0))
635                       .setText(ensureHtmlTagged(
636                               txt + getHtmlFragment(text, false, true)));
637     }
638     else
639     {
640       ((JTextArea) ((JScrollPane) jobPanes.get(which)).getViewport()
641               .getComponent(0)).append(text);
642     }
643   }
644
645   /**
646    * setProgressText(0, text)
647    */
648   public void setProgressText(String text)
649   {
650     setProgressText(0, text);
651   }
652
653   /**
654    * appendProgressText(0, text)
655    */
656   public void appendProgressText(String text)
657   {
658     appendProgressText(0, text);
659   }
660
661   /**
662    * getProgressText(0)
663    */
664   public String getProgressText()
665   {
666     return getProgressText(0);
667   }
668
669   /**
670    * get the tab title for a subjob
671    * 
672    * @param which
673    *          int
674    * @return String
675    */
676   public String getProgressName(int which)
677   {
678     if (jobPanes == null)
679     {
680       addJobPane();
681     }
682     if (subjobs != null)
683     {
684       return subjobs.getTitleAt(which);
685     }
686     else
687     {
688       return ((JScrollPane) jobPanes.get(which)).getViewport()
689               .getComponent(0).getName();
690     }
691   }
692
693   /**
694    * set the tab title for a subjob
695    * 
696    * @param name
697    *          String
698    * @param which
699    *          int
700    */
701   public void setProgressName(String name, int which)
702   {
703     if (subjobs != null)
704     {
705       subjobs.setTitleAt(which, name);
706       subjobs.revalidate();
707       subjobs.repaint();
708     }
709     JScrollPane c = (JScrollPane) jobPanes.get(which);
710     c.getViewport().getComponent(0).setName(name);
711     c.repaint();
712   }
713
714   /**
715    * Gui action for cancelling the current job, if possible.
716    * 
717    * @param e
718    *          DOCUMENT ME!
719    */
720   @Override
721   protected void cancel_actionPerformed(ActionEvent e)
722   {
723     if (!serviceIsCancellable)
724     {
725       // JBPNote : TODO: We should REALLY just tell the WSClientI to cancel
726       // anyhow - it has to stop threads and clean up
727       // JBPNote : TODO: Instead of a warning, we should have an optional 'Are
728       // you sure?' prompt
729       warnUser(
730               MessageManager.getString(
731                       "warn.job_cannot_be_cancelled_close_window"),
732               MessageManager.getString("action.cancel_job"));
733     }
734     else
735     {
736       thisService.cancelJob();
737     }
738     frame.setClosable(true);
739   }
740
741   /**
742    * Spawns a thread that pops up a warning dialog box with the given message
743    * and title.
744    * 
745    * @param message
746    * @param title
747    */
748   public void warnUser(final String message, final String title)
749   {
750     javax.swing.SwingUtilities.invokeLater(new Runnable()
751     {
752       @Override
753       public void run()
754       {
755         JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), message,
756                 title, JvOptionPane.WARNING_MESSAGE);
757
758       }
759     });
760   }
761
762   /**
763    * Set up GUI for user to get at results - and possibly automatically display
764    * them if viewResultsImmediatly is set.
765    */
766   public void setResultsReady()
767   {
768     frame.setClosable(true);
769     buttonPanel.remove(cancel);
770     buttonPanel.add(showResultsNewFrame);
771     if (serviceCanMergeResults)
772     {
773       buttonPanel.add(mergeResults);
774       buttonPanel.setLayout(new GridLayout(2, 1, 5, 5));
775     }
776     buttonPanel.validate();
777     validate();
778     if (viewResultsImmediatly)
779     {
780       showResultsNewFrame.doClick();
781     }
782   }
783
784   /**
785    * called when job has finished but no result objects can be passed back to
786    * user
787    */
788   public void setFinishedNoResults()
789   {
790     frame.setClosable(true);
791     buttonPanel.remove(cancel);
792     buttonPanel.validate();
793     validate();
794   }
795
796   class AnimatedPanel extends JPanel implements Runnable
797   {
798     long startTime = 0;
799
800     BufferedImage offscreen;
801
802     @Override
803     public void run()
804     {
805       startTime = System.currentTimeMillis();
806
807       float invSpeed = 15f;
808       float factor = 1f;
809       while (currentStatus < STATE_STOPPED_OK)
810       {
811         if (currentStatus == STATE_QUEUING)
812         {
813           invSpeed = 25f;
814           factor = 1f;
815         }
816         else if (currentStatus == STATE_RUNNING)
817         {
818           invSpeed = 10f;
819           factor = (float) (0.5 + 1.5
820                   * (0.5 - (0.5 * Math.sin(3.14159 / 180 * (angle + 45)))));
821         }
822         try
823         {
824           Thread.sleep(50);
825
826           float delta = (System.currentTimeMillis() - startTime) / invSpeed;
827           angle += delta * factor;
828           angle %= 360;
829           startTime = System.currentTimeMillis();
830
831           if (currentStatus >= STATE_STOPPED_OK)
832           {
833             park();
834             angle = 0;
835           }
836
837           repaint();
838         } catch (Exception ex)
839         {
840         }
841       }
842
843       cancel.setEnabled(false);
844     }
845
846     public void park()
847     {
848       startTime = System.currentTimeMillis();
849
850       while (angle < 360)
851       {
852         float invSpeed = 5f;
853         float factor = 1f;
854         try
855         {
856           Thread.sleep(25);
857
858           float delta = (System.currentTimeMillis() - startTime) / invSpeed;
859           angle += delta * factor;
860           startTime = System.currentTimeMillis();
861
862           if (angle >= 360)
863           {
864             angle = 360;
865           }
866
867           repaint();
868         } catch (Exception ex)
869         {
870         }
871       }
872
873     }
874
875     void drawPanel()
876     {
877       if (offscreen == null || offscreen.getWidth(this) != getWidth()
878               || offscreen.getHeight(this) != getHeight())
879       {
880         offscreen = new BufferedImage(getWidth(), getHeight(),
881                 BufferedImage.TYPE_INT_RGB);
882       }
883
884       Graphics2D g = (Graphics2D) offscreen.getGraphics();
885
886       g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
887               RenderingHints.VALUE_ANTIALIAS_ON);
888       g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
889               RenderingHints.VALUE_INTERPOLATION_BICUBIC);
890       g.setRenderingHint(RenderingHints.KEY_RENDERING,
891               RenderingHints.VALUE_RENDER_QUALITY);
892
893       g.setColor(Color.white);
894       g.fillRect(0, 0, getWidth(), getHeight());
895
896       if (image != null)
897       {
898         int x = image.getWidth(this) / 2, y = image.getHeight(this) / 2;
899         g.rotate(3.14159 / 180 * (angle), x, y);
900         g.drawImage(image, 0, 0, this);
901         g.rotate(-3.14159 / 180 * (angle), x, y);
902       }
903     }
904
905     @Override
906     public void paintComponent(Graphics g1)
907     {
908       drawPanel();
909
910       g1.drawImage(offscreen, 0, 0, this);
911     }
912   }
913
914   boolean renderAsHtml = false;
915
916   public void setRenderAsHtml(boolean b)
917   {
918     renderAsHtml = b;
919   }
920
921   @Override
922   public void hyperlinkUpdate(HyperlinkEvent e)
923   {
924     Desktop.hyperlinkUpdate(e);
925   }
926
927   /*
928    * (non-Javadoc)
929    * 
930    * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
931    */
932   @Override
933   public void setProgressBar(String message, long id)
934   {
935     progressBar.setProgressBar(message, id);
936   }
937   
938   @Override
939   public void removeProgressBar(long id)
940   {
941     progressBar.removeProgressBar(id);
942   }
943
944   @Override
945   public void registerHandler(final long id,
946           final IProgressIndicatorHandler handler)
947   {
948     progressBar.registerHandler(id, handler);
949   }
950
951   /**
952    * 
953    * @return true if any progress bars are still active
954    */
955   @Override
956   public boolean operationInProgress()
957   {
958     return progressBar.operationInProgress();
959   }
960 }