package test_figue; import figue.*; import figue.box.*; import figue.resource.*; import figue.io.xml.Utility ; import org.apache.xerces.parsers.DOMParser; import org.xml.sax.SAXException; import org.w3c.dom.Document; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.lang.reflect.*; import java.io.IOException; import javax.swing.*; import javax.swing.event.DocumentListener; import javax.swing.event.DocumentEvent; public class TestStringMathML extends JFrame implements ActionListener{ public JTextField mathmltext; public JTextArea textArea; public Container contentPane; public org.apache.xerces.parsers.DOMParser parser; public static void main(String[] args) { TestStringMathML aTestMathML = new TestStringMathML(); aTestMathML.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { System.exit(0); }; }); aTestMathML.setVisible(true); } public void actionPerformed(ActionEvent evt) { } public TestStringMathML() { // initialisation du menu de l'application setJMenuBar(createTestMathMLMenuBar()); try { parser = new org.apache.xerces.parsers.DOMParser(); // specifying validation boolean validate = true; parser.setFeature("http://xml.org/sax/features/validation", validate); boolean nameSpaceProcessing = true; parser.setFeature("http://xml.org/sax/features/namespaces", nameSpaceProcessing); } catch (SAXException e ) { e.printStackTrace(); return; } addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent e) { System.exit (0); }}); // initialisation de l'editeur et la facade figue createEditAndFigueFacade(); pack(); setSize (new java.awt.Dimension (600, 800)); setVisible(true); } private JMenuBar createTestMathMLMenuBar() { JMenuBar testMenuBar = new JMenuBar(); JMenu editMenu = new JMenu("Edit"); JMenu figueMenu = new JMenu("Figue"); // Edit Menu JMenuItem pasteMenuItem = new JMenuItem("Paste"); JMenuItem quitMenuItem = new JMenuItem("Quit"); quitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); // Figue Menu JMenuItem displayMenuItem = new JMenuItem("Display"); displayMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { displayMenuItemAction(e); } }); pasteMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textArea.paste(); } }); editMenu.add(pasteMenuItem); editMenu.add(quitMenuItem); figueMenu.add(displayMenuItem); testMenuBar.add(editMenu); testMenuBar.add(figueMenu); setJMenuBar(testMenuBar); return testMenuBar; } private void createEditAndFigueFacade() { // The next two lines should be in one line. class MyDocumentListener implements DocumentListener { public void insertUpdate(DocumentEvent evt) { // Some text was inserted. } public void removeUpdate(DocumentEvent evt) { // Some text was inserted. } public void changedUpdate(DocumentEvent evt) { // The style of some text was changed. } } mathmltext = new JTextField(20); textArea = new JTextArea(5, 20); textArea.setFont(new java.awt.Font("Serif", java.awt.Font.PLAIN, 14)); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setEditable(true); MyDocumentListener myListener= new MyDocumentListener(); textArea.getDocument().addDocumentListener(myListener); JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); GridBagLayout gridBag = new GridBagLayout(); contentPane = getContentPane(); contentPane.removeAll(); contentPane.setLayout(gridBag); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; gridBag.setConstraints(scrollPane, c); contentPane.add(scrollPane); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weighty = 1.0; gridBag.setConstraints(scrollPane, c); _facade = new AWTFacade(); initResources(); contentPane.add(_facade.getAwtComponent()); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weighty = 1.0; gridBag.setConstraints(_facade.getAwtComponent(), c); show(); } private void displayMenuItemAction(ActionEvent e) { String text = textArea.getText(); // read the string and parse it with xerces parser try { // give a parser in parametre long time = System.currentTimeMillis(); System.out.println("le temps avant"+ time); doc=Utility.xercesParseXMLStringReader(text,"/net/home/hnaciri/THESE/implementation/test_figue/dtd/dtdMathML/mmlents/mathml.dtd",parser); //comment : a parser is created after by this method //doc=Utility.xercesParseXMLStringReader(text,"/net/home/hnaciri/THESE/implementation/test_figue/dtd/dtdMathML/mmlents/mathml.dtd"); time= System.currentTimeMillis()-time; System.out.println("le temps d'execution du parser"+ time); // comment : there is the case witch a dtd path is fixed by this // method //doc=Utility.xercesParseXMLStringReader(text); } catch (SAXException e1) { e1.printStackTrace(); } catch ( IOException e1 ) { e1.printStackTrace(); } long time1 = System.currentTimeMillis(); System.out.println("le temps avant"+ time1); Utility.buildFacade( _facade, doc.getDocumentElement(),"MathML"); time1= System.currentTimeMillis()-time1; System.out.println("le temps d'execution de buildFacade"+ time1); _facade.buildInit(null); _facade.buildComplete(); show(); } public static void initResources() { try { _essaiFont = _facade.doGetFont(null, FontFamily.SYMBOL, FontStyle.PLAIN, 24, false); //_facade.doGetColor("red",BasicColor.RED); _blue = _facade.doGetColor(null,0,0,255); _red = _facade.doGetColor("red",BasicColor.RED); _yellow = _facade.doGetColor("yellow",BasicColor.YELLOW); _facade.doGetStyle("style hot", _facade.getFont("big font"), _facade.getColor("red"), _facade.getColor("yellow")); _facade.doGetStyle("flashy",null,_red,null); } catch ( WrongResourceException anException ) { ; } } // attributs public static AWTFacade _facade; public static FontInterface _essaiFont; public static ColorInterface _blue; public static ColorInterface _red; public static ColorInterface _yellow; // document representing the XML File private static Document doc=null; }