djok_fb C'était mieux avant! | c'est plutot conséquent...
Code :
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import oracle.xml.parser.v2.*;
- import java.io.*;
- import java.util.*;
- import org.w3c.dom.*;
- public class CDebugFrame extends JFrame implements ActionListener,WindowListener,MouseListener
- {
- protected XMLDocument xd;
- protected XMLDocument xmlOutDoc;
- protected XMLElement xmlOut;
-
- protected FileInputStream fd;
- protected DOMParser parser;
-
- protected JList bodyL;
- protected Vector bodyV;
- protected JScrollPane scrollList;
-
- protected JLabel nfoLabel;
-
- protected CEnvDisplay envDisp;
-
- protected String fXML;
-
- protected FileOutputStream outFile;
-
- protected String lastOpenPath;
-
- // Bouttons sud
- private JButton showXMLB;
- private JButton saveDB;
- private JButton saveOB;
- private JButton exitB;
-
- // Autre
- protected JFrame parentF;
-
- public CDebugFrame(String titre, JFrame parent,String fichierXMLDebug,XMLElement xe)
- {
- super(titre);
- parentF = parent;
- xmlOut = xe;
- lastOpenPath = null;
- xmlOutDoc = new XMLDocument();
- Node mNode = (Node)xmlOutDoc.createElement("SPOT_Production_Orders" );
- mNode.appendChild(xe.cloneNode(true));
- xmlOutDoc.appendChild(mNode.cloneNode(true));
- xmlOutDoc.setEncoding("UTF-8" );
- xmlOutDoc.setVersion("1.0" );
- fXML = fichierXMLDebug;
- try
- {
- outFile = new FileOutputStream("result.xml" );
- xmlOutDoc.print(outFile);
- outFile.close();
- }
- catch(Exception eX)
- {
- System.out.println("Warning! Could not create XML Result File." );
- CWarningDlg g = new CWarningDlg(this,"Simulator message","Could not create XML Result File." );
- }
-
- try
- {
- parser = new DOMParser();
- fd = new FileInputStream(fichierXMLDebug);
- parser.parse(fd);
- xd = parser.getDocument();
- }
- catch (Exception e)
- {
- System.out.println("Warning! Could not open XML Debug File." );
- CWarningDlg g = new CWarningDlg(this,"Simulator message","Could not open XML Debug File." );
- }
- CEnvDisplay envDisp = new CEnvDisplay("Used vars",xd);
- init();
- this.show();
- parent.setEnabled(false);
- envDisp.show();
- }
-
- public void mouseClicked(MouseEvent e)
- {
- if (!(bodyL.isSelectionEmpty()))
- {
- int index = bodyL.getSelectedIndex();
- envDisp.currentInstr=index;
- envDisp.setMainListVector();
- }
- }
-
- public void mouseEntered(MouseEvent e) {}
- public void mouseExited(MouseEvent e) {}
- public void mousePressed(MouseEvent e) {}
- public void mouseReleased(MouseEvent e) {}
-
- public void init()
- {
- JPanel southP = new JPanel(new GridLayout(1,4));
- if (xmlOut!=null)
- nfoLabel = new JLabel("<html><p align=\"center\">Generated XML File OK</p></html>" );
- else
- nfoLabel = new JLabel("<html><p align=\"center\">Generated XML File KO</p></html>" );
- this.setSize(800,480);
- this.setLocation(10,96);
- this.getContentPane().setLayout(new BorderLayout());
- this.setResizable(true);
-
- // Mise en place des bouttons
- showXMLB = new JButton("Show XML" );
- showXMLB.addActionListener(this);
- saveDB = new JButton("Save Debug Info" );
- saveDB.addActionListener(this);
- saveOB = new JButton("Save Generated XML" );
- saveOB.addActionListener(this);
- exitB = new JButton("Quit" );
- exitB.addActionListener(this);
-
- // Ajout au panel Sud
- southP.add(saveDB);
- southP.add(saveOB);
- southP.add(showXMLB);
- southP.add(exitB);
-
- // Mise en place du corps principal
- bodyL = new JList(bodyV = loadInfoFromDebugXML());
- bodyL.addMouseListener(this);
- scrollList = new JScrollPane(bodyL);
- bodyL.setSelectedIndex(0);
- bodyL.setVisibleRowCount(23);
- // Ajout dans le main panel
- this.getContentPane().add(nfoLabel,BorderLayout.NORTH);
- this.getContentPane().add(scrollList,BorderLayout.CENTER);
- this.getContentPane().add(southP,BorderLayout.SOUTH);
- }
-
- public Vector loadInfoFromDebugXML()
- {
- Vector res = new Vector(10,10);
- int i;
- NodeList nl = xd.getElementsByTagName("currentInstruction" );
- NodeList nlR = xd.getElementsByTagName("Results" );
- for (i=0;i<nl.getLength();i++)
- res.add("<HTML>" + nl.item(i).getFirstChild().getNodeValue() + "<font color=\"red\"> = " + nlR.item(i).getFirstChild().getNodeValue() + "</font></HTML>" );
- System.out.println("->" + i);
- return res;
- }
-
- public void windowActivated(WindowEvent e) {}
- public void windowClosed(WindowEvent e) {}
- public void windowClosing(WindowEvent e) { parentF.setEnabled(true);this.dispose(); }
- public void windowDeactivated(WindowEvent e) {}
- public void windowDeiconified(WindowEvent e) {}
- public void windowIconified(WindowEvent e) {}
- public void windowOpened(WindowEvent e) {}
-
- public void actionPerformed(ActionEvent e)
- {
- if (e.getActionCommand().equals("Quit" ))
- {
- envDisp.dispose();
- parentF.setEnabled(true);
- this.dispose();
- }
- if (e.getActionCommand().equals("Save Debug Info" ))
- {
- JFileChooser cdataChoice;
- if (lastOpenPath==null)
- cdataChoice = new JFileChooser();
- else
- cdataChoice = new JFileChooser(lastOpenPath);
- ExampleFileFilter filter = new ExampleFileFilter();
- filter.addExtension("xml" );
- filter.setDescription("XML Files" );
- cdataChoice.setFileFilter(filter);
- int choiceRet = cdataChoice.showSaveDialog(this);
- if(choiceRet == JFileChooser.APPROVE_OPTION)
- {
- try
- {
- //sqlLabel.setText(cdataChoice.getSelectedFile().getAbsolutePath());
- lastOpenPath = cdataChoice.getSelectedFile().getParent();
- File fSour = new File(fXML);
- File fDest = new File(cdataChoice.getSelectedFile().getAbsolutePath());
- CommonClass.fileCopy(fSour,fDest);
- System.out.println("Save as " + cdataChoice.getSelectedFile().getAbsolutePath() + " : Successful." );
- }
- catch(Exception exc)
- {
- System.out.println("Error while writing XML Debug file : " + exc);
- CWarningDlg g = new CWarningDlg(this,"CData file saving","Error while saving XML Debug file." );
- }
- }
- }
-
- if (e.getActionCommand().equals("Save Generated XML" ))
- {
- JFileChooser cdataChoice;
- if (lastOpenPath==null)
- cdataChoice = new JFileChooser();
- else
- cdataChoice = new JFileChooser(lastOpenPath);
- ExampleFileFilter filter = new ExampleFileFilter();
- filter.addExtension("xml" );
- filter.addExtension("ord" );
- filter.setDescription("XML Files" );
- cdataChoice.setFileFilter(filter);
- int choiceRet = cdataChoice.showSaveDialog(this);
- if(choiceRet == JFileChooser.APPROVE_OPTION)
- {
- try
- {
- //sqlLabel.setText(cdataChoice.getSelectedFile().getAbsolutePath());
- lastOpenPath = cdataChoice.getSelectedFile().getParent();
- File fSour = new File("result.xml" );
- File fDest = new File(cdataChoice.getSelectedFile().getAbsolutePath());
- CommonClass.fileCopy(fSour,fDest);
- System.out.println("Save as " + cdataChoice.getSelectedFile().getAbsolutePath() + " : Successful." );
- }
- catch(Exception exc)
- {
- System.out.println("Error while writing XML Result file : " + exc);
- CWarningDlg g = new CWarningDlg(this,"CData file saving","Error while saving XML Result file." );
- }
- }
- }
-
- if (e.getActionCommand().equals("Show XML" ))
- {
- try
- {
- Runtime.getRuntime().exec("cmd /c result.xml" );
- }
- catch(Exception eRT)
- {
- System.out.println("Cannot show XML File" );
- CWarningDlg g = new CWarningDlg(this,"Simulator message","Could not open XML file." );
- }
- }
- }
- }
|
mais le voila...chuis plutot perturbé car en 5 ans, ca me l'a jamais fait |