1 package fr.ove.openmath.courses.editor;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.util.*;
6 import fr.ove.openmath.jome.Jome;
7
8 import fr.ove.openmath.courses.editor.events.*;
9
10 public class BasicEditor extends Frame {
11 TextField entry;
12 Jome jome;
13
14 private Vector listeners = new Vector();
15
16 public BasicEditor() {
17 setLayout(new BorderLayout(0,0));
18 setTitle("Modify the Current Expression");
19 setSize(350,250);
20
21 addWindowListener(
22 new WindowAdapter() {
23 public void windowClosing(WindowEvent event) {
24 setVisible(false);
25 dispose();
26 }
27 }
28 );
29
30 jome = new Jome();
31 jome.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
32 jome.setFont(new Font("Times New Roman", Font.PLAIN, 18));
33 jome.setDrawBounds(false);
34 add("Center", jome);
35
36 entry = new TextField();
37 entry.setBounds(0,323,405,24);
38 entry.setFont(new Font("Dialog", Font.BOLD, 14));
39 add("South", entry);
40
41 entry.addTextListener(
42 new TextListener() {
43 public void textValueChanged(TextEvent event) {
44 jome.setLinear(entry.getText());
45 }
46 }
47 );
48
49 entry.addActionListener(
50 new ActionListener() {
51 public void actionPerformed(ActionEvent event) {
52 setVisible(false);
53
54 EditorEvent editorEvent = new EditorEvent(BasicEditor.this);
55 editorEvent.setAction("update", jome.getLinear());
56 fireEditorEvent(editorEvent);
57 }
58 }
59 );
60 }
61
62 public void setExpression(String linearExpr) {
63 jome.setLinear(linearExpr);
64 entry.setText(linearExpr);
65 }
66
67 /***
68 * Registers a listener of the instance.
69 */
70 public void addEditorListener(EditorListener editorListener) {
71 listeners.addElement(editorListener);
72 }
73
74 /***
75 * Unregisters the specified listener of the instance.
76 * @param editorListener the listener to remove.
77 */
78 public void removeEditorListener(EditorListener editorListener) {
79 listeners.removeElement(editorListener);
80 }
81
82 /***
83 * Fires an event to all the registered listeners of the instance.
84 * @param editorEvent the event to fire.
85 */
86 public void fireEditorEvent(EditorEvent editorEvent) {
87 for (int i = 0; i < listeners.size(); i++)
88 ((EditorListener) listeners.elementAt(i)).consumeEditorEvent(editorEvent);
89 }
90 }
91