1 package fr.ove.openmath.mfd2.frames;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import fr.ove.openmath.mfd2.*;
6 import fr.ove.openmath.mfd2.events.*;
7
8 /***
9 * A frame to display the OpenMath object exchanged by the application.
10 *
11 * @author © 1999 DIRAT Laurent
12 * @version 1.0 27/10/1999
13 */
14 public class ShowOM extends Frame implements PanelJomesListener, RequestContainingListener {
15 TextArea openMathArea;
16 Button sendRequest;
17 PanelJomes panelJomes;
18 String type;
19
20 public ShowOM(String type) {
21 super("The OpenMath Syntax");
22 setLayout(new BorderLayout(0, 0));
23 setSize(310,360);
24
25 this.type = type;
26
27
28 addWindowListener(
29 new WindowAdapter() {
30 public void windowClosing(WindowEvent event) {
31 dispose();
32 }
33 }
34 );
35
36
37 Font font = new Font("Dialog", Font.PLAIN, 14);
38
39
40 openMathArea = new TextArea();
41 openMathArea.setFont(font);
42 add("Center", openMathArea);
43
44 Label title;
45
46 if (type.equals("Request")) {
47 title = new Label("The OpenMath Object of the Request", Label.CENTER);
48
49
50 sendRequest = new Button();
51 sendRequest.setLabel("Set New Request");
52 sendRequest.setFont(font);
53 sendRequest.setBackground(new Color(12632256));
54 add("South", sendRequest);
55
56
57 sendRequest.addActionListener(
58 new ActionListener() {
59 public void actionPerformed(ActionEvent event) {
60
61
62 try {
63 panelJomes.setOpenMathRequest(openMathArea.getText());
64 }
65 catch(Exception e) {
66 e.printStackTrace();
67 }
68 }
69 }
70 );
71 }
72 else {
73 title = new Label("The OpenMath Object of the Result", Label.CENTER);
74 openMathArea.setEditable(false);
75 }
76
77 title.setFont(font);
78 title.setBackground(new Color(12632256));
79 add("North", title);
80
81 }
82
83 /***
84 */
85 public void consumePanelJomesEvent(PanelJomesEvent panelJomesEvent) {
86 panelJomes = (PanelJomes) panelJomesEvent.getSource();
87
88 int action = panelJomesEvent.getAction();
89 switch (action) {
90 case PanelJomesEvent.UPDATE_REQUEST :
91 if (type.equals("Request"))
92 openMathArea.setText(panelJomes.getOpenMathRequest());
93
94 break;
95 case PanelJomesEvent.UPDATE_RESULT :
96 if (type.equals("Result"))
97 openMathArea.setText(panelJomes.getOpenMathResult());
98
99 break;
100 case PanelJomesEvent.UPDATE :
101 if (type.equals("Request"))
102 openMathArea.setText(panelJomes.getOpenMathRequest());
103 else
104 openMathArea.setText(panelJomes.getOpenMathResult());
105 }
106 }
107
108 /***
109 * Consumes (i.e. treats) the event received.
110 * @param requestContainingEvent the event to consume.
111 */
112 public void consumeRequestContainingEvent(RequestContainingEvent requestContainingEvent) {
113 RequestContaining source = (RequestContaining) requestContainingEvent.getSource();
114
115 int action = requestContainingEvent.getAction();
116 switch (action) {
117 case RequestContainingEvent.UPDATE_REQUEST :
118 if (type.equals("Request"))
119 openMathArea.setText(source.getOpenMathRequest());
120
121 break;
122 case RequestContainingEvent.UPDATE_RESULT :
123 if (type.equals("Result"))
124 openMathArea.setText(source.getOpenMathResult());
125
126 break;
127 }
128 }
129 }
130