nl.cloudfarming.client.geoviewer.render.GeographicalWidget Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geoviewer-render Show documentation
Show all versions of geoviewer-render Show documentation
AgroSense geoviewer render - contains classes for rendering of various geo objects
The newest version!
/**
* Copyright (C) 2008-2012 AgroSense Foundation.
*
* 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 nl.cloudfarming.client.geoviewer.render;
import java.awt.Point;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.SwingUtilities;
import nl.cloudfarming.client.geoviewer.Geographical;
import nl.cloudfarming.client.geoviewer.Palette;
import org.netbeans.api.visual.widget.Scene;
import org.netbeans.api.visual.widget.Widget;
/**
*
* @author Timon Veenstra
*/
public abstract class GeographicalWidget extends Widget {
private final Geographical geographical;
Palette palette;
static final double DISTANCE = 0.00001;
public GeographicalWidget(Geographical geographical, Palette palette, Scene scene) {
super(scene);
this.palette = palette;
this.geographical = geographical;
geographical.addPropertyChangeListener(new WidgetRefresher());
setForeground(this.palette.getColorForState(getState()));
}
public Palette getPalette() {
return palette;
}
public void setPalette(Palette palette) {
this.palette = palette;
setForeground(this.palette.getColorForState(getState()));
repaint();
}
/**
* Determines if a widget isHit. A widget is hit when a point lays between
* the bounds of the widget and: - The localLocation intersects the widgets
* GeoPostition - the localLocation is within a distance of DISTANCE of
* GeoPosition
*
* @param localLocation the Point which possibly hits the widget
* @return if the widget is hit
*/
@Override
public boolean isHitAt(Point localLocation) {
if (isVisible() && getBounds().contains(localLocation)) {
//FIXME check based on envelope
return true;
} else {
return false;
}
}
protected Geographical getGeographical() {
return geographical;
}
protected Rectangle getSceneViewport() {
// FIXME: points are still rendered on top of the map window border, though not outside of the map window anymore (AGROSENSE-1479);
// could be caused by the points render width (extends 4px down and left from its location),
// or we may need to subtract the map window border insets (may need to go all the way up the component tree to the MapTopComponent)
return getScene().getView().getBounds();
}
private class WidgetRefresher implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (SwingUtilities.isEventDispatchThread()) {
getScene().getView().repaint();
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
getScene().getView().repaint();
}
});
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy