- /*
- * JTableXml.java
- *
- * Created on 14 octobre 2004, 13:49
- */
-
- package anemf.lgc.xml;
-
- import javax.xml.transform.*;
- import javax.xml.parsers.*;
- import javax.xml.transform.sax.*;
- import org.xml.sax.*;
- import javax.xml.transform.dom.*;
- import javax.xml.transform.stream.*;
- import org.w3c.dom.*;
- import java.io.*;
- import anemf.lgc.basededonnee.*;
- import anemf.lgc.*;
- import java.sql.*;
- import java.util.*;
- import javax.swing.*;
- import javax.swing.table.*;
- import java.awt.*;
- /**
- *
- * @author renard
- */
- public class JTableXml extends JTable {
- Element e;
- /** Creates a new instance of JTableXml */
-
-
- public JTableXml(Element elem){
- this.e = elem;
- System.out.println("tototo" + e.getNodeName());
- init();
- }
- public void init(){
- this.setModel(new AbstractTableModel() {
- public String getColumnName(int col) {
- return JTableXml.this.getColumnName(col);
- }
- public int getRowCount() { return JTableXml.this.getRowCount(); }
- public int getColumnCount() {return JTableXml.this.getColumnCount();}
- public Object getValueAt(int row, int col) {
- return getValueAt(row, col);
- }
- public boolean isCellEditable(int row, int col)
- { return true; }
- public void setValueAt(Object value, int row, int col) {
- JTableXml.this.setValueAt(value, row, col);
- fireTableCellUpdated(row, col);
- }
- });
-
-
- }
-
-
- public String getColumnName(int col) {
- for(int i=0; i< e.getChildNodes().getLength(); i++ ){
- if(e.getChildNodes().item(i).getNodeType()!= Element.TEXT_NODE){
- int p=-1;
- for(int j = 0 ; j<e.getChildNodes().item(i).getChildNodes().getLength(); j++){
- if(e.getChildNodes().item(i).getChildNodes().item(j).getNodeType()!= Element.TEXT_NODE)
- p++;
- if(p==col)
- return e.getChildNodes().item(i).getChildNodes().item(j).getNodeName();
- }
- }
- }
- return null;
- }
-
- public int getRowCount() {
- if(e==null) return 0;
- int p=0;
- for(int i=0; i< e.getChildNodes().getLength(); i++ ){
- if(e.getChildNodes().item(i).getNodeType()!= Element.TEXT_NODE)
- p++;
- }
- return p;
- }
-
- public int getColumnCount() {
- int p=0;
- for(int i=0; i< e.getChildNodes().getLength(); i++ ){
- if(e.getChildNodes().item(i).getNodeType()!= Element.TEXT_NODE){
- for(int j = 0 ; j<e.getChildNodes().item(i).getChildNodes().getLength(); j++)
- if(e.getChildNodes().item(i).getChildNodes().item(j).getNodeType()!= Element.TEXT_NODE)
- p++;
- return p;
- }
- }
- return 0;
- }
-
- public Object getValueAt(int row, int col) {
- if(e==null) return null;
- int pp = -1;
- for(int i=0; i< e.getChildNodes().getLength(); i++ ){
- if(e.getChildNodes().item(i).getNodeType()!= Element.TEXT_NODE){
- pp++;
- if(pp==row){
- int p=-1;
- for(int j = 0 ; j<e.getChildNodes().item(i).getChildNodes().getLength(); j++){
- if(e.getChildNodes().item(i).getChildNodes().item(j).getNodeType()!= Element.TEXT_NODE)
- p++;
- if(p==col)
- try{
- return e.getChildNodes().item(i).getChildNodes().item(j).getFirstChild().getNodeValue();
- }
- catch(Exception er){er.printStackTrace();};
- }
- }
- }
- }
- return null;
-
-
- }
-
- public boolean isCellEditable(int row, int col) {
- return true;
- }
-
- public void setValueAt(Object value, int row, int col) {
-
- }
-
-
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- try{
- DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance();
- Document doc = DBF.newDocumentBuilder().parse(JTableXml.class.getResourceAsStream("test.xml"));
- System.out.println(doc.getDocumentElement().getNodeName());
- JTableXml jtx = new JTableXml(doc.getDocumentElement());
- JFrame f = new JFrame();
- f.getContentPane().setLayout(new BorderLayout());
- f.getContentPane().add(jtx.getTableHeader(), BorderLayout.NORTH);
- f.getContentPane().add(jtx, BorderLayout.CENTER);
- f.pack();
- f.show();
-
- }catch(Exception e){
- e.printStackTrace();
- }
-
-
-
- // TODO code application logic here
- }
-
-
-
- }
/*
* JTableXml.java
*
* Created on 14 octobre 2004, 13:49
*/
package anemf.lgc.xml;
import javax.xml.transform.*;
import javax.xml.parsers.*;
import javax.xml.transform.sax.*;
import org.xml.sax.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import java.io.*;
import anemf.lgc.basededonnee.*;
import anemf.lgc.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
/**
*
* @author renard
*/
public class JTableXml extends JTable {
Element e;
/** Creates a new instance of JTableXml */
public JTableXml(Element elem){
this.e = elem;
System.out.println("tototo" + e.getNodeName());
init();
}
public void init(){
this.setModel(new AbstractTableModel() {
public String getColumnName(int col) {
return JTableXml.this.getColumnName(col);
}
public int getRowCount() { return JTableXml.this.getRowCount(); }
public int getColumnCount() {return JTableXml.this.getColumnCount();}
public Object getValueAt(int row, int col) {
return getValueAt(row, col);
}
public boolean isCellEditable(int row, int col)
{ return true; }
public void setValueAt(Object value, int row, int col) {
JTableXml.this.setValueAt(value, row, col);
fireTableCellUpdated(row, col);
}
});
}
public String getColumnName(int col) {
for(int i=0; i< e.getChildNodes().getLength(); i++ ){
if(e.getChildNodes().item(i).getNodeType()!= Element.TEXT_NODE){
int p=-1;
for(int j = 0 ; j<e.getChildNodes().item(i).getChildNodes().getLength(); j++){
if(e.getChildNodes().item(i).getChildNodes().item(j).getNodeType()!= Element.TEXT_NODE)
p++;
if(p==col)
return e.getChildNodes().item(i).getChildNodes().item(j).getNodeName();
}
}
}
return null;
}
public int getRowCount() {
if(e==null) return 0;
int p=0;
for(int i=0; i< e.getChildNodes().getLength(); i++ ){
if(e.getChildNodes().item(i).getNodeType()!= Element.TEXT_NODE)
p++;
}
return p;
}
public int getColumnCount() {
int p=0;
for(int i=0; i< e.getChildNodes().getLength(); i++ ){
if(e.getChildNodes().item(i).getNodeType()!= Element.TEXT_NODE){
for(int j = 0 ; j<e.getChildNodes().item(i).getChildNodes().getLength(); j++)
if(e.getChildNodes().item(i).getChildNodes().item(j).getNodeType()!= Element.TEXT_NODE)
p++;
return p;
}
}
return 0;
}
public Object getValueAt(int row, int col) {
if(e==null) return null;
int pp = -1;
for(int i=0; i< e.getChildNodes().getLength(); i++ ){
if(e.getChildNodes().item(i).getNodeType()!= Element.TEXT_NODE){
pp++;
if(pp==row){
int p=-1;
for(int j = 0 ; j<e.getChildNodes().item(i).getChildNodes().getLength(); j++){
if(e.getChildNodes().item(i).getChildNodes().item(j).getNodeType()!= Element.TEXT_NODE)
p++;
if(p==col)
try{
return e.getChildNodes().item(i).getChildNodes().item(j).getFirstChild().getNodeValue();
}
catch(Exception er){er.printStackTrace();};
}
}
}
}
return null;
}
public boolean isCellEditable(int row, int col) {
return true;
}
public void setValueAt(Object value, int row, int col) {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try{
DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance();
Document doc = DBF.newDocumentBuilder().parse(JTableXml.class.getResourceAsStream("test.xml"));
System.out.println(doc.getDocumentElement().getNodeName());
JTableXml jtx = new JTableXml(doc.getDocumentElement());
JFrame f = new JFrame();
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(jtx.getTableHeader(), BorderLayout.NORTH);
f.getContentPane().add(jtx, BorderLayout.CENTER);
f.pack();
f.show();
}catch(Exception e){
e.printStackTrace();
}
// TODO code application logic here
}
}