[Schmitzm-commits] r628 - in branches/2.0-RC2/src/schmitzm/geotools: gui gui/resource/locales map/event
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jan 28 14:48:09 CET 2010
Author: mojays
Date: 2010-01-28 14:48:07 +0100 (Thu, 28 Jan 2010)
New Revision: 628
Added:
branches/2.0-RC2/src/schmitzm/geotools/gui/JMapEditorPane.java
branches/2.0-RC2/src/schmitzm/geotools/gui/JMapEditorToolBar.java
Removed:
branches/2.0-RC2/src/schmitzm/geotools/gui/JEditorPane.java
branches/2.0-RC2/src/schmitzm/geotools/gui/JEditorToolBar.java
Modified:
branches/2.0-RC2/src/schmitzm/geotools/gui/FeatureTypeInputOption.java
branches/2.0-RC2/src/schmitzm/geotools/gui/LayeredEditorFrame.java
branches/2.0-RC2/src/schmitzm/geotools/gui/StyleToolBar.java
branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle.properties
branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties
branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_fr.properties
branches/2.0-RC2/src/schmitzm/geotools/map/event/FeatureModifiedEvent.java
branches/2.0-RC2/src/schmitzm/geotools/map/event/JEditorPaneEvent.java
branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditCanceledEvent.java
branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditFinishedEvent.java
branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditStartedEvent.java
Log:
JEditorPane renamed to JMapEditorPane
JEditorToolBar renamed to JMapEditorToolBar
Modified: branches/2.0-RC2/src/schmitzm/geotools/gui/FeatureTypeInputOption.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/FeatureTypeInputOption.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/FeatureTypeInputOption.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -105,7 +105,7 @@
* @return immer {@code true}
*/
protected boolean performSetValue(SimpleFeatureType newValue) {
- inpTableModel.setFeatureType(newValue, null);
+ inpTableModel.setFeatureType(newValue, newValue.getTypeName());
return true;
}
Deleted: branches/2.0-RC2/src/schmitzm/geotools/gui/JEditorPane.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/JEditorPane.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/JEditorPane.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -1,945 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program 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 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Krüger - additional utility classes
- ******************************************************************************/
-package schmitzm.geotools.gui;
-
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.event.MouseEvent;
-import java.awt.geom.Point2D;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Stack;
-
-import org.geotools.feature.DefaultFeatureCollection;
-import org.geotools.feature.DefaultFeatureCollections;
-import org.geotools.feature.FeatureCollection;
-import org.geotools.feature.GeometryAttributeType;
-import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
-import org.geotools.map.DefaultMapContext;
-import org.geotools.map.DefaultMapLayer;
-import org.geotools.map.MapContext;
-import org.geotools.map.MapLayer;
-import org.geotools.renderer.GTRenderer;
-import org.geotools.styling.Style;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.feature.type.AttributeDescriptor;
-
-import schmitzm.geotools.GTUtil;
-import schmitzm.geotools.feature.FeatureUtil;
-import schmitzm.geotools.feature.FeatureUtil.GeometryForm;
-import schmitzm.geotools.map.event.FeatureModifiedEvent;
-import schmitzm.geotools.map.event.LayerEditCanceledEvent;
-import schmitzm.geotools.map.event.LayerEditFinishedEvent;
-import schmitzm.geotools.map.event.LayerEditStartedEvent;
-import schmitzm.geotools.map.event.MapContextSynchronizer;
-import schmitzm.swing.InputOption;
-import schmitzm.swing.MultipleOptionPane;
-
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.LineString;
-import com.vividsolutions.jts.geom.LinearRing;
-import com.vividsolutions.jts.geom.MultiPoint;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.Polygon;
-
-
-/**
- * The {@code JEditorPane} extends the {@link SelectableXMapPane} with functionalities
- * to create new vector layers by successively click points via mouse.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
- * @version 1.0
- */
-public class JEditorPane extends SelectableXMapPane {
- /** Modes, the editor can be perform.
- * @see JEditorPane#startEditing(EditorMode, String, Style) */
- public static enum EditorMode {
- /** Create a new point layer. */
- New_Point,
- /** Create a new linestring layer. */
- New_Line,
- /** Create a new polygon layer. */
- New_Polygon
- }
-
- /** Attribute name used for the geometry of new layers. */
- public static final String GEOMETRY_ATTR = "the_geom";
-
- /** Default-Style for point layers (blue dots). */
- public static final Style DEFAULT_POINT_STYLE = FeatureUtil.createPointStyle(Color.BLUE);
- /** Default-Style for line layers (blue lines). */
- public static final Style DEFAULT_LINE_STYLE = FeatureUtil.createLineStyle(Color.BLUE,2);
- /** Default-Style for polygon layers (orange with black borders). */
- public static final Style DEFAULT_POLYGON_STYLE = FeatureUtil.createPolygonStyle(Color.ORANGE, Color.BLUE, 2);
-
- /** If the edited layer is empty, a dummy feature is inserted, because
- * the StreamingRenderer can not handle empty FeatureCollections yet. */
- private SimpleFeature DUMMY_EDITOR_FEATURE = null;
- private SimpleFeature DUMMY_LINE_FEATURE = null;
- private SimpleFeature DUMMY_POINT_FEATURE = null;
-
- /** The map context of the displayed layer. */
- protected MapContext mapContext = null;
-
- /** Contains the additional attributes for new FeatureCollections. */
- protected SimpleFeatureType additionalAttr = null;
- /** Contains the {@link InputOption} to specify the additional
- * attribute values. */
- protected FeatureInputOption attrInputOption = null;
-
- /** The map context where the edited layers are displayed. This
- * context is displayed on top of the other layers. */
- protected MapContext editorMapContext = null;
- /** The renderer the edited layers are rendered with. */
- protected GTRenderer editorRenderer = null;
- /** Holds the {@link Style styles} to display edited layers. */
- protected Map<GeometryForm,Style> editorStyles = null;
- /** Holds the operation the editor currently performs. */
- protected EditorMode editorMode = null;
-
- /** Holds the {@link SimpleFeatureType} of the edited layer. */
- protected SimpleFeatureType editorFeatureType = null;
- /** Holds the kind of geometry of the edited layer. */
- protected GeometryForm editorGeometryForm = null;
- /** Holds the {@link FeatureCollection} of the edited layer. */
- protected FeatureCollection<SimpleFeatureType, SimpleFeature> editorFeatureCollection = null;
- /** Holds the edited layer. */
- protected MapLayer editorLayer = null;
-
- /** Holds the {@link SimpleFeatureType} of the new segment (incomplete SimpleFeature)
- * displayed as line. */
- protected SimpleFeatureType segmLineFeatureType = null;
- /** Holds the {@link FeatureCollection} which holds the new segment
- * (incomplete SimpleFeature) displayed as line. */
- protected DefaultFeatureCollection segmLineFeatureCollection = null;
- /** Holds the layer, the new segment (incomplete SimpleFeature) is displayed in
- * as line. */
- protected MapLayer segmLineLayer = null;
-
- /** Holds the {@link SimpleFeatureType} of the new segment (incomplete SimpleFeature)
- * displayed as points. */
- protected SimpleFeatureType segmPointFeatureType = null;
- /** Holds the {@link FeatureCollection} which holds the new segment
- * (incomplete SimpleFeature) displayed as points. */
- protected DefaultFeatureCollection segmPointFeatureCollection = null;
- /** Holds the layer, the new segment (incomplete SimpleFeature) is displayed in
- * as points. */
- protected MapLayer segmPointLayer = null;
-
-
- /** Holds the points of the edited segment (incomplete SimpleFeature) which
- * can be undone. */
- protected Stack<Coordinate> segmUndoPoints = new Stack<Coordinate>();
- /** Holds the undone points of the edited segment (incomplete SimpleFeature) which
- * can be redone. */
- protected Stack<Coordinate> segmRedoPoints = new Stack<Coordinate>();
- /** Holds the points of former segments (complete Features) which
- * can be undone. */
- protected Stack<Stack<Coordinate>> globalUndoPoints = new Stack<Stack<Coordinate>>();
- /** Holds the undone points of former segments (complete Features) which
- * can be redone. */
- protected Stack<Stack<Coordinate>> globalRedoPoints = new Stack<Stack<Coordinate>>();
- /** Holds the former segments (complete Features) which can be undone. */
- protected Stack<SimpleFeature> globalUndoFeatures = new Stack<SimpleFeature>();
- /** Holds the undone segments (complete Features) which can be redone. */
- protected Stack<SimpleFeature> globalRedoFeatures = new Stack<SimpleFeature>();
-
- /**
- * Creates a new {@code JEditorPane}.
- */
- public JEditorPane() {
- this(null);
- }
-
- /**
- * Creates a new {@code JEditorPane}. This constructor provides the possibility
- * to use alternative implementations of the internal components.
- * <b>The specified parameter all can be {@code null}! In this case
- * the respective default component is used.</b>
- */
- public JEditorPane(MapContext context) {
- super(context);
- this.mapContext = getMapContext();
- // initalize the editor styles
- this.editorStyles = new HashMap<GeometryForm, Style>();
- for (GeometryForm geomForm : GeometryForm.values())
- this.setEditorStyle(geomForm, null);
-
- // no standard action on left mouse button, instead: adding points
- setState( NONE );
- setState( ZOOM_IN );
- // special map context for the editor layers, so the
- // editor layers are not shown in "normal" layer list
- this.editorMapContext = new DefaultMapContext( mapContext.getCoordinateReferenceSystem() );
- this.editorRenderer = GTUtil.createGTRenderer(this.editorMapContext);
- // listen to CRS/Area changes on the "normal" Context to
- // synchronize the editor context
- this.mapContext.addMapBoundsListener( new MapContextSynchronizer(editorMapContext) );
-
- // create the input option to specify additional attribute values
- attrInputOption = new FeatureInputOption(null,true,(SimpleFeature)null);
- }
-
-/**
- * After the actions of the super method, this method paints the
- * special editor layers in {@link #editorMapContext}.
- */
- protected void paintComponent(Graphics g) {
- resetEditorLayerVisibility();
- super.paintComponent(g);
- Rectangle r = getBounds();
- Rectangle dr = new Rectangle(r.width, r.height);
- editorRenderer.setContext(editorMapContext);
- editorRenderer.paint((Graphics2D) g, dr, mapArea);
- }
-
- /**
- * Ignores the actions of the super class for left-clicks.
- * Instead this method reacts according to the current
- * editor mode.
- */
-// @Override
- public void mouseClicked(MouseEvent e) {
- Point2D geoCoord = getScreenToWorld().transform(e.getPoint(), null);
- // Zunaechst Modus auf NULL pruefen, da ansonsten
- // NullPointerException in switch-Statement
- if ( editorMode == null )
- return;
-
- switch( editorMode ) {
- case New_Point:
- case New_Line:
- case New_Polygon: addSegment( new Coordinate(geoCoord.getX(), geoCoord.getY()) );
- break;
- }
- }
-
- //**********************************************************************
- //***** General public methods
- //**********************************************************************
-
- /**
- * Checks, whether a layer is edited.
- */
- public boolean isEditorEnabled() {
- return editorMode != null;
- }
-
- /**
- * Sets the style for edited layers.
- * @param geomForm kind of layers the style is set for
- * @param style a Style (if {@code null} a default style is set, so
- * {@link #getEditorStyle(GeometryForm)} never returns null)
- */
- public void setEditorStyle(GeometryForm geomForm, Style style) {
- // If no style is specified, set a default style
- if ( style == null )
- switch ( geomForm ) {
- case POINT: style = DEFAULT_POINT_STYLE; break;
- case LINE: style = DEFAULT_LINE_STYLE; break;
- case POLYGON: style = DEFAULT_POLYGON_STYLE; break;
- }
-
- // Set the style
- editorStyles.put(geomForm, style);
-
- // Apply the style also to the current edited layer
- if ( editorLayer != null && FeatureUtil.getGeometryForm(editorLayer) == geomForm )
- editorLayer.setStyle(style);
- if ( segmLineLayer != null && FeatureUtil.getGeometryForm(segmLineLayer) == geomForm )
- segmLineLayer.setStyle(style);
- if ( segmPointLayer != null && FeatureUtil.getGeometryForm(segmPointLayer) == geomForm )
- segmPointLayer.setStyle(style);
- }
-
- /**
- * Returns the style for edited layers.
- * @param geomForm type of layers the style is returned for
- */
- public Style getEditorStyle(GeometryForm geomForm) {
- return this.editorStyles.get(geomForm);
- }
-
- /**
- * Returns the style for the current edited layer.
- */
- public Style getEditorStyle() {
- if ( editorGeometryForm == null )
- return null;
- return this.editorStyles.get(editorGeometryForm);
- }
-
- /**
- * Sets the additional attributes for new FeatureCollections (besides
- * the geometric attribute, which is added automatically).
- * @param fType defines the attributes (If {@code null}, new FeatureCollections
- * only contain the geometric attribute)
- */
- public void setAdditionalAttributes(SimpleFeatureType fType) {
- this.additionalAttr = fType;
- }
-
- /**
- * Returns the additional attributes for new FeatureCollections (besides
- * the geometric attribute, which is added automatically).
- */
- public SimpleFeatureType getAdditionalAttributes() {
- return this.additionalAttr;
- }
-
- /**
- * Returns the current editor mode.
- */
- public EditorMode getEditorMode() {
- return this.editorMode;
- }
-
- /**
- * Returns the edited layer.
- */
- public MapLayer getEditorLayer() {
- return this.editorLayer;
- }
-
- /**
- * Returns the {@link FeatureCollection} of the edited layer.
- */
- public FeatureCollection<SimpleFeatureType, SimpleFeature> getEditorFeatureCollection() {
- return this.editorFeatureCollection;
- }
-
- //**********************************************************************
- //***** Public Methods controlling the editor operations
- //**********************************************************************
-
- /**
- * Starts a new layer.
- * @param mode type of layer
- * @param layerTitle Title for the new layer
- * @exception UnsupportedOperationException if no map area is defined yet
- */
- public void startEditing(EditorMode mode, String layerTitle) {
- // to create a new layer, first an existing layer must be
- // displayed, so that a CRS and geo-position is available
- // for the new layer
- if ( getMapArea() == null )
- throw new UnsupportedOperationException( GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JEditorPane.Err.MissingMap") );
- // cancel active editings
- cancelEditing();
- editorMode = mode;
-
- // Create new Layers
- initEditorFeatureCollection(layerTitle);
- initSegmentFeatureCollection();
- editorMapContext.addLayer(0,editorLayer);
- fireMapPaneEvent( new LayerEditStartedEvent(this,editorLayer,this) );
- }
-
- /**
- * Called when the mouse is clicked on map during creating a new layer.
- * @param coord World coordinates of click position
- * @param refresh indicates whether the visualization will be refreshed
- * @param aClearRedo indicates whether the REDO-Stack is cleared (normally {@code true},
- * but {@code false} during REDO operation!)
- */
- protected void addSegment(Coordinate coord, boolean refresh, boolean clearRedo) {
- if ( editorMode != EditorMode.New_Point &&
- editorMode != EditorMode.New_Line &&
- editorMode != EditorMode.New_Polygon )
- return;
-
- // store the new point for undoing
- segmUndoPoints.push(coord);
- // delete all former redo possibilities
- if ( clearRedo )
- segmRedoPoints.clear();
- // recreate the segment FeatureCollection to show the extended line
- generateSegmentFeatureCollection();
-
- // finish the feature automatically
- // - when editing points, because there are no segments for point layer,
- // because every point is a new feature
- // - when editing polygons and reaching the start point
- if ( editorGeometryForm == GeometryForm.POINT ||
- editorGeometryForm == GeometryForm.POLYGON && segmUndoPoints.size() > 1 && segmUndoPoints.lastElement().equals(segmUndoPoints.firstElement()) )
- finishFeature(refresh, clearRedo); // refresh is done by finishFeature()
- else
- if ( refresh )
- refresh();
- }
-
- /**
- * Called when the mouse is clicked on map during creating a new layer.
- * @param coord World coordinates of click position
- */
- protected void addSegment(Coordinate coord) {
- addSegment(coord, true, true);
- }
-
- /**
- * Finishes the editing of the current segment (SimpleFeature).
- * If no editing operation is currently in progress, this method does nothing.
- * @param refresh indicates whether the visualization will be refreshed
- * @param aClearRedo indicates whether the REDO-Stack is cleared (normally {@code true},
- * but {@code false} during REDO operation!)
- * @exception UnsupportedOperationException if a line or polygon feature can not
- * be finished because of less specified points
- */
- protected void finishFeature(boolean refresh, boolean clearRedo) {
- if ( editorMode == null )
- return;
-
- if ( editorGeometryForm == GeometryForm.LINE && segmUndoPoints.size() < 2 )
- throw new UnsupportedOperationException( GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JEditorPane.Err.Line.LessPoints") );
- if ( editorGeometryForm == GeometryForm.POLYGON && segmUndoPoints.size() < 3 )
- throw new UnsupportedOperationException( GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JEditorPane.Err.Polygon.LessPoints") );
-
- // close a polygon automatically
- if ( editorGeometryForm == GeometryForm.POLYGON &&
- !segmUndoPoints.lastElement().equals(segmUndoPoints.firstElement()) ) {
- addSegment( segmUndoPoints.firstElement(), refresh, clearRedo );
- return; // !!!! finishFeature(.) is called again by addSegment(..) !!!!
- }
- // create a new SimpleFeature from the segment points
- SimpleFeature feature = createFeature();
- if ( feature == null )
- return;
- fireMapPaneEvent( new FeatureModifiedEvent(this,editorLayer,feature,this) );
-
- // update the global undo
- globalUndoPoints.push( segmUndoPoints );
- globalUndoFeatures.push( feature );
- editorFeatureCollection.add( feature );
-
- // after finishing a SimpleFeature, a new segment is started
- segmUndoPoints = new Stack<Coordinate>();
- if ( clearRedo )
- segmRedoPoints = globalRedoPoints.isEmpty() ? new Stack<Coordinate>() : globalRedoPoints.pop();
- initSegmentFeatureCollection();
- // refresh the display
- if ( refresh )
- refresh();
- }
-
- /**
- * Finishes the editing of the current segment (SimpleFeature).
- * If no editing operation is currently in progress, this method does nothing.
- */
- public void finishFeature() {
- finishFeature(true, true);
- }
-
- /**
- * Finishes the current editing operation. After that no more operations
- * on this layer can be performed.
- * As long as no other editing operation is started, the edited (new) layer is
- * available by {@link #getEditorLayer()} and {@link #getEditorFeatureCollection()}.
- * If no editing operation is currently in progress, this method does nothing.
- */
- public void finishEditing() {
- if ( editorMode == null )
- return;
-
- // if current segment is not closed, finish it automatically
- if ( !segmUndoPoints.isEmpty() )
- finishFeature();
- initUndoRedo();
-
- // move the edited layer to the "real" MapContext
- editorMapContext.removeLayer(editorLayer);
- if ( mapContext.indexOf(editorLayer) < 0 ) {
- mapContext.addLayer(editorLayer);
- editorLayer.setVisible(true);
- }
- fireMapPaneEvent( new LayerEditFinishedEvent(this,editorLayer,this) );
-
- // initialize the editing variables
- editorMode = null;
- editorLayer = null;
- editorFeatureCollection = null;
- editorGeometryForm = null;
-
- // refresh the display
- refresh();
- }
-
- /**
- * Cancels the current edititing operation. The edited layer is removed.
- */
- public void cancelEditing() {
- if ( editorLayer != null )
- this.editorMapContext.removeLayer( editorLayer );
- if ( editorFeatureCollection != null ) {
- if ( mapContext.indexOf(editorLayer) < 0 ) {
- // Layer was a new one, so clear it completly
- editorFeatureCollection.clear();
- initUndoRedo();
- fireMapPaneEvent( new LayerEditCanceledEvent(this,null,this) );
- } else {
- // Layer was an existing one, so undo all editing operations
- undoAll();
- initUndoRedo();
- fireMapPaneEvent( new LayerEditFinishedEvent(this,editorLayer,this) );
- }
- }
- if ( segmLineFeatureCollection != null )
- segmLineFeatureCollection.clear();
- if ( segmPointFeatureCollection != null )
- segmPointFeatureCollection.clear();
-
- // initialize the editing variables
- editorMode = null;
- editorLayer = null;
- editorFeatureCollection = null;
- editorGeometryForm = null;
-
- // refresh the display
- refresh();
- }
-
- /**
- * Makes previously made editing actions undone.
- * @param count count of operations made undone
- */
- public void undoEditing(int count) {
- for (int i=0; i<count; i++)
- {
- if ( segmUndoPoints.isEmpty() ) {
- if ( globalUndoPoints.isEmpty() )
- // No more undo operations available
- break;
- else {
- segmUndoPoints = globalUndoPoints.pop();
- editorFeatureCollection.remove( globalUndoFeatures.peek() );
-
- globalRedoFeatures.push( globalUndoFeatures.pop() );
- if ( !segmRedoPoints.isEmpty() )
- globalRedoPoints.push( segmRedoPoints );
- segmRedoPoints = new Stack<Coordinate>();
-
- // On lines the last point and finish feature operation
- // are separated, so they also must be undone
- // separately.
- if ( editorGeometryForm == GeometryForm.LINE ) {
- generateSegmentFeatureCollection();
- continue;
- }
- }
- }
- segmRedoPoints.push( segmUndoPoints.pop() );
- generateSegmentFeatureCollection();
- }
- refresh();
- }
-
- /**
- * Makes the last made editing action undone.
- */
- public void undoEditing() {
- undoEditing(1);
- }
-
- /**
- * Makes all made editing action undone.
- */
- public void undoAll() {
- undoEditing( Integer.MAX_VALUE );
- }
-
- /**
- * Checks wheater a undo operation can be performed.
- */
- public boolean isUndoPossible() {
- return !segmUndoPoints.isEmpty() || !globalUndoPoints.isEmpty();
- }
-
- /**
- * Restores previous undone editing actions.
- * @param count count of redo operations
- */
- public void redoEditing(int count) {
- for (int i=0; i<count; i++)
- {
- if ( segmRedoPoints.isEmpty() ) {
- if ( globalRedoPoints.isEmpty() )
- // No more redo operations available
- break;
- else {
- // Lines must be finished when all segment redo operations
- // are redone; Points and Polygons must not, because they
- // were already closed on last addSegment(.) (closing point
- // of polygon is also a part of the redo stack!)
- if ( editorGeometryForm == GeometryForm.LINE )
- finishFeature(false, false);
- segmRedoPoints = globalRedoPoints.pop();
- }
- }
- addSegment( segmRedoPoints.pop(), false, false );
- }
- refresh();
- }
-
- /**
- * Restores the last undone editing action.
- */
- public void redoEditing() {
- redoEditing(1);
- }
-
- /**
- * Checks wheater a redo operation can be performed.
- */
- public boolean isRedoPossible() {
- // Redo possible if
- // - some operations of the current segment can be redone
- // - some operations of former segments can be redone
- return !segmRedoPoints.isEmpty() || !globalRedoPoints.isEmpty();
- }
-
- //**********************************************************************
- //***** Helper methods for the editor operations
- //**********************************************************************
- /**
- * Sets {@link #editorFeatureCollection} and {@link #editorLayer} to completely
- * new instances.
- * @param title title for the new layer
- */
- protected void initUndoRedo() {
- // initialize the Undo/Redo-Stacks
- for ( Stack s : globalRedoPoints ) s.clear();
- for ( Stack s : globalUndoPoints ) s.clear();
- globalRedoPoints.clear();
- globalUndoPoints.clear();
- globalRedoFeatures.clear();
- globalUndoFeatures.clear();
- segmRedoPoints.clear();
- segmUndoPoints.clear();
- }
-
- /**
- * Sets {@link #editorFeatureCollection} and {@link #editorLayer} to completely
- * new instances.
- * @param title title for the new layer
- */
- protected void initEditorFeatureCollection(String title) {
- // create the new layer
- editorFeatureCollection = (DefaultFeatureCollection)DefaultFeatureCollections.newCollection(title);
- editorFeatureType = createFeatureType(editorMode, getAdditionalAttributes());
- DUMMY_EDITOR_FEATURE = createDummyFeature(editorFeatureType);
- editorFeatureCollection.add(DUMMY_EDITOR_FEATURE);
- editorGeometryForm = FeatureUtil.getGeometryForm(editorFeatureCollection);
- editorLayer = new DefaultMapLayer(editorFeatureCollection,getEditorStyle(editorGeometryForm));
- editorLayer.setTitle(title);
- }
-
- /**
- * Clears the {@link FeatureCollection} used to handle the current
- * edited segment.
- */
- protected void initSegmentFeatureCollection() {
- // initialize the segment to start a new feature
- if ( segmLineFeatureCollection == null ) {
- // initialize the objects used to display the
- // current segment as line
- segmLineFeatureCollection = (DefaultFeatureCollection)DefaultFeatureCollections.newCollection("SegmentAsLine");
- segmLineFeatureType = createFeatureType(LineString.class, null);
- DUMMY_LINE_FEATURE = createDummyFeature(segmLineFeatureType);
- segmLineFeatureCollection.add(DUMMY_LINE_FEATURE);
- segmLineLayer = new DefaultMapLayer(segmLineFeatureCollection,getEditorStyle(GeometryForm.LINE));
- segmLineLayer.setTitle("Line layer for current segment");
- editorMapContext.addLayer(segmLineLayer);
- // initialize the objects used to display the
- // current segment as points
- segmPointFeatureCollection = (DefaultFeatureCollection)DefaultFeatureCollections.newCollection("SegmentAsPoints");
- segmPointFeatureType = createFeatureType(MultiPoint.class, null);
- DUMMY_POINT_FEATURE = createDummyFeature(segmPointFeatureType);
- segmPointFeatureCollection.add(DUMMY_POINT_FEATURE);
- segmPointLayer = new DefaultMapLayer(segmPointFeatureCollection,getEditorStyle(GeometryForm.POINT));
- segmPointLayer.setTitle("Point layer for current segment");
- editorMapContext.addLayer(segmPointLayer);
- } else {
- segmLineFeatureCollection.clear();
- segmPointFeatureCollection.clear();
- }
- }
-
- /**
- * Creates a new segment SimpleFeature from the currently selected points.
- */
- protected void generateSegmentFeatureCollection() {
- initSegmentFeatureCollection();
- // show the segment as single points
- SimpleFeature segmPointFeature = createSegmentPointFeature();
- if ( segmPointFeature != null )
- segmPointFeatureCollection.add( segmPointFeature );
- // show the segment as a line
- SimpleFeature segmLineFeature = createSegmentLineFeature();
- if ( segmLineFeature != null )
- segmLineFeatureCollection.add( segmLineFeature );
- // Fire event even if no (real) feature is created!
- fireMapPaneEvent( new FeatureModifiedEvent(this,segmLineLayer,segmLineFeature,this) );
- }
-
- /**
- * Creates a new {@link SimpleFeature Line-SimpleFeature} from the currently selected
- * segment points.
- */
- protected SimpleFeature createSegmentLineFeature() {
- // Line can only be created with at least 2 points
- // For point layer the segment is not shown
- if ( segmUndoPoints.size() < 2 ||
- editorGeometryForm == GeometryForm.POINT )
- return null;
-
- Coordinate[] coord = segmUndoPoints.toArray(new Coordinate[0]);
- LineString lineString = createGeometryFromPoints(LineString.class, coord);
- try {
- return FeatureUtil.createFeature(segmLineFeatureType, lineString );
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Creates a new {@link SimpleFeature MultiPoint-SimpleFeature} from the currently selected
- * segment points.
- */
- protected SimpleFeature createSegmentPointFeature() {
- // Point can only be created with at least 1 point
- // For point layer the segment is not shown
- if ( segmUndoPoints.size() < 1 ||
- editorGeometryForm == GeometryForm.POINT )
- return null;
-
- Coordinate[] coord = segmUndoPoints.toArray(new Coordinate[0]);
- MultiPoint multiPoint = createGeometryFromPoints(MultiPoint.class, coord);
- try {
- return FeatureUtil.createFeature(segmPointFeatureType,multiPoint);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Creates a new SimpleFeature from the currently selected points. The non-geometric
- * attributes are set to default values.
- */
- private SimpleFeature createFeature() {
- Coordinate[] coord = segmUndoPoints.toArray(new Coordinate[0]);
- SimpleFeature feature = null;
- try {
- // if a feature was undone previously use this as
- // default for the new feature
- if ( !globalRedoFeatures.isEmpty() )
- feature = globalRedoFeatures.pop();
- else {
- // generate default attribute values
- Object[] attr = FeatureUtil.getDefaultAttributeValues(editorFeatureType);
- // replace default attribute values with auto generate
- // values (for all registered attributes)
- for (int i=0; i<attr.length; i++) {
- AttributeDescriptor aType = editorFeatureType.getDescriptor(i);
- if ( FeatureUtil.getAutoValueGenerator(aType) != null )
- attr[i] = FeatureUtil.getNextAutoValue(aType);
- }
- // create new feature
- feature = FeatureUtil.createFeature(editorFeatureType,attr);
- }
- feature.setDefaultGeometry(
- createGeometryFromPoints(getGeometryType(editorMode), coord )
- );
-
- if ( feature.getAttributeCount() > 1 ) {
- attrInputOption.setValue(feature);
- Object[] value = MultipleOptionPane.showMultipleInputDialog(
- this,
- GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JEditorToolBar.NewFeature.title"),
- attrInputOption
- );
- if ( value == null )
- return null;
- }
- return feature;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- }
-
-
- //**********************************************************************
- //***** Helper methods to deal with geometries
- //**********************************************************************
- /**
- * Determines the geometry type to deal with according to the
- * editor mode.
- * @param mode editor mode
- */
- private static Class<? extends Geometry> getGeometryType(EditorMode mode) {
- switch( mode ) {
- case New_Point: return Point.class;
- case New_Line: return LineString.class;
- case New_Polygon: return Polygon.class;
- }
- return null;
- }
-
- /**
- * Creates a geometry (point, linestring/ring, polygon) from a set of points. If
- * no points are specified ({@code null}), a default geometry is created.
- * @param gtype type of geometry
- * @param coord set of points (can be {@code null})
- */
- private static <G extends Geometry> G createGeometryFromPoints(Class<G> gtype, Coordinate[] coord) {
- // Point
- if ( gtype.isAssignableFrom( com.vividsolutions.jts.geom.Point.class ) ) {
- if ( coord == null )
- coord = new Coordinate[] { new Coordinate() };
- return (G)FeatureUtil.GEOMETRY_FACTORY.createPoint( coord[0] );
- }
- // MultiPoint
- if ( gtype.isAssignableFrom( com.vividsolutions.jts.geom.MultiPoint.class ) ) {
- if ( coord == null )
- coord = new Coordinate[] { new Coordinate() };
- return (G)FeatureUtil.GEOMETRY_FACTORY.createMultiPoint( coord );
- }
- // LineString
- if ( gtype.isAssignableFrom( com.vividsolutions.jts.geom.LineString.class ) ) {
- if ( coord != null && coord.length > 2 && coord[0].equals(coord[coord.length-1]) )
- return (G)FeatureUtil.GEOMETRY_FACTORY.createLinearRing(coord);
- return (G)FeatureUtil.GEOMETRY_FACTORY.createLineString(coord);
- }
- // Polygon
- if ( gtype.isAssignableFrom( com.vividsolutions.jts.geom.Polygon.class ) ) {
- LinearRing shell = null;
- if ( coord != null && coord.length > 2 && coord[0].equals(coord[coord.length-1]) )
- shell = FeatureUtil.GEOMETRY_FACTORY.createLinearRing(coord);
- return (G)FeatureUtil.GEOMETRY_FACTORY.createPolygon(shell,null);
- }
-
- throw new UnsupportedOperationException("Can not create geometry for "+gtype.getName());
- }
-
- /**
- * Extends a feature type with a default geometry attribute.
- * @param gtype default geometry of the new feature type
- * @param ftype a feature type which is extended (can be {@code null})
- */
- private SimpleFeatureType createFeatureType(Class<? extends Geometry> gtype, SimpleFeatureType ftype) {
-// GeometryAttributeType geomAttrType = new GeometricAttributeType(
-// GEOMETRY_ATTR,
-// gtype,
-// false,
-// createGeometryFromPoints(gtype,null),
-// mapContext.getCoordinateReferenceSystem(),
-// null
-// );
- GeometryAttributeType geomAttrType = FeatureUtil.createGeometryAttributeType(
- GEOMETRY_ATTR,
- gtype,
- createGeometryFromPoints(gtype,null),
- mapContext.getCoordinateReferenceSystem()
- );
- SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
- builder.init(ftype);
- if ( ftype == null )
- builder.setName( gtype.getSimpleName()+"_feature" );
- builder.add( geomAttrType ); // automatically sets the default geometry!
-
- return builder.buildFeatureType();
- }
-
- /**
- * Extends a feature type with a default geometry attribute.
- * @param mode specifies the the default geometry used for the feature type
- * @param ftype a feature type which is extended (can be {@code null})
- */
- private SimpleFeatureType createFeatureType(EditorMode mode, SimpleFeatureType ftype) {
- Class<? extends Geometry> gtype = null;
- switch( mode ) {
- case New_Point: gtype = Point.class; break;
- case New_Line: gtype = LineString.class; break;
- case New_Polygon: gtype = Polygon.class; break;
- }
- return createFeatureType(gtype,ftype);
- }
-
- /**
- * Creates a feature with default values for a given feature type.
- * @param ftype a feature type
- */
- private static SimpleFeature createDummyFeature(SimpleFeatureType ftype) {
- try {
- return FeatureUtil.createSampleFeature(ftype);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Checks, whether the editor layer is empty. If it is, a dummy feature is inserted
- * because the StreamingRenderer can not handle empty SimpleFeature-Layers yet
- * (also if the layer is hidden!).
- * At the moment, the first a feature is added, the dummy feature is removed, so
- * is is not displayed any time.
- */
- private void resetEditorLayerVisibility() {
- // if layer is empty, insert a Dummy-SimpleFeature (and hide the
- // layer) because the StreamingRenderer can not handle empty
- // SimpleFeature-Layers yet
- if ( segmLineFeatureCollection != null && segmLineFeatureCollection.size() == 0 )
- segmLineFeatureCollection.add( DUMMY_LINE_FEATURE );
- if ( segmPointFeatureCollection != null && segmPointFeatureCollection.size() == 0 )
- segmPointFeatureCollection.add( DUMMY_POINT_FEATURE );
- if ( editorFeatureCollection != null && editorFeatureCollection.size() == 0 )
- editorFeatureCollection.add( DUMMY_EDITOR_FEATURE );
-
- // if the layer is not empty anymore, remove the Dummy-SimpleFeature, so
- // it is not displayed
- if ( segmLineFeatureCollection != null && segmLineFeatureCollection.size() == 2 )
- segmLineFeatureCollection.remove( DUMMY_LINE_FEATURE );
- if ( segmPointFeatureCollection != null && segmPointFeatureCollection.size() == 2 )
- segmPointFeatureCollection.remove( DUMMY_POINT_FEATURE );
- if ( editorFeatureCollection != null && editorFeatureCollection.size() == 2 )
- editorFeatureCollection.remove( DUMMY_EDITOR_FEATURE );
-
- // hide the editor layer if it only contains the dummy feature
- if ( editorLayer != null )
- editorLayer.setVisible(editorFeatureCollection.size() > 1 || !editorFeatureCollection.contains(DUMMY_EDITOR_FEATURE));
- if ( segmLineLayer != null )
- segmLineLayer.setVisible(segmLineFeatureCollection.size() > 1 || !segmLineFeatureCollection.contains(DUMMY_LINE_FEATURE));
- if ( segmPointLayer != null )
- segmPointLayer.setVisible(segmPointFeatureCollection.size() > 1 || !segmPointFeatureCollection.contains(DUMMY_POINT_FEATURE));
- }
-
-}
Deleted: branches/2.0-RC2/src/schmitzm/geotools/gui/JEditorToolBar.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/JEditorToolBar.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/JEditorToolBar.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -1,532 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program 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 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Krüger - additional utility classes
- ******************************************************************************/
-package schmitzm.geotools.gui;
-
-import java.awt.event.ActionEvent;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import javax.swing.AbstractAction;
-import javax.swing.AbstractButton;
-import javax.swing.Icon;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JToolBar;
-
-import org.apache.log4j.Logger;
-import org.opengis.feature.simple.SimpleFeatureType;
-
-import schmitzm.geotools.gui.JEditorPane.EditorMode;
-import schmitzm.geotools.map.event.JEditorPaneEvent;
-import schmitzm.geotools.map.event.JMapPaneListener;
-import schmitzm.geotools.map.event.LayerEditCanceledEvent;
-import schmitzm.geotools.map.event.LayerEditFinishedEvent;
-import schmitzm.geotools.map.event.MapPaneEvent;
-import schmitzm.swing.ExceptionDialog;
-import schmitzm.swing.ManualInputOption;
-import schmitzm.swing.MultipleOptionPane;
-import schmitzm.swing.SelectionInputOption;
-
-/**
- * A toolbar to control the operations of a {@link JEditorPane}.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
- */
-public class JEditorToolBar extends JToolBar {
- private static final Logger LOGGER = Logger.getLogger(JEditorToolBar.class.getName());
- /** Constant for the tool "New layer" (10). */
- public static final int LAYER_NEW = 10;
- /** Constant for the tool "Save layer" (20). */
- public static final int LAYER_SAVE = 20;
- /** Constant for the tool "Cancel layer" (30). */
- public static final int LAYER_CANCEL = 30;
- /** Constant for the tool "Undo all editor actions" (100). */
- public static final int EDIT_CLEAR = 100;
- /** Constant for the tool "Undo last editor action" (110). */
- public static final int EDIT_UNDO = 110;
- /** Constant for the tool "Redo last undone editor action" (120). */
- public static final int EDIT_REDO = 120;
- /** Constant for the tool "Finish current segment" (130). */
- public static final int EDIT_FINISH = 130;
-
- /** Holds the action buttons of the bar. */
- protected SortedMap<Integer, JButton> actionButtons = null;
-
- /** Holds the {@link JEditorPane} this tool bar controls. */
- protected JEditorPane editorPane = null;
-
- /** Holds the listener, that reacts on editor actions. */
- protected JMapPaneListener mapPaneListener = null;
-
- /**
- * Creates a new toolbar. Notice: This toolbar does nothing
- * until {@link #setMapPane(JEditorPane)} is called!
- */
- public JEditorToolBar() {
- this(null);
- }
-
- /**
- * Creates a new tool bar.
- * @param editorPane {@link JEditorPane} the tool bar controls
- */
- public JEditorToolBar(JEditorPane editorPane) {
- super("Control the editor actions", JToolBar.HORIZONTAL);
- this.actionButtons = new TreeMap<Integer,JButton>();
- // Create a Listener to sniff the zooms on the JMapPane
- this.mapPaneListener = new JMapPaneListener() {
- public void performMapPaneEvent(MapPaneEvent e) {
- if ( !(e instanceof JEditorPaneEvent) )
- return;
-
- // At the moment the layer editing is finished, the editor mode
- // is not yet initialized. However for the button activation the
- // mode NULL is essential in this case.
- EditorMode mode = ((JEditorPaneEvent)e).getEditorMode();
- if ( e instanceof LayerEditCanceledEvent ||
- e instanceof LayerEditFinishedEvent )
- mode = null;
- updateButtonActivation(mode);
- }
- };
-
- setMapPane(editorPane);
- setFloatable(false);
- setRollover(true);
-
- init();
- }
-
- /**
- * Sets the {@link JEditorPane} controlled by this tool bar.
- * @param editorPane {@link JEditorPane} to control (if {@code null} this
- * tool bar controls NOTHING!)
- */
- public void setMapPane(JEditorPane editorPane) {
- // Remove listener from old MapPane
- if ( this.editorPane != null )
- this.editorPane.removeMapPaneListener( mapPaneListener );
- this.editorPane = editorPane;
- if ( this.editorPane != null && mapPaneListener != null )
- this.editorPane.addMapPaneListener( mapPaneListener );
- }
-
- /**
- * Calls {@link #initActions()} and then puts all action buttons
- * to the tool bar.
- */
- protected void init() {
- initActions();
- initToolBar();
- updateButtonActivation(null);
- }
-
- /**
- * Creates the action buttons and adds them to {@link #actionButtons}.
- */
- protected void initActions() {
- // Action button to create a new layer
- addAction( new EditorPaneToolBarAction(
- LAYER_NEW,
- this,
- "button.layer.new",
- new ImageIcon(JEditorPane.class.getResource("resource/icons/layer_new.png"))
- ), false);
-
- // Action button to finish a layer
- addAction( new EditorPaneToolBarAction(
- LAYER_SAVE,
- this,
- "button.layer.save",
- new ImageIcon(JEditorPane.class.getResource("resource/icons/layer_finish.png"))
- ), false);
-
- // Action button to cancel a layer
- addAction( new EditorPaneToolBarAction(
- LAYER_CANCEL,
- this,
- "button.layer.cancel",
- new ImageIcon(JEditorPane.class.getResource("resource/icons/layer_cancel.png"))
- ), false);
-
- // Action button to undo all editing action
- addAction( new EditorPaneToolBarAction(
- EDIT_CLEAR,
- this,
- "button.edit.clear",
- new ImageIcon(JEditorPane.class.getResource("resource/icons/edit_clear.png"))
- ), false);
-
- // Action button to undo a editing action
- addAction( new EditorPaneToolBarAction(
- EDIT_UNDO,
- this,
- "button.edit.undo",
- new ImageIcon(JEditorPane.class.getResource("resource/icons/edit_undo.png"))
- ), false);
-
- // Action button to redo a undone editing action
- addAction( new EditorPaneToolBarAction(
- EDIT_REDO,
- this,
- "button.edit.redo",
- new ImageIcon(JEditorPane.class.getResource("resource/icons/edit_redo.png"))
- ), false);
-
- // Action button to finish a feature
- addAction( new EditorPaneToolBarAction(
- EDIT_FINISH,
- this,
- "button.edit.finish",
- new ImageIcon(JEditorPane.class.getResource("resource/icons/edit_finish.png"))
- ), false);
- }
-
- /**
- * Clears the GUI of all components and adds all action buttons to the
- * tool bar.
- */
- protected void initToolBar() {
- setAlignmentY( 1f );
- removeAll();
-// // Separator to the left of the tool actions to start
-// // the tool buttons with the map (not with the coordinate grid)
-// Dimension dimension = new Dimension( 49,10);
-// addSeparator(dimension);
-// // Space between tool buttons and action buttons
-// Dimension dimension2 = new Dimension( 10,10);
-// this.addSeparator(dimension2);
- // Action buttons
- for (JButton b : actionButtons.values())
- add(b);
- }
-
-
- /**
- * Performs the action of an action button.
- * @param tool the action
- * @param e the event of the button
- */
- protected void performActionButton(int action, ActionEvent e) {
- if ( editorPane == null )
- return;
-
- try {
- // Perform the action "New layer"
- if ( action == LAYER_NEW )
- createNewLayer();
- // Perform the action "Finish layer"
- if ( action == LAYER_SAVE )
- editorPane.finishEditing();
- // Perform the action "Cancel layer"
- if ( action == LAYER_CANCEL )
- editorPane.cancelEditing();
-
- // Perform the action "Finish feature"
- if ( action == EDIT_FINISH )
- editorPane.finishFeature();
- // Perform the action "Undo editing"
- if ( action == EDIT_UNDO )
- editorPane.undoEditing();
- // Perform the action "Redo editing"
- if ( action == EDIT_REDO )
- editorPane.redoEditing();
- // Perform the action "Clear editing"
- if ( action == EDIT_CLEAR )
- editorPane.undoAll();
- } catch (Exception err) {
- ExceptionDialog.show(err);
- }
- }
-
- /**
- * Sets the enables/disables property for every toolbar button according
- * to the current editor state.
- * @param editorMode editor mode (because some events are fired BEFORE
- * the new mode is set)
- */
- protected void updateButtonActivation(EditorMode editorMode) {
- if ( editorPane == null ) {
- setAllActionsEnabled(false, false);
- return;
- }
- getButton( LAYER_NEW ).setEnabled( editorMode == null );
- getButton( LAYER_SAVE ).setEnabled( editorMode != null );
- getButton( LAYER_CANCEL ).setEnabled( editorMode != null );
- getButton( EDIT_UNDO ).setEnabled( editorPane.isUndoPossible() );
- getButton( EDIT_REDO ).setEnabled( editorPane.isRedoPossible() );
- getButton( EDIT_CLEAR ).setEnabled( editorPane.isUndoPossible() );
- getButton( EDIT_FINISH ).setEnabled( editorMode != null && editorMode != EditorMode.New_Point );
- }
-
- /**
- * Starts new layer.
- */
- protected void createNewLayer() {
- // Ask layer type and name
- ManualInputOption.Text titleOption = new ManualInputOption.Text(
- getResourceString("NewLayer.layer.title"), true, getResourceString("NewLayer.layer.title.default")
- );
- SelectionInputOption.Radio<JEditorPane.EditorMode> typeOption = new SelectionInputOption.Radio<JEditorPane.EditorMode>(
- getResourceString("NewLayer.layer.type"),
- true,
- new JEditorPane.EditorMode[] { EditorMode.New_Point, EditorMode.New_Line, EditorMode.New_Polygon },
- new String[] { getResourceString("NewLayer.layer.type.point"), getResourceString("NewLayer.layer.type.line"), getResourceString("NewLayer.layer.type.polygon") }
- );
- FeatureTypeInputOption ftOption = new FeatureTypeInputOption(
- getResourceString("NewLayer.ftype.title"),
- false
- ) {
- // Checks whether "the_geom" is used as attribute name
- // --> not allowed because JEditorPane uses this attribute
- // for the default geometry of new layers
- public boolean performIsInputValid() {
- if ( super.performIsInputValid() ) {
- SimpleFeatureType ft = inpTableModel.createFeatureType();
- if ( ft.getDescriptor( JEditorPane.GEOMETRY_ATTR ) != null )
- throw new UnsupportedOperationException(getResourceString("NewLayer.Err.GeomAttr",JEditorPane.GEOMETRY_ATTR));
- }
- return true;
- }
- };
- Object[] value = MultipleOptionPane.showMultipleInputDialog(
- this,
- getResourceString("NewLayer.dialog.title"),
- titleOption,
- typeOption,
- ftOption
- );
- if ( value == null )
- return; // Dialog canceled
- editorPane.setAdditionalAttributes( ftOption.getValue() );
- editorPane.startEditing(
- (JEditorPane.EditorMode)value[1],
- (String)value[0]
- );
- }
-
- /**
- * Adds an action to the tool bar. Does nothing if a tool or action with the
- * specified ID already exists!
- * @param buttonAction action for the button
- * @param resetToolBar indicates whether the toolbar GUI is reset after adding
- * the button (if adding several actions it useful only to
- * reset the GUI for the last added tool)
- */
- public void addAction(EditorPaneToolBarAction buttonAction, boolean resetToolBar) {
- if ( isButtonIDUsed(buttonAction.getID()) ) {
- LOGGER.warn("addAction(.) ignored because ID already used for tool or action: "+buttonAction.getID());
- return;
- }
- JButton button = new JButton(buttonAction);
- actionButtons.put( buttonAction.getID(), button );
- if ( resetToolBar )
- initToolBar();
- }
-
- /**
- * Adds an action to the tool bar and resets the toolbar GUI.
- * @param buttonAction action for the toggle button
- */
- public void addAction(EditorPaneToolBarAction buttonAction) {
- addAction(buttonAction, true);
- }
-
- /**
- * Returns the button for a specific tool or action.
- * @param id the constant for a tool
- * @return a {@link JButton} if {@code id} specifies an {@linkplain #getActionButton(int) action button}
- * or {@link JToogleButton} if {@code id} specifies a {@linkplain #getToolButton(int) tool button}
- */
- public AbstractButton getButton(int id) {
- AbstractButton button = actionButtons.get(id);
- if ( button == null )
- LOGGER.warn("Unknown action ID: "+id);
- return button;
- }
-
- /**
- * Returns the button for a specific action.
- * @param action the constant an action
- */
- public JButton getActionButton(int action) {
- AbstractButton button = getButton(action);
- if ( button != null && !(button instanceof JButton) ) {
- LOGGER.warn("ID specifies no action: "+action);
- button = null;
- }
- return (JButton)button;
-
- }
-
- /**
- * Sets whether an action is activated or not. The visible property
- * of the button is not affected.
- * @param id actionID
- * @param enabled if {@code true} the action becomes available
- */
- public void setButtonEnabled(int id, boolean enabled) {
- AbstractButton button = getButton(id);
- if ( button == null )
- return;
- button.setEnabled( enabled );
- }
-
- /**
- * Sets whether an action is activated or not.
- * @param id actionID
- * @param enabled if {@code true} the tool becomes available
- * @param hideOnDisable if {@code true} the button is also hidden if
- * {@code enabled} is {@code false}
- */
- public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {
- AbstractButton button = getButton(id);
- if ( button == null )
- return;
- button.setEnabled( enabled );
- // if button is enabled, it becomes visible anyway
- // if button is disabled and the "hide" option is set, it is also hidden
- if ( enabled )
- button.setVisible( true );
- else
- button.setVisible( !hideOnDisable );
- }
-
- /**
- * Checks whether a ID is already used for a tool or action.
- * @param tool tool ID
- */
- public boolean isButtonIDUsed(int id) {
- return actionButtons.get(id) != null;
- }
-
- /**
- * Checks whether a tool is activated.
- * @param tool tool ID
- * @return {@code false} if an unknown ID is specified
- */
- public boolean isButtonEnabled(int id) {
- AbstractButton button = getButton(id);
- if ( button != null )
- return button.isEnabled();
- return false;
- }
-
- /**
- * Sets the activation for all actions.
- * @param enabled if {@code true} all actions becomes available
- * @param hideOnDisable if {@code true} the buttons are also hidden if
- * {@code enabled} is {@code false}
- */
- public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {
- for (int tool : actionButtons.keySet())
- setButtonEnabled(tool,enabled,hideOnDisable);
- }
-
- /**
- * Returns the maximum ID of actions.
- */
- public int getMaxActionID() {
- return actionButtons.lastKey();
- }
-
- /**
- * Returns the minimum ID of actions.
- */
- public int getMinActionID() {
- return actionButtons.firstKey();
- }
-
- protected static String getResourceString(String key, Object... params) {
- return GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JEditorToolBar."+key,params);
- }
-
- /**
- * Extends the {@link AbstractAction} with maintaining an ID and
- * the {@link JEditorToolBar} the action controls.
- * Additionally this class automatically calls
- * {@link JEditorToolBar#performActionButton(int, ActionEvent)}.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
- */
- public static class EditorPaneToolBarAction extends AbstractAction {
- /** The ID of the action */
- protected int id = -1;
- /** The tool bar, this action is made for. */
- protected JEditorToolBar toolBar = null;
-
- /**
- * Creates a new action with a dummy description and no icon.
- * @param id unique ID for the action
- * @param toolBar toolbar this action is made for
- */
- public EditorPaneToolBarAction(int id, JEditorToolBar toolBar) {
- this(id,toolBar,""+id);
- }
-
- /**
- * Creates a new action without an icon.
- * @param id unique ID for the action
- * @param toolBar toolbar this action is made for
- * @param name description used for buttons or menus
- */
- public EditorPaneToolBarAction(int id, JEditorToolBar toolBar, String name) {
- this(id,toolBar,name,null);
- }
-
- /**
- * Creates a new action.
- * @param id unique ID for the action
- * @param toolBar toolbar this action is made for
- * @param name description used for buttons or menus
- * @param icon icon used for buttons or menus
- */
- public EditorPaneToolBarAction(int id, JEditorToolBar toolBar, String name, Icon icon) {
- super("",icon);
- this.id = id;
- this.toolBar = toolBar;
- this.putValue(SHORT_DESCRIPTION, getResourceString(name));
- }
-
- /**
- * Calls {@link JEditorToolBar#performActionButton(int, ActionEvent)}.
- */
- public void actionPerformed(ActionEvent e) {
- if ( toolBar.actionButtons.get(id) != null )
- toolBar.performActionButton(id, e);
- }
-
- /**
- * Returns the (unique) id of this action.
- * @return
- */
- public int getID() {
- return id;
- }
- }
-}
Added: branches/2.0-RC2/src/schmitzm/geotools/gui/JMapEditorPane.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/JMapEditorPane.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/JMapEditorPane.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -0,0 +1,945 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program 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 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Krüger - additional utility classes
+ ******************************************************************************/
+package schmitzm.geotools.gui;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.event.MouseEvent;
+import java.awt.geom.Point2D;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import org.geotools.feature.DefaultFeatureCollection;
+import org.geotools.feature.DefaultFeatureCollections;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.GeometryAttributeType;
+import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
+import org.geotools.map.DefaultMapContext;
+import org.geotools.map.DefaultMapLayer;
+import org.geotools.map.MapContext;
+import org.geotools.map.MapLayer;
+import org.geotools.renderer.GTRenderer;
+import org.geotools.styling.Style;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.feature.type.AttributeDescriptor;
+
+import schmitzm.geotools.GTUtil;
+import schmitzm.geotools.feature.FeatureUtil;
+import schmitzm.geotools.feature.FeatureUtil.GeometryForm;
+import schmitzm.geotools.map.event.FeatureModifiedEvent;
+import schmitzm.geotools.map.event.LayerEditCanceledEvent;
+import schmitzm.geotools.map.event.LayerEditFinishedEvent;
+import schmitzm.geotools.map.event.LayerEditStartedEvent;
+import schmitzm.geotools.map.event.MapContextSynchronizer;
+import schmitzm.swing.InputOption;
+import schmitzm.swing.MultipleOptionPane;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.LineString;
+import com.vividsolutions.jts.geom.LinearRing;
+import com.vividsolutions.jts.geom.MultiPoint;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.Polygon;
+
+
+/**
+ * The {@code JMapEditorPane} extends the {@link SelectableXMapPane} with functionalities
+ * to create new vector layers by successively click points via mouse.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * @version 1.0
+ */
+public class JMapEditorPane extends SelectableXMapPane {
+ /** Modes, the editor can be perform.
+ * @see JMapEditorPane#startEditing(EditorMode, String, Style) */
+ public static enum EditorMode {
+ /** Create a new point layer. */
+ New_Point,
+ /** Create a new linestring layer. */
+ New_Line,
+ /** Create a new polygon layer. */
+ New_Polygon
+ }
+
+ /** Attribute name used for the geometry of new layers. */
+ public static final String GEOMETRY_ATTR = "the_geom";
+
+ /** Default-Style for point layers (blue dots). */
+ public static final Style DEFAULT_POINT_STYLE = FeatureUtil.createPointStyle(Color.BLUE);
+ /** Default-Style for line layers (blue lines). */
+ public static final Style DEFAULT_LINE_STYLE = FeatureUtil.createLineStyle(Color.BLUE,2);
+ /** Default-Style for polygon layers (orange with black borders). */
+ public static final Style DEFAULT_POLYGON_STYLE = FeatureUtil.createPolygonStyle(Color.ORANGE, Color.BLUE, 2);
+
+ /** If the edited layer is empty, a dummy feature is inserted, because
+ * the StreamingRenderer can not handle empty FeatureCollections yet. */
+ private SimpleFeature DUMMY_EDITOR_FEATURE = null;
+ private SimpleFeature DUMMY_LINE_FEATURE = null;
+ private SimpleFeature DUMMY_POINT_FEATURE = null;
+
+ /** The map context of the displayed layer. */
+ protected MapContext mapContext = null;
+
+ /** Contains the additional attributes for new FeatureCollections. */
+ protected SimpleFeatureType additionalAttr = null;
+ /** Contains the {@link InputOption} to specify the additional
+ * attribute values. */
+ protected FeatureInputOption attrInputOption = null;
+
+ /** The map context where the edited layers are displayed. This
+ * context is displayed on top of the other layers. */
+ protected MapContext editorMapContext = null;
+ /** The renderer the edited layers are rendered with. */
+ protected GTRenderer editorRenderer = null;
+ /** Holds the {@link Style styles} to display edited layers. */
+ protected Map<GeometryForm,Style> editorStyles = null;
+ /** Holds the operation the editor currently performs. */
+ protected EditorMode editorMode = null;
+
+ /** Holds the {@link SimpleFeatureType} of the edited layer. */
+ protected SimpleFeatureType editorFeatureType = null;
+ /** Holds the kind of geometry of the edited layer. */
+ protected GeometryForm editorGeometryForm = null;
+ /** Holds the {@link FeatureCollection} of the edited layer. */
+ protected FeatureCollection<SimpleFeatureType, SimpleFeature> editorFeatureCollection = null;
+ /** Holds the edited layer. */
+ protected MapLayer editorLayer = null;
+
+ /** Holds the {@link SimpleFeatureType} of the new segment (incomplete SimpleFeature)
+ * displayed as line. */
+ protected SimpleFeatureType segmLineFeatureType = null;
+ /** Holds the {@link FeatureCollection} which holds the new segment
+ * (incomplete SimpleFeature) displayed as line. */
+ protected DefaultFeatureCollection segmLineFeatureCollection = null;
+ /** Holds the layer, the new segment (incomplete SimpleFeature) is displayed in
+ * as line. */
+ protected MapLayer segmLineLayer = null;
+
+ /** Holds the {@link SimpleFeatureType} of the new segment (incomplete SimpleFeature)
+ * displayed as points. */
+ protected SimpleFeatureType segmPointFeatureType = null;
+ /** Holds the {@link FeatureCollection} which holds the new segment
+ * (incomplete SimpleFeature) displayed as points. */
+ protected DefaultFeatureCollection segmPointFeatureCollection = null;
+ /** Holds the layer, the new segment (incomplete SimpleFeature) is displayed in
+ * as points. */
+ protected MapLayer segmPointLayer = null;
+
+
+ /** Holds the points of the edited segment (incomplete SimpleFeature) which
+ * can be undone. */
+ protected Stack<Coordinate> segmUndoPoints = new Stack<Coordinate>();
+ /** Holds the undone points of the edited segment (incomplete SimpleFeature) which
+ * can be redone. */
+ protected Stack<Coordinate> segmRedoPoints = new Stack<Coordinate>();
+ /** Holds the points of former segments (complete Features) which
+ * can be undone. */
+ protected Stack<Stack<Coordinate>> globalUndoPoints = new Stack<Stack<Coordinate>>();
+ /** Holds the undone points of former segments (complete Features) which
+ * can be redone. */
+ protected Stack<Stack<Coordinate>> globalRedoPoints = new Stack<Stack<Coordinate>>();
+ /** Holds the former segments (complete Features) which can be undone. */
+ protected Stack<SimpleFeature> globalUndoFeatures = new Stack<SimpleFeature>();
+ /** Holds the undone segments (complete Features) which can be redone. */
+ protected Stack<SimpleFeature> globalRedoFeatures = new Stack<SimpleFeature>();
+
+ /**
+ * Creates a new {@code JMapEditorPane}.
+ */
+ public JMapEditorPane() {
+ this(null);
+ }
+
+ /**
+ * Creates a new {@code JMapEditorPane}. This constructor provides the possibility
+ * to use alternative implementations of the internal components.
+ * <b>The specified parameter all can be {@code null}! In this case
+ * the respective default component is used.</b>
+ */
+ public JMapEditorPane(MapContext context) {
+ super(context);
+ this.mapContext = getMapContext();
+ // initalize the editor styles
+ this.editorStyles = new HashMap<GeometryForm, Style>();
+ for (GeometryForm geomForm : GeometryForm.values())
+ this.setEditorStyle(geomForm, null);
+
+ // no standard action on left mouse button, instead: adding points
+ setState( NONE );
+ setState( ZOOM_IN );
+ // special map context for the editor layers, so the
+ // editor layers are not shown in "normal" layer list
+ this.editorMapContext = new DefaultMapContext( mapContext.getCoordinateReferenceSystem() );
+ this.editorRenderer = GTUtil.createGTRenderer(this.editorMapContext);
+ // listen to CRS/Area changes on the "normal" Context to
+ // synchronize the editor context
+ this.mapContext.addMapBoundsListener( new MapContextSynchronizer(editorMapContext) );
+
+ // create the input option to specify additional attribute values
+ attrInputOption = new FeatureInputOption(null,true,(SimpleFeature)null);
+ }
+
+/**
+ * After the actions of the super method, this method paints the
+ * special editor layers in {@link #editorMapContext}.
+ */
+ protected void paintComponent(Graphics g) {
+ resetEditorLayerVisibility();
+ super.paintComponent(g);
+ Rectangle r = getBounds();
+ Rectangle dr = new Rectangle(r.width, r.height);
+ editorRenderer.setContext(editorMapContext);
+ editorRenderer.paint((Graphics2D) g, dr, mapArea);
+ }
+
+ /**
+ * Ignores the actions of the super class for left-clicks.
+ * Instead this method reacts according to the current
+ * editor mode.
+ */
+// @Override
+ public void mouseClicked(MouseEvent e) {
+ Point2D geoCoord = getScreenToWorld().transform(e.getPoint(), null);
+ // Zunaechst Modus auf NULL pruefen, da ansonsten
+ // NullPointerException in switch-Statement
+ if ( editorMode == null )
+ return;
+
+ switch( editorMode ) {
+ case New_Point:
+ case New_Line:
+ case New_Polygon: addSegment( new Coordinate(geoCoord.getX(), geoCoord.getY()) );
+ break;
+ }
+ }
+
+ //**********************************************************************
+ //***** General public methods
+ //**********************************************************************
+
+ /**
+ * Checks, whether a layer is edited.
+ */
+ public boolean isEditorEnabled() {
+ return editorMode != null;
+ }
+
+ /**
+ * Sets the style for edited layers.
+ * @param geomForm kind of layers the style is set for
+ * @param style a Style (if {@code null} a default style is set, so
+ * {@link #getEditorStyle(GeometryForm)} never returns null)
+ */
+ public void setEditorStyle(GeometryForm geomForm, Style style) {
+ // If no style is specified, set a default style
+ if ( style == null )
+ switch ( geomForm ) {
+ case POINT: style = DEFAULT_POINT_STYLE; break;
+ case LINE: style = DEFAULT_LINE_STYLE; break;
+ case POLYGON: style = DEFAULT_POLYGON_STYLE; break;
+ }
+
+ // Set the style
+ editorStyles.put(geomForm, style);
+
+ // Apply the style also to the current edited layer
+ if ( editorLayer != null && FeatureUtil.getGeometryForm(editorLayer) == geomForm )
+ editorLayer.setStyle(style);
+ if ( segmLineLayer != null && FeatureUtil.getGeometryForm(segmLineLayer) == geomForm )
+ segmLineLayer.setStyle(style);
+ if ( segmPointLayer != null && FeatureUtil.getGeometryForm(segmPointLayer) == geomForm )
+ segmPointLayer.setStyle(style);
+ }
+
+ /**
+ * Returns the style for edited layers.
+ * @param geomForm type of layers the style is returned for
+ */
+ public Style getEditorStyle(GeometryForm geomForm) {
+ return this.editorStyles.get(geomForm);
+ }
+
+ /**
+ * Returns the style for the current edited layer.
+ */
+ public Style getEditorStyle() {
+ if ( editorGeometryForm == null )
+ return null;
+ return this.editorStyles.get(editorGeometryForm);
+ }
+
+ /**
+ * Sets the additional attributes for new FeatureCollections (besides
+ * the geometric attribute, which is added automatically).
+ * @param fType defines the attributes (If {@code null}, new FeatureCollections
+ * only contain the geometric attribute)
+ */
+ public void setAdditionalAttributes(SimpleFeatureType fType) {
+ this.additionalAttr = fType;
+ }
+
+ /**
+ * Returns the additional attributes for new FeatureCollections (besides
+ * the geometric attribute, which is added automatically).
+ */
+ public SimpleFeatureType getAdditionalAttributes() {
+ return this.additionalAttr;
+ }
+
+ /**
+ * Returns the current editor mode.
+ */
+ public EditorMode getEditorMode() {
+ return this.editorMode;
+ }
+
+ /**
+ * Returns the edited layer.
+ */
+ public MapLayer getEditorLayer() {
+ return this.editorLayer;
+ }
+
+ /**
+ * Returns the {@link FeatureCollection} of the edited layer.
+ */
+ public FeatureCollection<SimpleFeatureType, SimpleFeature> getEditorFeatureCollection() {
+ return this.editorFeatureCollection;
+ }
+
+ //**********************************************************************
+ //***** Public Methods controlling the editor operations
+ //**********************************************************************
+
+ /**
+ * Starts a new layer.
+ * @param mode type of layer
+ * @param layerTitle Title for the new layer
+ * @exception UnsupportedOperationException if no map area is defined yet
+ */
+ public void startEditing(EditorMode mode, String layerTitle) {
+ // to create a new layer, first an existing layer must be
+ // displayed, so that a CRS and geo-position is available
+ // for the new layer
+ if ( getMapArea() == null )
+ throw new UnsupportedOperationException( GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JMapEditorPane.Err.MissingMap") );
+ // cancel active editings
+ cancelEditing();
+ editorMode = mode;
+
+ // Create new Layers
+ initEditorFeatureCollection(layerTitle);
+ initSegmentFeatureCollection();
+ editorMapContext.addLayer(0,editorLayer);
+ fireMapPaneEvent( new LayerEditStartedEvent(this,editorLayer,this) );
+ }
+
+ /**
+ * Called when the mouse is clicked on map during creating a new layer.
+ * @param coord World coordinates of click position
+ * @param refresh indicates whether the visualization will be refreshed
+ * @param aClearRedo indicates whether the REDO-Stack is cleared (normally {@code true},
+ * but {@code false} during REDO operation!)
+ */
+ protected void addSegment(Coordinate coord, boolean refresh, boolean clearRedo) {
+ if ( editorMode != EditorMode.New_Point &&
+ editorMode != EditorMode.New_Line &&
+ editorMode != EditorMode.New_Polygon )
+ return;
+
+ // store the new point for undoing
+ segmUndoPoints.push(coord);
+ // delete all former redo possibilities
+ if ( clearRedo )
+ segmRedoPoints.clear();
+ // recreate the segment FeatureCollection to show the extended line
+ generateSegmentFeatureCollection();
+
+ // finish the feature automatically
+ // - when editing points, because there are no segments for point layer,
+ // because every point is a new feature
+ // - when editing polygons and reaching the start point
+ if ( editorGeometryForm == GeometryForm.POINT ||
+ editorGeometryForm == GeometryForm.POLYGON && segmUndoPoints.size() > 1 && segmUndoPoints.lastElement().equals(segmUndoPoints.firstElement()) )
+ finishFeature(refresh, clearRedo); // refresh is done by finishFeature()
+ else
+ if ( refresh )
+ refresh();
+ }
+
+ /**
+ * Called when the mouse is clicked on map during creating a new layer.
+ * @param coord World coordinates of click position
+ */
+ protected void addSegment(Coordinate coord) {
+ addSegment(coord, true, true);
+ }
+
+ /**
+ * Finishes the editing of the current segment (SimpleFeature).
+ * If no editing operation is currently in progress, this method does nothing.
+ * @param refresh indicates whether the visualization will be refreshed
+ * @param aClearRedo indicates whether the REDO-Stack is cleared (normally {@code true},
+ * but {@code false} during REDO operation!)
+ * @exception UnsupportedOperationException if a line or polygon feature can not
+ * be finished because of less specified points
+ */
+ protected void finishFeature(boolean refresh, boolean clearRedo) {
+ if ( editorMode == null )
+ return;
+
+ if ( editorGeometryForm == GeometryForm.LINE && segmUndoPoints.size() < 2 )
+ throw new UnsupportedOperationException( GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JMapEditorPane.Err.Line.LessPoints") );
+ if ( editorGeometryForm == GeometryForm.POLYGON && segmUndoPoints.size() < 3 )
+ throw new UnsupportedOperationException( GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JMapEditorPane.Err.Polygon.LessPoints") );
+
+ // close a polygon automatically
+ if ( editorGeometryForm == GeometryForm.POLYGON &&
+ !segmUndoPoints.lastElement().equals(segmUndoPoints.firstElement()) ) {
+ addSegment( segmUndoPoints.firstElement(), refresh, clearRedo );
+ return; // !!!! finishFeature(.) is called again by addSegment(..) !!!!
+ }
+ // create a new SimpleFeature from the segment points
+ SimpleFeature feature = createFeature();
+ if ( feature == null )
+ return;
+ fireMapPaneEvent( new FeatureModifiedEvent(this,editorLayer,feature,this) );
+
+ // update the global undo
+ globalUndoPoints.push( segmUndoPoints );
+ globalUndoFeatures.push( feature );
+ editorFeatureCollection.add( feature );
+
+ // after finishing a SimpleFeature, a new segment is started
+ segmUndoPoints = new Stack<Coordinate>();
+ if ( clearRedo )
+ segmRedoPoints = globalRedoPoints.isEmpty() ? new Stack<Coordinate>() : globalRedoPoints.pop();
+ initSegmentFeatureCollection();
+ // refresh the display
+ if ( refresh )
+ refresh();
+ }
+
+ /**
+ * Finishes the editing of the current segment (SimpleFeature).
+ * If no editing operation is currently in progress, this method does nothing.
+ */
+ public void finishFeature() {
+ finishFeature(true, true);
+ }
+
+ /**
+ * Finishes the current editing operation. After that no more operations
+ * on this layer can be performed.
+ * As long as no other editing operation is started, the edited (new) layer is
+ * available by {@link #getEditorLayer()} and {@link #getEditorFeatureCollection()}.
+ * If no editing operation is currently in progress, this method does nothing.
+ */
+ public void finishEditing() {
+ if ( editorMode == null )
+ return;
+
+ // if current segment is not closed, finish it automatically
+ if ( !segmUndoPoints.isEmpty() )
+ finishFeature();
+ initUndoRedo();
+
+ // move the edited layer to the "real" MapContext
+ editorMapContext.removeLayer(editorLayer);
+ if ( mapContext.indexOf(editorLayer) < 0 ) {
+ mapContext.addLayer(editorLayer);
+ editorLayer.setVisible(true);
+ }
+ fireMapPaneEvent( new LayerEditFinishedEvent(this,editorLayer,this) );
+
+ // initialize the editing variables
+ editorMode = null;
+ editorLayer = null;
+ editorFeatureCollection = null;
+ editorGeometryForm = null;
+
+ // refresh the display
+ refresh();
+ }
+
+ /**
+ * Cancels the current edititing operation. The edited layer is removed.
+ */
+ public void cancelEditing() {
+ if ( editorLayer != null )
+ this.editorMapContext.removeLayer( editorLayer );
+ if ( editorFeatureCollection != null ) {
+ if ( mapContext.indexOf(editorLayer) < 0 ) {
+ // Layer was a new one, so clear it completly
+ editorFeatureCollection.clear();
+ initUndoRedo();
+ fireMapPaneEvent( new LayerEditCanceledEvent(this,null,this) );
+ } else {
+ // Layer was an existing one, so undo all editing operations
+ undoAll();
+ initUndoRedo();
+ fireMapPaneEvent( new LayerEditFinishedEvent(this,editorLayer,this) );
+ }
+ }
+ if ( segmLineFeatureCollection != null )
+ segmLineFeatureCollection.clear();
+ if ( segmPointFeatureCollection != null )
+ segmPointFeatureCollection.clear();
+
+ // initialize the editing variables
+ editorMode = null;
+ editorLayer = null;
+ editorFeatureCollection = null;
+ editorGeometryForm = null;
+
+ // refresh the display
+ refresh();
+ }
+
+ /**
+ * Makes previously made editing actions undone.
+ * @param count count of operations made undone
+ */
+ public void undoEditing(int count) {
+ for (int i=0; i<count; i++)
+ {
+ if ( segmUndoPoints.isEmpty() ) {
+ if ( globalUndoPoints.isEmpty() )
+ // No more undo operations available
+ break;
+ else {
+ segmUndoPoints = globalUndoPoints.pop();
+ editorFeatureCollection.remove( globalUndoFeatures.peek() );
+
+ globalRedoFeatures.push( globalUndoFeatures.pop() );
+ if ( !segmRedoPoints.isEmpty() )
+ globalRedoPoints.push( segmRedoPoints );
+ segmRedoPoints = new Stack<Coordinate>();
+
+ // On lines the last point and finish feature operation
+ // are separated, so they also must be undone
+ // separately.
+ if ( editorGeometryForm == GeometryForm.LINE ) {
+ generateSegmentFeatureCollection();
+ continue;
+ }
+ }
+ }
+ segmRedoPoints.push( segmUndoPoints.pop() );
+ generateSegmentFeatureCollection();
+ }
+ refresh();
+ }
+
+ /**
+ * Makes the last made editing action undone.
+ */
+ public void undoEditing() {
+ undoEditing(1);
+ }
+
+ /**
+ * Makes all made editing action undone.
+ */
+ public void undoAll() {
+ undoEditing( Integer.MAX_VALUE );
+ }
+
+ /**
+ * Checks wheater a undo operation can be performed.
+ */
+ public boolean isUndoPossible() {
+ return !segmUndoPoints.isEmpty() || !globalUndoPoints.isEmpty();
+ }
+
+ /**
+ * Restores previous undone editing actions.
+ * @param count count of redo operations
+ */
+ public void redoEditing(int count) {
+ for (int i=0; i<count; i++)
+ {
+ if ( segmRedoPoints.isEmpty() ) {
+ if ( globalRedoPoints.isEmpty() )
+ // No more redo operations available
+ break;
+ else {
+ // Lines must be finished when all segment redo operations
+ // are redone; Points and Polygons must not, because they
+ // were already closed on last addSegment(.) (closing point
+ // of polygon is also a part of the redo stack!)
+ if ( editorGeometryForm == GeometryForm.LINE )
+ finishFeature(false, false);
+ segmRedoPoints = globalRedoPoints.pop();
+ }
+ }
+ addSegment( segmRedoPoints.pop(), false, false );
+ }
+ refresh();
+ }
+
+ /**
+ * Restores the last undone editing action.
+ */
+ public void redoEditing() {
+ redoEditing(1);
+ }
+
+ /**
+ * Checks wheater a redo operation can be performed.
+ */
+ public boolean isRedoPossible() {
+ // Redo possible if
+ // - some operations of the current segment can be redone
+ // - some operations of former segments can be redone
+ return !segmRedoPoints.isEmpty() || !globalRedoPoints.isEmpty();
+ }
+
+ //**********************************************************************
+ //***** Helper methods for the editor operations
+ //**********************************************************************
+ /**
+ * Sets {@link #editorFeatureCollection} and {@link #editorLayer} to completely
+ * new instances.
+ * @param title title for the new layer
+ */
+ protected void initUndoRedo() {
+ // initialize the Undo/Redo-Stacks
+ for ( Stack s : globalRedoPoints ) s.clear();
+ for ( Stack s : globalUndoPoints ) s.clear();
+ globalRedoPoints.clear();
+ globalUndoPoints.clear();
+ globalRedoFeatures.clear();
+ globalUndoFeatures.clear();
+ segmRedoPoints.clear();
+ segmUndoPoints.clear();
+ }
+
+ /**
+ * Sets {@link #editorFeatureCollection} and {@link #editorLayer} to completely
+ * new instances.
+ * @param title title for the new layer
+ */
+ protected void initEditorFeatureCollection(String title) {
+ // create the new layer
+ editorFeatureCollection = (DefaultFeatureCollection)DefaultFeatureCollections.newCollection(title);
+ editorFeatureType = createFeatureType(editorMode, getAdditionalAttributes());
+ DUMMY_EDITOR_FEATURE = createDummyFeature(editorFeatureType);
+ editorFeatureCollection.add(DUMMY_EDITOR_FEATURE);
+ editorGeometryForm = FeatureUtil.getGeometryForm(editorFeatureCollection);
+ editorLayer = new DefaultMapLayer(editorFeatureCollection,getEditorStyle(editorGeometryForm));
+ editorLayer.setTitle(title);
+ }
+
+ /**
+ * Clears the {@link FeatureCollection} used to handle the current
+ * edited segment.
+ */
+ protected void initSegmentFeatureCollection() {
+ // initialize the segment to start a new feature
+ if ( segmLineFeatureCollection == null ) {
+ // initialize the objects used to display the
+ // current segment as line
+ segmLineFeatureCollection = (DefaultFeatureCollection)DefaultFeatureCollections.newCollection("SegmentAsLine");
+ segmLineFeatureType = createFeatureType(LineString.class, null);
+ DUMMY_LINE_FEATURE = createDummyFeature(segmLineFeatureType);
+ segmLineFeatureCollection.add(DUMMY_LINE_FEATURE);
+ segmLineLayer = new DefaultMapLayer(segmLineFeatureCollection,getEditorStyle(GeometryForm.LINE));
+ segmLineLayer.setTitle("Line layer for current segment");
+ editorMapContext.addLayer(segmLineLayer);
+ // initialize the objects used to display the
+ // current segment as points
+ segmPointFeatureCollection = (DefaultFeatureCollection)DefaultFeatureCollections.newCollection("SegmentAsPoints");
+ segmPointFeatureType = createFeatureType(MultiPoint.class, null);
+ DUMMY_POINT_FEATURE = createDummyFeature(segmPointFeatureType);
+ segmPointFeatureCollection.add(DUMMY_POINT_FEATURE);
+ segmPointLayer = new DefaultMapLayer(segmPointFeatureCollection,getEditorStyle(GeometryForm.POINT));
+ segmPointLayer.setTitle("Point layer for current segment");
+ editorMapContext.addLayer(segmPointLayer);
+ } else {
+ segmLineFeatureCollection.clear();
+ segmPointFeatureCollection.clear();
+ }
+ }
+
+ /**
+ * Creates a new segment SimpleFeature from the currently selected points.
+ */
+ protected void generateSegmentFeatureCollection() {
+ initSegmentFeatureCollection();
+ // show the segment as single points
+ SimpleFeature segmPointFeature = createSegmentPointFeature();
+ if ( segmPointFeature != null )
+ segmPointFeatureCollection.add( segmPointFeature );
+ // show the segment as a line
+ SimpleFeature segmLineFeature = createSegmentLineFeature();
+ if ( segmLineFeature != null )
+ segmLineFeatureCollection.add( segmLineFeature );
+ // Fire event even if no (real) feature is created!
+ fireMapPaneEvent( new FeatureModifiedEvent(this,segmLineLayer,segmLineFeature,this) );
+ }
+
+ /**
+ * Creates a new {@link SimpleFeature Line-SimpleFeature} from the currently selected
+ * segment points.
+ */
+ protected SimpleFeature createSegmentLineFeature() {
+ // Line can only be created with at least 2 points
+ // For point layer the segment is not shown
+ if ( segmUndoPoints.size() < 2 ||
+ editorGeometryForm == GeometryForm.POINT )
+ return null;
+
+ Coordinate[] coord = segmUndoPoints.toArray(new Coordinate[0]);
+ LineString lineString = createGeometryFromPoints(LineString.class, coord);
+ try {
+ return FeatureUtil.createFeature(segmLineFeatureType, lineString );
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Creates a new {@link SimpleFeature MultiPoint-SimpleFeature} from the currently selected
+ * segment points.
+ */
+ protected SimpleFeature createSegmentPointFeature() {
+ // Point can only be created with at least 1 point
+ // For point layer the segment is not shown
+ if ( segmUndoPoints.size() < 1 ||
+ editorGeometryForm == GeometryForm.POINT )
+ return null;
+
+ Coordinate[] coord = segmUndoPoints.toArray(new Coordinate[0]);
+ MultiPoint multiPoint = createGeometryFromPoints(MultiPoint.class, coord);
+ try {
+ return FeatureUtil.createFeature(segmPointFeatureType,multiPoint);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Creates a new SimpleFeature from the currently selected points. The non-geometric
+ * attributes are set to default values.
+ */
+ private SimpleFeature createFeature() {
+ Coordinate[] coord = segmUndoPoints.toArray(new Coordinate[0]);
+ SimpleFeature feature = null;
+ try {
+ // if a feature was undone previously use this as
+ // default for the new feature
+ if ( !globalRedoFeatures.isEmpty() )
+ feature = globalRedoFeatures.pop();
+ else {
+ // generate default attribute values
+ Object[] attr = FeatureUtil.getDefaultAttributeValues(editorFeatureType);
+ // replace default attribute values with auto generate
+ // values (for all registered attributes)
+ for (int i=0; i<attr.length; i++) {
+ AttributeDescriptor aType = editorFeatureType.getDescriptor(i);
+ if ( FeatureUtil.getAutoValueGenerator(aType) != null )
+ attr[i] = FeatureUtil.getNextAutoValue(aType);
+ }
+ // create new feature
+ feature = FeatureUtil.createFeature(editorFeatureType,attr);
+ }
+ feature.setDefaultGeometry(
+ createGeometryFromPoints(getGeometryType(editorMode), coord )
+ );
+
+ if ( feature.getAttributeCount() > 1 ) {
+ attrInputOption.setValue(feature);
+ Object[] value = MultipleOptionPane.showMultipleInputDialog(
+ this,
+ GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JEditorToolBar.NewFeature.title"),
+ attrInputOption
+ );
+ if ( value == null )
+ return null;
+ }
+ return feature;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+
+ //**********************************************************************
+ //***** Helper methods to deal with geometries
+ //**********************************************************************
+ /**
+ * Determines the geometry type to deal with according to the
+ * editor mode.
+ * @param mode editor mode
+ */
+ private static Class<? extends Geometry> getGeometryType(EditorMode mode) {
+ switch( mode ) {
+ case New_Point: return Point.class;
+ case New_Line: return LineString.class;
+ case New_Polygon: return Polygon.class;
+ }
+ return null;
+ }
+
+ /**
+ * Creates a geometry (point, linestring/ring, polygon) from a set of points. If
+ * no points are specified ({@code null}), a default geometry is created.
+ * @param gtype type of geometry
+ * @param coord set of points (can be {@code null})
+ */
+ private static <G extends Geometry> G createGeometryFromPoints(Class<G> gtype, Coordinate[] coord) {
+ // Point
+ if ( gtype.isAssignableFrom( com.vividsolutions.jts.geom.Point.class ) ) {
+ if ( coord == null )
+ coord = new Coordinate[] { new Coordinate() };
+ return (G)FeatureUtil.GEOMETRY_FACTORY.createPoint( coord[0] );
+ }
+ // MultiPoint
+ if ( gtype.isAssignableFrom( com.vividsolutions.jts.geom.MultiPoint.class ) ) {
+ if ( coord == null )
+ coord = new Coordinate[] { new Coordinate() };
+ return (G)FeatureUtil.GEOMETRY_FACTORY.createMultiPoint( coord );
+ }
+ // LineString
+ if ( gtype.isAssignableFrom( com.vividsolutions.jts.geom.LineString.class ) ) {
+ if ( coord != null && coord.length > 2 && coord[0].equals(coord[coord.length-1]) )
+ return (G)FeatureUtil.GEOMETRY_FACTORY.createLinearRing(coord);
+ return (G)FeatureUtil.GEOMETRY_FACTORY.createLineString(coord);
+ }
+ // Polygon
+ if ( gtype.isAssignableFrom( com.vividsolutions.jts.geom.Polygon.class ) ) {
+ LinearRing shell = null;
+ if ( coord != null && coord.length > 2 && coord[0].equals(coord[coord.length-1]) )
+ shell = FeatureUtil.GEOMETRY_FACTORY.createLinearRing(coord);
+ return (G)FeatureUtil.GEOMETRY_FACTORY.createPolygon(shell,null);
+ }
+
+ throw new UnsupportedOperationException("Can not create geometry for "+gtype.getName());
+ }
+
+ /**
+ * Extends a feature type with a default geometry attribute.
+ * @param gtype default geometry of the new feature type
+ * @param ftype a feature type which is extended (can be {@code null})
+ */
+ private SimpleFeatureType createFeatureType(Class<? extends Geometry> gtype, SimpleFeatureType ftype) {
+// GeometryAttributeType geomAttrType = new GeometricAttributeType(
+// GEOMETRY_ATTR,
+// gtype,
+// false,
+// createGeometryFromPoints(gtype,null),
+// mapContext.getCoordinateReferenceSystem(),
+// null
+// );
+ GeometryAttributeType geomAttrType = FeatureUtil.createGeometryAttributeType(
+ GEOMETRY_ATTR,
+ gtype,
+ createGeometryFromPoints(gtype,null),
+ mapContext.getCoordinateReferenceSystem()
+ );
+ SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
+ builder.init(ftype);
+ if ( ftype == null )
+ builder.setName( gtype.getSimpleName()+"_feature" );
+ builder.add( geomAttrType ); // automatically sets the default geometry!
+
+ return builder.buildFeatureType();
+ }
+
+ /**
+ * Extends a feature type with a default geometry attribute.
+ * @param mode specifies the the default geometry used for the feature type
+ * @param ftype a feature type which is extended (can be {@code null})
+ */
+ private SimpleFeatureType createFeatureType(EditorMode mode, SimpleFeatureType ftype) {
+ Class<? extends Geometry> gtype = null;
+ switch( mode ) {
+ case New_Point: gtype = Point.class; break;
+ case New_Line: gtype = LineString.class; break;
+ case New_Polygon: gtype = Polygon.class; break;
+ }
+ return createFeatureType(gtype,ftype);
+ }
+
+ /**
+ * Creates a feature with default values for a given feature type.
+ * @param ftype a feature type
+ */
+ private static SimpleFeature createDummyFeature(SimpleFeatureType ftype) {
+ try {
+ return FeatureUtil.createSampleFeature(ftype);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Checks, whether the editor layer is empty. If it is, a dummy feature is inserted
+ * because the StreamingRenderer can not handle empty SimpleFeature-Layers yet
+ * (also if the layer is hidden!).
+ * At the moment, the first a feature is added, the dummy feature is removed, so
+ * is is not displayed any time.
+ */
+ private void resetEditorLayerVisibility() {
+ // if layer is empty, insert a Dummy-SimpleFeature (and hide the
+ // layer) because the StreamingRenderer can not handle empty
+ // SimpleFeature-Layers yet
+ if ( segmLineFeatureCollection != null && segmLineFeatureCollection.size() == 0 )
+ segmLineFeatureCollection.add( DUMMY_LINE_FEATURE );
+ if ( segmPointFeatureCollection != null && segmPointFeatureCollection.size() == 0 )
+ segmPointFeatureCollection.add( DUMMY_POINT_FEATURE );
+ if ( editorFeatureCollection != null && editorFeatureCollection.size() == 0 )
+ editorFeatureCollection.add( DUMMY_EDITOR_FEATURE );
+
+ // if the layer is not empty anymore, remove the Dummy-SimpleFeature, so
+ // it is not displayed
+ if ( segmLineFeatureCollection != null && segmLineFeatureCollection.size() == 2 )
+ segmLineFeatureCollection.remove( DUMMY_LINE_FEATURE );
+ if ( segmPointFeatureCollection != null && segmPointFeatureCollection.size() == 2 )
+ segmPointFeatureCollection.remove( DUMMY_POINT_FEATURE );
+ if ( editorFeatureCollection != null && editorFeatureCollection.size() == 2 )
+ editorFeatureCollection.remove( DUMMY_EDITOR_FEATURE );
+
+ // hide the editor layer if it only contains the dummy feature
+ if ( editorLayer != null )
+ editorLayer.setVisible(editorFeatureCollection.size() > 1 || !editorFeatureCollection.contains(DUMMY_EDITOR_FEATURE));
+ if ( segmLineLayer != null )
+ segmLineLayer.setVisible(segmLineFeatureCollection.size() > 1 || !segmLineFeatureCollection.contains(DUMMY_LINE_FEATURE));
+ if ( segmPointLayer != null )
+ segmPointLayer.setVisible(segmPointFeatureCollection.size() > 1 || !segmPointFeatureCollection.contains(DUMMY_POINT_FEATURE));
+ }
+
+}
Added: branches/2.0-RC2/src/schmitzm/geotools/gui/JMapEditorToolBar.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/JMapEditorToolBar.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/JMapEditorToolBar.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -0,0 +1,532 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program 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 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Krüger - additional utility classes
+ ******************************************************************************/
+package schmitzm.geotools.gui;
+
+import java.awt.event.ActionEvent;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JToolBar;
+
+import org.apache.log4j.Logger;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+import schmitzm.geotools.gui.JMapEditorPane.EditorMode;
+import schmitzm.geotools.map.event.JEditorPaneEvent;
+import schmitzm.geotools.map.event.JMapPaneListener;
+import schmitzm.geotools.map.event.LayerEditCanceledEvent;
+import schmitzm.geotools.map.event.LayerEditFinishedEvent;
+import schmitzm.geotools.map.event.MapPaneEvent;
+import schmitzm.swing.ExceptionDialog;
+import schmitzm.swing.ManualInputOption;
+import schmitzm.swing.MultipleOptionPane;
+import schmitzm.swing.SelectionInputOption;
+
+/**
+ * A toolbar to control the operations of a {@link JMapEditorPane}.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ */
+public class JMapEditorToolBar extends JToolBar {
+ private static final Logger LOGGER = Logger.getLogger(JMapEditorToolBar.class.getName());
+ /** Constant for the tool "New layer" (10). */
+ public static final int LAYER_NEW = 10;
+ /** Constant for the tool "Save layer" (20). */
+ public static final int LAYER_SAVE = 20;
+ /** Constant for the tool "Cancel layer" (30). */
+ public static final int LAYER_CANCEL = 30;
+ /** Constant for the tool "Undo all editor actions" (100). */
+ public static final int EDIT_CLEAR = 100;
+ /** Constant for the tool "Undo last editor action" (110). */
+ public static final int EDIT_UNDO = 110;
+ /** Constant for the tool "Redo last undone editor action" (120). */
+ public static final int EDIT_REDO = 120;
+ /** Constant for the tool "Finish current segment" (130). */
+ public static final int EDIT_FINISH = 130;
+
+ /** Holds the action buttons of the bar. */
+ protected SortedMap<Integer, JButton> actionButtons = null;
+
+ /** Holds the {@link JMapEditorPane} this tool bar controls. */
+ protected JMapEditorPane editorPane = null;
+
+ /** Holds the listener, that reacts on editor actions. */
+ protected JMapPaneListener mapPaneListener = null;
+
+ /**
+ * Creates a new toolbar. Notice: This toolbar does nothing
+ * until {@link #setMapPane(JMapEditorPane)} is called!
+ */
+ public JMapEditorToolBar() {
+ this(null);
+ }
+
+ /**
+ * Creates a new tool bar.
+ * @param editorPane {@link JMapEditorPane} the tool bar controls
+ */
+ public JMapEditorToolBar(JMapEditorPane editorPane) {
+ super("Control the editor actions", JToolBar.HORIZONTAL);
+ this.actionButtons = new TreeMap<Integer,JButton>();
+ // Create a Listener to sniff the zooms on the JMapPane
+ this.mapPaneListener = new JMapPaneListener() {
+ public void performMapPaneEvent(MapPaneEvent e) {
+ if ( !(e instanceof JEditorPaneEvent) )
+ return;
+
+ // At the moment the layer editing is finished, the editor mode
+ // is not yet initialized. However for the button activation the
+ // mode NULL is essential in this case.
+ EditorMode mode = ((JEditorPaneEvent)e).getEditorMode();
+ if ( e instanceof LayerEditCanceledEvent ||
+ e instanceof LayerEditFinishedEvent )
+ mode = null;
+ updateButtonActivation(mode);
+ }
+ };
+
+ setMapPane(editorPane);
+ setFloatable(false);
+ setRollover(true);
+
+ init();
+ }
+
+ /**
+ * Sets the {@link JMapEditorPane} controlled by this tool bar.
+ * @param editorPane {@link JMapEditorPane} to control (if {@code null} this
+ * tool bar controls NOTHING!)
+ */
+ public void setMapPane(JMapEditorPane editorPane) {
+ // Remove listener from old MapPane
+ if ( this.editorPane != null )
+ this.editorPane.removeMapPaneListener( mapPaneListener );
+ this.editorPane = editorPane;
+ if ( this.editorPane != null && mapPaneListener != null )
+ this.editorPane.addMapPaneListener( mapPaneListener );
+ }
+
+ /**
+ * Calls {@link #initActions()} and then puts all action buttons
+ * to the tool bar.
+ */
+ protected void init() {
+ initActions();
+ initToolBar();
+ updateButtonActivation(null);
+ }
+
+ /**
+ * Creates the action buttons and adds them to {@link #actionButtons}.
+ */
+ protected void initActions() {
+ // Action button to create a new layer
+ addAction( new EditorPaneToolBarAction(
+ LAYER_NEW,
+ this,
+ "button.layer.new",
+ new ImageIcon(JMapEditorPane.class.getResource("resource/icons/layer_new.png"))
+ ), false);
+
+ // Action button to finish a layer
+ addAction( new EditorPaneToolBarAction(
+ LAYER_SAVE,
+ this,
+ "button.layer.save",
+ new ImageIcon(JMapEditorPane.class.getResource("resource/icons/layer_finish.png"))
+ ), false);
+
+ // Action button to cancel a layer
+ addAction( new EditorPaneToolBarAction(
+ LAYER_CANCEL,
+ this,
+ "button.layer.cancel",
+ new ImageIcon(JMapEditorPane.class.getResource("resource/icons/layer_cancel.png"))
+ ), false);
+
+ // Action button to undo all editing action
+ addAction( new EditorPaneToolBarAction(
+ EDIT_CLEAR,
+ this,
+ "button.edit.clear",
+ new ImageIcon(JMapEditorPane.class.getResource("resource/icons/edit_clear.png"))
+ ), false);
+
+ // Action button to undo a editing action
+ addAction( new EditorPaneToolBarAction(
+ EDIT_UNDO,
+ this,
+ "button.edit.undo",
+ new ImageIcon(JMapEditorPane.class.getResource("resource/icons/edit_undo.png"))
+ ), false);
+
+ // Action button to redo a undone editing action
+ addAction( new EditorPaneToolBarAction(
+ EDIT_REDO,
+ this,
+ "button.edit.redo",
+ new ImageIcon(JMapEditorPane.class.getResource("resource/icons/edit_redo.png"))
+ ), false);
+
+ // Action button to finish a feature
+ addAction( new EditorPaneToolBarAction(
+ EDIT_FINISH,
+ this,
+ "button.edit.finish",
+ new ImageIcon(JMapEditorPane.class.getResource("resource/icons/edit_finish.png"))
+ ), false);
+ }
+
+ /**
+ * Clears the GUI of all components and adds all action buttons to the
+ * tool bar.
+ */
+ protected void initToolBar() {
+ setAlignmentY( 1f );
+ removeAll();
+// // Separator to the left of the tool actions to start
+// // the tool buttons with the map (not with the coordinate grid)
+// Dimension dimension = new Dimension( 49,10);
+// addSeparator(dimension);
+// // Space between tool buttons and action buttons
+// Dimension dimension2 = new Dimension( 10,10);
+// this.addSeparator(dimension2);
+ // Action buttons
+ for (JButton b : actionButtons.values())
+ add(b);
+ }
+
+
+ /**
+ * Performs the action of an action button.
+ * @param tool the action
+ * @param e the event of the button
+ */
+ protected void performActionButton(int action, ActionEvent e) {
+ if ( editorPane == null )
+ return;
+
+ try {
+ // Perform the action "New layer"
+ if ( action == LAYER_NEW )
+ createNewLayer();
+ // Perform the action "Finish layer"
+ if ( action == LAYER_SAVE )
+ editorPane.finishEditing();
+ // Perform the action "Cancel layer"
+ if ( action == LAYER_CANCEL )
+ editorPane.cancelEditing();
+
+ // Perform the action "Finish feature"
+ if ( action == EDIT_FINISH )
+ editorPane.finishFeature();
+ // Perform the action "Undo editing"
+ if ( action == EDIT_UNDO )
+ editorPane.undoEditing();
+ // Perform the action "Redo editing"
+ if ( action == EDIT_REDO )
+ editorPane.redoEditing();
+ // Perform the action "Clear editing"
+ if ( action == EDIT_CLEAR )
+ editorPane.undoAll();
+ } catch (Exception err) {
+ ExceptionDialog.show(err);
+ }
+ }
+
+ /**
+ * Sets the enables/disables property for every toolbar button according
+ * to the current editor state.
+ * @param editorMode editor mode (because some events are fired BEFORE
+ * the new mode is set)
+ */
+ protected void updateButtonActivation(EditorMode editorMode) {
+ if ( editorPane == null ) {
+ setAllActionsEnabled(false, false);
+ return;
+ }
+ getButton( LAYER_NEW ).setEnabled( editorMode == null );
+ getButton( LAYER_SAVE ).setEnabled( editorMode != null );
+ getButton( LAYER_CANCEL ).setEnabled( editorMode != null );
+ getButton( EDIT_UNDO ).setEnabled( editorPane.isUndoPossible() );
+ getButton( EDIT_REDO ).setEnabled( editorPane.isRedoPossible() );
+ getButton( EDIT_CLEAR ).setEnabled( editorPane.isUndoPossible() );
+ getButton( EDIT_FINISH ).setEnabled( editorMode != null && editorMode != EditorMode.New_Point );
+ }
+
+ /**
+ * Starts new layer.
+ */
+ protected void createNewLayer() {
+ // Ask layer type and name
+ ManualInputOption.Text titleOption = new ManualInputOption.Text(
+ getResourceString("NewLayer.layer.title"), true, getResourceString("NewLayer.layer.title.default")
+ );
+ SelectionInputOption.Radio<JMapEditorPane.EditorMode> typeOption = new SelectionInputOption.Radio<JMapEditorPane.EditorMode>(
+ getResourceString("NewLayer.layer.type"),
+ true,
+ new JMapEditorPane.EditorMode[] { EditorMode.New_Point, EditorMode.New_Line, EditorMode.New_Polygon },
+ new String[] { getResourceString("NewLayer.layer.type.point"), getResourceString("NewLayer.layer.type.line"), getResourceString("NewLayer.layer.type.polygon") }
+ );
+ FeatureTypeInputOption ftOption = new FeatureTypeInputOption(
+ getResourceString("NewLayer.ftype.title"),
+ false
+ ) {
+ // Checks whether "the_geom" is used as attribute name
+ // --> not allowed because JEditorPane uses this attribute
+ // for the default geometry of new layers
+ public boolean performIsInputValid() {
+ if ( super.performIsInputValid() ) {
+ SimpleFeatureType ft = inpTableModel.createFeatureType();
+ if ( ft.getDescriptor( JMapEditorPane.GEOMETRY_ATTR ) != null )
+ throw new UnsupportedOperationException(getResourceString("NewLayer.Err.GeomAttr",JMapEditorPane.GEOMETRY_ATTR));
+ }
+ return true;
+ }
+ };
+ Object[] value = MultipleOptionPane.showMultipleInputDialog(
+ this,
+ getResourceString("NewLayer.dialog.title"),
+ titleOption,
+ typeOption,
+ ftOption
+ );
+ if ( value == null )
+ return; // Dialog canceled
+ editorPane.setAdditionalAttributes( ftOption.getValue() );
+ editorPane.startEditing(
+ (JMapEditorPane.EditorMode)value[1],
+ (String)value[0]
+ );
+ }
+
+ /**
+ * Adds an action to the tool bar. Does nothing if a tool or action with the
+ * specified ID already exists!
+ * @param buttonAction action for the button
+ * @param resetToolBar indicates whether the toolbar GUI is reset after adding
+ * the button (if adding several actions it useful only to
+ * reset the GUI for the last added tool)
+ */
+ public void addAction(EditorPaneToolBarAction buttonAction, boolean resetToolBar) {
+ if ( isButtonIDUsed(buttonAction.getID()) ) {
+ LOGGER.warn("addAction(.) ignored because ID already used for tool or action: "+buttonAction.getID());
+ return;
+ }
+ JButton button = new JButton(buttonAction);
+ actionButtons.put( buttonAction.getID(), button );
+ if ( resetToolBar )
+ initToolBar();
+ }
+
+ /**
+ * Adds an action to the tool bar and resets the toolbar GUI.
+ * @param buttonAction action for the toggle button
+ */
+ public void addAction(EditorPaneToolBarAction buttonAction) {
+ addAction(buttonAction, true);
+ }
+
+ /**
+ * Returns the button for a specific tool or action.
+ * @param id the constant for a tool
+ * @return a {@link JButton} if {@code id} specifies an {@linkplain #getActionButton(int) action button}
+ * or {@link JToogleButton} if {@code id} specifies a {@linkplain #getToolButton(int) tool button}
+ */
+ public AbstractButton getButton(int id) {
+ AbstractButton button = actionButtons.get(id);
+ if ( button == null )
+ LOGGER.warn("Unknown action ID: "+id);
+ return button;
+ }
+
+ /**
+ * Returns the button for a specific action.
+ * @param action the constant an action
+ */
+ public JButton getActionButton(int action) {
+ AbstractButton button = getButton(action);
+ if ( button != null && !(button instanceof JButton) ) {
+ LOGGER.warn("ID specifies no action: "+action);
+ button = null;
+ }
+ return (JButton)button;
+
+ }
+
+ /**
+ * Sets whether an action is activated or not. The visible property
+ * of the button is not affected.
+ * @param id actionID
+ * @param enabled if {@code true} the action becomes available
+ */
+ public void setButtonEnabled(int id, boolean enabled) {
+ AbstractButton button = getButton(id);
+ if ( button == null )
+ return;
+ button.setEnabled( enabled );
+ }
+
+ /**
+ * Sets whether an action is activated or not.
+ * @param id actionID
+ * @param enabled if {@code true} the tool becomes available
+ * @param hideOnDisable if {@code true} the button is also hidden if
+ * {@code enabled} is {@code false}
+ */
+ public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {
+ AbstractButton button = getButton(id);
+ if ( button == null )
+ return;
+ button.setEnabled( enabled );
+ // if button is enabled, it becomes visible anyway
+ // if button is disabled and the "hide" option is set, it is also hidden
+ if ( enabled )
+ button.setVisible( true );
+ else
+ button.setVisible( !hideOnDisable );
+ }
+
+ /**
+ * Checks whether a ID is already used for a tool or action.
+ * @param tool tool ID
+ */
+ public boolean isButtonIDUsed(int id) {
+ return actionButtons.get(id) != null;
+ }
+
+ /**
+ * Checks whether a tool is activated.
+ * @param tool tool ID
+ * @return {@code false} if an unknown ID is specified
+ */
+ public boolean isButtonEnabled(int id) {
+ AbstractButton button = getButton(id);
+ if ( button != null )
+ return button.isEnabled();
+ return false;
+ }
+
+ /**
+ * Sets the activation for all actions.
+ * @param enabled if {@code true} all actions becomes available
+ * @param hideOnDisable if {@code true} the buttons are also hidden if
+ * {@code enabled} is {@code false}
+ */
+ public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {
+ for (int tool : actionButtons.keySet())
+ setButtonEnabled(tool,enabled,hideOnDisable);
+ }
+
+ /**
+ * Returns the maximum ID of actions.
+ */
+ public int getMaxActionID() {
+ return actionButtons.lastKey();
+ }
+
+ /**
+ * Returns the minimum ID of actions.
+ */
+ public int getMinActionID() {
+ return actionButtons.firstKey();
+ }
+
+ protected static String getResourceString(String key, Object... params) {
+ return GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.JMapEditorToolBar."+key,params);
+ }
+
+ /**
+ * Extends the {@link AbstractAction} with maintaining an ID and
+ * the {@link JMapEditorToolBar} the action controls.
+ * Additionally this class automatically calls
+ * {@link JMapEditorToolBar#performActionButton(int, ActionEvent)}.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ */
+ public static class EditorPaneToolBarAction extends AbstractAction {
+ /** The ID of the action */
+ protected int id = -1;
+ /** The tool bar, this action is made for. */
+ protected JMapEditorToolBar toolBar = null;
+
+ /**
+ * Creates a new action with a dummy description and no icon.
+ * @param id unique ID for the action
+ * @param toolBar toolbar this action is made for
+ */
+ public EditorPaneToolBarAction(int id, JMapEditorToolBar toolBar) {
+ this(id,toolBar,""+id);
+ }
+
+ /**
+ * Creates a new action without an icon.
+ * @param id unique ID for the action
+ * @param toolBar toolbar this action is made for
+ * @param name description used for buttons or menus
+ */
+ public EditorPaneToolBarAction(int id, JMapEditorToolBar toolBar, String name) {
+ this(id,toolBar,name,null);
+ }
+
+ /**
+ * Creates a new action.
+ * @param id unique ID for the action
+ * @param toolBar toolbar this action is made for
+ * @param name description used for buttons or menus
+ * @param icon icon used for buttons or menus
+ */
+ public EditorPaneToolBarAction(int id, JMapEditorToolBar toolBar, String name, Icon icon) {
+ super("",icon);
+ this.id = id;
+ this.toolBar = toolBar;
+ this.putValue(SHORT_DESCRIPTION, getResourceString(name));
+ }
+
+ /**
+ * Calls {@link JMapEditorToolBar#performActionButton(int, ActionEvent)}.
+ */
+ public void actionPerformed(ActionEvent e) {
+ if ( toolBar.actionButtons.get(id) != null )
+ toolBar.performActionButton(id, e);
+ }
+
+ /**
+ * Returns the (unique) id of this action.
+ * @return
+ */
+ public int getID() {
+ return id;
+ }
+ }
+}
Modified: branches/2.0-RC2/src/schmitzm/geotools/gui/LayeredEditorFrame.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/LayeredEditorFrame.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/LayeredEditorFrame.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -45,7 +45,7 @@
*/
public class LayeredEditorFrame extends LayeredMapFrame {
/** Toolbar, der die Editier-Funktionen steuert. */
- protected JEditorToolBar toolBar = null;
+ protected JMapEditorToolBar toolBar = null;
/** Toolbar, der die Style-Funktionen steuert. */
protected StyleToolBar styleBar = null;
@@ -80,16 +80,16 @@
* {@code null} wird eine neue {@link LayeredMapPane}-Instanz erzeugt)
*/
public LayeredEditorFrame(LayeredMapPane lmp, String title) {
- super( lmp != null ? lmp : new LayeredMapPane(new GeoMapPane(new JEditorPane(),null,null, null)),title);
- if ( !(layeredMapPane.geoMapPane.mapPane instanceof JEditorPane) )
+ super( lmp != null ? lmp : new LayeredMapPane(new GeoMapPane(new JMapEditorPane(),null,null, null)),title);
+ if ( !(layeredMapPane.geoMapPane.mapPane instanceof JMapEditorPane) )
throw new IllegalArgumentException("LayeredMapPane must contain a JEditorPane to use in LayeredEditorFrame.");
- this.toolBar = new JEditorToolBar( (JEditorPane)layeredMapPane.geoMapPane.mapPane );
+ this.toolBar = new JMapEditorToolBar( (JMapEditorPane)layeredMapPane.geoMapPane.mapPane );
this.styleBar = new StyleToolBar();
// Add a listener to the style bar, to apply every style
// change to the map
this.styleBar.addPropertyChangeListener( new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
- JEditorPane editorPane = (JEditorPane)layeredMapPane.geoMapPane.mapPane;
+ JMapEditorPane editorPane = (JMapEditorPane)layeredMapPane.geoMapPane.mapPane;
if ( e.getSource() == styleBar ) {
editorPane.setEditorStyle( GeometryForm.POINT, styleBar.createPointStyle() );
editorPane.setEditorStyle( GeometryForm.LINE, styleBar.createLineStyle() );
Modified: branches/2.0-RC2/src/schmitzm/geotools/gui/StyleToolBar.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/StyleToolBar.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/StyleToolBar.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -60,7 +60,7 @@
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
*/
public class StyleToolBar extends JToolBar implements InputOptionListener {
- protected static final Logger LOGGER = Logger.getLogger(JEditorToolBar.class.getName());
+ protected static final Logger LOGGER = Logger.getLogger(JMapEditorToolBar.class.getName());
private static final String RES_PREFIX = StyleToolBar.class.getName();
Modified: branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle.properties
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle.properties 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle.properties 2010-01-28 13:48:07 UTC (rev 628)
@@ -110,27 +110,27 @@
schmitzm.geotools.gui.CRSSelectionDialog.button.default=Default CRS (${0})
schmitzm.geotools.gui.CRSSelectionDialog.button.predefined=Predefined
schmitzm.geotools.gui.CRSSelectionDialog.button.userDefined=User defined:
-schmitzm.geotools.gui.JEditorPane.Err.MissingMap=First a layer must be displayed (to define CRS and geo-position).
-schmitzm.geotools.gui.JEditorPane.Err.Line.LessPoints=For a line feature at least 2 points must be specified!
-schmitzm.geotools.gui.JEditorPane.Err.Polygon.LessPoints=For a polygon feature at least 3 points must be specified!
-schmitzm.geotools.gui.JEditorToolBar.button.layer.new=Create new layer
-schmitzm.geotools.gui.JEditorToolBar.button.layer.save=Finish layer
-schmitzm.geotools.gui.JEditorToolBar.button.layer.cancel=Abort layer
-schmitzm.geotools.gui.JEditorToolBar.button.edit.undo=Undo last editing operation
-schmitzm.geotools.gui.JEditorToolBar.button.edit.redo=Redo last undone editing operation
-schmitzm.geotools.gui.JEditorToolBar.button.edit.clear=Undo all editing operation
-schmitzm.geotools.gui.JEditorToolBar.button.edit.finish=Start new feature
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.dialog.title=Create new layer...
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.title=Layer title
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.title.default=New Layer
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type=Layer type
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type.point=Point layer
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type.line=Line layer
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type.polygon=Polygon layer
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.ftype.title=Non-Geometric attributes
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.Err.GeomAttr=Attribute name '${0}' reserverd for default geometry.
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.Err.AutoVal=Auto value not supported for attribut type '${0}'.
-schmitzm.geotools.gui.JEditorToolBar.NewFeature.title=New feature attributes
+schmitzm.geotools.gui.JMapEditorPane.Err.MissingMap=First a layer must be displayed (to define CRS and geo-position).
+schmitzm.geotools.gui.JMapEditorPane.Err.Line.LessPoints=For a line feature at least 2 points must be specified!
+schmitzm.geotools.gui.JMapEditorPane.Err.Polygon.LessPoints=For a polygon feature at least 3 points must be specified!
+schmitzm.geotools.gui.JMapEditorToolBar.button.layer.new=Create new layer
+schmitzm.geotools.gui.JMapEditorToolBar.button.layer.save=Finish layer
+schmitzm.geotools.gui.JMapEditorToolBar.button.layer.cancel=Abort layer
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.undo=Undo last editing operation
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.redo=Redo last undone editing operation
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.clear=Undo all editing operation
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.finish=Start new feature
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.dialog.title=Create new layer...
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.title=Layer title
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.title.default=New Layer
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type=Layer type
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type.point=Point layer
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type.line=Line layer
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type.polygon=Polygon layer
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.ftype.title=Non-Geometric attributes
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.Err.GeomAttr=Attribute name '${0}' reserverd for default geometry.
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.Err.AutoVal=Auto value not supported for attribut type '${0}'.
+schmitzm.geotools.gui.JMapEditorToolBar.NewFeature.title=New feature attributes
schmitzm.geotools.gui.StyleToolBar.FillColor=Fill
schmitzm.geotools.gui.StyleToolBar.BorderColor=Border
schmitzm.geotools.gui.StyleToolBar.BorderWidth=Border width
Modified: branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties 2010-01-28 13:48:07 UTC (rev 628)
@@ -104,27 +104,27 @@
schmitzm.geotools.gui.CRSSelectionDialog.button.default=Standard CRS (${0})
schmitzm.geotools.gui.CRSSelectionDialog.button.predefined=Vordefiniert
schmitzm.geotools.gui.CRSSelectionDialog.button.userDefined=Benutzerdefiniert:
-schmitzm.geotools.gui.JEditorPane.Err.MissingMap=Bevor ein neues Layer erstellt werden kann, muss ein Layer angezeigt werden (um CRS und geogr. Lage zu definieren).
-schmitzm.geotools.gui.JEditorPane.Err.Line.LessPoints=F\u00fcr ein Line-Feature m\u00fcssen mind. 2 Punkte definiert werden!
-schmitzm.geotools.gui.JEditorPane.Err.Polygon.LessPoints=F\u00fcr ein Polygon-Feature m\u00fcssen mind. 3 Punkte definiert werden!
-schmitzm.geotools.gui.JEditorToolBar.button.layer.new=Neues Layer erstellen
-schmitzm.geotools.gui.JEditorToolBar.button.layer.save=Layer abschliessen
-schmitzm.geotools.gui.JEditorToolBar.button.layer.cancel=Layer abbrechen
-schmitzm.geotools.gui.JEditorToolBar.button.edit.undo=Letzte Operation zur\u00fccknehmen
-schmitzm.geotools.gui.JEditorToolBar.button.edit.redo=Letzte zur\u00fcckgenommene Operation wiederholen
-schmitzm.geotools.gui.JEditorToolBar.button.edit.clear=Layer leeren
-schmitzm.geotools.gui.JEditorToolBar.button.edit.finish=Neues Feature starten
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.dialog.title=Neues Layer erzeugen
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.title=Layer-Bezeichnung
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.title.default=Neues Layer
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type=Layer-Art
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type.point=Punkt-Layer
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type.line=Linien-Layer
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type.polygon=Polygon-Layer
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.ftype.title=Weitere Attribute
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.Err.GeomAttr=Attribut-Name '${0}' reserviert f\u00fcr das Default-Geometrie-Attribut.
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.Err.AutoVal=Auto-Wert f\u00fcr Attribut-Typ '${0}' nicht m\u00f6glich.
-schmitzm.geotools.gui.JEditorToolBar.NewFeature.title=Neues Feature
+schmitzm.geotools.gui.JMapEditorPane.Err.MissingMap=Bevor ein neues Layer erstellt werden kann, muss ein Layer angezeigt werden (um CRS und geogr. Lage zu definieren).
+schmitzm.geotools.gui.JMapEditorPane.Err.Line.LessPoints=F\u00fcr ein Line-Feature m\u00fcssen mind. 2 Punkte definiert werden!
+schmitzm.geotools.gui.JMapEditorPane.Err.Polygon.LessPoints=F\u00fcr ein Polygon-Feature m\u00fcssen mind. 3 Punkte definiert werden!
+schmitzm.geotools.gui.JMapEditorToolBar.button.layer.new=Neues Layer erstellen
+schmitzm.geotools.gui.JMapEditorToolBar.button.layer.save=Layer abschliessen
+schmitzm.geotools.gui.JMapEditorToolBar.button.layer.cancel=Layer abbrechen
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.undo=Letzte Operation zur\u00fccknehmen
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.redo=Letzte zur\u00fcckgenommene Operation wiederholen
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.clear=Layer leeren
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.finish=Neues Feature starten
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.dialog.title=Neues Layer erzeugen
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.title=Layer-Bezeichnung
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.title.default=Neues Layer
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type=Layer-Art
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type.point=Punkt-Layer
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type.line=Linien-Layer
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type.polygon=Polygon-Layer
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.ftype.title=Weitere Attribute
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.Err.GeomAttr=Attribut-Name '${0}' reserviert f\u00fcr das Default-Geometrie-Attribut.
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.Err.AutoVal=Auto-Wert f\u00fcr Attribut-Typ '${0}' nicht m\u00f6glich.
+schmitzm.geotools.gui.JMapEditorToolBar.NewFeature.title=Neues Feature
schmitzm.geotools.gui.StyleToolBar.FillColor=F\u00fcllfarbe
schmitzm.geotools.gui.StyleToolBar.BorderColor=Randfarbe
schmitzm.geotools.gui.StyleToolBar.BorderWidth=Randbreite
Modified: branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_fr.properties
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_fr.properties 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_fr.properties 2010-01-28 13:48:07 UTC (rev 628)
@@ -102,27 +102,27 @@
schmitzm.geotools.gui.CRSSelectionDialog.button.default=CRS standard (${0})
schmitzm.geotools.gui.CRSSelectionDialog.button.predefined=Defini en avance
schmitzm.geotools.gui.CRSSelectionDialog.button.userDefined=Defini par client :
-schmitzm.geotools.gui.JEditorPane.Err.MissingMap=Avant de creer une couche nouvelle, il faut que une couche est d\u00e9j\u00e0 visualis\u00e9e (pour la d\u00e9finition de CRS et la position g\u00e9ographique).
-schmitzm.geotools.gui.JEditorPane.Err.Line.LessPoints=Pour un Line-Feature il faut definir au moins 2 points!
-schmitzm.geotools.gui.JEditorPane.Err.Polygon.LessPoints=Pour un Polygone-Feature il faut definir au moins 2 points!
-schmitzm.geotools.gui.JEditorToolBar.button.layer.new=Creer une couche nouvelle
-schmitzm.geotools.gui.JEditorToolBar.button.layer.save=Terminer la couche
-schmitzm.geotools.gui.JEditorToolBar.button.layer.cancel=Abandonner une couche
-schmitzm.geotools.gui.JEditorToolBar.button.edit.undo=Retirer l'op\u00e9ration derni\u00e8re
-schmitzm.geotools.gui.JEditorToolBar.button.edit.redo=R\u00e9p\u00e9ter l'op\u00e9ration derni\u00e8re retir\u00e9e
-schmitzm.geotools.gui.JEditorToolBar.button.edit.clear=Vider une couche
-schmitzm.geotools.gui.JEditorToolBar.button.edit.finish=d\u00e9marrer un Feature nouveau
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.dialog.title=Cr\u00e9er une couche nouvelle
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.title=Nom de couche
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.title.default=Couche nouvelle
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type=Sorte de couche
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type.point=Couche de point
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type.line=Couche de ligne
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.layer.type.polygon=Couche de polygone
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.ftype.title=Autres attributs
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.Err.GeomAttr=Nom de l'attribut '${0}' reserv\u00e9 pour l'Attribut de g\u00e9ometrie d\u00e9faut.
-schmitzm.geotools.gui.JEditorToolBar.NewLayer.Err.AutoVal=Valeur automatique pour le type d'attribut '${0}' pas possible.
-schmitzm.geotools.gui.JEditorToolBar.NewFeature.title=Nouvau Feature
+schmitzm.geotools.gui.JMapEditorPane.Err.MissingMap=Avant de creer une couche nouvelle, il faut que une couche est d\u00e9j\u00e0 visualis\u00e9e (pour la d\u00e9finition de CRS et la position g\u00e9ographique).
+schmitzm.geotools.gui.JMapEditorPane.Err.Line.LessPoints=Pour un Line-Feature il faut definir au moins 2 points!
+schmitzm.geotools.gui.JMapEditorPane.Err.Polygon.LessPoints=Pour un Polygone-Feature il faut definir au moins 2 points!
+schmitzm.geotools.gui.JMapEditorToolBar.button.layer.new=Creer une couche nouvelle
+schmitzm.geotools.gui.JMapEditorToolBar.button.layer.save=Terminer la couche
+schmitzm.geotools.gui.JMapEditorToolBar.button.layer.cancel=Abandonner une couche
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.undo=Retirer l'op\u00e9ration derni\u00e8re
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.redo=R\u00e9p\u00e9ter l'op\u00e9ration derni\u00e8re retir\u00e9e
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.clear=Vider une couche
+schmitzm.geotools.gui.JMapEditorToolBar.button.edit.finish=d\u00e9marrer un Feature nouveau
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.dialog.title=Cr\u00e9er une couche nouvelle
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.title=Nom de couche
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.title.default=Couche nouvelle
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type=Sorte de couche
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type.point=Couche de point
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type.line=Couche de ligne
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.layer.type.polygon=Couche de polygone
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.ftype.title=Autres attributs
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.Err.GeomAttr=Nom de l'attribut '${0}' reserv\u00e9 pour l'Attribut de g\u00e9ometrie d\u00e9faut.
+schmitzm.geotools.gui.JMapEditorToolBar.NewLayer.Err.AutoVal=Valeur automatique pour le type d'attribut '${0}' pas possible.
+schmitzm.geotools.gui.JMapEditorToolBar.NewFeature.title=Nouvau Feature
schmitzm.geotools.gui.StyleToolBar.FillColor=Couleur de remplissage
schmitzm.geotools.gui.StyleToolBar.BorderColor=Couleur bordi\u00e8re
schmitzm.geotools.gui.StyleToolBar.BorderWidth=Largeur bordi\u00e8re
Modified: branches/2.0-RC2/src/schmitzm/geotools/map/event/FeatureModifiedEvent.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/map/event/FeatureModifiedEvent.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/map/event/FeatureModifiedEvent.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -32,10 +32,10 @@
import org.geotools.map.MapLayer;
import org.opengis.feature.simple.SimpleFeature;
-import schmitzm.geotools.gui.JEditorPane;
+import schmitzm.geotools.gui.JMapEditorPane;
/**
- * Diese Klasse stellt ein Ereignis dar, das ein {@link JEditorPane} ausloest,
+ * Diese Klasse stellt ein Ereignis dar, das ein {@link JMapEditorPane} ausloest,
* wenn der Anwender Features in der Karte veraendert.
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
* @version 1.0
@@ -52,7 +52,7 @@
* @param sourceObject Objekt, das die Aenderung initiiert hat (wenn {@code null},
* wird das MapPane als Ausloeser gesetzt)
*/
- public FeatureModifiedEvent(JEditorPane sourceMap, MapLayer sourceLayer, SimpleFeature feature, Object sourceObject) {
+ public FeatureModifiedEvent(JMapEditorPane sourceMap, MapLayer sourceLayer, SimpleFeature feature, Object sourceObject) {
super(sourceMap, sourceLayer, sourceObject);
this.feature = feature;
}
Modified: branches/2.0-RC2/src/schmitzm/geotools/map/event/JEditorPaneEvent.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/map/event/JEditorPaneEvent.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/map/event/JEditorPaneEvent.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -31,12 +31,12 @@
import org.geotools.map.MapLayer;
-import schmitzm.geotools.gui.JEditorPane;
-import schmitzm.geotools.gui.JEditorPane.EditorMode;
+import schmitzm.geotools.gui.JMapEditorPane;
+import schmitzm.geotools.gui.JMapEditorPane.EditorMode;
/**
* Diese Klasse stellt ein allgemeines Ereignis dar, das ein
- * {@link JEditorPane} ausloest.
+ * {@link JMapEditorPane} ausloest.
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
* @version 1.0
*/
@@ -53,17 +53,17 @@
* @param sourceObject Objekt, das die Aenderung initiiert hat (wenn {@code null},
* wird das MapPane als Ausloeser gesetzt)
*/
- public JEditorPaneEvent(JEditorPane sourceMap, MapLayer sourceLayer, Object sourceObject) {
+ public JEditorPaneEvent(JMapEditorPane sourceMap, MapLayer sourceLayer, Object sourceObject) {
super(sourceMap, sourceObject);
this.layer = sourceLayer;
this.editorMode = sourceMap.getEditorMode();
}
/**
- * Liefert das {@link JEditorPane}, das das Ereignis ausgeloest hat.
+ * Liefert das {@link JMapEditorPane}, das das Ereignis ausgeloest hat.
*/
- public JEditorPane getSource() {
- return(JEditorPane)super.getSource();
+ public JMapEditorPane getSource() {
+ return(JMapEditorPane)super.getSource();
}
/**
Modified: branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditCanceledEvent.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditCanceledEvent.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditCanceledEvent.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -31,10 +31,10 @@
import org.geotools.map.MapLayer;
-import schmitzm.geotools.gui.JEditorPane;
+import schmitzm.geotools.gui.JMapEditorPane;
/**
- * Diese Klasse stellt ein Ereignis dar, das ein {@link JEditorPane} ausloest,
+ * Diese Klasse stellt ein Ereignis dar, das ein {@link JMapEditorPane} ausloest,
* wenn der Anwender die Bearbeitung eines Layers abgebrochen hat.
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
* @version 1.0
@@ -48,7 +48,7 @@
* @param sourceObject Objekt, das die Aenderung initiiert hat (wenn {@code null},
* wird das MapPane als Ausloeser gesetzt)
*/
- public LayerEditCanceledEvent(JEditorPane sourceMap, MapLayer sourceLayer, Object sourceObject) {
+ public LayerEditCanceledEvent(JMapEditorPane sourceMap, MapLayer sourceLayer, Object sourceObject) {
super(sourceMap, sourceLayer, sourceObject);
}
}
Modified: branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditFinishedEvent.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditFinishedEvent.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditFinishedEvent.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -31,10 +31,10 @@
import org.geotools.map.MapLayer;
-import schmitzm.geotools.gui.JEditorPane;
+import schmitzm.geotools.gui.JMapEditorPane;
/**
- * Diese Klasse stellt ein Ereignis dar, das ein {@link JEditorPane} ausloest,
+ * Diese Klasse stellt ein Ereignis dar, das ein {@link JMapEditorPane} ausloest,
* wenn der Anwender die Bearbeitung eines Layers (erfolgreich) beendet hat.
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
* @version 1.0
@@ -47,7 +47,7 @@
* @param sourceObject Objekt, das die Aenderung initiiert hat (wenn {@code null},
* wird das MapPane als Ausloeser gesetzt)
*/
- public LayerEditFinishedEvent(JEditorPane sourceMap, MapLayer sourceLayer, Object sourceObject) {
+ public LayerEditFinishedEvent(JMapEditorPane sourceMap, MapLayer sourceLayer, Object sourceObject) {
super(sourceMap, sourceLayer, sourceObject);
}
}
Modified: branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditStartedEvent.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditStartedEvent.java 2010-01-28 11:47:42 UTC (rev 627)
+++ branches/2.0-RC2/src/schmitzm/geotools/map/event/LayerEditStartedEvent.java 2010-01-28 13:48:07 UTC (rev 628)
@@ -31,10 +31,10 @@
import org.geotools.map.MapLayer;
-import schmitzm.geotools.gui.JEditorPane;
+import schmitzm.geotools.gui.JMapEditorPane;
/**
- * Diese Klasse stellt ein Ereignis dar, das ein {@link JEditorPane} ausloest,
+ * Diese Klasse stellt ein Ereignis dar, das ein {@link JMapEditorPane} ausloest,
* wenn der Anwender die Bearbeitung eines Layers beginnt.
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
* @version 1.0
@@ -47,7 +47,7 @@
* @param sourceObject Objekt, das die Aenderung initiiert hat (wenn {@code null},
* wird das MapPane als Ausloeser gesetzt)
*/
- public LayerEditStartedEvent(JEditorPane sourceMap, MapLayer sourceLayer, Object sourceObject) {
+ public LayerEditStartedEvent(JMapEditorPane sourceMap, MapLayer sourceLayer, Object sourceObject) {
super(sourceMap, sourceLayer, sourceObject);
}
}
More information about the Schmitzm-commits
mailing list