1 package jp.naist.se.stigmata.ui.swing.actions;
\r
7 import java.awt.BorderLayout;
\r
8 import java.awt.Component;
\r
9 import java.awt.Dimension;
\r
10 import java.awt.event.ActionEvent;
\r
11 import java.io.BufferedReader;
\r
12 import java.io.IOException;
\r
13 import java.io.InputStreamReader;
\r
14 import java.io.PrintWriter;
\r
15 import java.io.StringWriter;
\r
16 import java.net.URL;
\r
18 import javax.swing.AbstractAction;
\r
19 import javax.swing.JEditorPane;
\r
20 import javax.swing.JLabel;
\r
21 import javax.swing.JOptionPane;
\r
22 import javax.swing.JPanel;
\r
23 import javax.swing.JScrollPane;
\r
27 * @author Haruaki TAMADA
\r
28 * @version $Revision$ $Date$
\r
30 abstract class ShowTextAction extends AbstractAction{
\r
31 private Component parent;
\r
33 public ShowTextAction(Component parent){
\r
34 this.parent = parent;
\r
37 public abstract String getMessage();
\r
39 protected void updatePanel(JPanel panel){
\r
42 public abstract String getTitle();
\r
44 public boolean isHtmlDocument(){
\r
48 public void actionPerformed(ActionEvent e){
\r
49 String message = getMessage();
\r
50 JPanel panel = new JPanel(new BorderLayout());
\r
51 JScrollPane scroll = new JScrollPane();
\r
52 String mimeType = "text/plain";
\r
53 if(isHtmlDocument()){
\r
54 mimeType = "text/html";
\r
56 JEditorPane text = new JEditorPane(mimeType, message);
\r
57 text.addHyperlinkListener(new LinkFollower());
\r
59 text.setEditable(false);
\r
60 text.setCaretPosition(0);
\r
61 text.setBackground(panel.getBackground());
\r
62 scroll.setViewportView(text);
\r
64 panel.add(scroll, BorderLayout.CENTER);
\r
65 panel.setPreferredSize(new Dimension(500, 300));
\r
69 JOptionPane.showMessageDialog(
\r
70 parent, panel, getTitle(),
\r
71 JOptionPane.INFORMATION_MESSAGE
\r
75 protected String loadStringFromFile(URL url){
\r
78 BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
\r
79 StringWriter writer = new StringWriter();
\r
80 PrintWriter out = new PrintWriter(writer);
\r
81 while((line = in.readLine()) != null){
\r
88 return writer.toString();
\r
89 }catch(IOException e){
\r
90 e.printStackTrace();
\r