All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.limetri.client.mapviewer.swing.jxmap.map.LengthMeasurementContext Maven / Gradle / Ivy

The newest version!
/**
 *  Copyright (C) 2008-2013 LimeTri. All rights reserved.
 *
 *  AgroSense 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.
 *
 *  There are special exceptions to the terms and conditions of the GPLv3 as it
 *  is applied to this software, see the FLOSS License Exception
 *  .
 *
 *  AgroSense 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
 *  AgroSense. If not, see .
 */
package eu.limetri.client.mapviewer.swing.jxmap.map;

import eu.limetri.client.mapviewer.data.GeoPosition;
import eu.limetri.client.mapviewer.data.util.ScaleUtil;
import eu.limetri.client.mapviewer.swing.JXMapViewer;
import eu.limetri.client.mapviewer.swing.render.DrawingRenderer;
import eu.limetri.client.mapviewer.swing.render.LineDrawingRenderer;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import org.openide.util.NbBundle;

/**
 *
 * @author Frantisek Post
 */
@NbBundle.Messages({"length_measurement_result_format=Complete length is:  %s", 
                     "length_measurement=Area measurement"})
public class LengthMeasurementContext extends AbstractMeasurementContext {

    public LengthMeasurementContext(JXMapViewer mapViewer) {
        super(mapViewer);
    }

    @Override
    public DrawingRenderer getRenderer() {
        return new LineDrawingRenderer(coords);
    }

    @Override
    protected JComponent createResultComponent() {
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        JLabel label = new JLabel();

        double length = 0;
        String[] data;

        if (coords.size() > 1) {
            data = new String[coords.size() - 1];

            for (int i = 1; i < coords.size(); i++) {
                float dist = coords.get(i).distanceTo(coords.get(i - 1));
                length += dist;
                data[i - 1] = ScaleUtil.formatLength(dist);
            }
        } else {
            data = new String[]{};
        }
        JList list = new JList<>(data);

        label.setText(String.format(Bundle.length_measurement_result_format(), ScaleUtil.formatLength(length)));

        if (coords.size() > 10) {
            JScrollPane scrollPane = new JScrollPane(list);
            scrollPane.setPreferredSize(new Dimension(200, 180));
            panel.add(scrollPane, BorderLayout.CENTER);
        } else {
            panel.add(list, BorderLayout.CENTER);
        }
        panel.add(label, BorderLayout.SOUTH);
        label.setBorder(new EmptyBorder(10, 8, 0, 0));
        panel.setBorder(new EmptyBorder(2, 2, 10, 2));

        return panel;
    }

    @Override
    public String getDescription() {
        return Bundle.length_measurement();
    }

    @Override
    protected void addPointImpl(GeoPosition position) {
        coords.add(position);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy