blob: 451b393719c2593584ffd1994982cf766fb679dd (
plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package com.c2kernel.gui.tabs.outcome;
import java.awt.Font;
import java.awt.GridLayout;
import java.io.File;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.PlainDocument;
import com.c2kernel.utils.FileStringUtility;
/**************************************************************************
*
* $Revision: 1.4 $
* $Date: 2005/09/07 13:46:31 $
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
* All rights reserved.
**************************************************************************/
public class BasicOutcomeEditor extends JPanel implements OutcomeHandler {
PlainDocument doc;
JTextArea textarea;
boolean unsaved;
public BasicOutcomeEditor() {
super();
this.setLayout(new GridLayout(1,1));
doc = new PlainDocument();
textarea = new JTextArea(doc);
textarea.setTabSize(2);
textarea.setFont(Font.decode("monospaced"));
add(new JScrollPane(textarea));
doc.addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) { unsaved = true; }
public void insertUpdate(DocumentEvent e) { unsaved = true; }
public void removeUpdate(DocumentEvent e) { unsaved = true; }
});
}
public void setOutcome(String outcome) throws InvalidOutcomeException {
try {
doc.insertString(0, outcome, null);
unsaved = false;
} catch (Exception ex) {
throw new InvalidOutcomeException(ex.getMessage());
}
}
public void setDescription(String description) throws InvalidSchemaException { }
public void setReadOnly(boolean readOnly) {
textarea.setEditable(!readOnly);
}
public JPanel getPanel() throws OutcomeNotInitialisedException {
return this;
}
/**
*
*/
public String getOutcome() throws OutcomeException {
try {
return doc.getText(0, doc.getLength());
} catch (Exception ex) {
throw new OutcomeException(ex.getMessage());
}
}
/**
*
*/
public void run() {
}
public boolean isUnsaved() {
return unsaved;
}
public void saved() {
unsaved = false;
}
public void export(File targetFile) throws Exception {
FileStringUtility.string2File(targetFile, getOutcome());
}
}
|