1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
public class Affichage {
public static void main(String[] args) throws ClassNotFoundException {
/* Création du parseur */
SAXBuilder builder = new SAXBuilder();
File fichierXML = new File("Exercice1.xml");
Document document;
try {
/* Parsing du fichier */
document = builder.build(fichierXML);
/* Racine du document XML : dans notre cas <diagramme> */
Element rootNode = document.getRootElement();
List<Element> elmts=rootNode.getChildren();
List<String> temps = new ArrayList<String>();
List<String> autres = new ArrayList<String>();
parserFichier(elmts,temps,autres);
window(temps,autres);
} catch (JDOMException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
}
}
public static void addOnce(List<String> list, String text) {
if ( !list.contains(text) ) list.add(text);
}
public static void collect(List<String> list, Element elmt, boolean addText) {
if ( addText ) {
addOnce(list, elmt.getName()+ " nom=" +elmt.getText());
}
else{ addOnce(list, elmt.getName()); }
}
public static void parserFichier(List<Element> elmts, List<String> temps, List<String> autres) throws ClassNotFoundException{
for (Element elmt : elmts) {
List<Element> children = elmt.getChildren();
if(("instant".equals(elmt.getName()))||("intervalle".equals(elmt.getName()))||("event".equals(elmt.getName()))) {
collect( temps, elmt, children.isEmpty() );
for (Element child : children) {
collect(temps,child,elmt.equals(children));
}
}
else{
collect( autres, elmt, children.isEmpty() );
if(!children.isEmpty()){
parserFichier( children, temps, autres );
}
}
}
}
public static void window( List<String> temps, List<String> autres){
JScrollPane texteAsc;
JScrollPane texteAsc1;
JLabel label = new JLabel("Extraction de connaissances");
JFrame window=new JFrame("extraction connaissances");
JTextArea grandeZone = new JTextArea(7,10);
JTextArea grandeZone1 = new JTextArea(7, 10);
texteAsc = new JScrollPane(grandeZone);
texteAsc1 = new JScrollPane(grandeZone1);
JPanel container = new JPanel();
JPanel surfTotPanel = new JPanel();
JPanel surfTotPanel2 = new JPanel();
surfTotPanel.setLayout(new BoxLayout(surfTotPanel,BoxLayout.Y_AXIS));
Dimension dimension = new Dimension(250,400);
surfTotPanel.setPreferredSize(dimension);
surfTotPanel2.setLayout(new BoxLayout(surfTotPanel2,BoxLayout.Y_AXIS));
Dimension dimension2 = new Dimension(250,400);
surfTotPanel2.setPreferredSize(dimension2);
surfTotPanel.add(texteAsc1);
surfTotPanel2.add(texteAsc);
container.setLayout(new BorderLayout());
label.setHorizontalAlignment(JLabel.CENTER);
container.add(label, BorderLayout.NORTH);
container.add(surfTotPanel2, BorderLayout.EAST);
container.add(surfTotPanel,BorderLayout.WEST);
window.setContentPane(container);
window.setVisible(true);
window.setSize(600,400);
Font police = new Font("Andalus", Font.CENTER_BASELINE, 25);
label.setFont(police);
label.setForeground(Color.blue);
StringBuilder texte = new StringBuilder(" ~~concepts décrivent le temps ~~");
texte.append( "\n" );
StringBuilder texte1 = new StringBuilder("~~concepts décrivent le domaine ~~");
texte1.append( "\n" );
for( String temp : temps ) {
texte.append( "\n" ); // pour passer à la ligne suivante
texte.append( "** " ); // un tiret stylisé
texte.append( temp ); // le texte de la ligne
}
// et à la fin :
grandeZone.setText(texte.toString());
for( String temp1 : autres ) {
texte1.append( "\n" );
// pour passer à la ligne suivante
texte1.append( "** " ); // un tiret stylisé
texte1.append( temp1); // le texte de la ligne
}
// et à la fin :
grandeZone1.setText(texte1.toString());
}
} |
Partager