MOA 12.03
Real Time Analytics for Data Streams
ClusteringEvalPanel.java
Go to the documentation of this file.
00001 /*
00002  *    ClusteringEvalPanel.java
00003  *    Copyright (C) 2010 RWTH Aachen University, Germany
00004  *    @author Jansen (moa@cs.rwth-aachen.de)
00005  *
00006  *    This program is free software; you can redistribute it and/or modify
00007  *    it under the terms of the GNU General Public License as published by
00008  *    the Free Software Foundation; either version 3 of the License, or
00009  *    (at your option) any later version.
00010  *
00011  *    This program is distributed in the hope that it will be useful,
00012  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *    GNU General Public License for more details.
00015  *
00016  *    You should have received a copy of the GNU General Public License
00017  *    along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  *    
00019  */
00020 package moa.gui.clustertab;
00021 
00022 import java.awt.GridBagConstraints;
00023 import java.util.ArrayList;
00024 import java.util.logging.Logger;
00025 import javax.swing.JCheckBox;
00026 import javax.swing.JLabel;
00027 import moa.core.AutoClassDiscovery;
00028 import moa.core.AutoExpandVector;
00029 import moa.evaluation.ClassificationMeasureCollection;
00030 import moa.evaluation.MeasureCollection;
00031 
00032 public class ClusteringEvalPanel extends javax.swing.JPanel {
00033 
00034     Class<?>[] measure_classes = null;
00035 
00036     ArrayList<JLabel> labels = null;
00037 
00038     ArrayList<JCheckBox> checkboxes = null;
00039 
00041     public ClusteringEvalPanel() {
00042         initComponents();
00043         measure_classes = findMeasureClasses();
00044         labels = new ArrayList<JLabel>();
00045         checkboxes = new ArrayList<JCheckBox>();
00046         addComponents();
00047     }
00048 
00049     private void addComponents() {
00050         GridBagConstraints gb = new GridBagConstraints();
00051         gb.insets = new java.awt.Insets(4, 7, 4, 7);
00052         int counter = 0;
00053         for (int i = 0; i < measure_classes.length; i++) {
00054             try {
00055                 MeasureCollection m = (MeasureCollection) measure_classes[i].newInstance();
00056                 for (int j = 0; j < m.getNumMeasures(); j++) {
00057                     String t = m.getName(j);
00058                     JLabel l = new JLabel(m.getName(j));
00059                     l.setPreferredSize(new java.awt.Dimension(100, 14));
00060                     //labels[i].setToolTipText("");
00061                     gb.gridx = 0;
00062                     gb.gridy = counter;
00063                     labels.add(l);
00064                     contentPanel.add(l, gb);
00065 
00066                     JCheckBox cb = new JCheckBox();
00067 
00068                     if (m.isEnabled(j)) {
00069                         cb.setSelected(true);
00070                     } else {
00071                         cb.setSelected(false);
00072                     }
00073 
00074                     gb.gridx = 1;
00075                     checkboxes.add(cb);
00076                     contentPanel.add(cb, gb);
00077                     counter++;
00078                 }
00079             } catch (Exception ex) {
00080                 Logger.getLogger("Couldn't create Instance for " + measure_classes[i].getName());
00081                 ex.printStackTrace();
00082             }
00083 
00084         }
00085         JLabel dummy = new JLabel();
00086         gb.gridx = 0;
00087         gb.gridy++;
00088         gb.gridwidth = 3;
00089         gb.weightx = 1;
00090         gb.weighty = 1;
00091         add(dummy, gb);
00092 
00093     }
00094 
00095     private Class<?>[] findMeasureClasses() {
00096         AutoExpandVector<Class<?>> finalClasses = new AutoExpandVector<Class<?>>();
00097         Class<?>[] classesFound = AutoClassDiscovery.findClassesOfType("moa.evaluation",
00098                 MeasureCollection.class);
00099         for (Class<?> foundClass : classesFound) {
00100             //Not add ClassificationMeasureCollection
00101             boolean noClassificationMeasures = true;
00102             for (Class cl: foundClass.getInterfaces()) {
00103                 if (cl.toString().contains("moa.evaluation.ClassificationMeasureCollection")){
00104                     noClassificationMeasures = false;
00105                 }
00106             }
00107             if (noClassificationMeasures ) { 
00108                 finalClasses.add(foundClass);
00109             }
00110         }
00111         return finalClasses.toArray(new Class<?>[finalClasses.size()]);
00112     }
00113 
00114     public MeasureCollection[] getSelectedMeasures() {
00115         ArrayList<MeasureCollection> measuresSelect = new ArrayList<MeasureCollection>();
00116 
00117         int counter = 0;
00118         for (int i = 0; i < measure_classes.length; i++) {
00119             try {
00120                 MeasureCollection m = (MeasureCollection) measure_classes[i].newInstance();
00121                 boolean addMeasure = false;
00122                 for (int j = 0; j < m.getNumMeasures(); j++) {
00123                     boolean selected = checkboxes.get(counter).isSelected();
00124                     m.setEnabled(j, selected);
00125                     if (selected) {
00126                         addMeasure = true;
00127                     }
00128                     counter++;
00129                 }
00130                 if (addMeasure) {
00131                     measuresSelect.add(m);
00132                 }
00133 
00134 
00135 
00136             } catch (Exception ex) {
00137                 Logger.getLogger("Couldn't create Instance for " + measure_classes[i].getName());
00138                 ex.printStackTrace();
00139             }
00140         }
00141 
00142 
00143         MeasureCollection[] measures = new MeasureCollection[measuresSelect.size()];
00144         for (int i = 0; i < measures.length; i++) {
00145             measures[i] = measuresSelect.get(i);
00146         }
00147         return measures;
00148     }
00149 
00155     @SuppressWarnings("unchecked")
00156     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
00157     private void initComponents() {
00158         java.awt.GridBagConstraints gridBagConstraints;
00159 
00160         scrollPane = new javax.swing.JScrollPane();
00161         contentPanel = new javax.swing.JPanel();
00162 
00163         setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Evaluation Measures", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
00164         setLayout(new java.awt.GridBagLayout());
00165 
00166         scrollPane.setBorder(null);
00167         scrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
00168         scrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
00169         scrollPane.setPreferredSize(new java.awt.Dimension(100, 225));
00170 
00171         contentPanel.setLayout(new java.awt.GridBagLayout());
00172         scrollPane.setViewportView(contentPanel);
00173 
00174         gridBagConstraints = new java.awt.GridBagConstraints();
00175         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00176         gridBagConstraints.weightx = 1.0;
00177         gridBagConstraints.weighty = 1.0;
00178         add(scrollPane, gridBagConstraints);
00179     }// </editor-fold>//GEN-END:initComponents
00180 
00181     // Variables declaration - do not modify//GEN-BEGIN:variables
00182     private javax.swing.JPanel contentPanel;
00183     private javax.swing.JScrollPane scrollPane;
00184     // End of variables declaration//GEN-END:variables
00185 }
 All Classes Namespaces Files Functions Variables Enumerations