Revision 40273

View differences:

tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.selectiontools.app.extension</artifactId>
6
	<packaging>jar</packaging>
7
	<name>Tools: Selection tools</name>
8
	<parent>
9
		<groupId>org.gvsig</groupId>
10
		<artifactId>org.gvsig.selectiontools.app</artifactId>
11
		<version>1.0.0</version>
12
	</parent>
13

  
14
	<dependencies>
15
		<dependency>
16
			<groupId>org.gvsig</groupId>
17
			<artifactId>org.gvsig.andami</artifactId>
18
            <scope>compile</scope>
19
		</dependency>
20
		<dependency>
21
			<groupId>org.gvsig</groupId>
22
			<artifactId>org.gvsig.i18n</artifactId>
23
            <scope>compile</scope>
24
		</dependency>
25
		<dependency>
26
			<groupId>org.gvsig</groupId>
27
			<artifactId>org.gvsig.tools.lib</artifactId>
28
            <scope>compile</scope>
29
		</dependency>
30
		<dependency>
31
			<groupId>org.gvsig</groupId>
32
			<artifactId>org.gvsig.tools.swing.api</artifactId>
33
            <scope>compile</scope>
34
		</dependency>
35
        <dependency>
36
			<groupId>org.gvsig</groupId>
37
			<artifactId>org.gvsig.app</artifactId>
38
			<version>2.0</version>
39
            <scope>compile</scope>
40
		</dependency>
41
        <dependency>
42
            <groupId>org.gvsig</groupId>
43
            <artifactId>org.gvsig.about.api</artifactId>
44
            <scope>compile</scope>
45
        </dependency>
46
        <dependency>
47
            <groupId>org.gvsig</groupId>
48
            <artifactId>org.gvsig.fmap.dal</artifactId>
49
            <scope>compile</scope>
50
        </dependency>
51
        <dependency>
52
            <groupId>org.gvsig</groupId>
53
            <artifactId>org.gvsig.fmap.geometry</artifactId>
54
            <scope>compile</scope>
55
        </dependency>
56
        <dependency>
57
            <groupId>org.gvsig</groupId>
58
            <artifactId>org.gvsig.ui</artifactId>
59
            <scope>compile</scope>
60
        </dependency>
61
        <dependency>
62
            <groupId>org.gvsig</groupId>
63
            <artifactId>org.gvsig.fmap.mapcontext</artifactId>
64
            <scope>compile</scope>
65
        </dependency>
66
        <dependency>
67
            <groupId>org.gvsig</groupId>
68
            <artifactId>org.gvsig.fmap.control</artifactId>
69
            <scope>compile</scope>
70
        </dependency>
71
        <dependency>
72
            <groupId>org.gvsig</groupId>
73
            <artifactId>org.gvsig.utils</artifactId>
74
            <scope>compile</scope>
75
        </dependency>
76
        <dependency>
77
            <groupId>org.gvsig</groupId>
78
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
79
            <scope>compile</scope>
80
        </dependency>
81
        <dependency>
82
            <groupId>org.gvsig</groupId>
83
            <artifactId>org.gvsig.projection</artifactId>
84
            <scope>compile</scope>
85
        </dependency>
86
        <dependency>
87
            <groupId>org.slf4j</groupId>
88
            <artifactId>slf4j-api</artifactId>
89
            <scope>compile</scope>
90
        </dependency>
91
        <dependency>
92
            <groupId>com.vividsolutions</groupId>
93
            <artifactId>jts</artifactId>
94
            <scope>compile</scope>
95
        </dependency>
96
	</dependencies>
97
	<description>Advanced selection tools: 
98
- select all 
99
- by buffer 
100
- by cicle 
101
- by polilyne
102
</description>
103
	<profiles>
104
		<profile>
105
			<id>gvsig-install</id>
106
			<activation>
107
				<activeByDefault>true</activeByDefault>
108
			</activation>
109
			<properties>
110
				<!--
111
					Default gvSIG installation folder relative to the current workspace
112
				-->
113
				<gvsig.install.dir>${basedir}/../../build/product</gvsig.install.dir>
114
			</properties>
115
		</profile>
116
	</profiles>
117
	<properties>
118
        <package.info.categories>View,Vector</package.info.categories>
119
	</properties>
120
</project>
0 121

  
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/distribution/distribution.xml
1
<assembly>
2
	<id>distribution</id>
3
	<formats>
4
		<format>dir</format>
5
	</formats>
6
	<fileSets>
7
		<!-- Estructure for the extension -->
8
		<fileSet>
9
			<directory>src/main/resources</directory>
10
			<outputDirectory>${extension.install.dir.name}
11
			</outputDirectory>
12
		</fileSet>
13
	</fileSets>
14
	<files>
15
        <file>
16
            <source>package.info</source>
17
            <outputDirectory>${extension.install.dir.name}
18
            </outputDirectory>
19
        </file>
20
    </files>
21
    <dependencySets>
22
		<dependencySet>
23
			<outputDirectory>${extension.install.dir.name}/${library-dir}
24
			</outputDirectory>
25
			<includes>
26
				<include>org.gvsig:org.gvsig.selectiontools.app.extension</include>
27
			</includes>
28
		</dependencySet>
29
	</dependencySets>
30
</assembly>
0 31

  
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Fri Feb 08 11:28:12 CET 2013
3
buildNumber=2075
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.selectiontools">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/behavior/CircleSelectionBehavior.java
1
package org.gvsig.selectiontools.app.extension.tools.behavior;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

  
25
import java.awt.Color;
26
import java.awt.Graphics;
27
import java.awt.Graphics2D;
28
import java.awt.Point;
29
import java.awt.Rectangle;
30
import java.awt.event.MouseEvent;
31
import java.awt.geom.Arc2D;
32
import java.awt.geom.Point2D;
33
import java.awt.geom.Rectangle2D;
34
import java.awt.image.BufferedImage;
35

  
36
import org.gvsig.fmap.mapcontext.ViewPort;
37
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
38
import org.gvsig.fmap.mapcontrol.tools.Behavior.CircleBehavior;
39
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent;
40
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener;
41

  
42
/**
43
 * 
44
 * 
45
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
46
 */
47
public class CircleSelectionBehavior extends CircleBehavior {
48

  
49
    /**
50
	 * 
51
	 */
52
    private CircleListener listener;
53

  
54
    /**
55
     * Auxiliary point that represents a corner selected in image coordinates.
56
     */
57
    private Point2D m_PointAnt;
58

  
59
    public CircleSelectionBehavior(CircleListener zili) {
60
        super(zili);
61

  
62
        listener = zili;
63
    }
64

  
65
    /*
66
     * (non-Javadoc)
67
     * 
68
     * @see
69
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt
70
     * .Graphics)
71
     */
72
    public void paintComponent(Graphics g) {
73
        double radio;
74
        BufferedImage img = getMapControl().getImage();
75
        g.drawImage(img, 0, 0, null);
76
        g.setColor(Color.black);
77
        g.setXORMode(Color.white);
78
        if ((m_FirstPoint != null) && (m_LastPoint != null)) {
79
            radio = m_LastPoint.distance(m_FirstPoint);
80
            Arc2D.Double arc =
81
                new Arc2D.Double(m_FirstPoint.getX() - radio,
82
                    m_FirstPoint.getY() - radio,
83
                    2 * radio,
84
                    2 * radio,
85
                    0,
86
                    360,
87
                    Arc2D.OPEN);
88

  
89
            ((Graphics2D) g).draw(arc);
90
        }
91
    }
92

  
93
    /*
94
     * (non-Javadoc)
95
     * 
96
     * @see
97
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt
98
     * .event.MouseEvent)
99
     */
100
    public void mousePressed(MouseEvent e) {
101

  
102
        Point pScreen = e.getPoint();
103
        m_PointAnt = pScreen;
104

  
105
        if ((!isClicked) && (e.getButton() == MouseEvent.BUTTON1)) {
106
            m_PointAnt = pScreen;
107
            m_FirstPoint = m_PointAnt;
108
            isClicked = true;
109
        }
110

  
111
        if (listener.cancelDrawing()) {
112
            getMapControl().cancelDrawing();
113
            isClicked = false;
114
        }
115
        getMapControl().repaint();
116
    }
117

  
118
    /*
119
     * (non-Javadoc)
120
     * 
121
     * @see
122
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt
123
     * .event.MouseEvent)
124
     */
125
    public void mouseReleased(MouseEvent e) throws BehaviorException {
126
        if ((m_FirstPoint == null) || (m_LastPoint == null))
127
            return;
128

  
129
        Point2D p1;
130
        Point2D p2;
131
        Point pScreen = e.getPoint();
132

  
133
        ViewPort vp = getMapControl().getMapContext().getViewPort();
134

  
135
        p1 = vp.toMapPoint(m_FirstPoint);
136
        p2 = vp.toMapPoint(pScreen);
137

  
138
        // Fijamos el nuevo extent
139
        Rectangle2D.Double r = new Rectangle2D.Double();
140
        r.setFrameFromDiagonal(p1, p2);
141

  
142
        Rectangle2D rectPixel = new Rectangle();
143
        rectPixel.setFrameFromDiagonal(m_FirstPoint, pScreen);
144

  
145
        Double[] x = new Double[2];
146
        Double[] y = new Double[2];
147
        x[0] = new Double(p1.getX());
148
        x[1] = new Double(p2.getX());
149
        y[0] = new Double(p1.getY());
150
        y[1] = new Double(p2.getY());
151
        MeasureEvent event = new MeasureEvent(x, y, e);
152
        listener.circle(event);
153
        getMapControl().repaint();
154

  
155
        m_FirstPoint = null;
156
        m_LastPoint = null;
157
        isClicked = false;
158
    }
159

  
160
    /*
161
     * (non-Javadoc)
162
     * 
163
     * @see
164
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt
165
     * .event.MouseEvent)
166
     */
167
    public void mouseDragged(MouseEvent e) throws BehaviorException {
168
        mouseMoved(e);
169
    }
170

  
171
    /*
172
     * (non-Javadoc)
173
     * 
174
     * @see
175
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseMoved(java.awt.event
176
     * .MouseEvent)
177
     */
178
    public void mouseMoved(MouseEvent e) throws BehaviorException {
179
        if (!isClicked)
180
            return;
181

  
182
        m_LastPoint = e.getPoint();
183

  
184
        if (m_FirstPoint == null)
185
            return;
186
        Point2D p1;
187
        Point2D p2;
188
        Point pScreen = e.getPoint();
189

  
190
        ViewPort vp = getMapControl().getMapContext().getViewPort();
191

  
192
        p1 = vp.toMapPoint(m_FirstPoint);
193
        p2 = vp.toMapPoint(pScreen);
194

  
195
        // Fijamos el nuevo extent
196
        Rectangle2D.Double r = new Rectangle2D.Double();
197
        r.setFrameFromDiagonal(p1, p2);
198

  
199
        Rectangle2D rectPixel = new Rectangle();
200
        rectPixel.setFrameFromDiagonal(m_FirstPoint, pScreen);
201

  
202
        Double[] x = new Double[2];
203
        Double[] y = new Double[2];
204
        x[0] = new Double(p1.getX());
205
        x[1] = new Double(p2.getX());
206
        y[0] = new Double(p1.getY());
207
        y[1] = new Double(p2.getY());
208
        MeasureEvent event = new MeasureEvent(x, y, e);
209
        listener.circle(event);
210
        getMapControl().repaint();
211
    }
212
}
0 213

  
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/PolyLineSelectListener.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.selectiontools.app.extension.tools;
24

  
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.fmap.mapcontrol.MapControl;
27
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
28
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent;
29

  
30
/**
31
 * 
32
 * @version 06/04/2009
33
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
34
 */
35
public class PolyLineSelectListener extends PolyLineSelectionListener {
36

  
37
    public PolyLineSelectListener(MapControl mc) {
38
        super(mc);
39
    }
40

  
41
    public void polylineFinished(MeasureEvent event) throws BehaviorException {
42
        super.polylineFinished(event);
43
        PluginServices.getMainFrame().enableControls();
44
    }
45
}
0 46

  
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/CircleSelectListener.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.selectiontools.app.extension.tools;
24

  
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.fmap.mapcontrol.MapControl;
27
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
28
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent;
29

  
30
/**
31
 * 
32
 * @version 06/04/2009
33
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
34
 */
35
public class CircleSelectListener extends CircleSelectionListener {
36

  
37
    public CircleSelectListener(MapControl mc) {
38
        super(mc);
39
    }
40

  
41
    public void circle(MeasureEvent event) throws BehaviorException {
42
        super.circle(event);
43
        PluginServices.getMainFrame().enableControls();
44
    }
45
}
0 46

  
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/PolyLineSelectionListener.java
1
package org.gvsig.selectiontools.app.extension.tools;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

  
25
import java.awt.Cursor;
26
import java.awt.Image;
27
import java.awt.Point;
28
import java.awt.Toolkit;
29

  
30
import javax.swing.ImageIcon;
31

  
32
import org.gvsig.andami.IconThemeHelper;
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.andami.messages.NotificationManager;
35
import org.gvsig.fmap.dal.feature.FeatureSelection;
36
import org.gvsig.fmap.dal.feature.FeatureSet;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
39
import org.gvsig.fmap.geom.Geometry.TYPES;
40
import org.gvsig.fmap.geom.GeometryLocator;
41
import org.gvsig.fmap.geom.GeometryManager;
42
import org.gvsig.fmap.geom.exception.CreateGeometryException;
43
import org.gvsig.fmap.geom.primitive.GeneralPathX;
44
import org.gvsig.fmap.geom.primitive.Surface;
45
import org.gvsig.fmap.mapcontext.layers.FLayer;
46
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
47
import org.gvsig.fmap.mapcontrol.MapControl;
48
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
49
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent;
50
import org.gvsig.fmap.mapcontrol.tools.Listeners.PolylineListener;
51

  
52
/**
53
 * <p>
54
 * Listener that selects all features of the active and vector layers which
55
 * intersect with the defined polyline in the associated {@link MapControl
56
 * MapControl} object.
57
 * </p>
58
 * 
59
 * <p>
60
 * The selection will be produced after user finishes the creation of the
61
 * polyline.
62
 * </p>
63
 * 
64
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
65
 */
66
public class PolyLineSelectionListener implements PolylineListener {
67

  
68
    /**
69
     * The image to display when the cursor is active.
70
     */
71
//    private final Image img = PluginServices.getIconTheme().get("cursor-select-by-polygon").getImage();
72

  
73
    /**
74
     * The cursor used to work with this tool listener.
75
     * 
76
     * @see #getCursor()
77
     */
78
    private Cursor cur = null;
79

  
80
    /**
81
     * Reference to the <code>MapControl</code> object that uses.
82
     */
83
    private MapControl mapCtrl;
84

  
85
    /**
86
     * <p>
87
     * Creates a new <code>PolygonSelectionListener</code> object.
88
     * </p>
89
     * 
90
     * @param mc
91
     *            the <code>MapControl</code> where is drawn the polyline
92
     */
93
    public PolyLineSelectionListener(MapControl mc) {
94
        this.mapCtrl = mc;
95
    }
96

  
97
    /*
98
     * (non-Javadoc)
99
     * 
100
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
101
     */
102
    public Cursor getCursor() {
103
    	if( cur == null ) {
104
    		cur = Toolkit.getDefaultToolkit().createCustomCursor(this.getImageCursor(),
105
    		        new Point(16, 16),
106
    		        "");
107
    	}
108
        return cur;
109
    }
110

  
111
    /*
112
     * (non-Javadoc)
113
     * 
114
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
115
     */
116
    public boolean cancelDrawing() {
117
        return false;
118
    }
119

  
120
    /*
121
     * (non-Javadoc)
122
     * 
123
     * @see
124
     * com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#points(com.iver
125
     * .cit.gvsig.fmap.tools.Events.MeasureEvent)
126
     */
127
    public void points(MeasureEvent event) throws BehaviorException {
128
    }
129

  
130
    /*
131
     * (non-Javadoc)
132
     * 
133
     * @see
134
     * com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#pointFixed(com
135
     * .iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
136
     */
137
    public void pointFixed(MeasureEvent event) throws BehaviorException {
138
    }
139

  
140
    /*
141
     * (non-Javadoc)
142
     * 
143
     * @see
144
     * com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#polylineFinished
145
     * (com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
146
     */
147
    public void polylineFinished(MeasureEvent event) throws BehaviorException {
148
        try {
149
            GeneralPathX gp = event.getGP();
150
            GeometryManager manager = GeometryLocator.getGeometryManager();
151
            Geometry geom = null;
152
            Surface surface = null;
153
            try {
154
                surface =
155
                    (Surface) manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
156
                surface.setGeneralPath(gp);
157
                geom = surface;
158
            } catch (CreateGeometryException e1) {
159
                NotificationManager.showMessageError(PluginServices.getText(null,
160
                    "Failed_creating_geometry"),
161
                    e1);
162
            }
163
            if (geom == null)
164
                return;
165

  
166
            FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();
167

  
168
            for (int i = 0; i < actives.length; i++) {
169
                if (actives[i] instanceof FLyrVect) {
170
                    FLyrVect lyrVect = (FLyrVect) actives[i];
171
                    FeatureSet newSelection = null;
172

  
173
                    newSelection =
174
                        lyrVect.queryByGeometry(geom, lyrVect.getFeatureStore()
175
                            .getDefaultFeatureType());
176

  
177
                    if (event.getEvent().isControlDown()) {
178
                        ((FeatureSelection) lyrVect.getDataStore()
179
                            .getSelection()).select(newSelection);
180
                    } else {
181
                        lyrVect.getFeatureStore().setSelection(newSelection);
182
                    }
183
                }
184
            }
185
        } catch (com.vividsolutions.jts.geom.TopologyException topEx) {
186
            NotificationManager.showMessageError(PluginServices.getText(null,
187
                "Failed_selecting_geometries_by_polyline_topology_exception_explanation"),
188
                topEx);
189
        } catch (Exception ex) {
190
            NotificationManager.showMessageError(PluginServices.getText(null,
191
                "Failed_selecting_geometries"), ex);
192
        }
193
    }
194

  
195
    public Image getImageCursor() {
196
        return IconThemeHelper.getImage("cursor-select-by-polyline");
197
    }
198
}
0 199

  
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/buffer/process/BufferSelectionProcess.java
1
package org.gvsig.selectiontools.app.extension.tools.buffer.process;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

  
25
import java.awt.event.MouseAdapter;
26
import java.awt.event.MouseEvent;
27
import java.util.ArrayList;
28
import java.util.Iterator;
29

  
30
import javax.swing.JButton;
31

  
32
import org.cresques.cts.IProjection;
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.andami.messages.NotificationManager;
35
import org.gvsig.andami.ui.mdiManager.IWindow;
36
import org.gvsig.app.project.documents.view.gui.IView;
37
import org.gvsig.fmap.dal.feature.Feature;
38
import org.gvsig.fmap.dal.feature.FeatureSelection;
39
import org.gvsig.fmap.dal.feature.FeatureSet;
40
import org.gvsig.fmap.geom.Geometry;
41
import org.gvsig.fmap.mapcontext.MapContext;
42
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
43
import org.gvsig.fmap.mapcontrol.MapControl;
44
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
45
import org.gvsig.gui.beans.incrementabletask.IncrementableProcess;
46
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
47
import org.gvsig.selectiontools.app.extension.tools.buffer.gui.BufferConfigurationPanel;
48
import org.gvsig.tools.dispose.DisposableIterator;
49

  
50
/**
51
 * 
52
 * 
53
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
54
 */
55
public class BufferSelectionProcess extends IncrementableProcess {
56

  
57
    // private boolean layerWasBeingEdited = false;
58

  
59
    private MapControl mapControl = null;
60
    private byte pol_side = -1;
61
    private byte line_side = -1;
62
    private byte point_side = -1;
63
    private byte multi_point_side = -1;
64
    private short selectedDistanceUnit = -1;
65
    private FLyrVect[] layers = null;
66
    private final double f_width;
67
    private boolean multiLayerSelection = false;
68

  
69
    /**
70
     * For polygonal buffers, only compute interior buffers
71
     */
72
    public static final byte BUFFER_INSIDE_POLY = 0;
73

  
74
    /**
75
     * For polygonal buffers, only compute exterior buffers (is the default
76
     * operation, it applies to any geometry type)
77
     */
78
    public static final byte BUFFER_OUTSIDE_POLY = 1;
79

  
80
    /**
81
     * For polygonal buffers, compute interior and exterior buffers
82
     */
83
    public static final byte BUFFER_INSIDE_OUTSIDE_POLY = 2;
84

  
85
    /**
86
     * Buffer with square cap
87
     */
88
    public static final byte CAP_SQUARE = 0;
89
    /**
90
     * Buffer with round cap
91
     */
92
    public static final byte CAP_ROUND = 1;
93

  
94
    /**
95
     * flag that represents buffer computing with one only buffer distance.
96
     */
97
    public static final byte CONSTANT_DISTANCE_STRATEGY = 0;
98

  
99
    /**
100
     * buffer computing with variable buffer distance in function of feature
101
     * attribute value
102
     */
103
    public static final byte ATTRIBUTE_DISTANCE_STRATEGY = 1;
104

  
105
    /**
106
     * Creates a new
107
     * <p>
108
     * BufferSelectionProcess
109
     * </p>
110
     * .
111
     * 
112
     * @param title
113
     *            of the progress dialog
114
     * @param label
115
     *            the label that explains the process
116
     * @param mapControl
117
     *            reference to the current active view's <code>MapControl</code>
118
     *            .
119
     * @param pol_side
120
     *            side of the buffer in a polyline layer:
121
     *            {@link BufferConfigurationPanel#OUTSIDE
122
     *            BufferConfigurationPanel#OUTSIDE},
123
     *            {@link BufferConfigurationPanel#INSIDE
124
     *            BufferConfigurationPanel#INSIDE}, or
125
     *            {@link BufferConfigurationPanel#OUTSIDE_AND_INSIDE
126
     *            BufferConfigurationPanel#OUTSIDE_AND_INSIDE}
127
     * @param line_side
128
     *            side of the buffer in a line layer:
129
     *            {@link BufferConfigurationPanel#OUTSIDE_AND_INSIDE
130
     *            BufferConfigurationPanel#OUTSIDE_AND_INSIDE}
131
     * @param point_side
132
     *            side of the buffer in a point layer:
133
     *            {@link BufferConfigurationPanel#OUTSIDE
134
     *            BufferConfigurationPanel#OUTSIDE}
135
     * @param multi_point_side
136
     *            side of the buffer in a multi point layer:
137
     *            {@link BufferConfigurationPanel#OUTSIDE
138
     *            BufferConfigurationPanel#OUTSIDE}
139
     * @param width
140
     *            buffer's width
141
     * @param selectedDistanceUnit
142
     *            distance unit selected
143
     * @param activeLayers
144
     *            current active view's active layers
145
     * @param showBufferLayers
146
     *            determines if will show the layers with the buffers as new
147
     *            temporal layers
148
     * @param multiLayerSelection
149
     *            determines if the selection in each active layer affects the
150
     *            other
151
     */
152
    public BufferSelectionProcess(String title,
153
        String label,
154
        MapControl mapControl,
155
        byte pol_side,
156
        byte line_side,
157
        byte point_side,
158
        byte multi_point_side,
159
        double width,
160
        short selectedDistanceUnit,
161
        FLyrVect[] activeLayers,
162
        boolean multiLayerSelection) {
163
        super(title);
164

  
165
        this.label = label;
166
        this.mapControl = mapControl;
167
        this.pol_side = pol_side;
168
        this.line_side = line_side;
169
        this.point_side = point_side;
170
        this.multi_point_side = multi_point_side;
171
        this.f_width = width;
172
        this.selectedDistanceUnit = selectedDistanceUnit;
173
        this.layers = activeLayers;
174
        this.multiLayerSelection = multiLayerSelection;
175
        this.isPausable = true;
176
    }
177

  
178
    /**
179
     * Sets the object that will display the evolution of this loading process
180
     * as a progress dialog.
181
     * 
182
     * @param iTask
183
     *            the object that will display the evolution of this loading
184
     *            process
185
     */
186
    public void setIncrementableTask(IncrementableTask iTask) {
187
        this.iTask = iTask;
188
        iTask.setAskCancel(true);
189
        iTask.getButtonsPanel().addAccept();
190
        iTask.getButtonsPanel().setEnabled(ButtonsPanel.BUTTON_ACCEPT, false);
191

  
192
        JButton jButton =
193
            iTask.getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT);
194
        jButton.addMouseListener(new MouseAdapter() {
195

  
196
            /*
197
             * (non-Javadoc)
198
             * 
199
             * @see
200
             * java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent
201
             * )
202
             */
203
            public void mouseClicked(MouseEvent e) {
204
                processFinalize();
205
            }
206
        });
207
    }
208

  
209
    /**
210
     * Importation process.
211
     * 
212
     * @throws InterruptedException
213
     *             if fails the process
214
     */
215
    public void process() throws InterruptedException {
216
        percentage = 5;
217
        double inc = 0;
218
        FeatureSelection selections[] = new FeatureSelection[layers.length];
219
        ArrayList<Geometry> buffer[] = new ArrayList[layers.length];
220
        try {
221

  
222
            /* 2- Gets the distance relation */
223
            percentage = 6;
224

  
225
            /* 3- Stores the new selections */
226
            FLyrVect layer = null;
227

  
228
            // int size;
229

  
230
            percentage = 9;
231

  
232
            /* 4- Gets the buffer and intersects to select new geometries */
233
            double width = 1; // default value (not used)
234
            byte side;
235

  
236
            percentage = 11;
237

  
238
            boolean isProjected = false;
239

  
240
            IWindow f = PluginServices.getMDIManager().getActiveWindow();
241
            if (f instanceof IView) {
242
                IView vista = (IView) f;
243

  
244
                // Sets projection
245
                IProjection proj =
246
                    vista.getMapControl().getViewPort().getProjection();
247

  
248
                // Sets distance units
249
                isProjected = proj.isProjected();
250
            }
251
            // Sets map units
252
            int mapUnits = -1;
253
            if (isProjected) {
254
                mapUnits =
255
                    ((IView) PluginServices.getMDIManager().getActiveWindow()).getMapControl()
256
                        .getViewPort()
257
                        .getMapUnits();
258
            } else {
259
                mapUnits = 1;
260
            }
261

  
262
            percentage = 14;
263

  
264
            inc = (100 - percentage) / layers.length;
265

  
266
            /* 4.1- For each vector layer with geometries selected */
267
            for (int i = 0; i < layers.length; i++) {
268
                try {
269
                    if (cancelProcess.isCanceled()) {
270
                        throw new InterruptedException();
271
                    }
272

  
273
                    layer = layers[i];
274
                    FeatureSelection selection =
275
                        (FeatureSelection) layer.getFeatureStore()
276
                            .getFeatureSelection()
277
                            .clone();
278
                    selections[i] = selection;
279

  
280
                    log.addLine(PluginServices.getText(null,
281
                        "Starting_selection_of_layer")
282
                        + " \""
283
                        + layer.getName() + "\"");
284

  
285
                    switch (layer.getShapeType()) {
286
                    case Geometry.TYPES.POINT:
287
                        side = point_side;
288
                        break;
289
                    case Geometry.TYPES.CURVE:
290
                    case Geometry.TYPES.MULTICURVE:
291
                        side = line_side;
292
                        break;
293
                    case Geometry.TYPES.SURFACE:
294
                    case Geometry.TYPES.MULTISURFACE:
295
                        side = pol_side;
296
                        break;
297
                    case Geometry.TYPES.MULTIPOINT:
298
                        side = multi_point_side;
299
                        break;
300
                    default: // UNDEFINED
301
                        // UNSUPPORTED
302
                        log.addLine(PluginServices.getText(null,
303
                            "Layer_with_unsupported_geometries_type"));
304
                        percentage += inc;
305
                        continue;
306
                    }
307

  
308
                    /* 4.2- Calculates the width */
309
                    width =
310
                        f_width
311
                            * MapContext.getDistanceTrans2Meter()[selectedDistanceUnit]
312
                            / MapContext.getDistanceTrans2Meter()[mapUnits];
313

  
314
                    /* 4.4- Sets the buffer width */
315
                    log.addLine(PluginServices.getText(null,
316
                        "Buffer_information") + ":");
317

  
318
                    /* 4.5- Shows width information */
319
                    if (mapControl.getProjection().isProjected()) {
320
                        log.addLine("    "
321
                            + PluginServices.getText(null, "Buffer_width")
322
                            + ": " + width + " m.");
323
                    } else {
324
                        log.addLine("    "
325
                            + PluginServices.getText(null, "Buffer_width")
326
                            + ": " + width + " m");
327
                        log.addLine("    "
328
                            + PluginServices.getText(null, "Buffer_width")
329
                            + ": " + width
330
                            / MapContext.getDistanceTrans2Meter()[8] + " ?");
331
                    }
332

  
333
                    log.addLine("    "
334
                        + PluginServices.getText(null, "Buffer_cap") + ": "
335
                        + PluginServices.getText(null, "Round"));
336

  
337
                    switch (side) {
338
                    case BUFFER_OUTSIDE_POLY:
339
                        log.addLine("    "
340
                            + PluginServices.getText(null, "Side") + ": "
341
                            + PluginServices.getText(null, "Outside"));
342
                        break;
343
                    case BUFFER_INSIDE_POLY:
344
                        log.addLine("    "
345
                            + PluginServices.getText(null, "Side") + ": "
346
                            + PluginServices.getText(null, "Inside"));
347
                        break;
348
                    case BUFFER_INSIDE_OUTSIDE_POLY:
349
                        log.addLine("    "
350
                            + PluginServices.getText(null, "Side")
351
                            + ": "
352
                            + PluginServices.getText(null, "Outside_and_inside"));
353
                        break;
354
                    }
355

  
356
                    /*
357
                     * 4.3- Creates the influence area
358
                     */
359
                    // if (cancelProcess.isCanceled()) {
360
                    // throw new InterruptedException();
361
                    // }
362

  
363
                    DisposableIterator selIt = selection.iterator();
364
                    ArrayList<Geometry> bufferLayer = new ArrayList<Geometry>();
365
                    while (selIt.hasNext()) {
366
                        Feature feat = (Feature) selIt.next();
367
                        Geometry geomBuffer = null;
368
                        switch (side) {
369
                        case BUFFER_OUTSIDE_POLY:
370
                            geomBuffer =
371
                                feat.getDefaultGeometry().buffer(width);
372
                            break;
373
                        case BUFFER_INSIDE_POLY:
374
                            geomBuffer =
375
                                feat.getDefaultGeometry().buffer(-width);
376
                            break;
377
                        case BUFFER_INSIDE_OUTSIDE_POLY:
378
                            // Aqu? no deber?a llegar nunca, por si acaso lo
379
                            // dejamos igual que el BUFFER_OUTSIDE_POLY
380
                            geomBuffer =
381
                                feat.getDefaultGeometry().buffer(width);
382
                            break;
383
                        }
384
                        bufferLayer.add(geomBuffer);
385
                    }
386
                    buffer[i] = bufferLayer;
387
                    selIt.dispose();
388

  
389
                } catch (Exception e3) {
390
                    /* Notifies the exception in the log */
391
                    if (!cancelProcess.isCanceled()) {
392
                        NotificationManager.showMessageError(PluginServices.getText(null,
393
                            "Error_fallo_geoproceso"),
394
                            e3);
395
                        log.addLine(PluginServices.getText(null,
396
                            "Error_fallo_geoproceso"));
397
                    }
398

  
399
                    throw new InterruptedException();
400
                }
401
            }
402

  
403
            for (int i = 0; i < layers.length; i++) {
404
                layer = layers[i];
405
                FeatureSelection layerSelection =
406
                    layer.getFeatureStore().getFeatureSelection();
407
                Geometry aux_geometry;
408
                if (multiLayerSelection) {
409
                    for (int j = 0; j < buffer.length; j++) {
410
                        ArrayList<Geometry> bufferLayer = buffer[j];
411
                        if (bufferLayer != null) {
412
                            Iterator<Geometry> geomIt = bufferLayer.iterator();
413
                            while (geomIt.hasNext()) {
414
                                aux_geometry = geomIt.next();
415
                                FeatureSet aux_featSet =
416
                                    layer.queryByGeometry(aux_geometry,
417
                                        layer.getFeatureStore()
418
                                            .getDefaultFeatureType());
419
                                layerSelection.select(aux_featSet);
420
                            }
421
                        }
422
                    }
423

  
424
                } else {
425
                    ArrayList<Geometry> bufferLayer = buffer[i];
426
                    Iterator<Geometry> geomIt = bufferLayer.iterator();
427
                    while (geomIt.hasNext()) {
428
                        aux_geometry = geomIt.next();
429
                        FeatureSet aux_featSet =
430
                            layer.queryByGeometry(aux_geometry,
431
                                layer.getFeatureStore().getDefaultFeatureType());
432
                        layerSelection.select(aux_featSet);
433
                    }
434

  
435
                }
436
            }
437

  
438
            log.addLine(PluginServices.getText(null,
439
                "Selection_process_finished_succesfully"));
440
            log.addLine(""); // Empty line
441

  
442
        } catch (Exception de) {
443
            /* 5- Notifies the exception in the log */
444
            if (!cancelProcess.isCanceled()) {
445
                log.addLine(PluginServices.getText(null, "Selection_restored"));
446

  
447
                throw new InterruptedException();
448
            }
449

  
450
            percentage += inc;
451
        }
452

  
453
        percentage = 100;
454
    }
455

  
456
}
0 457

  
tags/v2_0_0_Build_2065/1.0.0/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/buffer/gui/BufferConfigurationPanel.java
1
package org.gvsig.selectiontools.app.extension.tools.buffer.gui;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
 * MA  02110-1301, USA.
22
 *
23
 */
24

  
25
import java.awt.Dimension;
26
import java.awt.FlowLayout;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.awt.event.ComponentAdapter;
30
import java.awt.event.ComponentEvent;
31
import java.text.DecimalFormat;
32
import java.util.ArrayList;
33
import java.util.Arrays;
34
import java.util.Iterator;
35

  
36
import javax.swing.BorderFactory;
37
import javax.swing.JCheckBox;
38
import javax.swing.JLabel;
39
import javax.swing.JPanel;
40
import javax.swing.text.NumberFormatter;
41

  
42
import org.gvsig.andami.PluginServices;
43
import org.gvsig.andami.messages.NotificationManager;
44
import org.gvsig.andami.ui.mdiManager.IWindow;
45
import org.gvsig.andami.ui.mdiManager.WindowInfo;
46
import org.gvsig.app.project.documents.view.gui.IView;
47
import org.gvsig.fmap.dal.exception.DataException;
48
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
49
import org.gvsig.fmap.mapcontrol.MapControl;
50
import org.gvsig.gui.beans.AcceptCancelPanel;
51
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
52
import org.gvsig.gui.beans.progresspanel.ProgressPanel;
53
import org.gvsig.gui.beans.specificcaretposition.JFormattedTextFieldSCP;
54
import org.gvsig.selectiontools.app.extension.tools.buffer.process.BufferSelectionProcess;
55
import org.gvsig.utils.swing.JComboBox;
56

  
57
/**
58
 * 
59
 * 
60
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
61
 */
62
public class BufferConfigurationPanel extends JPanel implements IWindow {
63

  
64
    private WindowInfo viewInfo = null;
65
    private final short Window_Width = 354;
66
    private final short Window_Height = 315; // 35;
67
    private JFormattedTextFieldSCP distanceTextField = null;
68
    private JComboBox distanceUnitsCombo = null;
69
    private JComboBox polygonSidesCombo = null;
70
    private JComboBox lineSidesCombo = null;
71
    private JComboBox pointSidesCombo = null;
72
    private JComboBox multiPointSidesCombo = null;
73
    private JLabel distanceUnitsLabel = null;
74
    private JLabel polygonSideLabel = null;
75
    private JLabel lineSideLabel = null;
76
    private JLabel pointSideLabel = null;
77
    private JLabel multiPointSideLabel = null;
78
    private JPanel polygonSidePanel = null;
79
    private JPanel lineSidePanel = null;
80
    private JPanel pointSidePanel = null;
81
    private JPanel multiPointSidePanel = null;
82
    private JLabel widthLabel = null;
83
    private JPanel widthPanel = null;
84
    // private JPanel distanceUnits = null;
85
    private JPanel sidePanel = null;
86
    private JPanel optionsPanel = null;
87
    private AdaptedAcceptCancelPanel acceptCancelPanel = null;
88
    private FLyrVect[] layers;
89
    private MapControl mapControl;
90
    private IView view;
91
    private JCheckBox multiLayerSelectionCBox;
92
    private SideInfo outside, inside, out_in_side;
93

  
94
    /**
95
     * <p>
96
     * Creates a new form where user can define the option of the buffer.
97
     * </p>
98
     */
99
    public BufferConfigurationPanel(FLyrVect[] array, IView view) {
100
        super();
101

  
102
        layers = array;
103
        this.view = view;
104
        mapControl = view.getMapControl();
105

  
106
        initialize();
107
    }
108

  
109
    /**
110
     * <p>
111
     * Initializes this component.
112
     * </p>
113
     */
114
    private void initialize() {
115
        outside =
116
            new SideInfo(BufferSelectionProcess.BUFFER_OUTSIDE_POLY,
117
                PluginServices.getText(null, "Outside"));
118
        inside =
119
            new SideInfo(BufferSelectionProcess.BUFFER_INSIDE_POLY,
120
                PluginServices.getText(null, "Inside"));
121
        out_in_side =
122
            new SideInfo(BufferSelectionProcess.BUFFER_INSIDE_OUTSIDE_POLY,
123
                PluginServices.getText(null, "Both"));
124

  
125
        setLayout(new FlowLayout());
126
        add(getWidthPanel());
127
        add(getSidePanel());
128
        add(getOptionsPanel());
129
        add(getAdaptedAcceptCancelPanel());
130
    }
131

  
132
    private JPanel getOptionsPanel() {
133
        if (optionsPanel == null) {
134
            optionsPanel = new JPanel();
135
            optionsPanel.setLayout(new FlowLayout());
136
            optionsPanel.setPreferredSize(new Dimension(344, 80)); // 106));
137
            optionsPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(optionsPanel,
138
                "Options")));
139
            optionsPanel.add(getMultiLayerSelectionCBox());
140
        }
141

  
142
        return optionsPanel;
143
    }
144

  
145
    private JCheckBox getMultiLayerSelectionCBox() {
146
        if (multiLayerSelectionCBox == null) {
147
            multiLayerSelectionCBox = new JCheckBox();
148
            multiLayerSelectionCBox.setPreferredSize(new Dimension(330, 22));
149
            multiLayerSelectionCBox.setText(PluginServices.getText(multiLayerSelectionCBox,
150
                "multiLayer_selection"));
151
            multiLayerSelectionCBox.setSelected(true);
152
            multiLayerSelectionCBox.setToolTipText(PluginServices.getText(null,
153
                "multiLayerSelection_checkbox_TOOLTIP_HTML_explanation"));
154
        }
155

  
156
        return multiLayerSelectionCBox;
157
    }
158

  
159
    private JPanel getWidthPanel() {
160
        if (widthPanel == null) {
161
            widthPanel = new JPanel();
162
            widthPanel.setPreferredSize(new Dimension(344, 55));
163
            widthPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(widthPanel,
164
                "Width")));
165
            widthPanel.setLayout(new FlowLayout());
166
            widthPanel.add(getWidthLabel());
167
            widthPanel.add(getWidthTextField());
168
            widthPanel.add(getDistanceUnitsLabel());
169
            widthPanel.add(getDistanceUnitsCombo());
170
        }
171

  
172
        return widthPanel;
173
    }
174

  
175
    private JLabel getWidthLabel() {
176
        if (widthLabel == null) {
177
            widthLabel = new JLabel();
178
            widthLabel.setPreferredSize(new Dimension(68, 22));
179
            widthLabel.setText(PluginServices.getText(widthLabel, "Width"));
180
            widthLabel.setToolTipText(PluginServices.getText(null,
181
                "bufferWidth_TOOLTIP_HTML_explanation"));
182
        }
183

  
184
        return widthLabel;
185
    }
186

  
187
    private JFormattedTextFieldSCP getWidthTextField() {
188
        if (distanceTextField == null) {
189
            DecimalFormat decimalFormat = new DecimalFormat();
190
            decimalFormat.setDecimalSeparatorAlwaysShown(true);
191
            decimalFormat.setMaximumIntegerDigits(12);
192
            decimalFormat.setMinimumIntegerDigits(1);
193
            decimalFormat.setMinimumFractionDigits(2);
194
            decimalFormat.setMaximumFractionDigits(4);
195

  
196
            NumberFormatter numberFormatter = new NumberFormatter();
197
            numberFormatter.setAllowsInvalid(false);
198
            numberFormatter.setOverwriteMode(false);
199
            numberFormatter.setCommitsOnValidEdit(true);
200
            numberFormatter.setMinimum(new Double(0));
201
            numberFormatter.setFormat(decimalFormat);
202

  
203
            // numberFormatter.setFormat(new
204
            // DecimalFormat("([+]|[-])?[0-9]+([.][0-9]+)?"));
205

  
206
            distanceTextField = new JFormattedTextFieldSCP(numberFormatter);
207
            distanceTextField.setPreferredSize(new Dimension(85, 22));
208
            distanceTextField.setValue(new Double(100.00));
209
            distanceTextField.setToolTipText(PluginServices.getText(null,
210
                "bufferWidth_TOOLTIP_HTML_explanation"));
211
        }
212

  
213
        return distanceTextField;
214
    }
215

  
216
    private JLabel getDistanceUnitsLabel() {
217
        if (distanceUnitsLabel == null) {
218
            distanceUnitsLabel =
219
                new JLabel(PluginServices.getText(distanceUnitsLabel, "Unit"));
220
            distanceUnitsLabel.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
221
            distanceUnitsLabel.setPreferredSize(new Dimension(68, 22));
222
            distanceUnitsLabel.setToolTipText(PluginServices.getText(null,
223
                "distanceUnitsLabel_TOOLTIP_HTML_explanation"));
224
        }
225

  
226
        return distanceUnitsLabel;
227
    }
228

  
229
    private JComboBox getDistanceUnitsCombo() {
230
        if (distanceUnitsCombo == null) {
231
            distanceUnitsCombo = new JComboBox();
232
            distanceUnitsCombo.setPreferredSize(new Dimension(85, 22));
233
            distanceUnitsCombo.addItem("km");
234
            distanceUnitsCombo.addItem("m");
235
            distanceUnitsCombo.addItem("cm");
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff