Permalink
Browse files

pausing and different crs working

  • Loading branch information...
1 parent 770b811 commit 4df0118c5bac84e36646b7a6e0c6c55b58b39a5a @moovida moovida committed Apr 15, 2012
@@ -58,7 +58,9 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.TransformException;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
@@ -84,6 +86,8 @@
private Button playButton;
private Label currentFidValue;
+ private String previousLayerName = "";
+
public FeatureMovieView() {
ImageDescriptor playImageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(JGrassToolsPlugin.PLUGIN_ID,
"icons/play.gif");
@@ -107,9 +111,12 @@ public void createPartControl( Composite theparent ) {
playButton = new Button(playGroup, SWT.PUSH);
playButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
- playButton.setText("Play");
+ playButton.setText("start");
playButton.setImage(playImage);
playButton.addSelectionListener(new SelectionAdapter(){
+ private CoordinateReferenceSystem crs;
+ private SimpleFeatureIterator featureIterator;
+
public void widgetSelected( SelectionEvent e ) {
if (isRunning) {
// stop it
@@ -124,11 +131,23 @@ public void widgetSelected( SelectionEvent e ) {
if (selectedLayer != null) {
SimpleFeatureSource featureSource;
try {
- featureSource = (SimpleFeatureSource) selectedLayer.getResource(FeatureSource.class,
- new SubProgressMonitor(new NullProgressMonitor(), 1));
- SimpleFeatureCollection featureCollection = featureSource.getFeatures();
- final CoordinateReferenceSystem crs = featureCollection.getSchema().getCoordinateReferenceSystem();
- final SimpleFeatureIterator featureIterator = featureCollection.features();
+ String name = selectedLayer.getName();
+ if (featureIterator == null || !name.equals(previousLayerName) || !featureIterator.hasNext()) {
+ // restart
+ if (featureIterator != null) {
+ featureIterator.close();
+ }
+ featureSource = (SimpleFeatureSource) selectedLayer.getResource(FeatureSource.class,
+ new SubProgressMonitor(new NullProgressMonitor(), 1));
+ if (featureSource == null) {
+ noProperLayerSelected();
+ return;
+ }
+ SimpleFeatureCollection featureCollection = featureSource.getFeatures();
+ crs = featureCollection.getSchema().getCoordinateReferenceSystem();
+ featureIterator = featureCollection.features();
+ previousLayerName = name;
+ }
new Thread(new Runnable(){
public void run() {
@@ -160,6 +179,11 @@ public void run() {
Envelope envelope = geometry.getEnvelopeInternal();
envelope.expandBy(zoomBuffer);
ReferencedEnvelope ref = new ReferencedEnvelope(envelope, crs);
+ try {
+ ref = ref.transform(activeMap.getViewportModel().getCRS(), true);
+ } catch (Exception e1) {
+ // ignore
+ }
UndoableMapCommand selectCommand = SelectionCommandFactory.getInstance()
.createFIDSelectCommand(selectedLayer, currentFeature);
@@ -181,13 +205,17 @@ public void run() {
e1.printStackTrace();
}
} else {
- MessageDialog.openWarning(getSite().getShell(), "NO LAYER SELECTED",
- "A feature layer needs to be selected to use the tool.");
- stop();
+ noProperLayerSelected();
}
}
}
+ private void noProperLayerSelected() {
+ MessageDialog.openWarning(getSite().getShell(), "NO LAYER SELECTED",
+ "A feature layer needs to be selected to use the tool.");
+ stop();
+ }
+
});
Group paramsGroup = new Group(parent, SWT.NONE);
@@ -235,10 +263,12 @@ public void modifyText( ModifyEvent e ) {
private synchronized void start() {
playButton.setImage(stopImage);
+ playButton.setText("stop");
isRunning = true;
}
private synchronized void stop() {
playButton.setImage(playImage);
+ playButton.setText("start");
isRunning = false;
}

0 comments on commit 4df0118

Please sign in to comment.