$search
00001 package instruction.gui.tab; 00002 00003 import instruction.gui.internal.PlanImporterWrapper; 00004 import instruction.wrapper.IHowtoWebsiteWrapper; 00005 00006 import java.awt.BorderLayout; 00007 import java.awt.event.ComponentEvent; 00008 import java.awt.event.ComponentListener; 00009 import java.io.File; 00010 import javax.swing.JEditorPane; 00011 import javax.swing.JScrollPane; 00012 00013 public class BrowserTab extends InstructionTab { 00014 00015 private static final long serialVersionUID = 2094236267788921978L; 00016 00017 public static String TITLE = "HTML View"; 00018 00019 private static String htmlContent = "<html><head></head><body><table width=\"100%\"><tr><td align=\"center\"><img src=\"file:///IMGSRC\"></td></tr></table></body></html>"; 00020 private static String htmlContentError = "<html><head></head><body><table><tr><td align=\"center\">No Screenshot found for this Howto.</td></tr></table></body></html>"; 00021 00022 JEditorPane browser = null; 00023 JScrollPane scroll = null; 00024 00025 public BrowserTab () { 00026 00027 init(); 00028 } 00029 00030 @Override 00031 public void init() { 00032 00033 setLayout( new BorderLayout() ); 00034 00035 browser = new JEditorPane(); 00036 browser.setContentType( "text/html" ); 00037 browser.setEditable( false ); 00038 00039 addComponentListener( new ComponentListener() { 00040 00041 public void componentHidden( ComponentEvent arg0 ) { 00042 00043 } 00044 00045 public void componentMoved( ComponentEvent arg0 ) { 00046 00047 } 00048 00049 public void componentResized( ComponentEvent arg0 ) { 00050 00051 } 00052 00053 public void componentShown( ComponentEvent arg0 ) { 00054 00055 IHowtoWebsiteWrapper wrapper = PlanImporterWrapper.getImporter().getWrapper(); 00056 00057 if ( wrapper == null ) 00058 browser.setText( htmlContentError ); 00059 else { 00060 String url = wrapper.getUrl(); 00061 00062 if ( url != null ) { 00063 00064 File dummy = new File( url ); 00065 if ( dummy.exists() ) { 00066 String screenshotFile = dummy.getAbsolutePath().replaceAll( "\\\\", "/" ); 00067 screenshotFile += ".jpg"; 00068 00069 File screenshotDummy = new File( screenshotFile ); 00070 if ( screenshotDummy.exists() ) { 00071 // System.out.println( htmlContent.replaceAll( "IMGSRC", screenshotFile ) ); 00072 browser.setText( htmlContent.replaceAll( "IMGSRC", screenshotFile ) ); 00073 } 00074 else { 00075 browser.setText( htmlContentError ); 00076 } 00077 } 00078 } 00079 00080 else 00081 browser.setText( htmlContentError ); 00082 } 00083 } 00084 00085 } ); 00086 00087 scroll = new JScrollPane( browser ); 00088 add( scroll, BorderLayout.CENTER ); 00089 } 00090 }