1 package devisor2.grid.GUI.help; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.awt.event.*; 6 import java.io.*; 7 8 9 import devisor2.grid.options.*; 10 import devisor2.grid.GUI.framework.*; 11 12 /** 13 * This class acts as a container to display texts, which can be read from a 14 * file or passed to this class as a single String. This class does not 15 * support HTML, it is designed for plain text only. <br> 16 * You can get a full scale example of how to use this class in the event 17 * handling code for the DOMAINSTATISTICS action command. Note: this is a 18 * dialog, so it is used just like any other dialog throughout the 19 * application 20 * 21 * @author Dominik Goeddeke 22 * @version 1.0 fully tested 23 */ 24 public class ReadmeFrame extends JDialog implements ActionListener 25 { 26 27 /** 28 * the text to be displayed 29 */ 30 private String show; 31 32 /** 33 * a reference to the MainFrame instance 34 */ 35 private MainFrame parent; 36 37 /** 38 * the obligatory static self-reference 39 */ 40 private static ReadmeFrame dialog; 41 42 /** 43 * the controlcenter reference 44 */ 45 private ControlCenter cc; 46 47 /** 48 * creates a new instance of the dialog 49 * @param parent - the MainFrame reference 50 * @param title - the designated title for the dialog 51 * @param show - the text to be shown 52 */ initialize(MainFrame parent, String title, String show)53 public static void initialize (MainFrame parent, String title, String show) 54 { 55 dialog = new ReadmeFrame (parent, title, show); 56 57 StringBuffer ges = new StringBuffer(); 58 ges.append("README Version 2.1\n"); 59 ges.append("------------------\n"); 60 ges.append("\n"); 61 ges.append("New functions in this Version:\n\n"); 62 ges.append("UnDo, ReDo\n"); 63 ges.append("Spellchecker\n"); 64 ges.append("Improved Copy&Paste\n"); 65 ges.append("Generate PRM from TRI\n"); 66 ges.append("\n"); 67 ges.append("For more Information please consult the FAQ\n"); 68 ges.append("and manual sections of the HELP menu.\n"); 69 dialog.setText (ges.toString()); 70 71 } 72 73 /** 74 * displays the dialog modally on the screen 75 */ showDialog()76 public static void showDialog () 77 { 78 if (dialog != null) 79 dialog.setVisible (true); 80 } 81 82 83 /** 84 * adds the text to the container 85 */ readText(String s)86 private void readText(String s) 87 { 88 StringBuffer app; 89 String buffer; 90 BufferedReader in; 91 92 app = new StringBuffer(); 93 94 try 95 { 96 in = new BufferedReader(new FileReader(s)); 97 while (in.ready()) 98 { 99 buffer=in.readLine(); 100 app.append(buffer); 101 app.append("\n"); 102 } 103 in.close(); 104 buffer=app.toString(); 105 ta.setText(buffer); 106 } 107 catch (IOException e) 108 { 109 JOptionPane.showMessageDialog (parent, (String)cc.rb.getObject ("dialogs_textframe_loaderror_message"), (String)cc.rb.getObject ("dialogs_textframe_loaderror_title"), JOptionPane.ERROR_MESSAGE ); 110 } 111 } 112 113 114 /** 115 * the constructor need not be called directly, the initialize()- 116 * method suffices 117 */ ReadmeFrame(MainFrame parent, String title, String show)118 public ReadmeFrame(MainFrame parent, String title, String show) 119 { 120 super (parent, true); 121 cc = ControlCenter.getMyself (); 122 setTitle(title); 123 this.show = show; 124 this.parent = parent; 125 // layout gui 126 getContentPane ().setLayout (new BorderLayout ()); 127 ta = new JTextArea(80,25); 128 scroll = new JScrollPane (ta); 129 scroll.setPreferredSize (new Dimension (200,200)); 130 getContentPane().add(scroll, BorderLayout.CENTER); 131 okButton = new JButton ((String)cc.rb.getObject ("general_Ok")); 132 okButton.setToolTipText ((String)cc.rb.getObject ("dialogs_textframe_tooltip")); 133 okButton.setMnemonic ( ((Integer)cc.rb.getObject("general_Ok_mnemonic")).intValue()); 134 okButton.setActionCommand (OK); 135 okButton.addActionListener (this); 136 getRootPane().setDefaultButton (okButton); 137 getContentPane().add (okButton, BorderLayout.SOUTH); 138 setSize (new Dimension (400,400)); 139 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE); 140 141 142 143 } 144 145 /** 146 * re-reads the text to be displayed 147 */ update()148 public static void update() 149 { 150 if (dialog != null) 151 dialog.readText(dialog.show); 152 } 153 154 155 /** 156 * sets the text directly 157 */ setText(String s)158 public static void setText(String s) 159 { 160 if (dialog != null) 161 { 162 dialog.ta.setText(s); 163 dialog.ta.setCaretPosition (0); 164 } 165 } 166 167 /** 168 * the event handler for the ok button 169 */ actionPerformed( ActionEvent e )170 public void actionPerformed ( ActionEvent e ) 171 { 172 if (e.getActionCommand ().equals (OK)) 173 { 174 setVisible (false); 175 } 176 } 177 178 // the gui elements 179 private JTextArea ta; 180 private JButton okButton; 181 private JScrollPane scroll; 182 183 // action commands 184 public static final String OK = "OK"; 185 186 187 } 188