/*
* Copyright 2013 Serdar.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fub.maps.project.plugins.tasks.eval;
import de.fub.maps.project.aggregator.pipeline.processes.RoadNetworkProcess;
import de.fub.maps.project.api.statistics.StatisticProvider;
import de.fub.maps.project.plugins.tasks.eval.evaluator.EvalutationItem;
import java.awt.Component;
import java.awt.Dimension;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import javax.swing.Box;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.util.lookup.Lookups;
import org.openide.windows.TopComponent;
/**
*
* @author Serdar
*/
@NbBundle.Messages({
"CLT_MapComparationTopComponent_Name=RoadNetwork Evaluation",
"CLT_MapComparationTopComponent_Description=Evaluation the provided map in contect of certain features."
})
public class MapComparationTopComponent extends TopComponent implements ExplorerManager.Provider {
private static final String TOTAL_ROAD_LENGTH_ITEM = "total road length";
private static final String AVG_ROAD_LENGTH_ITEM = "average road length";
private static final String ROAD_COUNT_ITEM = "total number of roads";
private static final String INTERSECTION_COUNT_ITEM = "number of real intersections";
private static final String PSEUDO_INTERSECTION_COUNT_ITEM = "number of pseudo intersections";
private static final long serialVersionUID = 1L;
private final ExplorerManager explorerManager = new ExplorerManager();
/**
* Creates new form MapComparationModel
*/
public MapComparationTopComponent() {
initComponents();
outlineView1.getOutline().setRootVisible(false);
outlineView1.setPropertyColumns(
TOTAL_ROAD_LENGTH_ITEM, TOTAL_ROAD_LENGTH_ITEM,
AVG_ROAD_LENGTH_ITEM, AVG_ROAD_LENGTH_ITEM,
ROAD_COUNT_ITEM, ROAD_COUNT_ITEM,
INTERSECTION_COUNT_ITEM, INTERSECTION_COUNT_ITEM,
PSEUDO_INTERSECTION_COUNT_ITEM, PSEUDO_INTERSECTION_COUNT_ITEM);
jScrollPane1.getVerticalScrollBar().setUnitIncrement(16);
jScrollPane2.getVerticalScrollBar().setUnitIncrement(16);
setDisplayName(Bundle.CLT_MapComparationTopComponent_Name());
setToolTipText(Bundle.CLT_MapComparationTopComponent_Description());
associateLookup(Lookups.fixed(MapComparationTopComponent.this));
}
public MapComparationTopComponent(List<EvalutationItem> roadNetworkStatisticList) {
this();
overviewChart1.setEvaluationItems(roadNetworkStatisticList);
headingHistogrammContainer1.setEvaluationItems(roadNetworkStatisticList);
explorerManager.setRootContext(new AbstractNode(Children.create(new NodeFactory(roadNetworkStatisticList), true)));
for (EvalutationItem pair : roadNetworkStatisticList) {
RoadNetworkStatisticComparationPanel panel = new RoadNetworkStatisticComparationPanel(pair);
mapContainer.add(panel);
mapContainer.add(Box.createVerticalStrut(8));
}
int height = 0;
for (Component child : mapContainer.getComponents()) {
height += child.getPreferredSize().height;
}
jScrollPane1.getViewport().getView().setPreferredSize(new Dimension(0, height));
}
@Override
public int getPersistenceType() {
return TopComponent.PERSISTENCE_NEVER;
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
mapContainer = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
contentPanel = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
outlineView1 = new org.openide.explorer.view.OutlineView(NbBundle.getMessage(MapComparationTopComponent.class, "outlineview1.name.column"));
filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 8), new java.awt.Dimension(0, 8), new java.awt.Dimension(32767, 8));
overviewChart1 = new de.fub.maps.project.plugins.tasks.eval.OverviewChart();
filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 8), new java.awt.Dimension(0, 8), new java.awt.Dimension(32767, 8));
headingHistogrammContainer1 = new de.fub.maps.project.plugins.tasks.eval.heading.HeadingHistogrammContainer();
setLayout(new java.awt.BorderLayout());
jScrollPane1.setMaximumSize(new java.awt.Dimension(320, 32767));
jScrollPane1.setMinimumSize(new java.awt.Dimension(30, 23));
jScrollPane1.setPreferredSize(new java.awt.Dimension(320, 202));
mapContainer.setBackground(new java.awt.Color(255, 255, 255));
mapContainer.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
mapContainer.setMaximumSize(new java.awt.Dimension(20000, 20000));
mapContainer.setPreferredSize(new java.awt.Dimension(100, 200));
mapContainer.setLayout(new javax.swing.BoxLayout(mapContainer, javax.swing.BoxLayout.Y_AXIS));
jScrollPane1.setViewportView(mapContainer);
add(jScrollPane1, java.awt.BorderLayout.EAST);
contentPanel.setBackground(new java.awt.Color(255, 255, 255));
contentPanel.setLayout(new javax.swing.BoxLayout(contentPanel, javax.swing.BoxLayout.Y_AXIS));
jPanel1.setMaximumSize(new java.awt.Dimension(2147483647, 300));
jPanel1.setMinimumSize(new java.awt.Dimension(0, 300));
jPanel1.setPreferredSize(new java.awt.Dimension(0, 300));
jPanel1.setLayout(new java.awt.BorderLayout());
outlineView1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
outlineView1.setMaximumSize(new java.awt.Dimension(32767, 200));
outlineView1.setMinimumSize(new java.awt.Dimension(23, 200));
outlineView1.setPreferredSize(new java.awt.Dimension(0, 200));
jPanel1.add(outlineView1, java.awt.BorderLayout.CENTER);
contentPanel.add(jPanel1);
contentPanel.add(filler1);
overviewChart1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
overviewChart1.setMaximumSize(new java.awt.Dimension(2147483647, 300));
overviewChart1.setMinimumSize(new java.awt.Dimension(100, 300));
overviewChart1.setPreferredSize(new java.awt.Dimension(0, 300));
contentPanel.add(overviewChart1);
contentPanel.add(filler3);
headingHistogrammContainer1.setMaximumSize(new java.awt.Dimension(2147483647, 300));
headingHistogrammContainer1.setMinimumSize(new java.awt.Dimension(102, 300));
headingHistogrammContainer1.setPreferredSize(new java.awt.Dimension(0, 300));
contentPanel.add(headingHistogrammContainer1);
jScrollPane2.setViewportView(contentPanel);
add(jScrollPane2, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel contentPanel;
private javax.swing.Box.Filler filler1;
private javax.swing.Box.Filler filler3;
private de.fub.maps.project.plugins.tasks.eval.heading.HeadingHistogrammContainer headingHistogrammContainer1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JPanel mapContainer;
private org.openide.explorer.view.OutlineView outlineView1;
private de.fub.maps.project.plugins.tasks.eval.OverviewChart overviewChart1;
// End of variables declaration//GEN-END:variables
@Override
public ExplorerManager getExplorerManager() {
return explorerManager;
}
private static class NodeFactory extends ChildFactory<EvalutationItem> {
private final List<EvalutationItem> items;
public NodeFactory(List<EvalutationItem> items) {
this.items = items;
}
@Override
protected boolean createKeys(List<EvalutationItem> toPopulate) {
toPopulate.addAll(items);
return true;
}
@Override
protected Node createNodeForKey(EvalutationItem evaluationItem) {
return new StatisticNode(evaluationItem);
}
}
static class StatisticNode extends AbstractNode {
private final EvalutationItem evaluationItem;
public StatisticNode(EvalutationItem evaluationItem) {
super(Children.LEAF);
this.evaluationItem = evaluationItem;
setDisplayName(evaluationItem.getAggregator().getDataObject().getNodeDelegate().getDisplayName());
}
@NbBundle.Messages({
"CLT_StatisticNode_Set_Name=Road network metrics"
})
@Override
protected Sheet createSheet() {
Sheet sheet = Sheet.createDefault();
Sheet.Set set = Sheet.createPropertiesSet();
set.setDisplayName(Bundle.CLT_StatisticNode_Set_Name());
sheet.put(set);
if (evaluationItem != null) {
List<String> itemList = Arrays.asList(TOTAL_ROAD_LENGTH_ITEM, AVG_ROAD_LENGTH_ITEM,
ROAD_COUNT_ITEM, ROAD_COUNT_ITEM,
INTERSECTION_COUNT_ITEM, PSEUDO_INTERSECTION_COUNT_ITEM);
for (String itemName : itemList) {
Node.Property<?> property = createProperty(itemName);
if (property != null) {
set.put(property);
}
}
}
return sheet;
}
private Node.Property<?> createProperty(String statisticItemName) {
Node.Property<?> property = null;
if (statisticItemName != null) {
try {
RoadNetworkProcess roadNetwork = evaluationItem.getRoadNetworkProcess();
for (StatisticProvider.StatisticSection section : roadNetwork.getStatisticData()) {
if ("Road Network Statistics".equals(section.getName())) {
List<StatisticProvider.StatisticItem> statisticsItemList = section.getStatisticsItemList();
for (StatisticProvider.StatisticItem item : statisticsItemList) {
if (statisticItemName.equals(item.getName())) {
property = new StatisticProperty(item);
}
}
break;
}
}
} catch (StatisticProvider.StatisticNotAvailableException ex) {
Exceptions.printStackTrace(ex);
}
}
return property;
}
}
private static class StatisticProperty extends PropertySupport.ReadOnly<String> {
private final StatisticProvider.StatisticItem item;
private static final String PROP_NAME_SUPPRESS_CUSTOM_EDITOR = "suppressCustomEditor";
public StatisticProperty(StatisticProvider.StatisticItem item) {
super(item.getName(), String.class, item.getName(), item.getDescription());
this.item = item;
setValue(PROP_NAME_SUPPRESS_CUSTOM_EDITOR, Boolean.TRUE);
}
@Override
public String getValue() throws IllegalAccessException, InvocationTargetException {
return item.getValue();
}
}
}