package ui.xml;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JPanel;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
@SuppressWarnings("serial")
public class OnyxGridBag extends JPanel {
// XML
private String filename;
private Document document;
boolean compress = false;
// SWING
private int nbrMaxTD;
private int nbrTD;
public OnyxGridBag(String filename) {
this.filename = filename;
GridBagLayout gbMain = new GridBagLayout ();
GridBagConstraints cMain = new GridBagConstraints ();
this.setLayout(gbMain);
// Nombre maximum de colonnes
// C'est le nombre de
maximum trouv� dans une | du fichier xml
openXML ();
nbrMaxTD = getTR (document.getDocumentElement(), 0);
System.out.println (nbrMaxTD);
}
/*
* Tous ce qui concerne la manipulation du fichier xml...
*/
// renvoie le nombre maximum de TD trouv� dans un des TR
private int getTR (Node parent, int nbrTDs) {
int nbrMaxTD = 0;
NodeList trNodeList = parent.getChildNodes();
for (int i=0; i"+nbrMaxTD);
}
}
return nbrMaxTD;
}
// renvoie le nombre de TD trouv� dans un TR
private int getTD (Node parent, int nbrTD) {
boolean haveTable = false;
NodeList tdNodeList = parent.getChildNodes();
for (int i=0; i "+nbrTD+"\t"+tdNodeList.item(i).getFirstChild().getNodeValue());
}
}
return nbrTD;
}
private void openXML () {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
try {
document = builder.parse(new File (filename));
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}