//$HeadURL: svn+ssh://aschmitz@wald.intevation.org/deegree/base/branches/client/src/org/deegree/igeo/modules/ExampleModule.java $
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2009 by:
- Department of Geography, University of Bonn -
and
- lat/lon GmbH -
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library 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 Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact information:
lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/
Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/
e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.igeo.modules;
import static java.awt.GridBagConstraints.CENTER;
import static java.awt.GridBagConstraints.WEST;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.deegree.datatypes.QualifiedName;
import org.deegree.igeo.ChangeListener;
import org.deegree.igeo.ValueChangedEvent;
import org.deegree.igeo.dataadapter.FeatureAdapter;
import org.deegree.igeo.desktop.IGeoDesktop;
import org.deegree.igeo.mapmodel.Layer;
import org.deegree.igeo.mapmodel.LayerChangedEvent;
import org.deegree.igeo.mapmodel.MapModel;
import org.deegree.igeo.views.DialogFactory;
import org.deegree.igeo.views.swing.util.GuiUtils;
import org.deegree.igeo.views.swing.util.panels.OkCancelPanel;
import org.deegree.model.feature.Feature;
import org.deegree.model.feature.FeatureFactory;
/**
* ExampleModule
is an example module, showing some possibilities on how to write a custom module.
*
* @author Andreas Schmitz
* @author last edited by: $Author: apoth $
*
* @version $Revision: 20243 $, $Date: 2009-10-21 09:54:54 +0200 (Wed, 21 Oct 2009) $
* @param
* the class of the GUI container (currently usually IGeoDesktop)
*/
public class ExampleModule extends DefaultModule {
/***/
public void registerTree() {
// initial message
DialogFactory.openInformationDialog( "application", ( (IGeoDesktop) appContainer ).getMainWndow(),
"Please digitize a tree by clicking the"
+ " corresponding location in the map.",
"Information" );
// find the digitizing module
for ( IModule> m : appContainer.getModules() ) {
if ( m instanceof DigitizerModule ) {
DigitizerModule> dig = (DigitizerModule>) m;
// open the digitize dialog
dig.open();
// select the drawPoint action
dig.setDigitizingAction( "drawPoint" );
}
}
// find selected layer
MapModel mm = appContainer.getMapModelCollection().getMapModels().get( 0 );
final Layer layer = mm.getLayersSelectedForAction( MapModel.SELECTION_ACTION ).get( 0 );
// add a change listener to get events for the layer
final ChangeListener listener = new ChangeListener() {
public void valueChanged( ValueChangedEvent event ) {
if ( event instanceof LayerChangedEvent ) {
LayerChangedEvent e = (LayerChangedEvent) event;
switch ( e.getChangeType() ) {
// in case data changed, digitizing has finished
case dataChanged:
// remove listener to prevent retrieving other unrelated events
layer.removeChangeListener( this );
// this is the newly digitized feature
Feature f = (Feature) e.getValue();
// this is the dialog where the rest of the information is obtained
new TreeDialog( layer, f ).setVisible( true );
break;
case datasourceAdded:
case datasourceChanged:
case datasourceRemoved:
case scaleRangeChanged:
case featureSelected:
case featureUnselected:
case parentChanged:
case visibilityChanged:
case stylesSet:
case styleAdded:
case styleRemoved:
case selectedForChanged:
break;
}
}
}
};
layer.addChangeListener( listener );
}
private class TreeDialog extends JDialog implements ActionListener {
private static final long serialVersionUID = 3616397110215339925L;
private OkCancelPanel okcancel;
private Feature feature;
private JTextField treeType;
private URI APPNS;
private Layer layer;
// constructor initializes the GUI
TreeDialog( Layer l, Feature f ) {
try {
APPNS = new URI( "http://www.deegree.org/app" );
} catch ( URISyntaxException e ) {
// it's correct
}
feature = f;
layer = l;
okcancel = new OkCancelPanel( this, getRootPane(), true );
JPanel panel = (JPanel) getContentPane();
GridBagConstraints gb = GuiUtils.initPanel( panel );
gb.gridwidth = 2;
gb.anchor = WEST;
panel.add( new JLabel( "Please fill in the required information:" ), gb );
++gb.gridy;
panel.add( new JLabel( "Feature ID: " + f.getId() ), gb );
++gb.gridy;
gb.gridwidth = 1;
panel.add( new JLabel( "Tree type:" ), gb );
++gb.gridx;
panel.add( treeType = new JTextField( 20 ), gb );
++gb.gridy;
gb.anchor = CENTER;
gb.gridwidth = 2;
panel.add( okcancel, gb );
pack();
setLocationRelativeTo( ( (IGeoDesktop) appContainer ).getMainWndow() );
}
public void actionPerformed( ActionEvent e ) {
if ( e.getSource() == okcancel.okButton ) {
// update the feature with the values in the dialog
feature.setProperty( FeatureFactory.createFeatureProperty( new QualifiedName( "app", "NAME", APPNS ),
treeType.getText() ), 0 );
dispose();
}
if ( e.getSource() == okcancel.cancelButton ) {
// remove the feature
( (FeatureAdapter) layer.getDataAccess().get( 0 ) ).deleteFeature( feature );
dispose();
}
}
}
}