diff options
Diffstat (limited to 'source/com/c2kernel/gui/tabs/outcome/BasicOutcomeEditor.java')
| -rwxr-xr-x | source/com/c2kernel/gui/tabs/outcome/BasicOutcomeEditor.java | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/source/com/c2kernel/gui/tabs/outcome/BasicOutcomeEditor.java b/source/com/c2kernel/gui/tabs/outcome/BasicOutcomeEditor.java new file mode 100755 index 0000000..451b393 --- /dev/null +++ b/source/com/c2kernel/gui/tabs/outcome/BasicOutcomeEditor.java @@ -0,0 +1,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());
+ }
+}
|
