Source code: com/robrohan/tools/ReadMe.java
1 /*
2 * Treebeard: an xml xslt transfomer
3 * Copyright (C) 2002 Rob Rohan
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 * Email: me@robrohan.com
19 *
20 * ReadMe.java
21 *
22 * Created on August 23, 2002, 9:45 PM
23 */
24
25 package com.robrohan.tools;
26 import javax.swing.*;
27 import javax.swing.event.*;
28 import java.io.*;
29 /**
30 * the "information" ent. Really just shows html files.
31 * note: shouldn't this be in the fagorn directory?
32 * @author rob
33 */
34 public class ReadMe extends javax.swing.JInternalFrame {
35
36 String filename = "/Readme.txt";
37
38 /** Creates new form ReadMe */
39 public ReadMe() {
40 initComponents();
41
42 final javax.swing.JEditorPane finalPane = this.txtDisplay;
43 // try{
44 // finalPane.setDragEnabled(true);
45 // }catch(Exception e){
46 // System.err.println("ReadMe: Can't set Drag Enabled: " + e.toString());
47 // }
48
49 finalPane.addHyperlinkListener(new HyperlinkListener(){
50 public void hyperlinkUpdate(HyperlinkEvent ev){
51 try{
52 if(ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
53 finalPane.setPage(ev.getURL());
54 }catch(IOException e){
55 e.printStackTrace(System.err);
56 }
57 }
58 });
59 }
60
61 /** Set the file to load into the readme text pane. Note the files can only be in
62 * the resource (i.e. in the jar).
63 * @param filename the file to load
64 */
65 public void setFileName(String filename){
66 this.filename = filename;
67 }
68
69 /** returns the currently set file
70 * @return the file name
71 */
72 public String getFileName(){
73 return this.filename;
74 }
75
76 /** loads the file from the resouce */
77 public void loadFile(){
78 StringBuffer fileContents = new StringBuffer();
79 int b;
80
81 try{
82 java.io.DataInputStream fin = new java.io.DataInputStream(
83 getClass().getResourceAsStream(this.filename)
84 );
85
86 while((b = fin.read()) != -1){
87 fileContents.append((char)b);
88 }
89
90 }catch (Exception e){ System.err.println("ReadMe->ReadMe: " + e.toString());}
91
92 this.txtDisplay.setText(fileContents.toString());
93
94 this.txtDisplay.setEditable(false);
95 //seek to the top of the file
96 this.txtDisplay.setCaretPosition(0);
97 }
98
99 /** Set the text contents to the passed string
100 * @param data String data to be displayed in the text area of the readme
101 */
102 public void showString(String data){
103 txtDisplay.setText(data);
104 txtDisplay.setEditable(false);
105 txtDisplay.setCaretPosition(0);
106 }
107
108
109 /** This method is called from within the constructor to
110 * initialize the form.
111 * WARNING: Do NOT modify this code. The content of this method is
112 * always regenerated by the Form Editor.
113 */
114 private void initComponents() {//GEN-BEGIN:initComponents
115 panCenter = new javax.swing.JPanel();
116 jScrollPane1 = new javax.swing.JScrollPane();
117 txtDisplay = new javax.swing.JEditorPane();
118 panTop = new javax.swing.JPanel();
119 jButton1 = new javax.swing.JButton();
120 jPanel3 = new javax.swing.JPanel();
121 jPanel4 = new javax.swing.JPanel();
122 jPanel5 = new javax.swing.JPanel();
123
124 setClosable(true);
125 setIconifiable(true);
126 setMaximizable(true);
127 setResizable(true);
128 setTitle("Information");
129 setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
130 panCenter.setLayout(new java.awt.BorderLayout());
131
132 jScrollPane1.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
133 txtDisplay.setContentType("text/html");
134 jScrollPane1.setViewportView(txtDisplay);
135
136 panCenter.add(jScrollPane1, java.awt.BorderLayout.CENTER);
137
138 getContentPane().add(panCenter, java.awt.BorderLayout.CENTER);
139
140 panTop.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 10, 5));
141
142 jButton1.setText("Okay");
143 jButton1.addActionListener(new java.awt.event.ActionListener() {
144 public void actionPerformed(java.awt.event.ActionEvent evt) {
145 jButton1ActionPerformed(evt);
146 }
147 });
148
149 panTop.add(jButton1);
150
151 getContentPane().add(panTop, java.awt.BorderLayout.NORTH);
152
153 getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
154
155 getContentPane().add(jPanel4, java.awt.BorderLayout.EAST);
156
157 getContentPane().add(jPanel5, java.awt.BorderLayout.WEST);
158
159 pack();
160 }//GEN-END:initComponents
161
162 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
163 this.setVisible(false);
164 }//GEN-LAST:event_jButton1ActionPerformed
165
166 // Variables declaration - do not modify//GEN-BEGIN:variables
167 private javax.swing.JPanel jPanel5;
168 private javax.swing.JPanel jPanel4;
169 private javax.swing.JPanel jPanel3;
170 private javax.swing.JPanel panTop;
171 private javax.swing.JButton jButton1;
172 private javax.swing.JEditorPane txtDisplay;
173 private javax.swing.JScrollPane jScrollPane1;
174 private javax.swing.JPanel panCenter;
175 // End of variables declaration//GEN-END:variables
176
177 }