Files
eva2/src/javaeva/gui/HtmlDemo.java
2007-12-11 16:38:11 +00:00

133 lines
4.1 KiB
Java

package javaeva.gui;
/*
* Title: JavaEvA
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 199 $
* $Date: 2007-10-23 16:58:12 +0200 (Tue, 23 Oct 2007) $
* $Author: mkron $
*/
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import javaeva.tools.EVAHELP;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.HyperlinkEvent;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
import javax.swing.text.html.HTMLDocument;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.io.IOException;
import java.applet.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.awt.Toolkit;
import wsi.ra.tool.BasicResourceLoader;
import javaeva.client.EvAClient;
/**
*
*/
public class HtmlDemo {
private JEditorPane m_html;
private String m_name;
/**
*
*/
public HtmlDemo(String name) {
m_name = name;
}
/**
*
*/
public JEditorPane getPane() {
return m_html;
}
/**
*
*/
public static void main(String[] args) {
HtmlDemo demo = new HtmlDemo("ES.html");
demo.show();
}
public boolean resourceExists() {
URL url = ClassLoader.getSystemResource("resources/"+m_name);
return (url != null);
}
public static boolean resourceExists(String mname) {
URL url = ClassLoader.getSystemResource("resources/"+mname);
return (url != null);
}
/**
*
*/
public void show() {
try {
URL url = null;
url = this.getClass().getClassLoader().getSystemResource("resources/"+m_name);
try {
m_html = new JEditorPane(url);
} catch (java.io.IOException ioe) {
url = this.getClass().getClassLoader().getSystemResource("resources/Default.html");
m_html = new JEditorPane(url);
}
//m_html = new JEditorPane(htmlDescription);
m_html.setEditable(false);
m_html.addHyperlinkListener(createHyperLinkListener());
} catch (MalformedURLException e) {
System.out.println("Malformed URL: " + e);
return;
} catch (IOException e) {
System.out.println("IOException: " + e);
e.printStackTrace();
return;
}
JFrame frame = new JFrame (m_name);
BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(EvAClient.iconLocation);
try {
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find JavaEvA icon, please move rescoure folder to working directory!");
}
JScrollPane scroller = new JScrollPane();
JViewport vp = scroller.getViewport();
vp.add(m_html);
scroller.setPreferredSize( new Dimension(600,500) );
frame.getContentPane().add(scroller, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
/**
*
*/
public HyperlinkListener createHyperLinkListener() {
return new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (e instanceof HTMLFrameHyperlinkEvent) {
((HTMLDocument)m_html.getDocument()).processHTMLFrameHyperlinkEvent(
(HTMLFrameHyperlinkEvent)e);
} else {
try {
m_html.setPage(e.getURL());
} catch (IOException ioe) {
System.out.println("IOE: " + ioe);
}
}
}
}
};
}
}