1 25 package org.jrobin.mrtg.client; 26 27 import org.jrobin.mrtg.MrtgException; 28 29 import javax.swing.*; 30 import java.awt.*; 31 import java.awt.event.ActionEvent ; 32 import java.awt.event.ActionListener ; 33 import java.awt.event.WindowEvent ; 34 35 class HelpDialog extends JDialog { 36 static final String TITLE = "Help"; 37 static final String HTML = Client.RESOURCE_PATH + "help.html"; 38 static final Dimension SIZE = new Dimension(600, 300); 39 40 HelpDialog(Frame parent) { 41 super(parent, TITLE); 42 constructUI(); 43 pack(); 44 Util.centerOnScreen(this); 45 setVisible(true); 46 } 47 48 private void constructUI() { 49 Box box = Box.createVerticalBox(); 50 JTextPane textPane = new JTextPane(); 51 textPane.setContentType("text/html"); 52 textPane.setEditable(false); 53 try { 54 textPane.setText(Resources.getString(HTML)); 55 textPane.setCaretPosition(0); 56 } 57 catch(MrtgException e) { 58 e.printStackTrace(); 59 } 60 JScrollPane scrollPane = new JScrollPane(textPane); 61 scrollPane.setPreferredSize(SIZE); 62 scrollPane.setAlignmentX(0.5F); 63 box.add(scrollPane); 64 box.add(Box.createVerticalStrut(2)); 65 JButton okButton = Util.standardButton("Close"); 66 okButton.addActionListener(new ActionListener () { 67 public void actionPerformed(ActionEvent e) { ok(); } 68 }); 69 okButton.setAlignmentX(0.5F); 70 box.add(okButton); 71 box.add(Box.createVerticalStrut(2)); 72 getContentPane().add(box); 73 getRootPane().setDefaultButton(okButton); 74 } 75 76 private void ok() { 77 close(); 78 } 79 80 private void close() { 81 dispatchEvent(new WindowEvent (this, WindowEvent.WINDOW_CLOSING)); 82 } 83 } 84 | Popular Tags |