analyseWriter/src/fenetres/allContent.java

235 lines
9.7 KiB
Java

package fenetres;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import MEPTL.commandes;
import cXML.node;
import list.listeDesNodesAllContent;
import java.awt.Color;
public class allContent extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textFieldPoint;
private JLabel lblExplication;
node nod;
afficheText J;
JComboBox<String> comboBoxValeur;
String valeur="strict";
int point=0;
/**
* Evaluation de tous les contenu d'un node.
* @param nod : Le node à évaluer.
* @param J : Affichage du texte
* @param Childs : Si TRUE alors évaluation de tous les contenus des nodes enfants.
*/
public allContent(node nod, afficheText J,boolean Childs) {
this.nod=nod;
this.J=J;
if(nod.getAttributs().get("allContent")!=null) {
String value = nod.getAttributs().get("allContent");
if(value.contains("SansCasseEspaceChiffre")) { value=value.replace("SansCasseEspaceChiffre", "");valeur="SansCasseEspaceChiffre";}
if(value.contains("strictSansEspace")) { value=value.replace("strictSansEspace", "");valeur="strictSansEspace";}
if(value.contains("strict")) {value=value.replace("strict", "");valeur="strict";}
if(value.contains("environ")) {value=value.replace("environ", "");valeur="environ";}
point = Integer.valueOf(value);
}
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 589, 366);
ImageIcon img = new ImageIcon(getClass().getResource("/evalwriter.png") );
int screenWidth = (int) java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getWidth();
int screenHeight = (int) java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getHeight();
setLocation(( (screenWidth) - getWidth()) / 2, (screenHeight - getHeight()) / 2);
setTitle("Méthode allContent - " + commandes.Titre + " " + commandes.version + " " + commandes.branch);
setIconImage(img.getImage());
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("Valider");
btnNewButton.setIcon(new ImageIcon(allContent.class.getResource("/resources/truemini.png")));
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 18));
btnNewButton.setBounds(347, 266, 216, 50);
contentPane.add(btnNewButton);
JLabel lblValeurDeLattribut = new JLabel("Algorithme d'évaluation");
lblValeurDeLattribut.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 13));
lblValeurDeLattribut.setBounds(10, 124, 165, 23);
contentPane.add(lblValeurDeLattribut);
JLabel lblDescription = new JLabel("<html>Cet attribut permet d'évaluer le contenu du node et de celui des nodes enfants.<br>Par conséquent, tous les nodes enfants seront évalués.</html>");
lblDescription.setLabelFor(this);
lblDescription.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblDescription.setBounds(10, 11, 520, 50);
contentPane.add(lblDescription);
comboBoxValeur = new JComboBox<String>();
comboBoxValeur.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
comboBoxValeur.setModel(new DefaultComboBoxModel<String>(new String[] {"strict", "strictSansEspace", "SansCasseEspaceChiffre", "environ"}));
comboBoxValeur.setSelectedItem(valeur);
comboBoxValeur.setBounds(185, 119, 224, 30);
contentPane.add(comboBoxValeur);
JLabel lblPoint = new JLabel("Combien de point ?");
lblPoint.setFont(new Font("Tahoma", Font.BOLD, 13));
lblPoint.setBounds(10, 72, 171, 22);
contentPane.add(lblPoint);
textFieldPoint = new JTextField();
textFieldPoint.setFont(new Font("Tahoma", Font.BOLD, 14));
textFieldPoint.setHorizontalAlignment(SwingConstants.CENTER);
textFieldPoint.setText("0");
textFieldPoint.setBounds(181, 72, 72, 23);
textFieldPoint.setColumns(6);
textFieldPoint.setText(String.valueOf(point));
contentPane.add(textFieldPoint);
lblExplication = new JLabel("<html>Dans le fichier de l'étudiants.<br>Le contenu du node doit être rigoureusement identique, CASSE comprise.</html>");
lblExplication.setFont(new Font("Tahoma", Font.PLAIN, 13));
lblExplication.setForeground(new Color(0, 0, 205));
lblExplication.setVerticalAlignment(SwingConstants.TOP);
if(comboBoxValeur.getSelectedItem().equals("strict")) {
lblExplication.setText("<html>Dans le fichier de l'étudiants.<br>Le contenu du node doit être rigoureusement identique, CASSE comprise.</html>");
}
if(comboBoxValeur.getSelectedItem().equals("strictSansEspace")) {
lblExplication.setText("<html>Dans le fichier de l'étudiants.<br>Le contenu du node doit être rigoureusement identique, CASSE comprise, mais ignore les espaces en début et fin.</html>");
}
if(comboBoxValeur.getSelectedItem().equals("SansCasseEspaceChiffre")) {
lblExplication.setText("<html>Dans le fichier de l'étudiants.<br>La CASSE, les espaces, les chiffres et les caractères accentués sont ignorés.</html>");
}
if(comboBoxValeur.getSelectedItem().equals("environ")) {
lblExplication.setText("<html>Dans le fichier de l'étudiants.<br>Le contenu du node peut être plus ou moins proche (voir le paramètre similude), la CASSE est ignorée.</html>");
}
lblExplication.setBounds(10, 175, 553, 80);
contentPane.add(lblExplication);
JLabel lblNewLabel = new JLabel("<html>Pour supprimer l'évaluation, <br>saisissez 0 point.</html>");
lblNewLabel.setVerticalAlignment(SwingConstants.TOP);
lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel.setFont(new Font("Tahoma", Font.ITALIC, 13));
lblNewLabel.setIcon(new ImageIcon(allContent.class.getResource("/resources/falsemini.png")));
lblNewLabel.setBounds(347, 69, 216, 39);
contentPane.add(lblNewLabel);
comboBoxValeur.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(comboBoxValeur.getSelectedItem().equals("strict")) {
lblExplication.setText("<html>Dans le fichier de l'étudiants.<br>Le contenu du node doit être rigoureusement identique, CASSE comprise.</html>");
}
if(comboBoxValeur.getSelectedItem().equals("strictSansEspace")) {
lblExplication.setText("<html>Dans le fichier de l'étudiants.<br>Le contenu du node doit être rigoureusement identique, CASSE comprise, mais ignore les espaces en début et fin.</html>");
}
if(comboBoxValeur.getSelectedItem().equals("SansCasseEspaceChiffre")) {
lblExplication.setText("<html>Dans le fichier de l'étudiants.<br>La CASSE, les espaces, les chiffres et les caractères accentués sont ignorés.</html>");
}
if(comboBoxValeur.getSelectedItem().equals("environ")) {
lblExplication.setText("<html>Dans le fichier de l'étudiants.<br>Le contenu du node peut être plus ou moins proche (voir le paramètre similude), la CASSE est ignorée.</html>");
}
}
});
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
int point = Integer.valueOf(textFieldPoint.getText());
if(point<0) point =0;
if(!Childs) {
nod.getAttributs().put("allContent", comboBoxValeur.getSelectedItem().toString() + String.valueOf(point));
nod.evaluerAllChildTrue();
J.refreshAffichage(nod);
}else {
if(nod.getNomElt().equals("page")) {
placeAtrtibutAllContentDansLesNodesDeLaPage(nod,comboBoxValeur.getSelectedItem().toString(),point);
}
if(nod.getNomElt().equals("structurepage")) {
for(int i = 0 ; i < nod.getNodes().size(); i++) {
if(nod.getNodes().get(i).getNomElt().equals("page")) {
placeAtrtibutAllContentDansLesNodesDeLaPage(nod.getNodes().get(i),comboBoxValeur.getSelectedItem().toString(),point);
}
}
}
if(nod.getNomElt().equals("text:index-body")) {
for(int i = 0 ; i < nod.getNodes().size(); i++) {
placeAtrtibutAllContentDansLesNodesDeLaPage(nod,comboBoxValeur.getSelectedItem().toString(),point);
}
}
J.refreshAffichage(nod);
}
dispose();
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "Le nombre de point doit être un entier.");
}
TreePath path = fenetres.create.getTree().getSelectionPath();
DefaultTreeModel model = (DefaultTreeModel) fenetres.create.getTree().getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
model.reload(root);
fenetres.create.getTree().setSelectionPath(path);
fenetres.create.getTree().expandPath(path);
fenetres.create.getTextNodeSelect().refreshAffichage(nod);
}
});
setVisible(true);
}
private void placeAtrtibutAllContentDansLesNodesDeLaPage(node nod,String methode, Integer point) {
for(int i = 0 ; i < nod.getNodes().size(); i++) {
if( listeDesNodesAllContent.isAllContent(nod.getNodes().get(i))){
nod.getNodes().get(i).getAttributs().put("allContent", methode+String.valueOf(point));
nod.getNodes().get(i).evaluerAllChildTrue(); }
}
}
}