/**
*
*/
package de.axxeed.animosy.gui;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.text.html.HTMLEditorKit;
import org.apache.log4j.Logger;
import de.axxeed.animosy.model.Constants;
import de.axxeed.animosy.tools.FileHandler;
/**
* OptionsDialog.java
* Created 12.12.2007 11:13:23
* @author Markus J. Luzius
*
*/
public class HTMLDialog extends JDialog implements Constants {
private static final long serialVersionUID = -1574694043263550395L;
private static Logger log = Logger.getLogger(HTMLDialog.class);
private boolean initial = true;
private JEditorPane htmlBox = new JEditorPane();
JScrollPane sp = new JScrollPane (htmlBox);
public HTMLDialog(String filename, String title) {
log.debug("new htmlBox dialog, root pane: "+this.getRootPane().getWidth());
this.setSize(640,450);
this.setResizable(false);
this.setTitle("AnImOSY Help");
this.setModal(true);
this.setLayout(new BorderLayout());
Point loc = PanelRepository.get(PanelRepository.MAIN_WINDOW).getLocation();
loc.translate((PanelRepository.get(PanelRepository.MAIN_WINDOW).getWidth()-640)/2, 75);
this.setLocation( loc );
htmlBox.setEditorKit(new HTMLEditorKit());
FileHandler htmlFile = new FileHandler(filename);
String msg = htmlFile.readAll();
log.debug("L�nge: "+msg.length());
htmlBox.setText(msg.toString());
htmlBox.setEditable(false);
htmlBox.setCaretPosition(0);
this.add(sp, BorderLayout.CENTER);
JButton ok = new JButton("OK");
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
log.debug("ok "+arg0.getActionCommand());
setVisible(false);
}
});
this.add(ok, BorderLayout.SOUTH);
}
public void paint(Graphics g) {
if(initial) {
log.debug("Text:\n"+htmlBox.getText());
log.debug("L�nge: "+htmlBox.getText().length());
sp.getViewport().setViewPosition(new Point(0,0));
initial = false;
}
super.paint(g);
}
}