import figue.*; import figue.box.*; import figue.path.*; import figue.internal.*; import figue.resource.*; import figue.geometry.*; import figue.jape.*; import figue.io.xml.Utility ; import figue.selection.*; import org.apache.xml.serialize.*; import figue.event.*; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Element; import org.w3c.dom.Text; import org.xml.sax.InputSource; import org.xml.sax.ErrorHandler; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import ui.DOMParserSaveEncoding; import javax.swing.JTree; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import javax.swing.*; import javax.swing.tree.*; import javax.swing.event.*; import java.net.URL; import java.net.MalformedURLException; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.FileOutputStream; import java.io.*; import javax.swing.text.JTextComponent; import javax.swing.*; import javax.swing.border.*; import javax.swing.tree.*; import javax.swing.event.*; import java.net.URL; import java.io.IOException; import java.net.MalformedURLException; import java.io.File; import java.awt.*; import java.awt.event.*; import java.lang.reflect.*; import java.util.StringTokenizer; import figue.io.xml.Utility; import figue.io.xml.XmlToFigue; import ui.DOMParserSaveEncoding; import ui.DOMTree; import ui.DOMTreeFull; import ui.DefaultImages; // ajouter import org.apache.xerces.dom.*; import org.xml.sax.*; import org.w3c.dom.*; import org.apache.xerces.parsers.DOMParser; import aioli.dom.util.DomUtil; import aioli.path.IPath; import aioli.path.IPathFigue; import aioli.path.IPathDom; import javax.swing.JApplet.*; import java.applet.Applet; /** * Creates a concrete tree corresponding to an XML document * and display both tree + a textual representation on a window */ public class Test2 extends JApplet { String newline = "\n"; public Container contentPane; public org.apache.xerces.parsers.DOMParser parser; public String source = null; public final void init() { openMenuItemAction(); setSize (new java.awt.Dimension (600, 800)); } public Test2() { // initialisation du menu de l'application // setJMenuBar(createTestMenuBar()); try { // le parser de xml 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; } //contentPane = getContentPane(); openMenuItemAction(); // pack(); setSize (new java.awt.Dimension (600, 800)); //setSize (new Dimension (600, 400)); setVisible(true); } // Le menu // Charge un fichier xml avec du mathML private void openMenuItemAction() { //JFileChooser chooser = new JFileChooser("./examples/"); _isBoxSelection=false; //int returnVal = chooser.showOpenDialog(this); //if (returnVal == JFileChooser.APPROVE_OPTION) { // String filename = "/0/user/dbaccial/LEMME/XSL/ZIP/classes/exaples/test1.xml"; try { _facade = new AWTFacade(); // nouvelle facade initResources();//???? // Create a URL object corresponding to input file URL sourceUrl = null; //source = getParameter ("source"); source="file:/net/serveurs/www-sop/lemme/personnel/Hanane.Naciri/test1.xml"; System.out.println(source); try { sourceUrl = new URL (source); }catch (MalformedURLException ex) {ex.printStackTrace();} // le parser lit le fichier et remplit le document doc (DOM) try { doc=Utility.xercesParseXMLFile(sourceUrl,parser); }catch (FileNotFoundException eFile) { eFile.printStackTrace(); } catch ( IOException eFile ) { eFile.printStackTrace(); } catch (SAXException eFile ) { eFile.printStackTrace(); } // Construit la facade final Element anElement = doc.getDocumentElement(); // la racine du document, c'est un tag math // // visualise le DOM mathml dans la facade, tout le boulot est fait là. // Utility.buildFacade( _facade, anElement,"MathML"); _facade.buildInit(null); _facade.buildComplete(); // la vue de la facade JScrollPane facadeView = new JScrollPane(_facade.getAwtComponent()); contentPane = getContentPane(); contentPane.removeAll(); contentPane.setLayout(new GridLayout());//????? contentPane.add(facadeView); show(); /* Pour éditer??? ct = new Ctedit(var,"disp",new SwingInitializer()); Component cn = ct.getComponent(); contentPane.add(cn); setContentPane(contentPane); */ ////////////////////////////////////////////////// /// detection de click sur la facade _facade.addPointingListener(new PointingListenerInterface() { public final void mouseEntered(PointingEvent anEvent) { } public final void mouseExited(PointingEvent anEvent) { } public final void mousePressed(PointingEvent anEvent) { } public final void mouseReleased(PointingEvent anEvent) { } public final void mouseClicked(PointingEvent anEvent) { if ( anEvent.getPath() != null ) { hightlightBox(anEvent.getPath()); PathInterface tmpPath= anEvent.getPath(); _isBoxSelection = false; } } }); try { _facade.doGetSelection("current selection", Priority.MEDIUM, null, "yellow"); _facade.doGetSelection("last selection", Priority.MEDIUM, null, "red"); } catch ( WrongSelectionException anException ) { ; } } catch (java.lang.Exception ex) { ; } } private static final void hightlightBox(PathInterface aPath) { try { final SelectionInterface theSelection = _facade.getSelection("current selection"); if ( _previousPath != null ) { PathInterface theCurrentPath = _previousPath; while ( theCurrentPath.numberOfChildren() > 0 ) { theCurrentPath = theCurrentPath.getChild(0); } theCurrentPath.addOperation(new ShrinkSelection(theSelection)); _facade.updateSelectionAndRedisplay(_previousPath); _previousPath = null; } ////////////////////// if (_lasPath != null) shrinkSelectionOnFacade(_lasPath, _lastTreeNode); ////////////////////// PathInterface theCurrentPath = aPath; while ( theCurrentPath.numberOfChildren() > 0 ) { theCurrentPath = theCurrentPath.getChild(0); } theCurrentPath.addOperation(new ExtendSelection(theSelection)); PathInterface theExtendedPath = new Path(); theExtendedPath.addChild(aPath); _facade.updateSelectionAndRedisplay(theExtendedPath); _previousPath = theExtendedPath; } catch ( WrongSelectionException anException ) { ; } } private static void shrinkSelectionOnFacade(TreePath path, TreeNode node) { try { final SelectionInterface theSelection = _facade.getSelection("current selection"); int rank = path.getPathCount()-1; int[] tab=new int[rank]; TreeNode nodeParent =node.getParent(); TreeNode nodeChild = node; for (int j = rank-1; j >= 0; j--) { tab[j]=nodeParent.getIndex(nodeChild); nodeChild= nodeParent; nodeParent =nodeChild.getParent(); } PathInterface thePath = new Path(); Path res = null; Path res1 = null; for (int i = 0; i < tab.length; i++) { res1 = new Path(tab[i]); if (res == null) thePath.addChild(res1); else res.addChild(res1); res = res1; } res.addOperation(new ShrinkSelection(theSelection)); _facade.updateSelectionAndRedisplay(thePath); } catch ( WrongSelectionException anException ) { ; } } 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 ) { anException.printStackTrace(); } } // attributs public static AWTFacade _facade; // la zone graphique où on voit le mathml public static FontInterface _essaiFont; public static ColorInterface _blue; public static ColorInterface _red; public static ColorInterface _yellow; public static boolean _selectFlag; public static TreePath _lasPath = null; public static TreeNode _lastTreeNode; public static boolean _isBoxSelection=true; private static PathInterface _previousPath = null; static Vector textLine; // document representing the XML File private static Document doc=null; }