1 19 package org.columba.core.gui.base; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Color ; 23 import java.awt.Dimension ; 24 import java.awt.Font ; 25 import java.awt.GridLayout ; 26 import java.awt.event.ActionEvent ; 27 import java.awt.event.ActionListener ; 28 import java.awt.event.KeyEvent ; 29 import java.io.IOException ; 30 import java.net.URL ; 31 32 import javax.swing.BorderFactory ; 33 import javax.swing.JButton ; 34 import javax.swing.JComponent ; 35 import javax.swing.JDialog ; 36 import javax.swing.JFrame ; 37 import javax.swing.JPanel ; 38 import javax.swing.JScrollPane ; 39 import javax.swing.JTextPane ; 40 import javax.swing.KeyStroke ; 41 import javax.swing.SwingConstants ; 42 import javax.swing.UIManager ; 43 import javax.swing.text.html.HTMLEditorKit ; 44 import javax.swing.text.html.StyleSheet ; 45 46 import org.columba.core.resourceloader.GlobalResourceLoader; 47 48 54 public class InfoViewerDialog extends JDialog implements ActionListener { 55 protected JButton helpButton; 56 57 protected JButton closeButton; 58 59 protected JTextPane textPane; 60 61 64 public InfoViewerDialog(String message) { 65 this(); 66 HTMLEditorKit editorKit = new HTMLEditorKit (); 67 StyleSheet styles = new StyleSheet (); 68 69 Font font = UIManager.getFont("Label.font"); 70 String name = font.getName(); 71 int size = font.getSize(); 72 String css = "<style type=\"text/css\"><!--p {font-family:\"" + name 73 + "\"; font-size:\"" + size + "pt\"}--></style>"; 74 styles.addRule(css); 75 editorKit.setStyleSheet(styles); 76 77 textPane.setEditorKit(editorKit); 78 textPane.setText(message); 79 setVisible(true); 80 } 81 82 85 public InfoViewerDialog(URL url) throws IOException { 86 this(); 87 textPane.setPage(url); 88 setVisible(true); 89 } 90 91 94 protected InfoViewerDialog() { 95 super(new JFrame (), "Info", true); 96 initComponents(); 97 pack(); 98 setLocationRelativeTo(null); 99 } 100 101 protected void initComponents() { 102 JPanel mainPanel = new JPanel (new BorderLayout ()); 103 mainPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); 104 getContentPane().add(mainPanel); 105 106 textPane = new JTextPane (); 108 textPane.setEditable(false); 109 110 JScrollPane scrollPane = new JScrollPane (textPane); 111 scrollPane.setPreferredSize(new Dimension (450, 300)); 112 scrollPane.getViewport().setBackground(Color.white); 113 114 mainPanel.add(scrollPane); 115 116 JPanel bottomPanel = new JPanel (new BorderLayout ()); 117 bottomPanel.setBorder(new SingleSideEtchedBorder(SwingConstants.TOP)); 118 119 JPanel buttonPanel = new JPanel (new GridLayout (1, 2, 6, 0)); 120 buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); 121 122 ButtonWithMnemonic closeButton = new ButtonWithMnemonic( 123 GlobalResourceLoader.getString("global", "global", "close")); 124 closeButton.setActionCommand("CLOSE"); 125 closeButton.addActionListener(this); 126 buttonPanel.add(closeButton); 127 128 ButtonWithMnemonic helpButton = new ButtonWithMnemonic( 129 GlobalResourceLoader.getString("global", "global", "help")); 130 131 buttonPanel.add(helpButton); 133 bottomPanel.add(buttonPanel, BorderLayout.EAST); 134 getContentPane().add(bottomPanel, BorderLayout.SOUTH); 135 getRootPane().setDefaultButton(closeButton); 136 getRootPane().registerKeyboardAction(this, "CLOSE", 137 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), 138 JComponent.WHEN_IN_FOCUSED_WINDOW); 139 } 140 141 public void actionPerformed(ActionEvent e) { 142 String action = e.getActionCommand(); 143 144 if (action.equals("CLOSE")) { 145 setVisible(false); 146 } 147 } 148 } | Popular Tags |