/*
* 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.agg2graph.structs.DoubleRect;
import de.fub.agg2graphui.controller.AbstractLayer;
import de.fub.maps.project.aggregator.pipeline.processes.RoadNetworkProcess;
import de.fub.maps.project.aggregator.xml.Source;
import de.fub.maps.project.models.Aggregator;
import de.fub.maps.project.plugins.tasks.eval.evaluator.EvalutationItem;
import geofiletypeapi.GeoUtil;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.openide.util.Exceptions;
/**
*
* @author Serdar
*/
public final class RoadNetworkStatisticComparationPanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
private Aggregator aggregator;
/**
* Creates new form RoadNetworkStatisticComparationPanel
*/
public RoadNetworkStatisticComparationPanel() {
initComponents();
if (aggTopComponent1.isStatusBarVisible()) {
aggTopComponent1.setStatusBarVisible(false);
}
aggTopComponent1.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
updateMap();
aggTopComponent1.setDisplayToFitMapMarkers();
}
@Override
public void componentShown(ComponentEvent e) {
updateMap();
aggTopComponent1.setDisplayToFitMapMarkers();
}
});
}
private void updateMap() {
if (aggregator != null) {
List<Source> sourceList = aggregator.getSourceList();
if (sourceList != null) {
Area totalBoundingBox = new Area();
for (Source source : sourceList) {
String url = source.getUrl();
if (url != null) {
File file = new File(url);
Rectangle2D boundingBox = GeoUtil.getBoundingBox(file);
if (boundingBox != null) {
totalBoundingBox.add(new Area(boundingBox));
}
}
}
Rectangle2D bounds = totalBoundingBox.getBounds2D();
aggTopComponent1.showArea(
new DoubleRect(
bounds.getX(),
bounds.getY(),
bounds.getWidth(),
bounds.getHeight()));
}
}
}
@SuppressWarnings("unchecked")
public RoadNetworkStatisticComparationPanel(EvalutationItem evaluationItem) {
this();
aggregator = evaluationItem.getAggregator();
if (aggregator != null) {
getTitleLabel().setText(aggregator.getDataObject().getNodeDelegate().getDisplayName());
RoadNetworkProcess roadNetworkProcess = evaluationItem.getRoadNetworkProcess();
if (roadNetworkProcess != null) {
for (AbstractLayer<?> layer : roadNetworkProcess.getLayers()) {
try {
AbstractLayer clonedLayer = layer.getClass().newInstance();
for (Object item : layer.getItemList()) {
clonedLayer.add(item);
}
aggTopComponent1.addLayer(clonedLayer);
} catch (InstantiationException ex) {
Exceptions.printStackTrace(ex);
} catch (IllegalAccessException ex) {
Exceptions.printStackTrace(ex);
}
}
}
updateMap();
}
}
public JPanel getMapView() {
return aggTopComponent1;
}
public JLabel getTitleLabel() {
return titleLabel;
}
/**
* 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() {
jPanel1 = new javax.swing.JPanel();
mapContainer = new javax.swing.JPanel();
aggTopComponent1 = new de.fub.agg2graphui.AggTopComponent();
jPanel2 = new javax.swing.JPanel();
titleLabel = new javax.swing.JLabel();
setBackground(new java.awt.Color(255, 216, 178));
setMaximumSize(new java.awt.Dimension(22222, 300));
setMinimumSize(new java.awt.Dimension(313, 300));
setPreferredSize(new java.awt.Dimension(0, 300));
setLayout(new java.awt.BorderLayout());
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setLayout(new java.awt.BorderLayout(8, 0));
mapContainer.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
mapContainer.setMinimumSize(new java.awt.Dimension(300, 300));
mapContainer.setOpaque(false);
mapContainer.setPreferredSize(new java.awt.Dimension(300, 300));
mapContainer.setLayout(new java.awt.BorderLayout());
mapContainer.add(aggTopComponent1, java.awt.BorderLayout.CENTER);
jPanel1.add(mapContainer, java.awt.BorderLayout.CENTER);
add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 177, 101)));
jPanel2.setMaximumSize(new java.awt.Dimension(32767, 24));
jPanel2.setMinimumSize(new java.awt.Dimension(100, 24));
jPanel2.setOpaque(false);
jPanel2.setPreferredSize(new java.awt.Dimension(960, 24));
jPanel2.setLayout(new java.awt.BorderLayout());
titleLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(RoadNetworkStatisticComparationPanel.class, "RoadNetworkStatisticComparationPanel.titleLabel.text")); // NOI18N
titleLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(246, 197, 151)));
jPanel2.add(titleLabel, java.awt.BorderLayout.CENTER);
add(jPanel2, java.awt.BorderLayout.NORTH);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private de.fub.agg2graphui.AggTopComponent aggTopComponent1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel mapContainer;
private javax.swing.JLabel titleLabel;
// End of variables declaration//GEN-END:variables
}