Revision 2329
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.134/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/test/resources/README.txt | ||
---|---|---|
1 |
==== |
|
2 |
gvSIG. Desktop Geographic Information System. |
|
3 |
|
|
4 |
Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
For any additional information, do not hesitate to contact us |
|
22 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
==== |
|
24 |
|
|
25 |
Put into this folder the resources needed by your test classes. |
|
26 |
|
|
27 |
This folder is added to the Tests classpath, so you can load any resources |
|
28 |
through the ClassLoader. |
|
29 |
|
|
30 |
By default, in this folder you can find an example of log4j configuration, |
|
31 |
prepared to log messages through the console, so logging works when you |
|
32 |
run your tests classes. |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.134/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!-- |
|
3 |
|
|
4 |
gvSIG. Desktop Geographic Information System. |
|
5 |
|
|
6 |
Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
For any additional information, do not hesitate to contact us |
|
24 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
25 |
|
|
26 |
--> |
|
27 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
28 |
|
|
29 |
<!-- |
|
30 |
Log4J configuration file for unit tests execution. |
|
31 |
--> |
|
32 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
33 |
|
|
34 |
<!-- Appender configuration to show logging messages through the console --> |
|
35 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
36 |
<layout class="org.apache.log4j.PatternLayout"> |
|
37 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
38 |
</layout> |
|
39 |
</appender> |
|
40 |
|
|
41 |
<!-- |
|
42 |
Activate logging messages of DEBUG level of higher only for the |
|
43 |
org.gvsig.tools packages. |
|
44 |
You can put full classes names or packages instead, to configure |
|
45 |
logging for all the classes and subpackages of the package. |
|
46 |
--> |
|
47 |
<category name="org.gvsig.tools"> |
|
48 |
<priority value="DEBUG" /> |
|
49 |
</category> |
|
50 |
<category name="org.gvsig.vectorediting"> |
|
51 |
<priority value="DEBUG" /> |
|
52 |
</category> |
|
53 |
|
|
54 |
<!-- |
|
55 |
By default, show only logging messages of INFO level or higher, |
|
56 |
through the previously configured CONSOLE appender. |
|
57 |
--> |
|
58 |
<root> |
|
59 |
<priority value="INFO" /> |
|
60 |
<appender-ref ref="CONSOLE" /> |
|
61 |
</root> |
|
62 |
</log4j:configuration> |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.134/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/EditingContextSymbolTable.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
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 3 |
|
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, see <https://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* For any additional information, do not hesitate to contact us |
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
21 |
*/ |
|
22 |
|
|
23 |
package org.gvsig.vectorediting.swing.impl; |
|
24 |
|
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.Collection; |
|
27 |
import java.util.Collections; |
|
28 |
import java.util.List; |
|
29 |
import org.apache.commons.lang3.StringUtils; |
|
30 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
|
31 |
import org.gvsig.fmap.geom.Geometry; |
|
32 |
import org.gvsig.fmap.geom.primitive.Point; |
|
33 |
import org.gvsig.temporarystorage.TemporaryStorageGroup; |
|
34 |
import org.gvsig.temporarystorage.TemporaryStorageLocator; |
|
35 |
import org.gvsig.temporarystorage.TemporaryStorageManager; |
|
36 |
|
|
37 |
/** |
|
38 |
* |
|
39 |
* @author gvSIG Team |
|
40 |
*/ |
|
41 |
public class EditingContextSymbolTable extends AbstractSymbolTable { |
|
42 |
|
|
43 |
private static class ListWithMaximumSize<T> extends ArrayList<T> { |
|
44 |
|
|
45 |
private final int maximumSize; |
|
46 |
|
|
47 |
public ListWithMaximumSize(int maximumSize) { |
|
48 |
this.maximumSize = maximumSize; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public boolean add(T e) { |
|
53 |
if( this.size()>this.maximumSize ) { |
|
54 |
this.remove(0); |
|
55 |
} |
|
56 |
return super.add(e); |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public void add(int index, T element) { |
|
61 |
if( this.size()>this.maximumSize ) { |
|
62 |
this.remove(0); |
|
63 |
} |
|
64 |
super.add(index, element); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
private final List<Point> lastPoints; |
|
69 |
private final TemporaryStorageGroup globalPointsStorage; |
|
70 |
|
|
71 |
public EditingContextSymbolTable() { |
|
72 |
this.lastPoints = new ListWithMaximumSize(100); |
|
73 |
TemporaryStorageManager manager = TemporaryStorageLocator.getTemporaryStorageManager(); |
|
74 |
this.globalPointsStorage = manager.create("Points",Point.class); |
|
75 |
} |
|
76 |
|
|
77 |
public void addPoint(Point point) { |
|
78 |
this.lastPoints.add(point); |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public boolean exists(String name) { |
|
83 |
if( globalPointsStorage.contains(name) ) { |
|
84 |
return true; |
|
85 |
} |
|
86 |
if( globalPointsStorage.contains(name+"$x") ) { |
|
87 |
return true; |
|
88 |
} |
|
89 |
if( globalPointsStorage.contains(name+"$y") ) { |
|
90 |
return true; |
|
91 |
} |
|
92 |
if( this.lastPoints.isEmpty() || StringUtils.isBlank(name) ) { |
|
93 |
return false; |
|
94 |
} |
|
95 |
name = name.toLowerCase(); |
|
96 |
int index = -1; |
|
97 |
if( name.length()==2 ) { |
|
98 |
index = this.lastPoints.size()-1; |
|
99 |
} else if( name.length()<3 ) { |
|
100 |
return false; |
|
101 |
} else { |
|
102 |
try { |
|
103 |
index = Integer.parseUnsignedInt(name.substring(2)); |
|
104 |
} catch(NumberFormatException ex) { |
|
105 |
return false; |
|
106 |
} |
|
107 |
} |
|
108 |
if( index < 0 || index >= this.lastPoints.size() ) { |
|
109 |
return false; |
|
110 |
} |
|
111 |
if( name.startsWith("$p") || name.startsWith("$x") || name.startsWith("$y") ) { |
|
112 |
return true; |
|
113 |
} |
|
114 |
return false; |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public Object value(String name) { |
|
119 |
if( globalPointsStorage.contains(name) ) { |
|
120 |
return globalPointsStorage.get(name); |
|
121 |
} |
|
122 |
if( globalPointsStorage.contains(name+"$x") ) { |
|
123 |
Point point = (Point) globalPointsStorage.get(name+"$x"); |
|
124 |
return point.getX(); |
|
125 |
} |
|
126 |
if( globalPointsStorage.contains(name+"$y") ) { |
|
127 |
Point point = (Point) globalPointsStorage.get(name+"$y"); |
|
128 |
return point.getY(); |
|
129 |
} |
|
130 |
if( this.lastPoints.isEmpty() || StringUtils.isBlank(name) ) { |
|
131 |
return null; |
|
132 |
} |
|
133 |
name = name.toLowerCase(); |
|
134 |
int index = -1; |
|
135 |
if( name.length()==2 ) { |
|
136 |
index = 0; |
|
137 |
} else if( name.length()<3 ) { |
|
138 |
return null; |
|
139 |
} else { |
|
140 |
try { |
|
141 |
index = Integer.parseUnsignedInt(name.substring(2)); |
|
142 |
} catch(NumberFormatException ex) { |
|
143 |
return null; |
|
144 |
} |
|
145 |
} |
|
146 |
if( index < 0 || index >= this.lastPoints.size() ) { |
|
147 |
return false; |
|
148 |
} |
|
149 |
// El index 0 es el ultimo en la lista |
|
150 |
index = (this.lastPoints.size() - index) - 1; |
|
151 |
|
|
152 |
if( name.startsWith("$p") ) { |
|
153 |
Point point = this.lastPoints.get(index); |
|
154 |
return point; |
|
155 |
} |
|
156 |
if( name.startsWith("$x") ) { |
|
157 |
Point point = this.lastPoints.get(index); |
|
158 |
return point.getX(); |
|
159 |
} |
|
160 |
if( name.startsWith("$y") ) { |
|
161 |
Point point = this.lastPoints.get(index); |
|
162 |
return point.getY(); |
|
163 |
} |
|
164 |
return null; |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public Collection<String> localvariables() { |
|
169 |
if( this.lastPoints.isEmpty() ) { |
|
170 |
return Collections.EMPTY_LIST; |
|
171 |
} |
|
172 |
List<String> names = new ArrayList<>(); |
|
173 |
names.add("$p"); |
|
174 |
names.add("$x"); |
|
175 |
names.add("$y"); |
|
176 |
for (int i = 0; i < this.lastPoints.size(); i++) { |
|
177 |
names.add("$p"+i); |
|
178 |
names.add("$x"+i); |
|
179 |
names.add("$y"+i); |
|
180 |
} |
|
181 |
return names; |
|
182 |
} |
|
183 |
|
|
184 |
|
|
185 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.134/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingBehavior.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.swing.impl; |
|
26 |
|
|
27 |
import java.awt.Color; |
|
28 |
import java.awt.Graphics; |
|
29 |
import java.awt.Image; |
|
30 |
import java.awt.event.MouseEvent; |
|
31 |
import java.awt.geom.Point2D; |
|
32 |
import java.awt.image.BufferedImage; |
|
33 |
import java.util.Iterator; |
|
34 |
import java.util.Set; |
|
35 |
|
|
36 |
import javax.swing.SwingUtilities; |
|
37 |
|
|
38 |
import org.slf4j.Logger; |
|
39 |
import org.slf4j.LoggerFactory; |
|
40 |
|
|
41 |
import org.gvsig.fmap.geom.Geometry; |
|
42 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
43 |
import org.gvsig.fmap.geom.primitive.Point; |
|
44 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
45 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
46 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
|
47 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
|
48 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
|
49 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
50 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
|
51 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
|
52 |
import org.gvsig.tools.ToolsLocator; |
|
53 |
import org.gvsig.tools.exception.BaseException; |
|
54 |
import org.gvsig.tools.i18n.I18nManager; |
|
55 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
56 |
import org.gvsig.vectorediting.lib.api.DrawingStatus.Status; |
|
57 |
import org.gvsig.vectorediting.lib.api.EditingService; |
|
58 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
59 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
60 |
import org.gvsig.vectorediting.lib.api.exceptions.CreateEditingBehaviorException; |
|
61 |
import org.gvsig.vectorediting.lib.api.exceptions.VectorEditingException; |
|
62 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator; |
|
63 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
|
64 |
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener; |
|
65 |
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu; |
|
66 |
|
|
67 |
public class DefaultEditingBehavior extends Behavior { |
|
68 |
|
|
69 |
private static final Logger logger = LoggerFactory |
|
70 |
.getLogger(DefaultEditingBehavior.class); |
|
71 |
|
|
72 |
private DefaultEditingContext editingContext; |
|
73 |
|
|
74 |
private Point adjustedPoint; |
|
75 |
|
|
76 |
private static final Image imageCursor = new BufferedImage(32, 32, |
|
77 |
BufferedImage.TYPE_INT_ARGB); |
|
78 |
static { |
|
79 |
Graphics g = imageCursor.getGraphics(); |
|
80 |
int size1 = 15; |
|
81 |
int x = 16; |
|
82 |
int y = 16; |
|
83 |
g.setColor(Color.MAGENTA); |
|
84 |
g.drawLine((x - size1), (y), (x + size1), (y)); |
|
85 |
g.drawLine((x), (y - size1), (x), (y + size1)); |
|
86 |
g.drawRect((x - 6), (y - 6), 12, 12); |
|
87 |
g.drawRect((x - 3), (y - 3), 6, 6); |
|
88 |
} |
|
89 |
|
|
90 |
public DefaultEditingBehavior(DefaultEditingContext editingContext) |
|
91 |
throws CreateEditingBehaviorException { |
|
92 |
|
|
93 |
if (editingContext.getMapControl() != null) { |
|
94 |
this.editingContext = editingContext; |
|
95 |
setMapControl(editingContext.getMapControl()); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public ToolListener getListener() { |
|
101 |
return new ToolListener() { |
|
102 |
|
|
103 |
public boolean cancelDrawing() { |
|
104 |
return false; |
|
105 |
} |
|
106 |
|
|
107 |
public Image getImageCursor() { |
|
108 |
return imageCursor; |
|
109 |
} |
|
110 |
}; |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public void mouseClicked(MouseEvent e) { |
|
115 |
ViewPort vp = editingContext.getMapControl().getViewPort(); |
|
116 |
EditingServiceParameter currentParam = editingContext.getCurrentParam(); |
|
117 |
EditingService activeService = editingContext.getActiveService(); |
|
118 |
|
|
119 |
if ((activeService != null) && (currentParam != null)) { |
|
120 |
|
|
121 |
if (SwingUtilities.isLeftMouseButton(e)) { |
|
122 |
|
|
123 |
Set<TYPE> typesOfParam = currentParam.getTypes(); |
|
124 |
|
|
125 |
if (typesOfParam.contains(TYPE.LIST_POSITIONS)) { |
|
126 |
if (e.getClickCount() == 2) { |
|
127 |
editingContext.finishService(); |
|
128 |
return; |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
Point point = null; |
|
133 |
Point2D point2D = getMapControl().getMapAdjustedPoint(); |
|
134 |
if (point2D == null) { |
|
135 |
point2D = getMapControl().getAdjustedPoint(); |
|
136 |
point = vp.convertToMapPoint(point2D); |
|
137 |
} else { |
|
138 |
try { |
|
139 |
point = |
|
140 |
GeometryLocator.getGeometryManager().createPoint( |
|
141 |
point2D.getX(), point2D.getY(), |
|
142 |
Geometry.SUBTYPES.GEOM2D); |
|
143 |
} catch (BaseException ex) { |
|
144 |
logger.warn("Can't create point geometry from " |
|
145 |
+ point2D.toString()); |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
try { |
|
150 |
//FIXME: Estar?a bien hacer esto |
|
151 |
editingContext.setValue(currentParam, point); |
|
152 |
// editingContext.getActiveService().setValue(point); |
|
153 |
} catch (VectorEditingException ex) { |
|
154 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
155 |
editingContext.showConsoleMessage(i18nManager |
|
156 |
.getTranslation("invalid_option")); |
|
157 |
} |
|
158 |
|
|
159 |
// editingContext.nextParameter(); |
|
160 |
|
|
161 |
} else if (SwingUtilities.isRightMouseButton(e)) { |
|
162 |
|
|
163 |
EditingSwingManager swingManager = |
|
164 |
EditingSwingLocator.getSwingManager(); |
|
165 |
|
|
166 |
EditingContextMenu contextMenu = |
|
167 |
swingManager.getContextualMenu(getMapControl(), |
|
168 |
new AcceptValueListener() { |
|
169 |
|
|
170 |
public void acceptValue(Object value) { |
|
171 |
editingContext.textEntered((String) value); |
|
172 |
|
|
173 |
} |
|
174 |
}, currentParam, editingContext); |
|
175 |
|
|
176 |
contextMenu.show(getMapControl(), e.getX(), e.getY()); |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
|
183 |
} |
|
184 |
|
|
185 |
@Override |
|
186 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
187 |
ViewPort vp = editingContext.getMapControl().getViewPort(); |
|
188 |
adjustedPoint = vp.convertToMapPoint(e.getX(), e.getY()); |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
|
193 |
} |
|
194 |
|
|
195 |
@Override |
|
196 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
197 |
} |
|
198 |
|
|
199 |
@Override |
|
200 |
@SuppressWarnings("rawtypes") |
|
201 |
public void paintComponent(MapControlDrawer mapControlDrawer) { |
|
202 |
super.paintComponent(mapControlDrawer); |
|
203 |
|
|
204 |
if ((editingContext.getActiveService() == null) |
|
205 |
|| (adjustedPoint == null)) { |
|
206 |
return; |
|
207 |
} |
|
208 |
|
|
209 |
DrawingStatus helperGeo = null; |
|
210 |
|
|
211 |
try { |
|
212 |
helperGeo = |
|
213 |
editingContext.getActiveService().getDrawingStatus( |
|
214 |
adjustedPoint); |
|
215 |
} catch (VectorEditingException e) { |
|
216 |
logger.info("An error ocurred when draw service geometries", e); |
|
217 |
} |
|
218 |
|
|
219 |
if (helperGeo != null) { |
|
220 |
for (Iterator iterator = helperGeo.getStatus().iterator(); iterator |
|
221 |
.hasNext();) { |
|
222 |
Status status = (Status) iterator.next(); |
|
223 |
ISymbol symbol = status.getSymbol(); |
|
224 |
if (symbol == null) { |
|
225 |
symbol = |
|
226 |
MapControlLocator.getMapControlManager() |
|
227 |
.getAxisReferenceSymbol(); |
|
228 |
} |
|
229 |
if (symbol instanceof ITextSymbol) { |
|
230 |
((ITextSymbol) symbol).setText(status.getText()); |
|
231 |
} |
|
232 |
editingContext.getMapControl().getMapControlDrawer() |
|
233 |
.draw(status.getGeometry(), symbol); |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.134/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/EditingCompoundBehavior.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.swing.impl; |
|
26 |
|
|
27 |
import java.awt.Image; |
|
28 |
import java.awt.event.MouseEvent; |
|
29 |
import java.awt.event.MouseWheelEvent; |
|
30 |
|
|
31 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
32 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
|
33 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
34 |
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior; |
|
35 |
import org.gvsig.fmap.mapcontrol.tools.PointSelectionListener; |
|
36 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
|
37 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.IBehavior; |
|
38 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseWheelBehavior; |
|
39 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
|
40 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
|
41 |
|
|
42 |
public class EditingCompoundBehavior extends CompoundBehavior { |
|
43 |
|
|
44 |
private enum Mode { |
|
45 |
EDITING, SELECTION |
|
46 |
}; |
|
47 |
|
|
48 |
private Mode mode = Mode.EDITING; |
|
49 |
private IBehavior editing; |
|
50 |
private IBehavior selection; |
|
51 |
|
|
52 |
public final static int EDITING_INDEX = 0; |
|
53 |
public final static int SELECTION_INDEX = 1; |
|
54 |
|
|
55 |
public EditingCompoundBehavior(IBehavior editing) { |
|
56 |
super(new Behavior[0]); |
|
57 |
this.editing = editing; |
|
58 |
|
|
59 |
this.selection = null; |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public void addMapBehavior(Behavior mt, boolean draw) { |
|
64 |
if (mt instanceof MouseWheelBehavior) { |
|
65 |
return; |
|
66 |
} |
|
67 |
throw new UnsupportedOperationException(); |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public void removeMapBehavior(Behavior mt) { |
|
72 |
throw new UnsupportedOperationException(); |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
public boolean containsBehavior(Behavior mt) { |
|
77 |
return ((mt == this.editing) || (mt == this.selection)); |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public Behavior getBehavior(int index) { |
|
82 |
switch (index) { |
|
83 |
case EDITING_INDEX: |
|
84 |
return (Behavior) this.editing; |
|
85 |
case SELECTION_INDEX: |
|
86 |
return (Behavior) this.selection; |
|
87 |
default: |
|
88 |
throw new IndexOutOfBoundsException(); |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public boolean isDrawnBehavior(int index) { |
|
94 |
switch (mode) { |
|
95 |
case EDITING: |
|
96 |
return index == EDITING_INDEX; |
|
97 |
case SELECTION: |
|
98 |
return index == SELECTION_INDEX; |
|
99 |
default: |
|
100 |
return false; |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public void setDrawnBehavior(int index, boolean draw) { |
|
106 |
switch (index) { |
|
107 |
case EDITING_INDEX: |
|
108 |
if (draw) { |
|
109 |
mode = Mode.EDITING; |
|
110 |
} else { |
|
111 |
mode = Mode.SELECTION; |
|
112 |
} |
|
113 |
break; |
|
114 |
case SELECTION_INDEX: |
|
115 |
if (draw) { |
|
116 |
mode = Mode.SELECTION; |
|
117 |
} else { |
|
118 |
mode = Mode.EDITING; |
|
119 |
} |
|
120 |
break; |
|
121 |
default: |
|
122 |
throw new IndexOutOfBoundsException(); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public int size() { |
|
128 |
return 2; |
|
129 |
} |
|
130 |
|
|
131 |
@Override |
|
132 |
public Image getImageCursor() { |
|
133 |
switch (mode) { |
|
134 |
default: |
|
135 |
case EDITING: |
|
136 |
return this.editing.getImageCursor(); |
|
137 |
case SELECTION: |
|
138 |
return this.selection.getImageCursor(); |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
|
144 |
switch (mode) { |
|
145 |
default: |
|
146 |
case EDITING: |
|
147 |
this.editing.mouseClicked(e); |
|
148 |
break; |
|
149 |
case SELECTION: |
|
150 |
this.selection.mouseClicked(e); |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
|
156 |
switch (mode) { |
|
157 |
default: |
|
158 |
case EDITING: |
|
159 |
this.editing.mouseDragged(e); |
|
160 |
break; |
|
161 |
case SELECTION: |
|
162 |
this.selection.mouseDragged(e); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
@Override |
|
167 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
|
168 |
switch (mode) { |
|
169 |
default: |
|
170 |
case EDITING: |
|
171 |
this.editing.mouseEntered(e); |
|
172 |
break; |
|
173 |
case SELECTION: |
|
174 |
this.selection.mouseEntered(e); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
@Override |
|
179 |
public void mouseExited(MouseEvent e) throws BehaviorException { |
|
180 |
switch (mode) { |
|
181 |
default: |
|
182 |
case EDITING: |
|
183 |
this.editing.mouseExited(e); |
|
184 |
break; |
|
185 |
case SELECTION: |
|
186 |
this.selection.mouseExited(e); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
@Override |
|
191 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
192 |
switch (mode) { |
|
193 |
default: |
|
194 |
case EDITING: |
|
195 |
this.editing.mouseMoved(e); |
|
196 |
break; |
|
197 |
case SELECTION: |
|
198 |
this.selection.mouseMoved(e); |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
202 |
@Override |
|
203 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
|
204 |
switch (mode) { |
|
205 |
default: |
|
206 |
case EDITING: |
|
207 |
this.editing.mousePressed(e); |
|
208 |
break; |
|
209 |
case SELECTION: |
|
210 |
this.selection.mousePressed(e); |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
@Override |
|
215 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
216 |
switch (mode) { |
|
217 |
default: |
|
218 |
case EDITING: |
|
219 |
this.editing.mouseReleased(e); |
|
220 |
break; |
|
221 |
case SELECTION: |
|
222 |
this.selection.mouseReleased(e); |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
|
228 |
switch (mode) { |
|
229 |
default: |
|
230 |
case EDITING: |
|
231 |
this.editing.mouseWheelMoved(e); |
|
232 |
break; |
|
233 |
case SELECTION: |
|
234 |
this.selection.mouseWheelMoved(e); |
|
235 |
} |
|
236 |
} |
|
237 |
|
|
238 |
|
|
239 |
public void paintComponent(MapControlDrawer renderer, boolean clean) { |
|
240 |
if(clean){ |
|
241 |
clean(renderer); |
|
242 |
} |
|
243 |
paintComponent(renderer); |
|
244 |
} |
|
245 |
|
|
246 |
@Override |
|
247 |
public void paintComponent(MapControlDrawer renderer) { |
|
248 |
switch (mode) { |
|
249 |
default: |
|
250 |
case EDITING: |
|
251 |
this.editing.paintComponent(renderer); |
|
252 |
break; |
|
253 |
case SELECTION: |
|
254 |
this.selection.paintComponent(renderer); |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
@Override |
|
259 |
public void setListener(ToolListener listener) { |
|
260 |
if (listener != null) { |
|
261 |
throw new UnsupportedOperationException( |
|
262 |
"CompoundBehavior does not have listeners"); |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 |
@Override |
|
267 |
public ToolListener getListener() { |
|
268 |
return null; |
|
269 |
} |
|
270 |
|
|
271 |
@Override |
|
272 |
public void setMapControl(MapControl mc) { |
|
273 |
this.editing.setMapControl(mc); |
|
274 |
|
|
275 |
if (this.selection == null) { |
|
276 |
if (mc != null) { |
|
277 |
PointSelectionListener psl = new PointSelectionListener(mc); |
|
278 |
this.selection = |
|
279 |
new CompoundBehavior( |
|
280 |
new Behavior[] { new PointBehavior(psl) }); |
|
281 |
this.selection.setMapControl(mc); |
|
282 |
} |
|
283 |
} else { |
|
284 |
this.selection.setMapControl(mc); |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.134/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/contextmenu/DefaultEditingContextMenu.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.swing.impl.contextmenu; |
|
26 |
|
|
27 |
import java.awt.Component; |
|
28 |
import java.awt.event.ActionEvent; |
|
29 |
import java.util.List; |
|
30 |
import java.util.Map; |
|
31 |
import javax.swing.AbstractAction; |
|
32 |
import javax.swing.JComponent; |
|
33 |
import javax.swing.JOptionPane; |
|
34 |
import javax.swing.JSeparator; |
|
35 |
import javax.swing.SwingConstants; |
|
36 |
import javax.swing.SwingUtilities; |
|
37 |
import org.apache.commons.lang3.StringUtils; |
|
38 |
import org.gvsig.fmap.geom.primitive.Point; |
|
39 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
40 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior; |
|
41 |
import org.gvsig.tools.ToolsLocator; |
|
42 |
import org.gvsig.tools.i18n.I18nManager; |
|
43 |
import org.gvsig.tools.task.RunnableWithParameters; |
|
44 |
import org.gvsig.vectorediting.lib.api.EditingService; |
|
45 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
46 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
47 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
48 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
|
49 |
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener; |
|
50 |
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu; |
|
51 |
import org.slf4j.Logger; |
|
52 |
import org.slf4j.LoggerFactory; |
|
53 |
|
|
54 |
/** |
|
55 |
* @author llmarques |
|
56 |
* |
|
57 |
*/ |
|
58 |
public class DefaultEditingContextMenu extends EditingContextMenuView implements |
|
59 |
EditingContextMenu { |
|
60 |
|
|
61 |
private static Logger LOGGER = LoggerFactory |
|
62 |
.getLogger(DefaultEditingContextMenu.class); |
|
63 |
|
|
64 |
private static final long serialVersionUID = -3207749321400180897L; |
|
65 |
|
|
66 |
private AcceptValueListener listener; |
|
67 |
|
|
68 |
private Component parent; |
|
69 |
|
|
70 |
private EditingServiceParameter parameter; |
|
71 |
|
|
72 |
private EditingContext context; |
|
73 |
|
|
74 |
/** |
|
75 |
* @param parent |
|
76 |
* @param listener |
|
77 |
* @param parameter |
|
78 |
*/ |
|
79 |
public DefaultEditingContextMenu(Component parent, |
|
80 |
AcceptValueListener listener, EditingServiceParameter parameter) { |
|
81 |
|
|
82 |
this(parent, listener, parameter, null); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* @param parent |
|
87 |
* @param listener |
|
88 |
* @param parameter |
|
89 |
* @param context |
|
90 |
*/ |
|
91 |
public DefaultEditingContextMenu(Component parent, |
|
92 |
AcceptValueListener listener, EditingServiceParameter parameter, EditingContext context) { |
|
93 |
|
|
94 |
super(); |
|
95 |
this.listener = listener; |
|
96 |
this.parent = parent; |
|
97 |
this.parameter = parameter; |
|
98 |
this.context = context; |
|
99 |
initActions(); |
|
100 |
} |
|
101 |
|
|
102 |
@SuppressWarnings("serial") |
|
103 |
private void initActions() { |
|
104 |
|
|
105 |
EditingService service = context.getActiveService(); |
|
106 |
List<EditingServiceParameter> parameters = service.getParameters(); |
|
107 |
|
|
108 |
initAction(parameter, this.listener); |
|
109 |
|
|
110 |
this.add(new JSeparator(SwingConstants.HORIZONTAL)); |
|
111 |
|
|
112 |
boolean thereAreOptionalParameters = false; |
|
113 |
|
|
114 |
for (EditingServiceParameter param : parameters) { |
|
115 |
if(param.equals(this.parameter)){ |
|
116 |
continue; |
|
117 |
} |
|
118 |
if(param.isOptional() && service.isEnabled(param)){ |
|
119 |
thereAreOptionalParameters = true; |
|
120 |
initAction(param, new AcceptValueListener() { |
|
121 |
|
|
122 |
@Override |
|
123 |
public void acceptValue(Object value) { |
|
124 |
try { |
|
125 |
context.setValue(param, (String)value); |
|
126 |
} catch (InvalidEntryException ex) { |
|
127 |
LOGGER.warn("Invalid value", ex); |
|
128 |
} |
|
129 |
} |
|
130 |
}); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
if (thereAreOptionalParameters) { |
|
135 |
this.add(new JSeparator(SwingConstants.HORIZONTAL)); |
|
136 |
} |
|
137 |
|
|
138 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
139 |
AbstractAction action; |
|
140 |
|
|
141 |
action = new AbstractAction(i18nManager.getTranslation("cancel")) { |
|
142 |
|
|
143 |
@Override |
|
144 |
public void actionPerformed(ActionEvent e) { |
|
145 |
listener.acceptValue(null); |
|
146 |
} |
|
147 |
}; |
|
148 |
|
|
149 |
this.add(action); |
|
150 |
((JComponent) parent).add(this); |
|
151 |
|
|
152 |
} |
|
153 |
|
|
154 |
private void initAction(EditingServiceParameter param, AcceptValueListener listener){ |
|
155 |
|
|
156 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
157 |
AbstractAction action; |
|
158 |
|
|
159 |
for (final TYPE type : param.getTypes()) { |
|
160 |
|
|
161 |
switch (type) { |
|
162 |
case OPTION: |
|
163 |
Map<String, String> options = param.getOptions(); |
|
164 |
for (String key : options.keySet()) { |
|
165 |
String value = i18nManager.getTranslation(options.get(key)); |
|
166 |
action = new AbstractAction(value) { |
|
167 |
|
|
168 |
@Override |
|
169 |
public void actionPerformed(ActionEvent e) { |
|
170 |
String key = (String) this.getValue("key"); |
|
171 |
listener.acceptValue(key); |
|
172 |
} |
|
173 |
}; |
|
174 |
action.putValue("key", key); |
|
175 |
this.add(action); |
|
176 |
} |
|
177 |
break; |
|
178 |
case VALUE: |
|
179 |
String name = |
|
180 |
i18nManager.getTranslation(param.getName()) + " (" |
|
181 |
+ i18nManager.getTranslation("value") + ")"; |
|
182 |
action = new AbstractAction(name) { |
|
183 |
|
|
184 |
@Override |
|
185 |
public void actionPerformed(ActionEvent e) { |
|
186 |
String value = showValueDialog(param); |
|
187 |
if (StringUtils.isNotEmpty(value)) { |
|
188 |
listener.acceptValue(value); |
|
189 |
} |
|
190 |
} |
|
191 |
}; |
|
192 |
this.add(action); |
|
193 |
break; |
|
194 |
|
|
195 |
case POSITION: |
|
196 |
case LIST_POSITIONS: |
|
197 |
name = |
|
198 |
i18nManager.getTranslation(param.getName()) + " (" |
|
199 |
+ i18nManager.getTranslation("point") + ")"; |
|
200 |
action = new AbstractAction(name) { |
|
201 |
|
|
202 |
@Override |
|
203 |
public void actionPerformed(ActionEvent e) { |
|
204 |
String value = showPointDialog(param); |
|
205 |
if (value != null) { |
|
206 |
listener.acceptValue(value); |
|
207 |
} |
|
208 |
} |
|
209 |
}; |
|
210 |
this.add(action); |
|
211 |
break; |
|
212 |
|
|
213 |
case DISTANCE: |
|
214 |
name = i18nManager.getTranslation(param.getName()) + " (" |
|
215 |
+ i18nManager.getTranslation("_graphic_distance") + ")"; |
|
216 |
|
|
217 |
MapControl mapCtrl = context.getMapControl(); |
|
218 |
String currentTool = mapCtrl.getCurrentTool(); |
|
219 |
DistanceListener mli = new DistanceListener(mapCtrl, listener); |
|
220 |
PolylineBehavior polylineBehavior = new PolylineBehavior(mli); |
|
221 |
mapCtrl.addBehavior("distance", polylineBehavior); |
|
222 |
|
|
223 |
action = new AbstractAction(name) { |
|
224 |
|
|
225 |
@Override |
|
226 |
public void actionPerformed(ActionEvent e) { |
|
227 |
mapCtrl.setTool("distance"); |
|
228 |
} |
|
229 |
}; |
|
230 |
this.add(action); |
|
231 |
break; |
|
232 |
|
|
233 |
|
|
234 |
case SELECTION: |
|
235 |
case GEOMETRY: |
|
236 |
break; |
|
237 |
} |
|
238 |
|
|
239 |
} |
|
240 |
|
|
241 |
} |
|
242 |
|
|
243 |
/** |
|
244 |
* @return this as JComponent |
|
245 |
*/ |
|
246 |
public JComponent asJComponent() { |
|
247 |
return this; |
|
248 |
} |
|
249 |
|
|
250 |
private String showPointDialog(EditingServiceParameter parameter) { |
|
251 |
|
|
252 |
int dimension = 2; |
|
253 |
|
|
254 |
Object defaultValue = parameter.getDefaultValue(); |
|
255 |
Point defaultPoint = null; |
|
256 |
if (defaultValue != null && defaultValue instanceof Point) { |
|
257 |
defaultPoint = (Point)defaultValue; |
|
258 |
dimension = defaultPoint.getDimension(); |
|
259 |
} |
|
260 |
|
|
261 |
final DefaultDynamicEditingPointPanel pointPanel = new DefaultDynamicEditingPointPanel(null, defaultPoint); |
|
262 |
if(defaultPoint!=null){ |
|
263 |
for(int i=0; i<dimension; i++){ |
|
264 |
pointPanel.setValue(i, String.valueOf(defaultPoint.getCoordinateAt(i))); |
|
265 |
} |
|
266 |
} |
|
267 |
final String title = ToolsLocator.getI18nManager().getTranslation(parameter.getName()); |
|
268 |
|
|
269 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
270 |
|
|
271 |
public void run() { |
|
272 |
this.returnValue = |
|
273 |
JOptionPane.showConfirmDialog(null, pointPanel, title, JOptionPane.OK_CANCEL_OPTION); |
|
274 |
} |
|
275 |
}; |
|
276 |
|
|
277 |
if (SwingUtilities.isEventDispatchThread()) { |
|
278 |
runnable.run(); |
|
279 |
} else { |
|
280 |
try { |
|
281 |
SwingUtilities.invokeAndWait(runnable); |
|
282 |
} catch (Exception e) { |
|
283 |
LOGGER.info("Can't show point dialog.", e); |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
int result = ((Integer) runnable.getReturnValue()); |
|
288 |
|
|
289 |
if (result == JOptionPane.OK_OPTION) { |
|
290 |
StringBuilder stb = new StringBuilder(); |
|
291 |
for(int i=0; i<dimension; i++){ |
|
292 |
String value = pointPanel.getValue(i); |
|
293 |
stb.append(value); |
|
294 |
if(i<dimension-1){ |
|
295 |
stb.append(","); |
|
296 |
} |
|
297 |
} |
|
298 |
return stb.toString(); |
|
299 |
} |
|
300 |
|
|
301 |
return null; |
|
302 |
} |
|
303 |
|
|
304 |
private String showValueDialog(EditingServiceParameter parameter) { |
|
305 |
|
|
306 |
final DefaultEditingValuePanel valuePanel = |
|
307 |
new DefaultEditingValuePanel(); |
|
308 |
|
|
309 |
final String title = |
|
310 |
ToolsLocator.getI18nManager().getTranslation(parameter.getName()); |
|
311 |
|
|
312 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
313 |
|
|
314 |
@Override |
|
315 |
public void run() { |
|
316 |
this.returnValue = |
|
317 |
JOptionPane.showConfirmDialog(null, valuePanel, title, |
|
318 |
JOptionPane.OK_CANCEL_OPTION); |
|
319 |
} |
|
320 |
}; |
|
321 |
|
|
322 |
if (SwingUtilities.isEventDispatchThread()) { |
|
323 |
runnable.run(); |
|
324 |
} else { |
|
325 |
try { |
|
326 |
SwingUtilities.invokeAndWait(runnable); |
|
327 |
} catch (Exception e) { |
|
328 |
LOGGER.info("Can't show value dialog.", e); |
|
329 |
} |
|
330 |
} |
|
331 |
|
|
332 |
int result = ((Integer) runnable.getReturnValue()); |
|
333 |
|
|
334 |
if (result == JOptionPane.OK_OPTION) { |
|
335 |
return valuePanel.getValue(); |
|
336 |
} |
|
337 |
|
|
338 |
return null; |
|
339 |
|
|
340 |
} |
|
341 |
|
|
342 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.134/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/contextmenu/DefaultEditingPointPanel.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
/* gvSIG. Desktop Geographic Information System. |
|
26 |
* |
|
27 |
* Copyright ? 2007-2014 gvSIG Association |
|
28 |
* |
|
29 |
* This program is free software; you can redistribute it and/or |
|
30 |
* modify it under the terms of the GNU General Public License |
|
31 |
* as published by the Free Software Foundation; either version 2 |
|
32 |
* of the License, or (at your option) any later version. |
|
33 |
* |
|
34 |
* This program is distributed in the hope that it will be useful, |
|
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
36 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
37 |
* GNU General Public License for more details. |
|
38 |
* |
|
39 |
* You should have received a copy of the GNU General Public License |
|
40 |
* along with this program; if not, write to the Free Software |
|
41 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
42 |
* MA 02110-1301, USA. |
|
43 |
* |
|
44 |
* For any additional information, do not hesitate to contact us |
|
45 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
46 |
*/ |
|
47 |
package org.gvsig.vectorediting.swing.impl.contextmenu; |
|
48 |
|
|
49 |
import javax.swing.JComponent; |
|
50 |
|
|
51 |
/** |
|
52 |
* @author llmarques |
|
53 |
* |
|
54 |
*/ |
|
55 |
public class DefaultEditingPointPanel extends EditingPointPanelView { |
|
56 |
|
|
57 |
private static final long serialVersionUID = 6598180137544454743L; |
|
58 |
|
|
59 |
public DefaultEditingPointPanel() { |
|
60 |
super(); |
|
61 |
this.initComponents(); |
|
62 |
} |
|
63 |
|
|
64 |
public JComponent asJComponent() { |
|
65 |
return this; |
|
66 |
} |
|
67 |
|
|
68 |
private void initComponents() { |
|
69 |
addHierarchyChanged(); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Adds an hierarchy listener to value text field. The purpose of this is |
|
74 |
* request focus when texfield ancestor gains focus. |
|
75 |
*/ |
|
76 |
private void addHierarchyChanged() { |
|
77 |
getXTextField().addHierarchyListener(new DefaultHierarchyListener()); |
|
78 |
} |
|
79 |
|
|
80 |
public String getXValue() { |
|
81 |
return getXTextField().getText(); |
|
82 |
} |
|
83 |
|
|
84 |
public String getYValue() { |
|
85 |
return getYTextField().getText(); |
|
86 |
} |
|
87 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.134/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/contextmenu/DefaultEditingValuePanel.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.swing.impl.contextmenu; |
|
26 |
|
|
27 |
import javax.swing.JComponent; |
|
28 |
|
|
29 |
public class DefaultEditingValuePanel extends EditingValuePanelView { |
|
30 |
|
|
31 |
private static final long serialVersionUID = -2429230493027567705L; |
|
32 |
|
|
33 |
public JComponent asJComponent() { |
|
34 |
return this; |
|
35 |
} |
|
36 |
|
|
37 |
public String getValue() { |
|
38 |
return getValueTextField().getText(); |
|
39 |
} |
|
40 |
|
|
41 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.134/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/contextmenu/DefaultDynamicEditingPointPanel.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
/* gvSIG. Desktop Geographic Information System. |
|
26 |
* |
|
27 |
* Copyright ? 2007-2014 gvSIG Association |
|
28 |
* |
|
29 |
* This program is free software; you can redistribute it and/or |
|
30 |
* modify it under the terms of the GNU General Public License |
|
31 |
* as published by the Free Software Foundation; either version 2 |
|
32 |
* of the License, or (at your option) any later version. |
|
33 |
* |
|
34 |
* This program is distributed in the hope that it will be useful, |
|
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
36 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
37 |
* GNU General Public License for more details. |
|
38 |
* |
|
39 |
* You should have received a copy of the GNU General Public License |
|
40 |
* along with this program; if not, write to the Free Software |
|
41 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
42 |
* MA 02110-1301, USA. |
|
43 |
* |
|
44 |
* For any additional information, do not hesitate to contact us |
|
45 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
46 |
*/ |
|
47 |
package org.gvsig.vectorediting.swing.impl.contextmenu; |
|
48 |
|
|
49 |
import java.awt.event.ActionEvent; |
|
50 |
import java.awt.event.ActionListener; |
|
51 |
import java.awt.event.ItemEvent; |
|
52 |
import java.awt.event.ItemListener; |
|
53 |
import java.util.Objects; |
|
54 |
import javax.swing.DefaultComboBoxModel; |
|
55 |
import javax.swing.JComponent; |
|
56 |
import org.apache.commons.lang3.StringUtils; |
|
57 |
import org.apache.commons.lang3.tuple.Pair; |
|
58 |
import org.gvsig.expressionevaluator.swing.CalculatorController; |
|
59 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
|
60 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
|
61 |
import org.gvsig.fmap.dal.DataTypes; |
|
62 |
import org.gvsig.fmap.geom.Geometry; |
|
63 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
64 |
|
|
65 |
import org.gvsig.fmap.geom.primitive.Point; |
|
66 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
67 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
|
68 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
|
69 |
import org.gvsig.temporarystorage.TemporaryStorageGroup; |
|
70 |
import org.gvsig.temporarystorage.TemporaryStorageLocator; |
|
71 |
import org.gvsig.tools.locator.LocatorException; |
|
72 |
import org.gvsig.tools.swing.api.ListElement; |
|
73 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
74 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
|
75 |
|
|
76 |
/** |
|
77 |
* @author fdiaz |
|
78 |
* |
|
79 |
*/ |
|
80 |
public class DefaultDynamicEditingPointPanel extends DynamicEditingPointPanelView { |
|
81 |
|
|
82 |
/** |
|
83 |
* |
|
84 |
*/ |
|
85 |
private static final long serialVersionUID = 2398169399771503091L; |
|
86 |
private final Point defaultPoint; |
|
87 |
private final CalculatorController pickers[]; |
|
88 |
private CalculatorController pickerX; |
|
89 |
private CalculatorController pickerY; |
|
90 |
private CalculatorController pickerZ; |
|
91 |
private CalculatorController pickerM; |
|
92 |
private final GeometryType geomType; |
|
93 |
|
|
94 |
/** |
|
95 |
* @param geomType |
|
96 |
* @param point |
|
97 |
*/ |
|
98 |
public DefaultDynamicEditingPointPanel(GeometryType geomType, Point point) { |
|
99 |
super(); |
|
100 |
this.defaultPoint = point; |
|
101 |
if( geomType==null ) { |
|
102 |
if( this.defaultPoint==null ) { |
|
103 |
try { |
|
104 |
this.geomType = GeometryLocator.getGeometryManager().getGeometryType( |
|
105 |
Geometry.TYPES.POINT, |
|
106 |
Geometry.SUBTYPES.GEOM2D |
|
107 |
); |
|
108 |
} catch (GeometryTypeNotSupportedException | GeometryTypeNotValidException | LocatorException ex) { |
|
109 |
throw new IllegalArgumentException("Can't create the geometry type, and params are null."); |
|
110 |
} |
|
111 |
} else { |
|
112 |
this.geomType = this.defaultPoint.getGeometryType(); |
|
113 |
} |
|
114 |
} else { |
|
115 |
this.geomType = geomType; |
|
116 |
} |
|
117 |
this.pickers = new CalculatorController[this.geomType.getDimension()]; |
|
118 |
this.initComponents(); |
|
119 |
} |
|
120 |
|
|
121 |
private void initComponents() { |
|
122 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
123 |
ExpressionEvaluatorSwingManager evaluatorManager = ExpressionEvaluatorSwingLocator.getManager(); |
|
124 |
|
|
125 |
toolsSwingManager.translate(this.rdbEnterTheCoordinatesManually); |
|
126 |
toolsSwingManager.translate(this.rdbUseAPointPreviouslyCaptured); |
|
127 |
|
|
128 |
toolsSwingManager.addClearButton(this.txtX); |
|
129 |
toolsSwingManager.addClearButton(this.txtY); |
|
130 |
toolsSwingManager.addClearButton(this.txtZ); |
|
131 |
toolsSwingManager.addClearButton(this.txtM); |
|
132 |
|
|
133 |
toolsSwingManager.setDefaultPopupMenu(this.txtX); |
|
134 |
toolsSwingManager.setDefaultPopupMenu(this.txtY); |
|
135 |
toolsSwingManager.setDefaultPopupMenu(this.txtZ); |
|
136 |
toolsSwingManager.setDefaultPopupMenu(this.txtM); |
|
137 |
|
|
138 |
this.pickerX = evaluatorManager.createCalculatorController( |
|
139 |
this.txtX, DataTypes.DOUBLE |
|
140 |
); |
|
141 |
this.pickerY = evaluatorManager.createCalculatorController( |
|
142 |
this.txtY, DataTypes.DOUBLE |
|
143 |
); |
|
144 |
this.pickerZ = evaluatorManager.createCalculatorController( |
|
145 |
this.txtZ, DataTypes.DOUBLE |
|
146 |
); |
|
147 |
this.pickerM = evaluatorManager.createCalculatorController( |
|
148 |
this.txtM, DataTypes.DOUBLE |
|
149 |
); |
|
150 |
this.pickers[0] = this.pickerX; |
|
151 |
this.pickers[1] = this.pickerY; |
|
152 |
if( this.geomType.hasZ() && this.geomType.hasM() ) { |
|
153 |
this.pickers[2] = this.pickerZ; |
|
154 |
this.pickers[3] = this.pickerM; |
|
155 |
} else if( this.geomType.hasZ() ) { |
|
156 |
this.pickers[2] = this.pickerZ; |
|
157 |
} else if( this.geomType.hasM() ) { |
|
158 |
this.pickers[2] = this.pickerM; |
|
159 |
} |
|
160 |
|
|
161 |
addHierarchyChanged(); |
|
162 |
|
|
163 |
TemporaryStorageGroup points = TemporaryStorageLocator.getTemporaryStorageManager() |
|
164 |
.create("Points",Point.class); |
|
165 |
|
|
166 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
167 |
model.addElement(new ListElement("", null)); |
|
168 |
for (Pair<String, Object> pair : points.asList()) { |
|
169 |
model.addElement(new ListElement(pair.getKey(), (Point)(pair.getValue()))); |
|
170 |
} |
|
171 |
this.cboCapturedPoints.setModel(model); |
|
172 |
this.cboCapturedPoints.addItemListener(new ItemListener() { |
|
173 |
@Override |
|
174 |
public void itemStateChanged(ItemEvent e) { |
|
175 |
if( e.getStateChange()==ItemEvent.SELECTED ) { |
|
176 |
setPoint(((ListElement<Point>)e.getItem()).getValue()); |
|
177 |
} |
|
178 |
} |
|
179 |
}); |
|
180 |
this.rdbEnterTheCoordinatesManually.addActionListener(new ActionListener() { |
Also available in: Unified diff