1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.client.browser;
30
31 import java.io.InputStream;
32 import java.io.InputStreamReader;
33 import java.io.BufferedReader;
34 import java.io.Reader;
35 import java.io.IOException;
36
37 import uk.ac.rdg.resc.jstyx.client.CStyxFileInputStream;
38 import uk.ac.rdg.resc.jstyx.client.CStyxFileInputStreamReader;
39 import uk.ac.rdg.resc.jstyx.StyxUtils;
40
41 /***
42 * Displays the text from a file in a widget
43 * @todo handle the window sizing properly
44 *
45 * @author Jon Blower
46 * $Revision: 377 $
47 * $Date: 2005-08-31 18:03:19 +0100 (Wed, 31 Aug 2005) $
48 * $Log$
49 * Revision 1.5 2005/08/31 17:03:18 jonblower
50 * Renamed "StyxFile*putStream*" to "CStyxFile*putStream*" for consistency with CStyxFile class
51 *
52 * Revision 1.4 2005/03/19 21:47:02 jonblower
53 * Further fixes relating to releasing ByteBuffers
54 *
55 * Revision 1.3 2005/02/18 17:52:40 jonblower
56 * Added client.browser package
57 *
58 */
59 public class TextDisplayer extends javax.swing.JFrame
60 {
61
62 /*** Creates new form TextDisplayer */
63 public TextDisplayer(String title)
64 {
65 super(title);
66 initComponents();
67 }
68
69 /*** This method is called from within the constructor to
70 * initialize the form.
71 * WARNING: Do NOT modify this code. The content of this method is
72 * always regenerated by the Form Editor.
73 */
74 private void initComponents()
75 {
76 jScrollPane1 = new javax.swing.JScrollPane();
77 jTextPane1 = new javax.swing.JTextPane();
78
79 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
80 jScrollPane1.setViewportView(jTextPane1);
81
82 getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
83
84 pack();
85 }
86
87 /***
88 * Reads all the data from the input stream and displays in the text area
89 */
90 public void displayData (InputStream is) throws IOException
91 {
92 Reader reader;
93 if (is instanceof CStyxFileInputStream)
94 {
95 reader = new CStyxFileInputStreamReader((CStyxFileInputStream)is);
96 }
97 else
98 {
99
100 reader = new InputStreamReader(is);
101 }
102 BufferedReader bufReader = new BufferedReader(reader);
103
104 StringBuffer sBuf = new StringBuffer(this.jTextPane1.getText());
105 String s;
106 do
107 {
108 s = bufReader.readLine();
109 if (s != null)
110 {
111 sBuf.append(s + StyxUtils.SYSTEM_NEWLINE);
112 }
113 } while (s != null);
114
115 is.close();
116 this.jTextPane1.setText(sBuf.toString());
117 this.repaint();
118 }
119
120
121 private javax.swing.JScrollPane jScrollPane1;
122 private javax.swing.JTextPane jTextPane1;
123
124
125 }