1 package gate.gui.jape;
2
3 import java.io.*;
4 import javax.swing.*;
5 import java.net.*;
6 import java.awt.*;
7
8 import gate.*;
9 import gate.creole.*;
10
11
19
20
21 public class JapeViewer extends AbstractVisualResource implements ANNIEConstants {
22
23 public JapeViewer() {
24 }
25
26
28 protected JTextArea textArea;
29
30
31 protected JScrollPane textScroll;
32
33
34 protected JToolBar toolbar;
35
36
37 private boolean editable = false;
38
39
40 private JButton saveButton;
41
42
43 private JButton revertButton;
44
45
46 private URL japeFileURL;
47
48
49 private String japeFileContents;
50
51
52 private Transducer transducer;
53
54
55 public Resource init() {
56 initGuiComponents();
57 japeFileContents = new String();
58 return this;
59 }
60
61 private void initGuiComponents() {
62 setLayout(new BorderLayout());
63 textArea = new JTextArea();
64 textArea.setEditable(editable);
65 textScroll = new JScrollPane(textArea,
66 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
67 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
68 add(textScroll, BorderLayout.CENTER);
69 }
70
71 public void setTarget(Object target) {
72 if(!(target instanceof Transducer)) {
73 throw new IllegalArgumentException(
74 "The GATE jape editor can only be used with a GATE jape transducer!\n" +
75 target.getClass().toString() + " is not a GATE Jape Transducer!");
76 }
77
78 this.transducer = (Transducer) target;
79 japeFileURL = transducer.getGrammarURL();
81 try {
83 BufferedReader br = new BufferedReader(new InputStreamReader(japeFileURL.
84 openStream()));
85 String content = br.readLine();
86 while(content != null) {
87 japeFileContents += content + "\n";
88 content = br.readLine();
89 }
90 textArea.setText(japeFileContents);
91 br.close();
92 } catch (IOException ioe) {
93 }
94 }
95 }