View Javadoc

1   /*
2   	A basic extension of the java.applet.Applet class
3    */
4   
5   import java.awt.*;
6   import java.applet.*;
7   
8   import fr.ove.openmath.jome.Jome;
9   public class AppletTest extends Applet
10  {
11  	public void init()
12  	{
13  		// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
14  		//symantec.itools.lang.Context.setApplet(this);
15  	
16  		// This code is automatically generated by Visual Cafe when you add
17  		// components to the visual environment. It instantiates and initializes
18  		// the components. To modify the code, only use code syntax that matches
19  		// what Visual Cafe can generate, or Visual Cafe may be unable to back
20  		// parse your Java file into its visual environment.
21  		//{{INIT_CONTROLS
22  		setLayout(new BorderLayout(0,0));
23  		setSize(650,334);
24  		setFont(new Font("Dialog", Font.PLAIN, 14));
25  		setBackground(new Color(12632256));
26  		panelFont = new java.awt.Panel();
27  		panelFont.setLayout(new FlowLayout(FlowLayout.LEFT,5,5));
28  		panelFont.setBounds(0,0,658,34);
29  		add("North", panelFont);
30  		labelFontSize = new java.awt.Label("Font Size");
31  		labelFontSize.setBounds(5,5,73,24);
32  		panelFont.add(labelFontSize);
33  		entryFontSize = new java.awt.TextField();
34  		entryFontSize.setText("14");
35  		entryFontSize.setBounds(83,5,40,24);
36  		panelFont.add(entryFontSize);
37  		panel1 = new java.awt.Panel();
38  		panel1.setLayout(new GridLayout(1,2,0,0));
39  		panel1.setBounds(0,34,658,381);
40  		add("Center", panel1);
41  		panelJome = new java.awt.Panel();
42  		panelJome.setLayout(new BorderLayout(0,0));
43  		panelJome.setBounds(0,0,329,381);
44  		panel1.add(panelJome);
45  		panelSubstIcon = new java.awt.Panel();
46  		panelSubstIcon.setLayout(new BorderLayout(0,0));
47  		panelSubstIcon.setBounds(0,0,329,48);
48  		panelJome.add("North", panelSubstIcon);
49  		panelSubstitute = new java.awt.Panel();
50  		panelSubstitute.setLayout(new BorderLayout(0,0));
51  		panelSubstitute.setBounds(0,0,329,24);
52  		panelSubstIcon.add("Center", panelSubstitute);
53  		labelSubstitute = new java.awt.Label("Substitute Selection by :");
54  		labelSubstitute.setBounds(0,0,166,34);
55  		panelSubstitute.add("West", labelSubstitute);
56  		entrySubstitute = new java.awt.TextField();
57  		entrySubstitute.setBounds(166,0,129,24);
58  		panelSubstitute.add("Center", entrySubstitute);
59  		buttonSubstOK = new java.awt.Button();
60  		buttonSubstOK.setLabel("OK");
61  		buttonSubstOK.setBounds(295,0,34,24);
62  		buttonSubstOK.setBackground(new Color(12632256));
63  		panelSubstitute.add("East", buttonSubstOK);
64  		panelIconify = new java.awt.Panel();
65  		panelIconify.setLayout(new GridLayout(1,3,0,0));
66  		panelIconify.setBounds(0,24,329,24);
67  		panelSubstIcon.add("South", panelIconify);
68  		buttonIconify = new java.awt.Button();
69  		buttonIconify.setLabel("Iconify");
70  		buttonIconify.setBounds(0,0,109,24);
71  		buttonIconify.setBackground(new Color(12632256));
72  		panelIconify.add(buttonIconify);
73  		buttonUniconify = new java.awt.Button();
74  		buttonUniconify.setLabel("Uniconify");
75  		buttonUniconify.setBounds(109,0,109,24);
76  		buttonUniconify.setBackground(new Color(12632256));
77  		panelIconify.add(buttonUniconify);
78  		buttonUniconifyAll = new java.awt.Button();
79  		buttonUniconifyAll.setLabel("Uniconify All");
80  		buttonUniconifyAll.setBounds(218,0,109,24);
81  		buttonUniconifyAll.setBackground(new Color(12632256));
82  		panelIconify.add(buttonUniconifyAll);
83  		panelEntry = new java.awt.Panel();
84  		panelEntry.setLayout(new BorderLayout(0,0));
85  		panelEntry.setBounds(0,48,329,261);
86  		panelEntry.setBackground(new Color(16777215));
87  		panelJome.add("Center", panelEntry);
88  		scrollPaneJome = new java.awt.ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
89  		scrollPaneJome.setBounds(0,0,329,237);
90  		panelEntry.add("Center", scrollPaneJome);
91  		jome = new fr.ove.openmath.jome.Jome();
92  /*		jome.setMathML("<mathml>\n"+
93  		    "<apply>\n"+
94  		      "<plus/>\n"+
95  		      "<cn>1</cn>\n"+
96  		      "<ci>x</ci>\n"+
97  		    "</apply>\n"+
98  		"</mathml>\n" 
99  		); */
100 		jome.setShiftY(1);
101 		jome.setShiftX(1);
102 		jome.setOpenMath("<OMOBJ>\n"+
103 		    "<OMA>\n"+
104 		      "<OMS cd=\"arith1\" name=\"plus\"/>\n"+
105 		      "<OMI>1</OMI>\n"+
106 		      "<OMV name=\"x\"/>\n"+
107 		    "</OMA>\n"+
108 		"</OMOBJ>\n"
109 		);
110 		jome.setDrawBounds(false);
111 		jome.setLinear("1+x");
112 		jome.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
113 		jome.setBounds(0,0,325,233);
114 		jome.setFont(new Font("Dialog", Font.PLAIN, 14));
115 		Panel jomeContainer = new Panel();
116 			jomeContainer.setLayout(new GridLayout(1,1));
117 			jomeContainer.add(jome);
118 		scrollPaneJome.add(jomeContainer);
119 		linearEntry = new java.awt.TextField();
120 		linearEntry.setText("1+x");
121 		linearEntry.setBounds(0,237,329,24);
122 		panelEntry.add("South", linearEntry);
123 		panelGetButtons = new java.awt.Panel();
124 		panelGetButtons.setLayout(new GridLayout(3,2,0,0));
125 		panelGetButtons.setBounds(0,309,329,72);
126 		panelJome.add("South", panelGetButtons);
127 		buttonGetOm = new java.awt.Button();
128 		buttonGetOm.setLabel("Get OpenMath");
129 		buttonGetOm.setBounds(0,0,164,24);
130 		buttonGetOm.setBackground(new Color(12632256));
131 		panelGetButtons.add(buttonGetOm);
132 		buttonGetOmSelection = new java.awt.Button();
133 		buttonGetOmSelection.setLabel("Get OpenMath Selection");
134 		buttonGetOmSelection.setBounds(164,0,164,24);
135 		buttonGetOmSelection.setBackground(new Color(12632256));
136 		panelGetButtons.add(buttonGetOmSelection);
137 		buttonGetMml = new java.awt.Button();
138 		buttonGetMml.setLabel("Get MathML");
139 		buttonGetMml.setBounds(0,24,164,24);
140 		buttonGetMml.setBackground(new Color(12632256));
141 		panelGetButtons.add(buttonGetMml);
142 		buttonGetMmlSelection = new java.awt.Button();
143 		buttonGetMmlSelection.setLabel("Get MathML Selection");
144 		buttonGetMmlSelection.setBounds(164,24,164,24);
145 		buttonGetMmlSelection.setBackground(new Color(12632256));
146 		panelGetButtons.add(buttonGetMmlSelection);
147 		buttonGetLinear = new java.awt.Button();
148 		buttonGetLinear.setLabel("Get Linear");
149 		buttonGetLinear.setBounds(0,48,164,24);
150 		buttonGetLinear.setBackground(new Color(12632256));
151 		panelGetButtons.add(buttonGetLinear);
152 		buttonGetLinearSelection = new java.awt.Button();
153 		buttonGetLinearSelection.setLabel("Get Linear Selection");
154 		buttonGetLinearSelection.setBounds(164,48,164,24);
155 		buttonGetLinearSelection.setBackground(new Color(12632256));
156 		panelGetButtons.add(buttonGetLinearSelection);
157 		panelGetArea = new java.awt.Panel();
158 		panelGetArea.setLayout(new BorderLayout(0,0));
159 		panelGetArea.setBounds(329,0,329,381);
160 		panel1.add(panelGetArea);
161 		panelSet = new java.awt.Panel();
162 		panelSet.setLayout(new GridLayout(1,2,0,0));
163 		panelSet.setBounds(0,0,329,24);
164 		panelGetArea.add("North", panelSet);
165 		setOM = new java.awt.Button();
166 		setOM.setLabel("Set OpenMath Object");
167 		setOM.setBounds(0,0,164,24);
168 		setOM.setBackground(new Color(12632256));
169 		panelSet.add(setOM);
170 		setMML = new java.awt.Button();
171 		setMML.setLabel("Set MathML Object");
172 		setMML.setBounds(164,0,164,24);
173 		setMML.setBackground(new Color(12632256));
174 		panelSet.add(setMML);
175 		omArea = new java.awt.TextArea();
176 		omArea.setBounds(0,24,329,333);
177 		panelGetArea.add("Center", omArea);
178 		linearArea = new java.awt.TextField();
179 		linearArea.setBounds(0,357,329,24);
180 		panelGetArea.add("South", linearArea);
181 		//}}
182 	
183 		//{{REGISTER_LISTENERS
184 		SymText lSymText = new SymText();
185 		linearEntry.addTextListener(lSymText);
186 		SymAction lSymAction = new SymAction();
187 		buttonGetLinear.addActionListener(lSymAction);
188 		buttonGetLinearSelection.addActionListener(lSymAction);
189 		buttonGetOm.addActionListener(lSymAction);
190 		buttonGetOmSelection.addActionListener(lSymAction);
191 		buttonIconify.addActionListener(lSymAction);
192 		buttonUniconify.addActionListener(lSymAction);
193 		buttonUniconifyAll.addActionListener(lSymAction);
194 		entrySubstitute.addActionListener(lSymAction);
195 		buttonSubstOK.addActionListener(lSymAction);
196 		setOM.addActionListener(lSymAction);
197 		entryFontSize.addActionListener(lSymAction);
198 		buttonGetMml.addActionListener(lSymAction);
199 		setMML.addActionListener(lSymAction);
200 		buttonGetMmlSelection.addActionListener(lSymAction);
201 		//}}
202 	}
203 	
204 	//{{DECLARE_CONTROLS
205 	java.awt.Panel panelFont;
206 	java.awt.Label labelFontSize;
207 	java.awt.TextField entryFontSize;
208 	java.awt.Panel panel1;
209 	java.awt.Panel panelJome;
210 	java.awt.Panel panelSubstIcon;
211 	java.awt.Panel panelSubstitute;
212 	java.awt.Label labelSubstitute;
213 	java.awt.TextField entrySubstitute;
214 	java.awt.Button buttonSubstOK;
215 	java.awt.Panel panelIconify;
216 	java.awt.Button buttonIconify;
217 	java.awt.Button buttonUniconify;
218 	java.awt.Button buttonUniconifyAll;
219 	java.awt.Panel panelEntry;
220 	java.awt.ScrollPane scrollPaneJome;
221 	fr.ove.openmath.jome.Jome jome;
222 	java.awt.TextField linearEntry;
223 	java.awt.Panel panelGetButtons;
224 	java.awt.Button buttonGetOm;
225 	java.awt.Button buttonGetOmSelection;
226 	java.awt.Button buttonGetMml;
227 	java.awt.Button buttonGetMmlSelection;
228 	java.awt.Button buttonGetLinear;
229 	java.awt.Button buttonGetLinearSelection;
230 	java.awt.Panel panelGetArea;
231 	java.awt.Panel panelSet;
232 	java.awt.Button setOM;
233 	java.awt.Button setMML;
234 	java.awt.TextArea omArea;
235 	java.awt.TextField linearArea;
236 	//}}
237 
238 	class SymText implements java.awt.event.TextListener
239 	{
240 		public void textValueChanged(java.awt.event.TextEvent event)
241 		{
242 			Object object = event.getSource();
243 			if (object == linearEntry)
244 				linearEntry_TextValueChanged(event);
245 		}
246 	}
247 
248 	void linearEntry_TextValueChanged(java.awt.event.TextEvent event)
249 	{
250 		// to do: code goes here.
251 			 
252 		//{{CONNECTION
253 		// setLinear... Get the contents of the TextField
254 		{
255 			jome.setLinear(linearEntry.getText());
256 			scrollPaneJome.validate();
257 		}
258 		//}}
259 	}
260 
261 	class SymAction implements java.awt.event.ActionListener
262 	{
263 		public void actionPerformed(java.awt.event.ActionEvent event)
264 		{
265 			Object object = event.getSource();
266 			if (object == buttonGetLinear)
267 				buttonGetLinear_ActionPerformed(event);
268 			else if (object == buttonGetLinearSelection)
269 				buttonGetLinearSelection_ActionPerformed(event);
270 			else if (object == buttonGetOm)
271 				buttonGetOm_ActionPerformed(event);
272 			else if (object == buttonGetOmSelection)
273 				buttonGetOmSelection_ActionPerformed(event);
274 			else if (object == buttonIconify)
275 				buttonIconify_ActionPerformed(event);
276 			else if (object == buttonUniconify)
277 				buttonUniconify_ActionPerformed(event);
278 			else if (object == buttonUniconifyAll)
279 				buttonUniconifyAll_ActionPerformed(event);
280 			else if (object == entrySubstitute)
281 				entrySubstitute_EnterHit(event);
282 			else if (object == buttonSubstOK)
283 				buttonSubstOK_ActionPerformed(event);
284 			else if (object == setOM)
285 				setOM_ActionPerformed(event);
286 			else if (object == entryFontSize)
287 				entryFontSize_EnterHit(event);
288 			else if (object == buttonGetMml)
289 				buttonGetMml_ActionPerformed(event);
290 			else if (object == setMML)
291 				setMML_ActionPerformed(event);
292 			else if (object == buttonGetMmlSelection)
293 				buttonGetMmlSelection_ActionPerformed(event);
294 		}
295 	}
296 
297 	void buttonGetLinear_ActionPerformed(java.awt.event.ActionEvent event)
298 	{
299 		// to do: code goes here.
300 			 
301 		//{{CONNECTION
302 		// Set the text for TextField... getLinear
303 		{
304 			linearArea.setText(jome.getLinear());
305 		}
306 		//}}
307 	}
308 
309 	void buttonGetLinearSelection_ActionPerformed(java.awt.event.ActionEvent event)
310 	{
311 		// to do: code goes here.
312 			 
313 		//{{CONNECTION
314 		// Set the text for TextField... getLinearSelection
315 		{
316 			linearArea.setText(jome.getLinearSelection());
317 		}
318 		//}}
319 	}
320 
321 	void buttonGetOm_ActionPerformed(java.awt.event.ActionEvent event)
322 	{
323 		// to do: code goes here.
324 			 
325 		//{{CONNECTION
326 		// Set the text for TextArea... getOpenMath
327 		{
328 			omArea.setText(jome.getOpenMath());
329 		}
330 		//}}
331 	}
332 
333 	void buttonGetOmSelection_ActionPerformed(java.awt.event.ActionEvent event)
334 	{
335 		// to do: code goes here.
336 			 
337 		//{{CONNECTION
338 		// Set the text for TextArea... getOpenMathSelection
339 		{
340 			omArea.setText(jome.getOpenMathSelection());
341 		}
342 		//}}
343 	}
344 
345 	void buttonIconify_ActionPerformed(java.awt.event.ActionEvent event)
346 	{
347 		// to do: code goes here.
348 			 
349 		//{{CONNECTION
350 		// iconifySelection
351 		{
352 			jome.iconifySelection();
353 		}
354 		//}}
355 	}
356 
357 	void buttonUniconify_ActionPerformed(java.awt.event.ActionEvent event)
358 	{
359 		// to do: code goes here.
360 			 
361 		//{{CONNECTION
362 		// uniconifySelectedIcons
363 		{
364 			jome.uniconifySelectedIcons();
365 		}
366 		//}}
367 	}
368 
369 	void buttonUniconifyAll_ActionPerformed(java.awt.event.ActionEvent event)
370 	{
371 		// to do: code goes here.
372 			 
373 		//{{CONNECTION
374 		// uniconifyAllIcons
375 		{
376 			jome.uniconifyAllIcons();
377 		}
378 		//}}
379 	}
380 
381 	void entrySubstitute_EnterHit(java.awt.event.ActionEvent event)
382 	{
383 		// to do: code goes here.
384 			 
385 		//{{CONNECTION
386 		// substitute... Get the contents of the TextField
387 		{
388 			jome.substitute(entrySubstitute.getText());
389 		}
390 		//}}
391 	}
392 
393 	void buttonSubstOK_ActionPerformed(java.awt.event.ActionEvent event)
394 	{
395 		// to do: code goes here.
396 			 
397 		//{{CONNECTION
398 		// substitute... Get the contents of the TextField
399 		{
400 			jome.substitute(entrySubstitute.getText());
401 		}
402 		//}}
403 	}
404 
405 	void setOM_ActionPerformed(java.awt.event.ActionEvent event)
406 	{
407 		// to do: code goes here.
408 			 
409 		//{{CONNECTION
410 		// setOpenMath... Get the contents of the TextArea
411 		{
412 			jome.setOpenMath(omArea.getText());
413 			linearEntry.setText(jome.getLinear());
414 			scrollPaneJome.validate();
415 		}
416 		//}}
417 	}
418 
419 	void entryFontSize_EnterHit(java.awt.event.ActionEvent event)
420 	{
421 		// to do: code goes here.
422 			 
423 		//{{CONNECTION
424 		// Set the Jome's Font... Get the TextField's Font
425 		{
426 		    TextField src = (TextField) event.getSource();
427             int size = new Integer(src.getText()).intValue();
428 			jome.setFont(new Font("Dialog", Font.PLAIN, size));
429 			scrollPaneJome.validate();
430 		}
431 		//}}
432 	}
433 
434 	void buttonGetMml_ActionPerformed(java.awt.event.ActionEvent event)
435 	{
436 		// to do: code goes here.
437 			 
438 		//{{CONNECTION
439 		// Set the text for TextArea... getMathML
440 		{
441 			omArea.setText(jome.getMathML());
442 		}
443 		//}}
444 	}
445 
446 	void setMML_ActionPerformed(java.awt.event.ActionEvent event)
447 	{
448 		// to do: code goes here.
449 			 
450 		//{{CONNECTION
451 		// setMathML... Get the contents of the TextArea
452 		{
453 			jome.setMathML(omArea.getText());
454 			linearEntry.setText(jome.getLinear());
455 			scrollPaneJome.validate();
456 		}
457 		//}}
458 	}
459 
460 	void buttonGetMmlSelection_ActionPerformed(java.awt.event.ActionEvent event)
461 	{
462 		// to do: code goes here.
463 			 
464 		//{{CONNECTION
465 		// Set the text for TextArea... getMathMLSelection
466 		{
467 			omArea.setText(jome.getMathMLSelection());
468 		}
469 		//}}
470 	}
471 
472 	public static void main(String[] args) {
473 		Frame frame = new Frame("Jome AppletTest");
474 		Applet applet = new AppletTest();
475 		frame.add(applet);
476 		applet.init();
477 		frame.show();
478 	}
479 }