/* *Copyright 2007, 2011 CCLS Columbia University (USA), LIFO University of Orl��ans (France), BRGM (France) * *Authors: Cyril Nortet, Xiangrong Kong, Ansaf Salleb-Aouissi, Christel Vrain, Daniel Cassard * *This file is part of QuantMiner. * *QuantMiner is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. * *QuantMiner is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * *You should have received a copy of the GNU General Public License along with QuantMiner. If not, see <http://www.gnu.org/licenses/>. */ package src.graphicalInterface; import java.io.*; import java.util.*; import javax.swing.*; import javax.swing.tree.*; import javax.swing.table.*; import src.database.*; import src.graphicalInterface.TreeTable.*; import src.solver.*; import src.tools.*; import java.awt.*; public class PanelPreExtraction extends DatabasePanelAssistant { public PanelPreExtraction(ResolutionContext contexteResolution) {//step 2 super(contexteResolution); initComponents(); InitialiserContenuPanneau(); super.DefinirEtape(2, "Choosing rule templates", ENV.REPERTOIRE_AIDE + "preextraction_english.htm"); super.DefinirPanneauPrecedent(MainWindow.PANNEAU_PRE_CHARGEMENT_BD); //previous step is step 1 super.DefinirPanneauSuivant(MainWindow.PANNEAU_CONFIG_TECHNIQUE); //next step is algorithm chosen and set parameters super.initBaseComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents jScrollPaneAttributs = new javax.swing.JScrollPane(); jButtonToutSelectionner = new javax.swing.JButton(); //select all jButtonNeRienSelectionner = new javax.swing.JButton(); //select nothing setLayout(null); jScrollPaneAttributs.setMaximumSize(new java.awt.Dimension(400, 250)); jScrollPaneAttributs.setMinimumSize(new java.awt.Dimension(400, 250)); jScrollPaneAttributs.setPreferredSize(new java.awt.Dimension(400, 250)); add(jScrollPaneAttributs); jScrollPaneAttributs.setBounds(0, 30, 450, 250); //select all button jButtonToutSelectionner.setText("Select all"); jButtonToutSelectionner.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonToutSelectionnerActionPerformed(evt); } }); add(jButtonToutSelectionner); jButtonToutSelectionner.setBounds(140, 0, 150, 20); //select none button jButtonNeRienSelectionner.setText("Select none"); jButtonNeRienSelectionner.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonNeRienSelectionnerActionPerformed(evt); } }); add(jButtonNeRienSelectionner); jButtonNeRienSelectionner.setBounds(300, 0, 150, 20); }//GEN-END:initComponents private void jButtonNeRienSelectionnerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNeRienSelectionnerActionPerformed super.m_contexteResolution.DefinirPositionnementPourTous(ResolutionContext.PRISE_EN_COMPTE_ITEM_NULLE_PART, false); jScrollPaneAttributs.repaint(); }//GEN-LAST:event_jButtonNeRienSelectionnerActionPerformed private void jButtonToutSelectionnerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonToutSelectionnerActionPerformed super.m_contexteResolution.DefinirPositionnementPourTous(ResolutionContext.PRISE_EN_COMPTE_ITEM_2_COTES, false); jScrollPaneAttributs.repaint(); //repaint this component }//GEN-LAST:event_jButtonToutSelectionnerActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonNeRienSelectionner; private javax.swing.JButton jButtonToutSelectionner; private javax.swing.JScrollPane jScrollPaneAttributs; // End of variables declaration//GEN-END:variables private void InitialiserContenuPanneau() { int iNombreColonnes = 0; int iIndiceColonne = 0; int iTypeNoeud = 0; String sNomColonne = null; AttributsBDModel attributsBD = null; //AttributsBDModel extends AbstractTreeTableModel JTreeTable treeTable = null; //JTreeTable extends JTable DatabaseAdmin gestionnaireBD = null; String [] tItems = null; int [] tOccurrences = null; int iIndiceItem = 0; DefaultMutableTreeNode noeudRacine = null; //noeud means node, Racine means root DefaultMutableTreeNode noeudCourant = null; String sDescriptionElement = null; if (super.m_contexteResolution == null) return; gestionnaireBD = super.m_contexteResolution.m_gestionnaireBD; if (gestionnaireBD == null) return; iNombreColonnes = gestionnaireBD.ObtenirNombreColonnesPrisesEnCompte(); //Get the number of columns that are selected in the first step if (iNombreColonnes == 0) return; attributsBD = new AttributsBDModel(); //A DefaultMutableTreeNode is a general-purpose node in a tree data structure noeudRacine = (DefaultMutableTreeNode)attributsBD.getRoot(); //return the root of the tree // Remplissage de la liste des noms de colonnes qualitatives disponibles au total dans la BD : for (iIndiceColonne=0; iIndiceColonne < iNombreColonnes; iIndiceColonne++) { //Name de l'attribut : DataColumn colonneDonnees = gestionnaireBD.ObtenirColonneBDPriseEnCompte(iIndiceColonne); if (colonneDonnees != null) { sNomColonne = new String( colonneDonnees.m_sNomColonne ); if (colonneDonnees.m_iTypeValeurs == DatabaseAdmin.TYPE_VALEURS_COLONNE_ITEM) { sDescriptionElement = String.valueOf( colonneDonnees.ObtenirNombreValeursDifferentes() ) //where did you get this distinct value + " distinct values"; noeudCourant = attributsBD.AjouterNoeud(noeudRacine, new AttributsBDModel.AttributBDDescription( sNomColonne, AttributsBDModel.ELEMENT_MODEL_ATTRIBUT_QUAL, sDescriptionElement, m_contexteResolution.ObtenirInfosPostionnementRegles(), false )); // On fait figurer dans une sous-arborescence chacunes des valeurs de l'attribut : tItems = colonneDonnees.ConstituerTableauValeurs(); if (tItems != null) if (tItems.length > 0) { // Constitution du tableau r�pertoriant les occurrences pour every item : tOccurrences = new int[tItems.length]; for (iIndiceItem = 0; iIndiceItem < tItems.length; iIndiceItem++) tOccurrences[iIndiceItem] = colonneDonnees.ObtenirNombreOccurrencesItem(tItems[iIndiceItem]); // Tri des items par occurrences : tItems = SortingTools.CompateurBiTableaux_Chaines_Entiers(tItems, tOccurrences, false); for (iIndiceItem = 0; iIndiceItem < tItems.length; iIndiceItem++) { sDescriptionElement = colonneDonnees.ObtenirNombreOccurrencesItem(tItems[iIndiceItem]) + " occurrences."; attributsBD.AjouterNoeud(noeudCourant, new AttributsBDModel.AttributBDDescription( sNomColonne, tItems[iIndiceItem], sDescriptionElement, m_contexteResolution.ObtenirInfosPostionnementRegles(), false ) ); } } } } } // Remplissage de la liste des noms de colonnes quantitatives disponibles au total dans la BD : for (iIndiceColonne = 0;iIndiceColonne < iNombreColonnes; iIndiceColonne++) { // Name de l'attribut : DataColumn colonneDonnees = gestionnaireBD.ObtenirColonneBDPriseEnCompte(iIndiceColonne); if (colonneDonnees != null) { sNomColonne = new String( colonneDonnees.m_sNomColonne ); if (colonneDonnees.m_iTypeValeurs == DatabaseAdmin.TYPE_VALEURS_COLONNE_REEL) { sDescriptionElement = "[ " + String.valueOf( colonneDonnees.ObtenirBorneMin() ) + ", " + String.valueOf( colonneDonnees.ObtenirBorneMax() ) + "]"; sDescriptionElement += ", " + String.valueOf(colonneDonnees.m_iNombreLignes-colonneDonnees.m_iNombreValeursReellesCorrectes) //where the hell does these data come from? + " missing values."; noeudCourant = attributsBD.AjouterNoeud(noeudRacine, new AttributsBDModel.AttributBDDescription( sNomColonne, AttributsBDModel.ELEMENT_MODEL_ATTRIBUT_QUANT, sDescriptionElement, m_contexteResolution.ObtenirInfosPostionnementRegles(), (colonneDonnees.m_iNombreValeursReellesCorrectes<=0) )); } } } treeTable = new JTreeTable(attributsBD); // Ajout � posteriori de certaines sp�cificit�s � la table : attributsBD.AdapterTreeTableAModele(treeTable); jScrollPaneAttributs.setViewportView(treeTable); jScrollPaneAttributs.validate(); } // Outrepassement de la m�thode m�re pour l'ajustement des champs : void ArrangerDisposition() { int iDeltaPosX = 0; int iDeltaPosY = 0; super.ArrangerDisposition(); iDeltaPosX = jScrollPaneAttributs.getX() - super.m_zoneControles.x; iDeltaPosY = jButtonToutSelectionner.getY() - super.m_zoneControles.y; jButtonNeRienSelectionner.setLocation( (super.m_zoneControles.width+super.m_zoneControles.x)-jButtonNeRienSelectionner.getWidth(), jButtonNeRienSelectionner.getY()-iDeltaPosY); jButtonToutSelectionner.setLocation(jButtonNeRienSelectionner.getX()-jButtonToutSelectionner.getWidth()-10, jButtonToutSelectionner.getY()-iDeltaPosY); jScrollPaneAttributs.setBounds( super.m_zoneControles.x, jScrollPaneAttributs.getY()-iDeltaPosY, super.m_zoneControles.width, super.m_zoneControles.height+super.m_zoneControles.y-(jScrollPaneAttributs.getY()-iDeltaPosY)); } protected boolean TraitementsSpecifiquesAvantSuivant() { if (!super.TraitementsSpecifiquesAvantSuivant()) return false; if (!super.m_contexteResolution.EstFiltreCoherent()) {//choose nothing, error JOptionPane.showMessageDialog(null, "For the procces of rule extraction to work properly, you need to specify an attribute on the left-hand side of the rules and a different one on the right-hand side", "Error", JOptionPane.ERROR_MESSAGE); return false; } super.m_contexteResolution.MettreAJourDonneesInternesFiltre(); return true; } }