Revision 3056
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.179/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.179/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.179/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingSwingLibrary.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 org.gvsig.fmap.dal.DALLibrary; |
|
28 |
import org.gvsig.fmap.geom.GeometryLibrary; |
|
29 |
import org.gvsig.fmap.mapcontrol.MapControlLibrary; |
|
30 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
|
31 |
import org.gvsig.fmap.mapcontrol.MapControlManager; |
|
32 |
import org.gvsig.tools.library.AbstractLibrary; |
|
33 |
import org.gvsig.tools.library.LibraryException; |
|
34 |
import org.gvsig.vectorediting.swing.api.EditingSwingLibrary; |
|
35 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator; |
|
36 |
|
|
37 |
public class DefaultEditingSwingLibrary extends AbstractLibrary { |
|
38 |
|
|
39 |
@Override |
|
40 |
public void doRegistration() { |
|
41 |
registerAsImplementationOf(EditingSwingLibrary.class); |
|
42 |
require(DALLibrary.class); |
|
43 |
require(MapControlLibrary.class); |
|
44 |
require(GeometryLibrary.class); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected void doInitialize() throws LibraryException { |
|
49 |
EditingSwingLocator.registerManager(DefaultEditingSwingManager.class); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
protected void doPostInitialize() throws LibraryException { |
|
54 |
MapControlManager mapControlManager = |
|
55 |
MapControlLocator.getMapControlManager(); |
|
56 |
|
|
57 |
mapControlManager |
|
58 |
.addMapControlCreationListener(new DefaultMapCreationListener()); |
|
59 |
} |
|
60 |
|
|
61 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.179/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/SelectionBehavior.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.event.InputEvent; |
|
28 |
import java.awt.event.MouseEvent; |
|
29 |
import java.awt.event.MouseWheelEvent; |
|
30 |
|
|
31 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
32 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
|
33 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
|
34 |
|
|
35 |
public class SelectionBehavior extends Behavior { |
|
36 |
|
|
37 |
@Override |
|
38 |
public ToolListener getListener() { |
|
39 |
// TODO Auto-generated method stub |
|
40 |
return null; |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
|
45 |
int clickWithShiftDown = |
|
46 |
InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK; |
|
47 |
int ctrlDown = InputEvent.CTRL_DOWN_MASK; |
|
48 |
if ((e.getModifiersEx() & (clickWithShiftDown | ctrlDown)) == clickWithShiftDown) { |
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
|
56 |
// TODO Auto-generated method stub |
|
57 |
|
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public void mouseExited(MouseEvent e) throws BehaviorException { |
|
62 |
// TODO Auto-generated method stub |
|
63 |
|
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
|
68 |
// TODO Auto-generated method stub |
|
69 |
|
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
74 |
// TODO Auto-generated method stub |
|
75 |
|
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
|
80 |
// TODO Auto-generated method stub |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
85 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
86 |
// TODO Auto-generated method stub |
|
87 |
|
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
|
92 |
// TODO Auto-generated method stub |
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.179/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.ExpressionUtils; |
|
31 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
|
32 |
import org.gvsig.fmap.geom.Geometry; |
|
33 |
import org.gvsig.fmap.geom.primitive.Point; |
|
34 |
import org.gvsig.temporarystorage.TemporaryStorageGroup; |
|
35 |
import org.gvsig.temporarystorage.TemporaryStorageLocator; |
|
36 |
import org.gvsig.temporarystorage.TemporaryStorageManager; |
|
37 |
|
|
38 |
/** |
|
39 |
* |
|
40 |
* @author gvSIG Team |
|
41 |
*/ |
|
42 |
public class EditingContextSymbolTable extends AbstractSymbolTable { |
|
43 |
|
|
44 |
private static class ListWithMaximumSize<T> extends ArrayList<T> { |
|
45 |
|
|
46 |
private final int maximumSize; |
|
47 |
|
|
48 |
public ListWithMaximumSize(int maximumSize) { |
|
49 |
this.maximumSize = maximumSize; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public boolean add(T e) { |
|
54 |
if( this.size()>this.maximumSize ) { |
|
55 |
this.remove(0); |
|
56 |
} |
|
57 |
return super.add(e); |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public void add(int index, T element) { |
|
62 |
if( this.size()>this.maximumSize ) { |
|
63 |
this.remove(0); |
|
64 |
} |
|
65 |
super.add(index, element); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
private final List<Point> lastPoints; |
|
70 |
private final TemporaryStorageGroup globalPointsStorage; |
|
71 |
|
|
72 |
public EditingContextSymbolTable() { |
|
73 |
this.lastPoints = new ListWithMaximumSize(100); |
|
74 |
TemporaryStorageManager manager = TemporaryStorageLocator.getTemporaryStorageManager(); |
|
75 |
this.globalPointsStorage = manager.create("Points",Point.class); |
|
76 |
this.addSymbolTable(ExpressionUtils.createSymbolTable()); |
|
77 |
} |
|
78 |
|
|
79 |
public void addPoint(Point point) { |
|
80 |
this.lastPoints.add(point); |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public boolean exists(String name) { |
|
85 |
if( globalPointsStorage.contains(name) ) { |
|
86 |
return true; |
|
87 |
} |
|
88 |
if( globalPointsStorage.contains(name+"$x") ) { |
|
89 |
return true; |
|
90 |
} |
|
91 |
if( globalPointsStorage.contains(name+"$y") ) { |
|
92 |
return true; |
|
93 |
} |
|
94 |
if( this.lastPoints.isEmpty() || StringUtils.isBlank(name) ) { |
|
95 |
return false; |
|
96 |
} |
|
97 |
name = name.toLowerCase(); |
|
98 |
int index = -1; |
|
99 |
if( name.length()==2 ) { |
|
100 |
index = this.lastPoints.size()-1; |
|
101 |
} else if( name.length()<3 ) { |
|
102 |
return false; |
|
103 |
} else { |
|
104 |
try { |
|
105 |
index = Integer.parseUnsignedInt(name.substring(2)); |
|
106 |
} catch(NumberFormatException ex) { |
|
107 |
return false; |
|
108 |
} |
|
109 |
} |
|
110 |
if( index < 0 || index >= this.lastPoints.size() ) { |
|
111 |
return false; |
|
112 |
} |
|
113 |
if( name.startsWith("$p") || name.startsWith("$x") || name.startsWith("$y") ) { |
|
114 |
return true; |
|
115 |
} |
|
116 |
return false; |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public Object value(String name) { |
|
121 |
if( globalPointsStorage.contains(name) ) { |
|
122 |
return globalPointsStorage.get(name); |
|
123 |
} |
|
124 |
if( globalPointsStorage.contains(name+"$x") ) { |
|
125 |
Point point = (Point) globalPointsStorage.get(name+"$x"); |
|
126 |
return point.getX(); |
|
127 |
} |
|
128 |
if( globalPointsStorage.contains(name+"$y") ) { |
|
129 |
Point point = (Point) globalPointsStorage.get(name+"$y"); |
|
130 |
return point.getY(); |
|
131 |
} |
|
132 |
if( this.lastPoints.isEmpty() || StringUtils.isBlank(name) ) { |
|
133 |
return null; |
|
134 |
} |
|
135 |
name = name.toLowerCase(); |
|
136 |
int index = -1; |
|
137 |
if( name.length()==2 ) { |
|
138 |
index = 0; |
|
139 |
} else if( name.length()<3 ) { |
|
140 |
return null; |
|
141 |
} else { |
|
142 |
try { |
|
143 |
index = Integer.parseUnsignedInt(name.substring(2)); |
|
144 |
} catch(NumberFormatException ex) { |
|
145 |
return null; |
|
146 |
} |
|
147 |
} |
|
148 |
if( index < 0 || index >= this.lastPoints.size() ) { |
|
149 |
return false; |
|
150 |
} |
|
151 |
// El index 0 es el ultimo en la lista |
|
152 |
index = (this.lastPoints.size() - index) - 1; |
|
153 |
|
|
154 |
if( name.startsWith("$p") ) { |
|
155 |
Point point = this.lastPoints.get(index); |
|
156 |
return point; |
|
157 |
} |
|
158 |
if( name.startsWith("$x") ) { |
|
159 |
Point point = this.lastPoints.get(index); |
|
160 |
return point.getX(); |
|
161 |
} |
|
162 |
if( name.startsWith("$y") ) { |
|
163 |
Point point = this.lastPoints.get(index); |
|
164 |
return point.getY(); |
|
165 |
} |
|
166 |
return null; |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
public Collection<String> localvariables() { |
|
171 |
if( this.lastPoints.isEmpty() ) { |
|
172 |
return Collections.EMPTY_LIST; |
|
173 |
} |
|
174 |
List<String> names = new ArrayList<>(); |
|
175 |
names.add("$p"); |
|
176 |
names.add("$x"); |
|
177 |
names.add("$y"); |
|
178 |
for (int i = 0; i < this.lastPoints.size(); i++) { |
|
179 |
names.add("$p"+i); |
|
180 |
names.add("$x"+i); |
|
181 |
names.add("$y"+i); |
|
182 |
} |
|
183 |
return names; |
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.179/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 |
import javax.swing.SwingUtilities; |
|
36 |
import org.gvsig.fmap.geom.Geometry; |
|
37 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
38 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
39 |
import org.gvsig.fmap.geom.primitive.Point; |
|
40 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
41 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
42 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
|
43 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
|
44 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
|
45 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
|
46 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
47 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
|
48 |
import org.gvsig.tools.ToolsLocator; |
|
49 |
import org.gvsig.tools.exception.BaseException; |
|
50 |
import org.gvsig.tools.i18n.I18nManager; |
|
51 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
52 |
import org.gvsig.vectorediting.lib.api.DrawingStatus.Status; |
|
53 |
import org.gvsig.vectorediting.lib.api.EditingService; |
|
54 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
55 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
56 |
import org.gvsig.vectorediting.lib.api.exceptions.CreateEditingBehaviorException; |
|
57 |
import org.gvsig.vectorediting.lib.api.exceptions.VectorEditingException; |
|
58 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator; |
|
59 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
|
60 |
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu; |
|
61 |
import org.slf4j.Logger; |
|
62 |
import org.slf4j.LoggerFactory; |
|
63 |
|
|
64 |
public class DefaultEditingBehavior extends Behavior { |
|
65 |
|
|
66 |
private static final Logger logger = LoggerFactory |
|
67 |
.getLogger(DefaultEditingBehavior.class); |
|
68 |
|
|
69 |
private DefaultEditingContext editingContext; |
|
70 |
|
|
71 |
private Point adjustedPoint; |
|
72 |
|
|
73 |
private static final Image imageCursor = new BufferedImage(32, 32, |
|
74 |
BufferedImage.TYPE_INT_ARGB); |
|
75 |
static { |
|
76 |
Graphics g = imageCursor.getGraphics(); |
|
77 |
int size1 = 15; |
|
78 |
int x = 16; |
|
79 |
int y = 16; |
|
80 |
g.setColor(Color.MAGENTA); |
|
81 |
g.drawLine((x - size1), (y), (x + size1), (y)); |
|
82 |
g.drawLine((x), (y - size1), (x), (y + size1)); |
|
83 |
g.drawRect((x - 6), (y - 6), 12, 12); |
|
84 |
g.drawRect((x - 3), (y - 3), 6, 6); |
|
85 |
} |
|
86 |
|
|
87 |
public DefaultEditingBehavior(DefaultEditingContext editingContext) |
|
88 |
throws CreateEditingBehaviorException { |
|
89 |
|
|
90 |
if (editingContext.getMapControl() != null) { |
|
91 |
this.editingContext = editingContext; |
|
92 |
setMapControl(editingContext.getMapControl()); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public ToolListener getListener() { |
|
98 |
return new ToolListener() { |
|
99 |
|
|
100 |
@Override |
|
101 |
public boolean cancelDrawing() { |
|
102 |
return false; |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public Image getImageCursor() { |
|
107 |
return imageCursor; |
|
108 |
} |
|
109 |
}; |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public void mouseClicked(MouseEvent e) { |
|
114 |
ViewPort vp = editingContext.getMapControl().getViewPort(); |
|
115 |
EditingServiceParameter currentParam = editingContext.getCurrentParam(); |
|
116 |
EditingService activeService = editingContext.getActiveService(); |
|
117 |
|
|
118 |
if ((activeService != null) && (currentParam != null)) { |
|
119 |
|
|
120 |
if (SwingUtilities.isLeftMouseButton(e)) { |
|
121 |
|
|
122 |
Set<TYPE> typesOfParam = currentParam.getTypes(); |
|
123 |
|
|
124 |
if (typesOfParam.contains(TYPE.LIST_POSITIONS)) { |
|
125 |
if (e.getClickCount() == 2) { |
|
126 |
editingContext.finishService(); |
|
127 |
return; |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
Point point = null; |
|
132 |
Point2D point2D = getMapControl().getMapAdjustedPoint(); |
|
133 |
if (point2D == null) { |
|
134 |
point2D = getMapControl().getAdjustedPoint(); |
|
135 |
point = vp.convertToMapPoint(point2D); |
|
136 |
} else { |
|
137 |
try { |
|
138 |
point = |
|
139 |
GeometryLocator.getGeometryManager().createPoint( |
|
140 |
point2D.getX(), point2D.getY(), |
|
141 |
Geometry.SUBTYPES.GEOM2D); |
|
142 |
} catch (BaseException ex) { |
|
143 |
logger.warn("Can't create point geometry from " |
|
144 |
+ point2D.toString()); |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
try { |
|
149 |
//FIXME: Estar?a bien hacer esto |
|
150 |
editingContext.setValue(currentParam, point); |
|
151 |
editingContext.nextParameter(); |
|
152 |
|
|
153 |
// editingContext.getActiveService().setValue(point); |
|
154 |
} catch (VectorEditingException ex) { |
|
155 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
156 |
editingContext.showConsoleMessage(i18nManager |
|
157 |
.getTranslation("invalid_option")); |
|
158 |
} |
|
159 |
|
|
160 |
// editingContext.nextParameter(); |
|
161 |
|
|
162 |
} else if (SwingUtilities.isRightMouseButton(e)) { |
|
163 |
|
|
164 |
EditingSwingManager swingManager = |
|
165 |
EditingSwingLocator.getSwingManager(); |
|
166 |
|
|
167 |
EditingContextMenu contextMenu = |
|
168 |
swingManager.getContextualMenu(getMapControl(), (Object value) -> { |
|
169 |
editingContext.textEntered((String) value); |
|
170 |
}, currentParam, editingContext); |
|
171 |
|
|
172 |
contextMenu.show(getMapControl(), e.getX(), e.getY()); |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
@Override |
|
178 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
183 |
ViewPort vp = editingContext.getMapControl().getViewPort(); |
|
184 |
adjustedPoint = vp.convertToMapPoint(e.getX(), e.getY()); |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
188 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
193 |
} |
|
194 |
|
|
195 |
@Override |
|
196 |
@SuppressWarnings("rawtypes") |
|
197 |
public void paintComponent(MapControlDrawer mapControlDrawer) { |
|
198 |
super.paintComponent(mapControlDrawer); |
|
199 |
|
|
200 |
if ((editingContext.getActiveService() == null) |
|
201 |
|| (adjustedPoint == null)) { |
|
202 |
return; |
|
203 |
} |
|
204 |
|
|
205 |
DrawingStatus helperGeo = null; |
|
206 |
|
|
207 |
try { |
|
208 |
helperGeo = |
|
209 |
editingContext.getActiveService().getDrawingStatus( |
|
210 |
adjustedPoint); |
|
211 |
} catch (VectorEditingException e) { |
|
212 |
logger.info("An error ocurred when draw service geometries", e); |
|
213 |
} |
|
214 |
|
|
215 |
if (helperGeo != null) { |
|
216 |
for (Iterator iterator = helperGeo.getStatus().iterator(); iterator |
|
217 |
.hasNext();) { |
|
218 |
Status status = (Status) iterator.next(); |
|
219 |
ISymbol symbol = status.getSymbol(); |
|
220 |
if (symbol == null) { |
|
221 |
symbol = |
|
222 |
MapControlLocator.getMapControlManager() |
|
223 |
.getAxisReferenceSymbol(); |
|
224 |
} |
|
225 |
if (symbol instanceof ITextSymbol) { |
|
226 |
((ITextSymbol) symbol).setText(status.getText()); |
|
227 |
} |
|
228 |
Geometry geom = status.getGeometry(); |
|
229 |
if(geom != null){ |
|
230 |
if(geom.getGeometryType().isTypeOf(Geometry.TYPES.MULTIPOINT)){ |
|
231 |
MultiPoint multipoint = (MultiPoint)geom; |
|
232 |
for (Geometry geometry : multipoint) { |
|
233 |
editingContext.getMapControl().getMapControlDrawer() |
|
234 |
.draw(geometry, symbol); |
|
235 |
} |
|
236 |
} else { |
|
237 |
editingContext.getMapControl().getMapControlDrawer() |
|
238 |
.draw(geom, symbol); |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.179/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.179/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/contextmenu/DynamicEditingPointPanelView.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.swing.impl.contextmenu; |
|
2 |
|
|
3 |
import com.jeta.open.i18n.I18NUtils; |
|
4 |
import com.jgoodies.forms.layout.CellConstraints; |
|
5 |
import com.jgoodies.forms.layout.FormLayout; |
|
6 |
import java.awt.BorderLayout; |
|
7 |
import java.awt.ComponentOrientation; |
|
8 |
import java.awt.Container; |
|
9 |
import java.awt.Dimension; |
|
10 |
import javax.swing.Box; |
|
11 |
import javax.swing.ButtonGroup; |
|
12 |
import javax.swing.ImageIcon; |
|
13 |
import javax.swing.JComboBox; |
|
14 |
import javax.swing.JFrame; |
|
15 |
import javax.swing.JLabel; |
|
16 |
import javax.swing.JPanel; |
|
17 |
import javax.swing.JRadioButton; |
|
18 |
import javax.swing.JTextField; |
|
19 |
|
|
20 |
|
|
21 |
public class DynamicEditingPointPanelView extends JPanel |
|
22 |
{ |
|
23 |
JRadioButton rdbUseAPointPreviouslyCaptured = new JRadioButton(); |
|
24 |
ButtonGroup buttongroup1 = new ButtonGroup(); |
|
25 |
JComboBox cboCapturedPoints = new JComboBox(); |
|
26 |
JRadioButton rdbEnterTheCoordinatesManually = new JRadioButton(); |
|
27 |
JLabel lblX = new JLabel(); |
|
28 |
JLabel lblY = new JLabel(); |
|
29 |
JTextField txtX = new JTextField(); |
|
30 |
JTextField txtY = new JTextField(); |
|
31 |
JLabel lblZ = new JLabel(); |
|
32 |
JLabel lblM = new JLabel(); |
|
33 |
JTextField txtZ = new JTextField(); |
|
34 |
JTextField txtM = new JTextField(); |
|
35 |
|
|
36 |
/** |
|
37 |
* Default constructor |
|
38 |
*/ |
|
39 |
public DynamicEditingPointPanelView() |
|
40 |
{ |
|
41 |
initializePanel(); |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Adds fill components to empty cells in the first row and first column of the grid. |
|
46 |
* This ensures that the grid spacing will be the same as shown in the designer. |
|
47 |
* @param cols an array of column indices in the first row where fill components should be added. |
|
48 |
* @param rows an array of row indices in the first column where fill components should be added. |
|
49 |
*/ |
|
50 |
void addFillComponents( Container panel, int[] cols, int[] rows ) |
|
51 |
{ |
|
52 |
Dimension filler = new Dimension(10,10); |
|
53 |
|
|
54 |
boolean filled_cell_11 = false; |
|
55 |
CellConstraints cc = new CellConstraints(); |
|
56 |
if ( cols.length > 0 && rows.length > 0 ) |
|
57 |
{ |
|
58 |
if ( cols[0] == 1 && rows[0] == 1 ) |
|
59 |
{ |
|
60 |
/** add a rigid area */ |
|
61 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
|
62 |
filled_cell_11 = true; |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
for( int index = 0; index < cols.length; index++ ) |
|
67 |
{ |
|
68 |
if ( cols[index] == 1 && filled_cell_11 ) |
|
69 |
{ |
|
70 |
continue; |
|
71 |
} |
|
72 |
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
|
73 |
} |
|
74 |
|
|
75 |
for( int index = 0; index < rows.length; index++ ) |
|
76 |
{ |
|
77 |
if ( rows[index] == 1 && filled_cell_11 ) |
|
78 |
{ |
|
79 |
continue; |
|
80 |
} |
|
81 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
|
82 |
} |
|
83 |
|
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Helper method to load an image file from the CLASSPATH |
|
88 |
* @param imageName the package and name of the file to load relative to the CLASSPATH |
|
89 |
* @return an ImageIcon instance with the specified image file |
|
90 |
* @throws IllegalArgumentException if the image resource cannot be loaded. |
|
91 |
*/ |
|
92 |
public ImageIcon loadImage( String imageName ) |
|
93 |
{ |
|
94 |
try |
|
95 |
{ |
|
96 |
ClassLoader classloader = getClass().getClassLoader(); |
|
97 |
java.net.URL url = classloader.getResource( imageName ); |
|
98 |
if ( url != null ) |
|
99 |
{ |
|
100 |
ImageIcon icon = new ImageIcon( url ); |
|
101 |
return icon; |
|
102 |
} |
|
103 |
} |
|
104 |
catch( Exception e ) |
|
105 |
{ |
|
106 |
e.printStackTrace(); |
|
107 |
} |
|
108 |
throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Method for recalculating the component orientation for |
|
113 |
* right-to-left Locales. |
|
114 |
* @param orientation the component orientation to be applied |
|
115 |
*/ |
|
116 |
public void applyComponentOrientation( ComponentOrientation orientation ) |
|
117 |
{ |
|
118 |
// Not yet implemented... |
|
119 |
// I18NUtils.applyComponentOrientation(this, orientation); |
|
120 |
super.applyComponentOrientation(orientation); |
|
121 |
} |
|
122 |
|
|
123 |
public JPanel createPanel() |
|
124 |
{ |
|
125 |
JPanel jpanel1 = new JPanel(); |
|
126 |
FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:8DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:4DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE"); |
|
127 |
CellConstraints cc = new CellConstraints(); |
|
128 |
jpanel1.setLayout(formlayout1); |
|
129 |
|
|
130 |
rdbUseAPointPreviouslyCaptured.setActionCommand("_Use_a_point_previously_captured"); |
|
131 |
rdbUseAPointPreviouslyCaptured.setName("rdbUseAPointPreviouslyCaptured"); |
|
132 |
rdbUseAPointPreviouslyCaptured.setText("_Use_a_point_previously_captured"); |
|
133 |
buttongroup1.add(rdbUseAPointPreviouslyCaptured); |
|
134 |
jpanel1.add(rdbUseAPointPreviouslyCaptured,cc.xywh(2,2,4,1)); |
|
135 |
|
|
136 |
cboCapturedPoints.setName("cboCapturedPoints"); |
|
137 |
jpanel1.add(cboCapturedPoints,cc.xywh(3,4,3,1)); |
|
138 |
|
|
139 |
rdbEnterTheCoordinatesManually.setActionCommand("_Enter_the_coordinates_manually"); |
|
140 |
rdbEnterTheCoordinatesManually.setName("rdbEnterTheCoordinatesManually"); |
|
141 |
rdbEnterTheCoordinatesManually.setText("_Enter_the_coordinates_manually"); |
|
142 |
buttongroup1.add(rdbEnterTheCoordinatesManually); |
|
143 |
jpanel1.add(rdbEnterTheCoordinatesManually,cc.xywh(2,6,4,1)); |
|
144 |
|
|
145 |
lblX.setName("lblX"); |
|
146 |
lblX.setText("X"); |
|
147 |
jpanel1.add(lblX,cc.xy(3,8)); |
|
148 |
|
|
149 |
lblY.setName("lblY"); |
|
150 |
lblY.setText("Y"); |
|
151 |
jpanel1.add(lblY,cc.xy(3,10)); |
|
152 |
|
|
153 |
txtX.setName("txtX"); |
|
154 |
jpanel1.add(txtX,cc.xy(5,8)); |
|
155 |
|
|
156 |
txtY.setName("txtY"); |
|
157 |
jpanel1.add(txtY,cc.xy(5,10)); |
|
158 |
|
|
159 |
lblZ.setName("lblZ"); |
|
160 |
lblZ.setText("Z"); |
|
161 |
jpanel1.add(lblZ,cc.xy(3,12)); |
|
162 |
|
|
163 |
lblM.setName("lblM"); |
|
164 |
lblM.setText("M"); |
|
165 |
jpanel1.add(lblM,cc.xy(3,14)); |
|
166 |
|
|
167 |
txtZ.setName("txtZ"); |
|
168 |
jpanel1.add(txtZ,cc.xy(5,12)); |
|
169 |
|
|
170 |
txtM.setName("txtM"); |
|
171 |
jpanel1.add(txtM,cc.xy(5,14)); |
|
172 |
|
|
173 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }); |
|
174 |
return jpanel1; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* Initializer |
|
179 |
*/ |
|
180 |
protected void initializePanel() |
|
181 |
{ |
|
182 |
setLayout(new BorderLayout()); |
|
183 |
add(createPanel(), BorderLayout.CENTER); |
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.179/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/contextmenu/DistanceListener.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.vectorediting.swing.impl.contextmenu; |
|
7 |
|
|
8 |
import java.awt.geom.Point2D; |
|
9 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
10 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
11 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
|
12 |
import org.gvsig.fmap.mapcontrol.tools.MeasureListenerImpl; |
|
13 |
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener; |
|
14 |
|
|
15 |
/** |
|
16 |
* |
|
17 |
* @author fdiaz |
|
18 |
*/ |
|
19 |
public class DistanceListener extends MeasureListenerImpl { |
|
20 |
|
|
21 |
AcceptValueListener listener; |
|
22 |
|
|
23 |
public DistanceListener(MapControl mc, AcceptValueListener listener) { |
|
24 |
super(mc); |
|
25 |
this.listener = listener; |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
public void polylineFinished(MeasureEvent event) { |
|
30 |
double distAll = 0; |
|
31 |
|
|
32 |
ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
|
33 |
|
|
34 |
Point2D p = new Point2D.Double(event.getXs()[0], event.getYs()[0]); |
|
35 |
for (int i = 1; i < (event.getXs().length); i++) { |
|
36 |
Point2D p2 = new Point2D.Double(event.getXs()[i], event.getYs()[i]); |
|
37 |
double dist = vp.distanceWorld(p, p2); |
|
38 |
distAll += dist; |
|
39 |
p=p2; |
|
40 |
} |
|
41 |
|
|
42 |
listener.acceptValue(String.valueOf(distAll)); |
|
43 |
} |
|
44 |
|
|
45 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.179/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 java.util.Objects; |
|
32 |
import javax.swing.AbstractAction; |
|
33 |
import javax.swing.JComponent; |
|
34 |
import javax.swing.JMenu; |
|
35 |
import javax.swing.JOptionPane; |
|
36 |
import javax.swing.JSeparator; |
|
37 |
import javax.swing.SwingConstants; |
|
38 |
import javax.swing.SwingUtilities; |
|
39 |
import org.apache.commons.lang3.StringUtils; |
|
40 |
import org.gvsig.fmap.dal.DataTypeUtils; |
|
41 |
import org.gvsig.fmap.geom.primitive.Point; |
|
42 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
43 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
44 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior; |
|
45 |
import org.gvsig.tools.ToolsLocator; |
|
46 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
47 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
48 |
import org.gvsig.tools.i18n.I18nManager; |
|
49 |
import org.gvsig.tools.task.RunnableWithParameters; |
|
50 |
import org.gvsig.vectorediting.lib.api.EditingService; |
|
51 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
52 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
53 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions; |
|
54 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
55 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions.ParameterOption; |
|
56 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
|
57 |
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener; |
|
58 |
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu; |
|
59 |
import org.slf4j.Logger; |
|
60 |
import org.slf4j.LoggerFactory; |
|
61 |
|
|
62 |
/** |
|
63 |
* @author gvSIG Team |
|
64 |
* |
|
65 |
*/ |
|
66 |
@SuppressWarnings("UseSpecificCatch") |
|
67 |
public class DefaultEditingContextMenu extends EditingContextMenuView implements |
|
68 |
EditingContextMenu { |
|
69 |
|
|
70 |
private static final Logger LOGGER = LoggerFactory |
|
71 |
.getLogger(DefaultEditingContextMenu.class); |
|
72 |
|
|
73 |
private static final long serialVersionUID = -3207749321400180897L; |
|
74 |
|
|
75 |
private final AcceptValueListener listener; |
|
76 |
|
|
77 |
private final Component parent; |
|
78 |
|
|
79 |
private final EditingServiceParameter parameter; |
|
80 |
|
|
81 |
private final EditingContext context; |
|
82 |
|
|
83 |
// /** |
|
84 |
// * @param parent |
|
85 |
// * @param listener |
|
86 |
// * @param parameter |
|
87 |
// */ |
|
88 |
// public DefaultEditingContextMenu(Component parent, |
|
89 |
// AcceptValueListener listener, EditingServiceParameter parameter) { |
|
90 |
// |
|
91 |
// this(parent, listener, parameter, null); |
|
92 |
// } |
|
93 |
|
|
94 |
/** |
|
95 |
* @param parent |
|
96 |
* @param listener |
|
97 |
* @param parameter |
|
98 |
* @param context |
|
99 |
*/ |
|
100 |
public DefaultEditingContextMenu(Component parent, |
|
101 |
AcceptValueListener listener, EditingServiceParameter parameter, EditingContext context) { |
|
102 |
|
|
103 |
super(); |
|
104 |
this.listener = listener; |
|
105 |
this.parent = parent; |
|
106 |
this.parameter = parameter; |
|
107 |
this.context = context; |
|
108 |
initActions(); |
|
109 |
} |
|
110 |
|
|
111 |
@SuppressWarnings("serial") |
|
112 |
private void initActions() { |
|
113 |
|
|
114 |
EditingService service = context.getActiveService(); |
|
115 |
List<EditingServiceParameter> parameters = service.getParameters(); |
|
116 |
|
|
117 |
initAction(parameter, this.listener); |
|
118 |
|
|
119 |
this.add(new JSeparator(SwingConstants.HORIZONTAL)); |
|
120 |
|
|
121 |
boolean thereAreOptionalParameters = false; |
|
122 |
|
|
123 |
for (EditingServiceParameter param : parameters) { |
|
124 |
if(param.equals(this.parameter)){ |
|
125 |
continue; |
|
126 |
} |
|
127 |
if(param.isOptional() && service.isEnabled(param)){ |
|
128 |
thereAreOptionalParameters = true; |
|
129 |
initAction(param, (Object value) -> { |
|
130 |
try { |
|
131 |
if(param.getOptions2() != null) { |
|
132 |
context.setValue(param, value); |
|
133 |
} else { |
|
134 |
context.setValue(param, (String)value); |
|
135 |
} |
|
136 |
context.nextParameter(); |
|
137 |
} catch (InvalidEntryException ex) { |
|
138 |
LOGGER.warn("Invalid value", ex); |
|
139 |
} |
|
140 |
}); |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
if (thereAreOptionalParameters) { |
|
145 |
this.add(new JSeparator(SwingConstants.HORIZONTAL)); |
|
146 |
} |
|
147 |
|
|
148 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
149 |
AbstractAction action; |
|
150 |
|
|
151 |
action = new AbstractAction(i18nManager.getTranslation("cancel")) { |
|
152 |
|
|
153 |
@Override |
|
154 |
public void actionPerformed(ActionEvent e) { |
|
155 |
listener.acceptValue(null); |
|
156 |
} |
|
157 |
}; |
|
158 |
|
|
159 |
this.add(action); |
|
160 |
((JComponent) parent).add(this); |
|
161 |
|
|
162 |
} |
|
163 |
|
|
164 |
private void initAction(EditingServiceParameter param, AcceptValueListener listener){ |
|
165 |
|
|
166 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
167 |
AbstractAction action; |
|
168 |
|
|
169 |
for (final TYPE type : param.getTypes()) { |
|
170 |
|
|
171 |
switch (type) { |
|
172 |
case OPTION: |
|
173 |
JMenu submenu = null; |
|
174 |
if(param != this.parameter) { |
|
175 |
EditingService service = context.getActiveService(); |
|
176 |
Object value = service.getValue(param); |
|
177 |
StringBuilder builder = new StringBuilder(); |
|
178 |
builder.append(i18nManager.getTranslation(param.getName())); |
|
179 |
if(value != null){ |
|
180 |
try { |
|
181 |
builder.append(" ("); |
|
182 |
EditingServiceParameterOptions opts = param.getOptions2(); |
|
183 |
if(opts != null){ |
|
184 |
builder.append(i18nManager.getTranslation(opts.getLabel(value))); |
|
185 |
} else { |
|
186 |
builder.append(i18nManager.getTranslation((String)DataTypeUtils.coerce(DataTypes.STRING, value))); |
|
187 |
} |
|
188 |
builder.append(")"); |
|
189 |
} catch (CoercionException ex) { |
|
190 |
LOGGER.warn("Can't coerce '" + Objects.toString(value) + "' to String", ex); |
|
191 |
} |
|
192 |
} |
|
193 |
submenu = new JMenu(builder.toString()); |
|
194 |
} |
|
195 |
Map<String, String> options = param.getOptions(); |
|
196 |
if(param.getOptions() == null){ |
|
197 |
for (ParameterOption option : param.getOptions2()) { |
|
198 |
String label = i18nManager.getTranslation(option.getLabel()); |
|
199 |
action = new AbstractAction(label) { |
|
200 |
|
|
201 |
ParameterOption opt = option; |
|
202 |
|
|
203 |
@Override |
|
204 |
public void actionPerformed(ActionEvent e) { |
|
205 |
listener.acceptValue(opt.getConsoleValue()); |
|
206 |
} |
|
207 |
}; |
|
208 |
if(submenu != null){ |
|
209 |
submenu.add(action); |
|
210 |
} else { |
|
211 |
this.add(action); |
|
212 |
} |
|
213 |
} |
|
214 |
} else { |
|
215 |
for (String key : options.keySet()) { |
|
216 |
String value = i18nManager.getTranslation(options.get(key)); |
|
217 |
action = new AbstractAction(value) { |
|
218 |
|
|
219 |
@Override |
|
220 |
public void actionPerformed(ActionEvent e) { |
|
221 |
String key = (String) this.getValue("key"); |
|
222 |
listener.acceptValue(key); |
|
223 |
} |
|
224 |
}; |
|
225 |
action.putValue("key", key); |
|
226 |
if(submenu != null){ |
|
227 |
submenu.add(action); |
|
228 |
} else { |
|
229 |
this.add(action); |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
if(submenu != null){ |
|
237 |
this.add(submenu); |
|
238 |
} |
|
239 |
break; |
|
240 |
|
|
241 |
|
|
242 |
case VALUE: |
|
243 |
String name = |
|
244 |
i18nManager.getTranslation(param.getName()) + " (" |
|
245 |
+ i18nManager.getTranslation("value") + ")"; |
|
246 |
action = new AbstractAction(name) { |
|
247 |
|
Also available in: Unified diff