/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package interfaceuppallcosmos.Vue; import interfaceuppallcosmos.Controle.Constante; import interfaceuppallcosmos.Controle.InterfaceUppaalCosmos; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JFormattedTextField; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTextPane; import org.jdom.JDOMException; /** * * @author Loic Lemonnier */ public class Vue extends JFrame implements ActionListener { private InterfaceUppaalCosmos iuc; private JPanel panneau; JScrollPane scrollPane; private Thread t; // quelques constantes final int LARGEUR_FENETRE = 1024; final int HAUTEUR_FENETRE = 650; // 650 800 final Color couleur_fond = new Color(82,142,199); // bleu clair (82,142,199) final Color couleur_police = Color.black; final Color couleur_champ_inactif = Color.GRAY; final Color couleur_champ_ok = new Color(49,180,49); // vert clair (49,247,49) final Color couleur_champ_erreur = new Color(247,49,49); // rouge clair final String regexDouble = "^(\\d)+(.(\\d)+)?$"; final String regexNom = "^([A-Za-z0-9])+$"; final String regexInt = "^(\\d)+$"; public static final String TOUS_LES_ETATS = "-All states-"; public static final String TOUTES_LES_VARIABLES = "-All variables-"; // ligne 0 private JLabel titre; // titre de l'application // ligne 1 private JLabel labelParcourirUppaal; private JButton boutonParcourirUppaal, boutonParserUppaal; private JTextField choixUppaal; private JFileChooser chooser; // ligne 2 private JLabel labelFormule; private JTextField champFormule; // ligne 3 private JLabel labelNomConstante, labelValeurConstante, labelTypeConstante; private JTextField champNomConstante; private JFormattedTextField champValeurConstante; private JButton boutonAjouterConstante; private JComboBox listeTypeConstante; // ligne 4 private JLabel labelConstante, labelSupprimerConstante; private JTextPane champConstantes; private JScrollPane scroll; private JButton boutonSupprimerConstante; private JComboBox listeConstantes; // ligne 5 et 6 private JLabel labelNomVariable, labelVariable, labelSupprimerVariable; private JTextPane champVariables; private JScrollPane scroll2; private JTextField champNomVariable; private JButton boutonAjouterVariable, boutonSupprimerVariable; private JComboBox listeVariables; // ligne 7 et 8 private JLabel labelEtatsInitiaux; private JTextPane champEtatsInitiaux; private JComboBox listeAjoutEtatsInitiaux, listeSupprEtatsInitiaux; private JButton boutonAjoutEtatInitial, boutonSupprimerEtatInitial; // ligne 9 et 10 private JLabel labelEtatsFinaux; private JTextPane champEtatsFinaux; private JComboBox listeAjoutEtatsFinaux, listeSupprEtatsFinaux; private JButton boutonAjoutEtatFinal, boutonSupprimerEtatFinal; // ligne 11 et 12 private JLabel labelPropLogMarquage, labelDans; private JTextPane champPropLogMarquage; private JTextField valeurPropLogMarquage; private JComboBox listeEtatsPropLogMarquage; private JButton boutonModifierPropLogMarquage; // ligne 13 et 14 private JLabel labelTauxVariables; private JTextPane champTauxVariables; private JComboBox listeEtatsTauxVariables, listeVariablesTauxVariables; private JTextField valeurTauxVariables; private JButton boutonModifierTauxVariables; // ligne X private JButton boutonGenerer; private JTextField valeurNomLHA; private JLabel nomFichierLHA, lha; private String nomFichierUppAal; public Vue() { super(); setTitle("Interface UppAal - Cosmos"); setSize(LARGEUR_FENETRE,HAUTEUR_FENETRE); // dimension de la fenetre setResizable(true); // fenetre redimensionnable setLocationRelativeTo(null); // fenetre centrée par défaut setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // active la croix rouge pour la fermeture // initialisation du JPanel de la fenêtre panneau = new JPanel(); // création du JPanel de la fenêtre scrollPane = new JScrollPane(panneau); // scroll pour la fenetre principale scrollPane.getVerticalScrollBar().setUnitIncrement(32); // augmente la vitesse du scroll panneau.setLayout(new BorderLayout()); // on ajoute un layout pour placer les éléments comme on veut panneau.setBackground(couleur_fond); // couleur de fond du panneau this.setContentPane(scrollPane); // on ajoute le panneau à la fenêtre panneau.add(build(),BorderLayout.NORTH); // on appelle la fonction build qui construit tous les éléments de la fenetre } public JPanel build() { JPanel p = new JPanel(); // JPanel principal p.setLayout(new BorderLayout()); p.setBackground(couleur_fond); p.setForeground(Color.black); JPanel p_haut = new JPanel(); // puis 3 trois JPanel pour placer les éléments comme on veut p_haut.setLayout(new BorderLayout()); p_haut.setBackground(couleur_fond); JPanel p_milieu = new JPanel(); p_milieu.setLayout(new BorderLayout()); p_milieu.setBackground(couleur_fond); JPanel p_bas = new JPanel(); p_bas.setLayout(new BorderLayout()); p_bas.setBackground(couleur_fond); JPanel ptemp = new JPanel(); ptemp.setLayout(new BorderLayout()); ptemp.setBackground(couleur_fond); // Ligne 0 - titre de l'application JPanel ligne0 = new JPanel(); // le JPanel de la ligne ligne0.setLayout(new FlowLayout()); titre = new JLabel("Interface UppAal - COSMOS"); // titre de l'application //titre.setBorder(BorderFactory.createLineBorder(Color.black)); // encadrement titre.setForeground(couleur_police); // couleur de la police titre.setFont(new Font("Arial", Font.BOLD, 24)); // modif de la police pour que le titre soit gros ligne0.setBackground(couleur_fond); // couleur du couleur_fond ligne0.add(titre); // ajout de la ligne au panel de la ligne ptemp.add(ligne0,BorderLayout.NORTH); // ajout de la ligne au panel // ligne 1 - choix du fichier Uppaal JPanel ligne1 = new JPanel(); ligne1.setLayout(new FlowLayout(FlowLayout.LEFT)); ligne1.setBackground(couleur_fond); labelParcourirUppaal = new JLabel("Fichier Uppaal (.xml): "); labelParcourirUppaal.setForeground(couleur_police); ligne1.add(labelParcourirUppaal); choixUppaal = new JTextField(""); choixUppaal.setPreferredSize(new Dimension(400,25)); choixUppaal.setEditable(false); choixUppaal.setBackground(couleur_champ_inactif); ligne1.add(choixUppaal); boutonParcourirUppaal = new JButton("Browse"); ligne1.add(boutonParcourirUppaal); boutonParserUppaal = new JButton("Parse"); boutonParserUppaal.setBackground(Color.yellow); ligne1.add(boutonParserUppaal); ptemp.add(ligne1,BorderLayout.WEST); // ligne 2 - formule HASL JPanel ligne2 = new JPanel(); ligne2.setLayout(new FlowLayout(FlowLayout.LEFT)); ligne2.setBackground(couleur_fond); labelFormule = new JLabel("HASL Formula: "); labelFormule.setForeground(couleur_police); ligne2.add(labelFormule); champFormule = new JTextField("AVG()"); champFormule.setPreferredSize(new Dimension(400,25)); ligne2.add(champFormule); ptemp.add(ligne2,BorderLayout.SOUTH); p_haut.add(ptemp,BorderLayout.NORTH); ptemp = new JPanel(); // réinitialiation du panel temporaire ptemp.setLayout(new BorderLayout()); ptemp.setBackground(couleur_fond); // ligne 3 - Label liste constantes JPanel ligne3 = new JPanel(); ligne3.setLayout(new FlowLayout(FlowLayout.LEFT, 75,0)); ligne3.setBackground(couleur_fond); labelConstante = new JLabel("Constants"); labelConstante.setForeground(couleur_police); ligne3.add(labelConstante); ptemp.add(ligne3,BorderLayout.NORTH); // ligne 4 - liste des constantes - ajout et suppression JPanel ligne4 = new JPanel(); ligne4.setLayout(new FlowLayout(FlowLayout.LEFT)); ligne4.setBackground(couleur_fond); champConstantes = new JTextPane(); //champConstantes.setText("Nom" + "\t"+ "Type"+ "\t"+ "Valeur"+ "\n"); champConstantes.setText("Aucune constante déclarée."); //champConstantes.setContentType("text/html"); // active le HTML pour la mise en forme champConstantes.setPreferredSize(new Dimension(300,100)); champConstantes.setBackground(couleur_champ_inactif); scroll = new JScrollPane(champConstantes); // ajout d'un scroll pour l'affichage des constantes scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); ligne4.add(scroll); JPanel l1 = new JPanel(); // ligne d'ajout des variables l1.setLayout(new FlowLayout(FlowLayout.LEFT)); l1.setBackground(couleur_fond); labelNomConstante = new JLabel("Name : "); // nom de la constante labelNomConstante.setForeground(couleur_police); l1.add(labelNomConstante); champNomConstante = new JTextField(""); champNomConstante.setPreferredSize(new Dimension(100,25)); l1.add(champNomConstante); labelTypeConstante = new JLabel("Type : "); // type de la constante labelTypeConstante.setForeground(couleur_police); l1.add(labelTypeConstante); listeTypeConstante = new JComboBox(); // type de la constante listeTypeConstante.addItem("double"); listeTypeConstante.addItem("int"); l1.add(listeTypeConstante); labelValeurConstante = new JLabel("Value : "); // valeur de la constante labelValeurConstante.setForeground(couleur_police); l1.add(labelValeurConstante); champValeurConstante = new JFormattedTextField(); champValeurConstante.setPreferredSize(new Dimension(100,25)); l1.add(champValeurConstante); boutonAjouterConstante = new JButton("Add constante"); boutonAjouterConstante.setBackground(Color.yellow); boutonAjouterConstante.setEnabled(false); l1.add(boutonAjouterConstante); JPanel l2 = new JPanel(); // ligne de suppression des constantes l2.setLayout(new FlowLayout(FlowLayout.LEFT)); l2.setBackground(couleur_fond); labelSupprimerConstante = new JLabel("Remove constant : "); labelSupprimerConstante.setForeground(couleur_police); l2.add(labelSupprimerConstante); listeConstantes = new JComboBox(); // liste déroulante pour choisir la constante à supprimer l2.add(listeConstantes); boutonSupprimerConstante = new JButton("Remove constant"); boutonSupprimerConstante.setBackground(Color.yellow); boutonSupprimerConstante.setEnabled(false); l2.add(boutonSupprimerConstante); JPanel l3 = new JPanel(); // panel en plus pour mettre ajout au dessus de suppression... l3.setLayout(new BorderLayout()); l3.add(l1,BorderLayout.NORTH); l3.add(l2,BorderLayout.CENTER); ligne4.add(l3); // ... sur la même ligne que le reste (= liste des constantes). ptemp.add(ligne4,BorderLayout.CENTER); // ligne 5 et 6 - gestion des variables JPanel ligne5 = new JPanel(); ligne5.setLayout(new FlowLayout(FlowLayout.LEFT, 75,0)); // décalage sur la droite ligne5.setBackground(couleur_fond); labelVariable = new JLabel("Variables"); labelVariable.setForeground(couleur_police); ligne5.add(labelVariable); // ajout du label au panel ptemp.add(ligne5, BorderLayout.SOUTH); p_haut.add(ptemp, BorderLayout.CENTER); ptemp = new JPanel(); // réinitialiation du panel temporaire ptemp.setLayout(new BorderLayout()); ptemp.setBackground(couleur_fond); JPanel ligne6 = new JPanel(); ligne6.setLayout(new FlowLayout(FlowLayout.LEFT)); ligne6.setBackground(couleur_fond); champVariables = new JTextPane(); // liste des variables champVariables.setText("Aucune variable déclarée."); champVariables.setPreferredSize(new Dimension(300,100)); champVariables.setBackground(couleur_champ_inactif); scroll = new JScrollPane(champVariables); // ajout d'un scroll pour l'affichage des variables scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); ligne6.add(scroll); l1 = new JPanel(); // ligne d'ajout des variables l1.setLayout(new FlowLayout(FlowLayout.LEFT)); l1.setBackground(couleur_fond); labelNomVariable = new JLabel("Name : "); // nom de la variable labelNomVariable.setForeground(couleur_police); l1.add(labelNomVariable); champNomVariable = new JTextField(""); // zone de saisie nom de la variable champNomVariable.setPreferredSize(new Dimension(100,25)); l1.add(champNomVariable); boutonAjouterVariable = new JButton("Add variable"); boutonAjouterVariable.setBackground(Color.yellow); boutonAjouterVariable.setEnabled(false); l1.add(boutonAjouterVariable); l2 = new JPanel(); // ligne de suppression des variables l2.setLayout(new FlowLayout(FlowLayout.LEFT)); l2.setBackground(couleur_fond); labelSupprimerVariable = new JLabel("Remove variable : "); labelSupprimerVariable.setForeground(couleur_police); l2.add(labelSupprimerVariable); listeVariables = new JComboBox(); // liste déroulante pour choisir la variable à supprimer l2.add(listeVariables); boutonSupprimerVariable = new JButton("Remove variable"); boutonSupprimerVariable.setBackground(Color.yellow); boutonSupprimerVariable.setEnabled(false); l2.add(boutonSupprimerVariable); l3 = new JPanel(); // panel en plus pour mettre ajout au dessus de suppression... l3.setLayout(new BorderLayout()); l3.add(l1,BorderLayout.NORTH); l3.add(l2,BorderLayout.CENTER); ligne6.add(l3); // ... sur la même ligne que le reste (= liste des variables). ptemp.add(ligne6, BorderLayout.NORTH); // ligne 7 et 8 - gestion des états initiaux JPanel ligne7 = new JPanel(); ligne7.setLayout(new FlowLayout(FlowLayout.LEFT, 75,0)); // décalage sur la droite ligne7.setBackground(couleur_fond); labelEtatsInitiaux = new JLabel("Initial states"); labelEtatsInitiaux.setForeground(couleur_police); ligne7.add(labelEtatsInitiaux); // ajout du label au panel ptemp.add(ligne7, BorderLayout.CENTER); JPanel ligne8 = new JPanel(); ligne8.setLayout(new FlowLayout(FlowLayout.LEFT)); ligne8.setBackground(couleur_fond); champEtatsInitiaux = new JTextPane(); // liste des etats initiaux champEtatsInitiaux.setText("Aucun état initial déclaré."); champEtatsInitiaux.setPreferredSize(new Dimension(300,100)); champEtatsInitiaux.setBackground(couleur_champ_erreur); scroll = new JScrollPane(champEtatsInitiaux); // ajout d'un scroll pour l'affichage des variables scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); ligne8.add(scroll); l1 = new JPanel(); // ligne d'ajout des états initiaux l1.setLayout(new FlowLayout(FlowLayout.LEFT)); l1.setBackground(couleur_fond); listeAjoutEtatsInitiaux = new JComboBox(); // liste pour choisir l'état à déf en état initial listeAjoutEtatsInitiaux.setPreferredSize(new Dimension(100,25)); l1.add(listeAjoutEtatsInitiaux); boutonAjoutEtatInitial = new JButton("Add initial state"); boutonAjoutEtatInitial.setBackground(Color.yellow); boutonAjoutEtatInitial.setEnabled(false); l1.add(boutonAjoutEtatInitial); l2 = new JPanel(); // ligne de suppression des états initiaux l2.setLayout(new FlowLayout(FlowLayout.LEFT)); l2.setBackground(couleur_fond); listeSupprEtatsInitiaux = new JComboBox(); // liste pour choisir l'état qui ne doit plus être initial l2.add(listeSupprEtatsInitiaux); boutonSupprimerEtatInitial = new JButton("Remove initial state"); boutonSupprimerEtatInitial.setBackground(Color.yellow); boutonSupprimerEtatInitial.setEnabled(false); l2.add(boutonSupprimerEtatInitial); l3 = new JPanel(); // panel en plus pour mettre ajout au dessus de suppression... l3.setLayout(new BorderLayout()); l3.add(l1,BorderLayout.NORTH); l3.add(l2,BorderLayout.CENTER); ligne8.add(l3); // ... sur la même ligne que le reste (= liste des variables). ptemp.add(ligne8, BorderLayout.SOUTH); p_haut.add(ptemp, BorderLayout.SOUTH); ptemp = new JPanel(); // réinitialiation du panel temporaire ptemp.setLayout(new BorderLayout()); ptemp.setBackground(couleur_fond); // ligne 9 et 10 - gestion des états finaux JPanel ligne9 = new JPanel(); ligne9.setLayout(new FlowLayout(FlowLayout.LEFT, 75,0)); // décalage sur la droite ligne9.setBackground(couleur_fond); labelEtatsFinaux = new JLabel("Final states"); labelEtatsFinaux.setForeground(couleur_police); ligne9.add(labelEtatsFinaux); // ajout du label au panel ptemp.add(ligne9, BorderLayout.NORTH); JPanel ligne10 = new JPanel(); ligne10.setLayout(new FlowLayout(FlowLayout.LEFT)); ligne10.setBackground(couleur_fond); champEtatsFinaux = new JTextPane(); // liste des etats finaux champEtatsFinaux.setText("Aucun état final déclaré."); champEtatsFinaux.setPreferredSize(new Dimension(300,100)); champEtatsFinaux.setBackground(couleur_champ_erreur); scroll = new JScrollPane(champEtatsFinaux); // ajout d'un scroll pour l'affichage des variables scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); ligne10.add(scroll); l1 = new JPanel(); // ligne d'ajout des états finaux l1.setLayout(new FlowLayout(FlowLayout.LEFT)); l1.setBackground(couleur_fond); listeAjoutEtatsFinaux = new JComboBox(); // liste pour choisir l'état à déf en état final l1.add(listeAjoutEtatsFinaux); boutonAjoutEtatFinal = new JButton("Add final state"); boutonAjoutEtatFinal.setBackground(Color.yellow); boutonAjoutEtatFinal.setEnabled(false); l1.add(boutonAjoutEtatFinal); l2 = new JPanel(); // ligne de suppression des états finaux l2.setLayout(new FlowLayout(FlowLayout.LEFT)); l2.setBackground(couleur_fond); listeSupprEtatsFinaux = new JComboBox(); // liste pour choisir l'état qui ne doit plus être initial l2.add(listeSupprEtatsFinaux); boutonSupprimerEtatFinal = new JButton("Remove final final"); boutonSupprimerEtatFinal.setBackground(Color.yellow); boutonSupprimerEtatFinal.setEnabled(false); l2.add(boutonSupprimerEtatFinal); l3 = new JPanel(); // panel en plus pour mettre ajout au dessus de suppression... l3.setLayout(new BorderLayout()); l3.add(l1,BorderLayout.NORTH); l3.add(l2,BorderLayout.CENTER); ligne10.add(l3); // ... sur la même ligne que le reste (= liste des variables). ptemp.add(ligne10, BorderLayout.CENTER); // ligne 11 et 12 - gestion des prop logique sur marquage JPanel ligne11 = new JPanel(); ligne11.setLayout(new FlowLayout(FlowLayout.LEFT, 25,0)); // décalage sur la droite ligne11.setBackground(couleur_fond); labelPropLogMarquage = new JLabel("Propriétés logiques sur le marquage"); labelPropLogMarquage.setForeground(couleur_police); ligne11.add(labelPropLogMarquage); // ajout du label au panel ptemp.add(ligne11, BorderLayout.SOUTH); p_milieu.add(ptemp, BorderLayout.NORTH); ptemp = new JPanel(); // réinitialiation du panel temporaire ptemp.setLayout(new BorderLayout()); ptemp.setBackground(couleur_fond); JPanel ligne12 = new JPanel(); ligne12.setLayout(new FlowLayout(FlowLayout.LEFT)); ligne12.setBackground(couleur_fond); champPropLogMarquage = new JTextPane(); // liste des prop. logiques sur le marquage champPropLogMarquage.setText(""); champPropLogMarquage.setPreferredSize(new Dimension(300,100)); champPropLogMarquage.setBackground(couleur_champ_erreur); scroll = new JScrollPane(champPropLogMarquage); // ajout d'un scroll pour l'affichage des variables scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); ligne12.add(scroll); labelDans = new JLabel("In :"); labelDans.setForeground(couleur_police); ligne12.add(labelDans); listeEtatsPropLogMarquage = new JComboBox(); // liste pour choisir l'état auquel on veut ajouter une prop logique // listeEtatsPropLogMarquage.addItemListener(new ItemState()); // listeEtatsPropLogMarquage.addActionListener(new ItemAction()); ligne12.add(listeEtatsPropLogMarquage); labelPropLogMarquage = new JLabel("Logical property :"); labelPropLogMarquage.setForeground(couleur_police); ligne12.add(labelPropLogMarquage); valeurPropLogMarquage = new JTextField(); // propriété logique du marquage valeurPropLogMarquage.setPreferredSize(new Dimension(200,25)); ligne12.add(valeurPropLogMarquage); boutonModifierPropLogMarquage = new JButton("Change property"); // bouton de modif de la propriété boutonModifierPropLogMarquage.setBackground(Color.yellow); boutonModifierPropLogMarquage.setEnabled(false); ligne12.add(boutonModifierPropLogMarquage); ptemp.add(ligne12, BorderLayout.NORTH); // ligne 13 et 14 - gestion des taux des variables JPanel ligne13 = new JPanel(); ligne13.setLayout(new FlowLayout(FlowLayout.LEFT, 75,0)); // décalage sur la droite ligne13.setBackground(couleur_fond); labelTauxVariables = new JLabel("Taux des variables"); labelTauxVariables.setForeground(couleur_police); ligne13.add(labelTauxVariables); // ajout du label au panel ptemp.add(ligne13, BorderLayout.CENTER); JPanel ligne14 = new JPanel(); ligne14.setLayout(new FlowLayout(FlowLayout.LEFT)); ligne14.setBackground(couleur_fond); champTauxVariables = new JTextPane(); // liste des prop. logiques sur le marquage champTauxVariables.setText(""); champTauxVariables.setPreferredSize(new Dimension(300,100)); champTauxVariables.setBackground(couleur_champ_erreur); scroll = new JScrollPane(champTauxVariables); // ajout d'un scroll pour l'affichage des variables scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); ligne14.add(scroll); listeEtatsTauxVariables = new JComboBox(); // liste pour choisir l'état auquel on veut modifier le taux listeEtatsTauxVariables.addItem(TOUS_LES_ETATS); ligne14.add(listeEtatsTauxVariables); listeVariablesTauxVariables = new JComboBox(); // liste pour choisir la variable auquel on veut modifier le taux listeVariablesTauxVariables.addItem(TOUTES_LES_VARIABLES); ligne14.add(listeVariablesTauxVariables); valeurTauxVariables = new JTextField(); // taux de la variable valeurTauxVariables.setPreferredSize(new Dimension(200,25)); ligne14.add(valeurTauxVariables); boutonModifierTauxVariables = new JButton("Change rate"); // bouton de modif du taux de la variable boutonModifierTauxVariables.setBackground(Color.yellow); boutonModifierTauxVariables.setEnabled(false); ligne14.add(boutonModifierTauxVariables); ptemp.add(ligne14, BorderLayout.SOUTH); p_milieu.add(ptemp, BorderLayout.CENTER); ptemp = new JPanel(); // réinitialiation du panel temporaire ptemp.setLayout(new BorderLayout()); ptemp.setBackground(couleur_fond); // ligne X - génération du .lha JPanel ligne17 = new JPanel(); ligne17.setLayout(new FlowLayout(FlowLayout.RIGHT)); ligne17.setBackground(couleur_fond); nomFichierLHA = new JLabel("Nom du fichier LHA"); nomFichierLHA.setForeground(couleur_police); ligne17.add(nomFichierLHA); valeurNomLHA = new JTextField(""); // champ pour indiquer le nom du .lha valeurNomLHA.setPreferredSize(new Dimension(100,25)); valeurNomLHA.setBackground(couleur_champ_inactif); ligne17.add(valeurNomLHA); lha = new JLabel(".lha"); // titre de l'application lha.setForeground(couleur_police); // couleur de la police ligne17.add(lha); // ajout de la ligne au panel de la ligne boutonGenerer = new JButton("Generate"); // bouton pour générer le .lha boutonGenerer.setEnabled(false); ligne17.add(boutonGenerer); ptemp.add(ligne17,BorderLayout.NORTH); p_milieu.add(ptemp,BorderLayout.SOUTH); // ajout des ActionListener boutonParcourirUppaal.addActionListener(this); boutonParserUppaal.addActionListener(this); boutonAjouterConstante.addActionListener(this); boutonSupprimerConstante.addActionListener(this); boutonAjouterVariable.addActionListener(this); boutonSupprimerVariable.addActionListener(this); boutonAjoutEtatInitial.addActionListener(this); boutonSupprimerEtatInitial.addActionListener(this); boutonAjoutEtatFinal.addActionListener(this); boutonSupprimerEtatFinal.addActionListener(this); boutonModifierPropLogMarquage.addActionListener(this); boutonModifierTauxVariables.addActionListener(this); boutonGenerer.addActionListener(this); p.add(p_haut, BorderLayout.NORTH); p.add(p_milieu, BorderLayout.CENTER); p.add(p_bas, BorderLayout.SOUTH); return p; } public static void main(String[] args) { Vue v = new Vue(); v.setVisible(true); // rend la fenetre visible } public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); // récupère le bouton actionné //choixUppaal.setText("/home/volodim/NetBeansProjects/InterfaceUppallCosmos/ps.xml"); // ACTION 1 - choix du fichier UppAal if(source == boutonParcourirUppaal) { chooser = new JFileChooser(); int retour = chooser.showOpenDialog(panneau); if(retour == JFileChooser.APPROVE_OPTION) { choixUppaal.setText(chooser.getSelectedFile().getPath().toString()); // affichage du fichier choisi dans la GUI nomFichierUppAal = chooser.getSelectedFile().getName(); } } // ACTION 2 - parsage du fichier UppAal else if(source == boutonParserUppaal) { if(choixUppaal.getText().toString().endsWith(".xml")) { try { iuc = new InterfaceUppaalCosmos(); iuc.parserXMLUppAal(new File(choixUppaal.getText())); // parsage System.out.println("Nom fichier uppaal "+nomFichierUppAal); valeurNomLHA.setText(nomFichierUppAal.replaceAll(".xml", "")); majAffichageConstantes(); majAffichageEtatsInitiaux(); majAffichageEtatsFinaux(); majAffichagePropLogMarquage(); majAffichageTauxVariables(); majAffichageVariables(); majAffichageGenererLHA(); } catch (JDOMException ex) { Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex); } } else { choixUppaal.setText(""); JOptionPane.showConfirmDialog(null, "Vous devez choisir un fichier XML.", "Parsage impossible", JOptionPane.PLAIN_MESSAGE ); } } // ACTION 3 - Ajouter une constante else if(source == boutonAjouterConstante) { String typeConstante = listeTypeConstante.getSelectedItem().toString(); String messageErreur = ""; boolean typeOk; boolean nomOk = champNomConstante.getText().matches(regexNom); boolean valeurOk; boolean csteExiste = false; double valeurConstante = 0; // verification du nom if(!nomOk) messageErreur = messageErreur + "Le nom doit être composé uniquement de lettres et de chiffres.\n"; else { csteExiste = iuc.estUneConstante(champNomConstante.getText()); } if(csteExiste) messageErreur = messageErreur + "Cette constante existe déjà.\n"; // verification du type if(typeConstante.equals("int") || typeConstante.equals("double")) typeOk = true; else { typeOk = false; messageErreur = messageErreur + "Le type de la constante doit être int ou double.\n"; } // verif valeur suivant le type if(typeConstante.equals("double")) { valeurOk = champValeurConstante.getText().replaceAll(",", ".").matches(regexDouble); if(valeurOk) valeurConstante = Double.parseDouble(champValeurConstante.getText().replaceAll(",", ".")); else messageErreur = messageErreur + "Valeur de la constante incorrecte.\n"; } else if(typeConstante.equals("int")) { valeurOk = champValeurConstante.getText().matches(regexInt); if(valeurOk) valeurConstante = Double.parseDouble(champValeurConstante.getText()); else messageErreur = messageErreur + "Valeur de la constante incorrecte.\n"; } else { valeurOk = false; messageErreur = messageErreur + "La valeur de la constante incorrecte.\n"; } // ajout de la constante si tout est ok if(nomOk && valeurOk && typeOk && !csteExiste) { String nomConstante = champNomConstante.getText(); iuc.ajouterConstante(new Constante(nomConstante, typeConstante, valeurConstante)); majAffichageConstantes(); // remise a zero des champs champNomConstante.setText(""); champValeurConstante.setText(""); } else { // sinon message d'erreur JOptionPane.showConfirmDialog(null, messageErreur, "Erreur(s) sur la constante", JOptionPane.PLAIN_MESSAGE ); } } // ACTION 4 - Retirer une constante else if(source == boutonSupprimerConstante && !iuc.getListeConstantes().isEmpty()) { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog(null, "Etes-vous sûr de vouloir supprimer cette constante ?", "Confirmation suppression d'une constante", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(option == JOptionPane.OK_OPTION) { int indexConstante = listeConstantes.getSelectedIndex(); iuc.supprimerConstante(indexConstante); // supprime la constante choisi majAffichageConstantes(); } } // ACTION 5 - ajouter une variable else if(source == boutonAjouterVariable) { String nomVariable, messageErreur = ""; boolean nomOk = champNomVariable.getText().matches(regexNom); boolean varExiste = false; if(nomOk) varExiste = iuc.estUneVariable(champNomVariable.getText()); else { messageErreur = "Le nom doit être composé uniquement de lettres et de chiffres.\n"; JOptionPane.showConfirmDialog(null, messageErreur, "Erreur(s) sur la variable", JOptionPane.PLAIN_MESSAGE ); } if(varExiste) { messageErreur = "Cette variable existe déjà.\n"; JOptionPane.showConfirmDialog(null, messageErreur, "Erreur(s) sur la variable", JOptionPane.PLAIN_MESSAGE ); } if(nomOk && !varExiste) { nomVariable = champNomVariable.getText(); iuc.ajouterVariable(nomVariable); majAffichageVariables(); majAffichageTauxVariables(); champNomVariable.setText(""); } } // ACTION 6 - supprimer une variable else if(source == boutonSupprimerVariable && !iuc.getListeVariables().isEmpty()) { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog(null, "Etes-vous sûr de vouloir supprimer cette variable ?", "Confirmation suppression d'une variable", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(option == JOptionPane.OK_OPTION) { int indexVariable = listeVariables.getSelectedIndex(); iuc.supprimerVariable(indexVariable); // supprime la constante choisi majAffichageVariables(); majAffichageTauxVariables(); } } // ACTION 7 - ajouter état initial else if(source == boutonAjoutEtatInitial) { // ajout si l'état existe if(iuc.estUnEtat((String) listeAjoutEtatsInitiaux.getSelectedItem())) { iuc.ajouterEtatInitial((String) listeAjoutEtatsInitiaux.getSelectedItem()); t = new Thread(new PlayAnimation()); t.start(); } // sinon message d'erreur else { JOptionPane.showConfirmDialog(null, "Cet état n'existe pas.", "Erreur sur l'état", JOptionPane.PLAIN_MESSAGE ); } } // ACTION 8 - supprimer état initial else if(source == boutonSupprimerEtatInitial) { // suppression si l'état initial existe if(iuc.estUnEtatInitial((String) listeSupprEtatsInitiaux.getSelectedItem())) { iuc.retirerEtatInitial((String) listeSupprEtatsInitiaux.getSelectedItem()); majAffichageEtatsInitiaux(); } else { // sinon message d'erreur (ne devrait pas arriver) JOptionPane.showConfirmDialog(null, "Cet état n'est pas initial", "Erreur sur l'état", JOptionPane.PLAIN_MESSAGE ); } } // ACTION 9 - ajouter état final else if(source == boutonAjoutEtatFinal) { // ajout si l'état existe if(iuc.estUnEtat((String) listeAjoutEtatsFinaux.getSelectedItem())) { iuc.ajouterEtatFinal((String) listeAjoutEtatsFinaux.getSelectedItem()); majAffichageEtatsFinaux(); } // sinon message d'erreur else { JOptionPane.showConfirmDialog(null, "Cet état n'existe pas.", "Erreur sur l'état", JOptionPane.PLAIN_MESSAGE ); } } // ACTION 10 - supprimer état final else if(source == boutonSupprimerEtatFinal) { // suppression si l'état initial existe if(iuc.estUnEtatFinal((String) listeSupprEtatsFinaux.getSelectedItem())) { iuc.retirerEtatFinal((String) listeSupprEtatsFinaux.getSelectedItem()); majAffichageEtatsFinaux(); } else { // sinon message d'erreur (ne devrait pas arriver) JOptionPane.showConfirmDialog(null, "Cet état n'est pas final", "Erreur sur l'état", JOptionPane.PLAIN_MESSAGE ); } } // ACTION 11 - modification d'une propriété logique else if(source == boutonModifierPropLogMarquage) { String propLog = valeurPropLogMarquage.getText(); valeurPropLogMarquage.setText(""); String nomEtat = listeEtatsPropLogMarquage.getSelectedItem().toString(); if(iuc.estUnEtat(nomEtat)) { int index = iuc.indexEtat(nomEtat); iuc.getListeEtats().get(index).setProprieteLogique(propLog); majAffichagePropLogMarquage(); } else { JOptionPane.showConfirmDialog(null, "Cet état n'existe pas.", "Erreur sur l'état", JOptionPane.PLAIN_MESSAGE ); } } // ACTION 12 - modification d'un taux d'une variable else if(source == boutonModifierTauxVariables) { String nomEtat = listeEtatsTauxVariables.getSelectedItem().toString().trim(); String variable = listeVariablesTauxVariables.getSelectedItem().toString().trim(); if(valeurTauxVariables.getText().matches(regexInt)) { iuc.setTauxVariable(nomEtat, variable, Integer.parseInt(valeurTauxVariables.getText())); System.out.println("Nom "+nomEtat+ " variable "+variable+ " taux "+Integer.parseInt(valeurTauxVariables.getText())); majAffichageTauxVariables(); } else { JOptionPane.showConfirmDialog(null, "Le taux doit être un entier.", "Erreur sur le taux", JOptionPane.PLAIN_MESSAGE ); } valeurTauxVariables.setText(""); // efface le champ } // ACTION 13 - générer le .lha else if(source == boutonGenerer) { String nomFichier = valeurNomLHA.getText(); if(nomFichier.matches(regexNom)) { nomFichier = nomFichier + ".lha"; // ajout de l'extension au nom du fichier if(iuc.verification()) { try { iuc.creationFichierCosmos(nomFichier); } catch (FileNotFoundException ex) { Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex); } } else JOptionPane.showConfirmDialog(null, "Les champs en rouge sont incorrects.", "Erreur sur le nom", JOptionPane.PLAIN_MESSAGE ); } else { JOptionPane.showConfirmDialog(null, "Le nom du fichier est incorrect.", "Erreur sur le nom", JOptionPane.PLAIN_MESSAGE ); } valeurTauxVariables.setText(""); // efface le champ } } public void majAffichageConstantes() { ArrayList c = iuc.getListeConstantes(); String s; // maj des boutons boutonAjouterConstante.setEnabled(true); if(c.size() == 0) boutonSupprimerConstante.setEnabled(false); else boutonSupprimerConstante.setEnabled(true); // maj des listes et resume if(c.size() > 0) s = "Nom" + "\t"+ "Type"+ "\t"+ "Valeur"+ "\n"; else s = "Aucune constante déclarée.\n"; listeConstantes.removeAllItems(); for(int i = 0; i < c.size(); i++) { s = s + c.get(i).getNom() + "\t" + c.get(i).getType() + "\t" + c.get(i).getValeur() + "\n"; listeConstantes.addItem(c.get(i).getNom()); // maj liste des constantes pour la suppression } champConstantes.setText(s); // maj resume des constantes } public void majAffichageVariables() { ArrayList v = iuc.getListeVariables(); String s; // maj des boutons boutonAjouterVariable.setEnabled(true); if(v.size() == 0) boutonSupprimerVariable.setEnabled(false); else boutonSupprimerVariable.setEnabled(true); // maj du resume if(iuc.getListeVariables().size() > 0) { s = ""; champVariables.setBackground(couleur_champ_ok); } else { s = "Aucune variable déclarée.\n"; champVariables.setBackground(couleur_champ_erreur); } // maj liste déroulante listeVariables.removeAllItems(); for(int i = 0; i < v.size(); i++) { s = s + v.get(i) + "\n"; listeVariables.addItem(v.get(i)); // maj liste des constantes pour la suppression } champVariables.setText(s); // maj resume des constantes } public void majAffichageEtatsInitiaux() { //System.out.println("\nmajAffichageEtatsInitiaux()"); // maj des boutons if(iuc.nombreEtatsInitiaux() < iuc.getListeEtats().size()) boutonAjoutEtatInitial.setEnabled(true); else boutonAjoutEtatInitial.setEnabled(false); if(iuc.nombreEtatsInitiaux() == 0) boutonSupprimerEtatInitial.setEnabled(false); else boutonSupprimerEtatInitial.setEnabled(true); // maj du resumé String s; if(iuc.nombreEtatsInitiaux() > 0) { s = ""; champEtatsInitiaux.setBackground(couleur_champ_ok); } else { s = "Aucun état initial déclaré."; champEtatsInitiaux.setBackground(couleur_champ_erreur); } // maj liste déroulante et resume listeAjoutEtatsInitiaux.removeAllItems(); listeSupprEtatsInitiaux.removeAllItems(); for(int i = 0; i < iuc.getListeEtats().size(); i++) { //System.out.println("For "); if(iuc.getListeEtats().get(i).getInitialLocation()) { listeSupprEtatsInitiaux.addItem(iuc.getListeEtats().get(i).getNom()); s = s + iuc.getListeEtats().get(i).getNom() + "\n"; } else { listeAjoutEtatsInitiaux.addItem(iuc.getListeEtats().get(i).getNom()); } } champEtatsInitiaux.setText(s); } public void majAffichageEtatsFinaux() { // maj des boutons if(iuc.nombreEtatsFinaux() < iuc.getListeEtats().size()) boutonAjoutEtatFinal.setEnabled(true); else boutonAjoutEtatFinal.setEnabled(false); if(iuc.nombreEtatsFinaux() == 0) boutonSupprimerEtatFinal.setEnabled(false); else boutonSupprimerEtatFinal.setEnabled(true); String s; if(iuc.nombreEtatsFinaux() > 0) { s = ""; champEtatsFinaux.setBackground(couleur_champ_ok); } else { s = "Aucun état final déclaré."; champEtatsFinaux.setBackground(couleur_champ_erreur); } // maj liste déroulante et resume listeAjoutEtatsFinaux.removeAllItems(); listeSupprEtatsFinaux.removeAllItems(); for(int i = 0; i < iuc.getListeEtats().size(); i++) { if(iuc.getListeEtats().get(i).getFinalLocation()) { listeSupprEtatsFinaux.addItem(iuc.getListeEtats().get(i).getNom()); s = s + iuc.getListeEtats().get(i).getNom() + "\n"; } else { listeAjoutEtatsFinaux.addItem(iuc.getListeEtats().get(i).getNom()); } } champEtatsFinaux.setText(s); } public void majAffichagePropLogMarquage() { boutonModifierPropLogMarquage.setEnabled(true); String s = ""; listeEtatsPropLogMarquage.removeAllItems(); for(int i = 0; i < iuc.getListeEtats().size(); i++) { s = s + iuc.getListeEtats().get(i).getNom() +"\t"+ iuc.getListeEtats().get(i).getProprieteLogique() +"\n"; listeEtatsPropLogMarquage.addItem(iuc.getListeEtats().get(i).getNom()); } champPropLogMarquage.setText(s); // maj resume des constantes } public void majAffichageTauxVariables() { boutonModifierTauxVariables.setEnabled(true); String s = ""; listeEtatsTauxVariables.removeAllItems(); listeEtatsTauxVariables.addItem(Vue.TOUS_LES_ETATS); for(int i = 0; i < iuc.getListeEtats().size(); i++) { s = s + iuc.getListeEtats().get(i).getNom() +"\t"+ iuc.getListeEtats().get(i).getTauxVariables() +"\n"; listeEtatsTauxVariables.addItem(iuc.getListeEtats().get(i).getNom()); } listeVariablesTauxVariables.removeAllItems(); listeVariablesTauxVariables.addItem(Vue.TOUTES_LES_VARIABLES); for(int i = 0; i < iuc.getListeVariables().size() ; i++) { listeVariablesTauxVariables.addItem(iuc.getListeVariables().get(i)); } champTauxVariables.setText(s); // maj resume des constantes scrollPane.updateUI(); } public void majAffichageGenererLHA() { boutonGenerer.setEnabled(true); } class PlayAnimation implements Runnable{ @Override public void run() { majAffichageEtatsInitiaux(); } } /* classes internes */ // class ItemState implements ItemListener{ // // public void itemStateChanged(ItemEvent e) { // System.out.println("ItemListener : événement déclenché sur : " + e.getItem()); // } // } // // class ItemAction implements ActionListener{ // // public void actionPerformed(ActionEvent e) { // String nomEtat = listeEtatsPropLogMarquage.getSelectedItem().toString(); // int pos = iuc.indexEtat(nomEtat); // String prop = iuc.getListeEtats().get(pos).getProprieteLogique(); // valeurPropLogMarquage.setText(prop); // } // } }