Skip to content

Commit

Permalink
pausing and different crs working
Browse files Browse the repository at this point in the history
  • Loading branch information
moovida committed Apr 15, 2012
1 parent 770b811 commit 4df0118
Showing 1 changed file with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -84,6 +86,8 @@ public class FeatureMovieView extends ViewPart {
private Button playButton;
private Label currentFidValue;

private String previousLayerName = "";

public FeatureMovieView() {
ImageDescriptor playImageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(JGrassToolsPlugin.PLUGIN_ID,
"icons/play.gif");
Expand All @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 4df0118

Please sign in to comment.