/* * Copyright (C) 2013 Serdar * * This program 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 * (at your option) any later version. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ package de.fub.maps.project.plugins.tasks.accuracy; import de.fub.maps.project.plugins.tasks.accuracy.AccuracyAnalyzer.AnalayzerDatasetItem; import java.beans.PropertyVetoException; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.Collection; import org.netbeans.api.settings.ConvertAsProperties; import org.openide.explorer.ExplorerManager; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.openide.nodes.PropertySupport.ReadOnly; import org.openide.nodes.Sheet; import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; import org.openide.windows.TopComponent; /** * Top component which displays something. */ @ConvertAsProperties( dtd = "-//de.fub.mapsforge.plugins.tasks.accuracy//AccuracyResult//EN", autostore = false) @Messages({ "CTL_AccuracyResultAction=AccuracyResult", "CTL_AccuracyResultTopComponent=AccuracyResult Window", "HINT_AccuracyResultTopComponent=This is a AccuracyResult window" }) public final class AccuracyResultTopComponent extends TopComponent implements ExplorerManager.Provider { private static final long serialVersionUID = 1L; private final ExplorerManager explorerManager = new ExplorerManager(); public AccuracyResultTopComponent() { initComponents(); setName(Bundle.CTL_AccuracyResultTopComponent()); setToolTipText(Bundle.HINT_AccuracyResultTopComponent()); } /** * 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { propertySheetView1 = new org.openide.explorer.propertysheet.PropertySheetView(); setLayout(new java.awt.BorderLayout()); add(propertySheetView1, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private org.openide.explorer.propertysheet.PropertySheetView propertySheetView1; // End of variables declaration//GEN-END:variables @Override public void componentOpened() { // TODO add custom code on component opening } @Override public void componentClosed() { // TODO add custom code on component closing } void writeProperties(java.util.Properties p) { // better to version settings since initial version as advocated at // http://wiki.apidesign.org/wiki/PropertyFiles p.setProperty("version", "1.0"); // TODO store your settings } void readProperties(java.util.Properties p) { String version = p.getProperty("version"); // TODO read your settings according to their version } void setResult(Collection<AnalayzerDatasetItem> resultMap) { ResultNode resultNode = new ResultNode(resultMap); getExplorerManager().setRootContext(resultNode); try { getExplorerManager().setSelectedNodes(new Node[]{resultNode}); } catch (PropertyVetoException ex) { Exceptions.printStackTrace(ex); } } @Override public ExplorerManager getExplorerManager() { return explorerManager; } private static class ResultNode extends AbstractNode { private final Collection<AnalayzerDatasetItem> resultSet; public ResultNode(Collection<AnalayzerDatasetItem> resultSet) { super(Children.LEAF); this.resultSet = resultSet; } @Override protected Sheet createSheet() { Sheet sheet = Sheet.createDefault(); Property<?> property = null; for (final AnalayzerDatasetItem entry : resultSet) { Sheet.Set set = Sheet.createPropertiesSet(); set.setName(entry.getTransportMode()); set.setDisplayName(entry.getTransportMode()); sheet.put(set); property = new ReadOnly<Double>(MessageFormat.format("{0}/TotalInstances", entry.getTransportMode()), Double.class, "Instances", "") { @Override public Double getValue() throws IllegalAccessException, InvocationTargetException { return entry.getTotalNumberOfInstances(); } }; set.put(property); property = new ReadOnly<Double>(MessageFormat.format("{0}/CorrectClassified", entry.getTransportMode()), Double.class, "Correct Classified Instances", "") { @Override public Double getValue() throws IllegalAccessException, InvocationTargetException { return entry.getCorrectClassifiedNumberInstances(); } }; set.put(property); property = new ReadOnly<Double>(MessageFormat.format("{0}/classified", entry.getTransportMode()), Double.class, "Classified Instances", "") { @Override public Double getValue() throws IllegalAccessException, InvocationTargetException { return entry.getClassifiedAsTransportModeInstances(); } }; set.put(property); property = new ReadOnly<Double>(MessageFormat.format("{0}/recallAcurracy", entry.getTransportMode()), Double.class, "Recall Acurracy", "") { @Override public Double getValue() throws IllegalAccessException, InvocationTargetException { return entry.getRecallAccuracy(); } }; set.put(property); property = new ReadOnly<Double>(MessageFormat.format("{0}/precisionAcurracy", entry.getTransportMode()), Double.class, "Precision Acurracy", "") { @Override public Double getValue() throws IllegalAccessException, InvocationTargetException { return entry.getPrecisionAccuracy(); } }; set.put(property); } return sheet; } } }