Revision 2075
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.vectorediting.swing.api.EditingSwingLibrary |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingSwingManager.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.api; |
|
26 |
|
|
27 |
import java.awt.Component; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
31 |
import org.gvsig.tools.service.Manager; |
|
32 |
import org.gvsig.utils.console.ResponseListener; |
|
33 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
34 |
import org.gvsig.vectorediting.swing.api.console.EditingConsole; |
|
35 |
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener; |
|
36 |
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu; |
|
37 |
|
|
38 |
/** |
|
39 |
* @author gvSIG team. |
|
40 |
*/ |
|
41 |
public interface EditingSwingManager extends Manager { |
|
42 |
|
|
43 |
/** |
|
44 |
* @param mapControl |
|
45 |
* @return |
|
46 |
*/ |
|
47 |
EditingContext getEditingContext(MapControl mapControl); |
|
48 |
|
|
49 |
/** |
|
50 |
* |
|
51 |
* @param mapControl |
|
52 |
*/ |
|
53 |
public void registerEditingContext(MapControl mapControl); |
|
54 |
|
|
55 |
/** |
|
56 |
* |
|
57 |
* @param layerName |
|
58 |
* @return |
|
59 |
*/ |
|
60 |
int showPanelExportOrDiscard(MapControl parent, String layerName); |
|
61 |
|
|
62 |
/** |
|
63 |
* |
|
64 |
* @param layerName |
|
65 |
* @return |
|
66 |
*/ |
|
67 |
int showPanelSaveOrDiscard(MapControl parent, String layerName); |
|
68 |
|
|
69 |
/** |
|
70 |
* Gets an instance of current parameter contextual menu. To show it, invoke |
|
71 |
* {@link EditingContextMenu#show(java.awt.Component, int, int)}. |
|
72 |
* |
|
73 |
* @param parent |
|
74 |
* of contextual menu |
|
75 |
* @param parameter |
|
76 |
* to build contextual menu according to it types. |
|
77 |
* @return contextual menu of parameter |
|
78 |
*/ |
|
79 |
EditingContextMenu getContextualMenu(Component parent, |
|
80 |
AcceptValueListener listener, EditingServiceParameter parameter); |
|
81 |
|
|
82 |
/** |
|
83 |
* Gets and instance of {@link EditingConsole}. |
|
84 |
* The response listener will receive the response typed |
|
85 |
* by user when ENTER key is pressed. |
|
86 |
* |
|
87 |
* @param listener |
|
88 |
* Object that will received the response |
|
89 |
* @return An instance of {@link EditingConsole} |
|
90 |
*/ |
|
91 |
EditingConsole getEditingConsole(ResponseListener listener); |
|
92 |
|
|
93 |
/** |
|
94 |
* Gets and instance of {@link EditingConsole}. |
|
95 |
* Response listener list will receive the response |
|
96 |
* typed by user when ENTER key is pressed. |
|
97 |
* |
|
98 |
* @param listener |
|
99 |
* Object that will received the response |
|
100 |
* @return An instance of {@link EditingConsole} |
|
101 |
*/ |
|
102 |
EditingConsole getEditingConsole(List<ResponseListener> liteners); |
|
103 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingContext.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.api; |
|
26 |
|
|
27 |
import java.lang.ref.WeakReference; |
|
28 |
|
|
29 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
30 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
31 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
|
32 |
import org.gvsig.tools.observer.Observable; |
|
33 |
|
|
34 |
public interface EditingContext extends Observable { |
|
35 |
|
|
36 |
static final int CANCEL = 0; |
|
37 |
static final int DISCARD_CHANGES = 1; |
|
38 |
static final int EXPORT_LAYER = 2; |
|
39 |
static final int SAVE_CHANGES = 3; |
|
40 |
static final String DEFAULT_TOOL = "default_tool"; |
|
41 |
|
|
42 |
static final String CHANGE_SELECTED_TOOL_NOTIFICATION = "EditingContext.changeSelectedTool"; |
|
43 |
static final String REFRESH_TOOLS_NOTIFICATION = "EditingContext.refreshTools"; |
|
44 |
static final String EXPORT_LAYER_NOTIFICATION = "EditingContext.exportLayer"; |
|
45 |
/** |
|
46 |
* Activates service as of name and {@link MapControl} |
|
47 |
* |
|
48 |
* @param name |
|
49 |
* of service |
|
50 |
* @param mapControl |
|
51 |
* of |
|
52 |
*/ |
|
53 |
public void activateService(String name); |
|
54 |
|
|
55 |
/** |
|
56 |
* @deprecated Use {@link EditingContext#beginEdition(FLyrVect)} |
|
57 |
*/ |
|
58 |
public void beginEdition(FLyrVect layer, Behavior[] additionalBehaviors); |
|
59 |
|
|
60 |
/** |
|
61 |
* Begins edition of a layer |
|
62 |
* |
|
63 |
* @param layer |
|
64 |
* to begin edition |
|
65 |
*/ |
|
66 |
public void beginEdition(FLyrVect layer); |
|
67 |
|
|
68 |
/** |
|
69 |
* Ends edition of a layer |
|
70 |
* |
|
71 |
* @param layer |
|
72 |
* to end edition |
|
73 |
*/ |
|
74 |
public void endEdition(FLyrVect layer); |
|
75 |
|
|
76 |
/** |
|
77 |
* Gets mapControl object. It is referenced by {@link WeakReference}. |
|
78 |
* |
|
79 |
* @return |
|
80 |
*/ |
|
81 |
public MapControl getMapControl(); |
|
82 |
|
|
83 |
/** |
|
84 |
* |
|
85 |
* @param name |
|
86 |
* @return |
|
87 |
*/ |
|
88 |
public boolean isServiceCompatible(String name); |
|
89 |
|
|
90 |
/** |
|
91 |
* Updates the weak reference at editing context. |
|
92 |
* |
|
93 |
* @param mapControl |
|
94 |
*/ |
|
95 |
public void setMapControl(MapControl mapControl); |
|
96 |
|
|
97 |
|
|
98 |
public Behavior[] getDefaultBehaviors(); |
|
99 |
|
|
100 |
public void setDefaultBehaviors(Behavior[] defaultBehaviors); |
|
101 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/contextmenu/EditingContextMenu.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.api.contextmenu; |
|
26 |
|
|
27 |
import java.awt.Component; |
|
28 |
|
|
29 |
/** |
|
30 |
* @author llmarques |
|
31 |
* |
|
32 |
*/ |
|
33 |
public interface EditingContextMenu { |
|
34 |
|
|
35 |
/** |
|
36 |
* @param mapControl |
|
37 |
* @param x |
|
38 |
* @param y |
|
39 |
*/ |
|
40 |
public void show(Component mapControl, int x, int y); |
|
41 |
|
|
42 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/contextmenu/AcceptValueListener.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.api.contextmenu; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author llmarques |
|
51 |
* |
|
52 |
*/ |
|
53 |
public interface AcceptValueListener { |
|
54 |
|
|
55 |
public void acceptValue(Object value); |
|
56 |
|
|
57 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingSwingLocator.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.api; |
|
26 |
|
|
27 |
import org.gvsig.tools.locator.BaseLocator; |
|
28 |
import org.gvsig.tools.locator.Locator; |
|
29 |
import org.gvsig.tools.locator.LocatorException; |
|
30 |
|
|
31 |
public class EditingSwingLocator extends BaseLocator { |
|
32 |
|
|
33 |
private static final String LOCATOR_NAME = "EditingSwingLocator"; |
|
34 |
|
|
35 |
public static final String MANAGER_NAME = "VectorEditingSwing.manager"; |
|
36 |
|
|
37 |
private static final String MANAGER_DESCRIPTION = |
|
38 |
"Editing Swing Manager of gvSIG"; |
|
39 |
|
|
40 |
private static final EditingSwingLocator instance = |
|
41 |
new EditingSwingLocator(); |
|
42 |
|
|
43 |
private EditingSwingLocator() { |
|
44 |
|
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* Return the singleton instance. |
|
49 |
* |
|
50 |
* @return the singleton instance |
|
51 |
*/ |
|
52 |
public static EditingSwingLocator getInstance() { |
|
53 |
return instance; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public String getLocatorName() { |
|
58 |
return LOCATOR_NAME; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Return a reference to EditingSwingManager. |
|
63 |
* |
|
64 |
* @return a reference to EditingSwingManager |
|
65 |
* @throws LocatorException |
|
66 |
* if there is no access to the class or the class |
|
67 |
* cannot be instantiated |
|
68 |
* @see Locator#get(String) |
|
69 |
*/ |
|
70 |
public static EditingSwingManager getSwingManager() throws LocatorException { |
|
71 |
return (EditingSwingManager) getInstance().get(MANAGER_NAME); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* Registers the Class implementing the EditingSwingLocator interface. |
|
76 |
* |
|
77 |
* @param clazz |
|
78 |
* implementing the EeditingSwingManager interface |
|
79 |
*/ |
|
80 |
public static void registerManager(Class clazz) { |
|
81 |
getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz); |
|
82 |
} |
|
83 |
|
|
84 |
public static void registerDefaultManager(Class clazz) { |
|
85 |
getInstance().registerDefault(MANAGER_NAME, MANAGER_DESCRIPTION, clazz); |
|
86 |
} |
|
87 |
|
|
88 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingSwingLibrary.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.api; |
|
26 |
|
|
27 |
import org.gvsig.fmap.dal.DALLibrary; |
|
28 |
import org.gvsig.fmap.geom.GeometryLibrary; |
|
29 |
import org.gvsig.tools.library.AbstractLibrary; |
|
30 |
import org.gvsig.tools.library.LibraryException; |
|
31 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
|
32 |
|
|
33 |
public class EditingSwingLibrary extends AbstractLibrary { |
|
34 |
|
|
35 |
@Override |
|
36 |
public void doRegistration() { |
|
37 |
registerAsAPI(EditingSwingLibrary.class); |
|
38 |
require(DALLibrary.class); |
|
39 |
require(GeometryLibrary.class); |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
protected void doInitialize() throws LibraryException { |
|
44 |
// TODO Auto-generated method stub |
|
45 |
|
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doPostInitialize() throws LibraryException { |
|
50 |
EditingSwingManager manager = EditingSwingLocator.getSwingManager(); |
|
51 |
if (manager == null) { |
|
52 |
throw new ReferenceNotRegisteredException( |
|
53 |
EditingSwingLocator.MANAGER_NAME, |
|
54 |
EditingSwingLocator.getInstance()); |
|
55 |
} |
|
56 |
|
|
57 |
} |
|
58 |
|
|
59 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/console/EditingConsole.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2015 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.api.console; |
|
26 |
|
|
27 |
import org.gvsig.utils.console.ResponseListener; |
|
28 |
|
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @author llmarques |
|
33 |
* |
|
34 |
*/ |
|
35 |
public interface EditingConsole { |
|
36 |
|
|
37 |
/** |
|
38 |
* Gets response text typed by user |
|
39 |
* |
|
40 |
* @return |
|
41 |
*/ |
|
42 |
public String getResponseText(); |
|
43 |
|
|
44 |
/** |
|
45 |
* Clears console |
|
46 |
*/ |
|
47 |
public void clear(); |
|
48 |
|
|
49 |
/** |
|
50 |
* Adds text to console |
|
51 |
* |
|
52 |
* @param text |
|
53 |
*/ |
|
54 |
public void addText(String text); |
|
55 |
|
|
56 |
/** |
|
57 |
* Add text that is taken like text typed by user |
|
58 |
* |
|
59 |
* @param responseText |
|
60 |
*/ |
|
61 |
public void addResponseText(String responseText); |
|
62 |
|
|
63 |
/** |
|
64 |
* Adds the listener |
|
65 |
* |
|
66 |
* @param listener |
|
67 |
*/ |
|
68 |
public void addResponseListener(ResponseListener listener); |
|
69 |
|
|
70 |
/** |
|
71 |
* Removes the listener |
|
72 |
* |
|
73 |
* @param listener |
|
74 |
*/ |
|
75 |
public void removeResponseListener(ResponseListener listener); |
|
76 |
|
|
77 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.vectorediting.swing.api</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.vectorediting.swing.api</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.vectorediting.swing</artifactId> |
|
10 |
<version>1.0.120</version> |
|
11 |
</parent> |
|
12 |
<build> |
|
13 |
<plugins> |
|
14 |
<plugin> |
|
15 |
<groupId>org.apache.maven.plugins</groupId> |
|
16 |
<artifactId>maven-jar-plugin</artifactId> |
|
17 |
<configuration> |
|
18 |
</configuration> |
|
19 |
<executions> |
|
20 |
<!-- Generates a jar file only with the test classes --> |
|
21 |
<execution> |
|
22 |
<goals> |
|
23 |
<goal>test-jar</goal> |
|
24 |
</goals> |
|
25 |
</execution> |
|
26 |
</executions> |
|
27 |
</plugin> |
|
28 |
</plugins> |
|
29 |
</build> |
|
30 |
<dependencies> |
|
31 |
<dependency> |
|
32 |
<groupId>org.gvsig</groupId> |
|
33 |
<artifactId>org.gvsig.vectorediting.lib.api</artifactId> |
|
34 |
</dependency> |
|
35 |
</dependencies> |
|
36 |
</project> |
|
0 | 37 |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
3 |
|
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.vectorediting.swing</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<name>org.gvsig.vectorediting.swing</name> |
|
8 |
<parent> |
|
9 |
<groupId>org.gvsig</groupId> |
|
10 |
<artifactId>org.gvsig.vectorediting</artifactId> |
|
11 |
<version>1.0.120</version> |
|
12 |
</parent> |
|
13 |
|
|
14 |
|
|
15 |
<modules> |
|
16 |
<module>org.gvsig.vectorediting.swing.api</module> |
|
17 |
<module>org.gvsig.vectorediting.swing.impl</module> |
|
18 |
</modules> |
|
19 |
</project> |
|
20 |
|
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.vectorediting.swing.impl.DefaultEditingSwingLibrary |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.120/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingContext.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.BorderLayout; |
|
28 |
import java.awt.Component; |
|
29 |
import java.lang.ref.WeakReference; |
|
30 |
import java.lang.reflect.InvocationTargetException; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Set; |
|
33 |
import java.util.Stack; |
|
34 |
import java.util.logging.Level; |
|
35 |
import java.util.prefs.PreferenceChangeEvent; |
|
36 |
import java.util.prefs.PreferenceChangeListener; |
|
37 |
import java.util.prefs.Preferences; |
|
38 |
|
|
39 |
import javax.swing.JComponent; |
|
40 |
import javax.swing.JOptionPane; |
|
41 |
import javax.swing.SwingUtilities; |
|
42 |
|
|
43 |
import org.gvsig.fmap.dal.exception.DataException; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
46 |
import org.gvsig.fmap.geom.Geometry; |
|
47 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
48 |
import org.gvsig.fmap.geom.GeometryManager; |
|
49 |
import org.gvsig.fmap.geom.primitive.Point; |
|
50 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
51 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
52 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
|
53 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
54 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
55 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
|
56 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
|
57 |
import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
|
58 |
import org.gvsig.fmap.mapcontext.layers.LayerListener; |
|
59 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
|
60 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
61 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
62 |
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior; |
|
63 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
|
64 |
import org.gvsig.tools.ToolsLocator; |
|
65 |
import org.gvsig.tools.i18n.I18nManager; |
|
66 |
import org.gvsig.tools.observer.BaseNotification; |
|
67 |
import org.gvsig.tools.observer.Notification; |
|
68 |
import org.gvsig.tools.observer.ObservableHelper; |
|
69 |
import org.gvsig.tools.observer.Observer; |
|
70 |
import org.gvsig.utils.console.JDockPanel; |
|
71 |
import org.gvsig.utils.console.ResponseListener; |
|
72 |
import org.gvsig.vectorediting.lib.api.EditingLocator; |
|
73 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
|
74 |
import org.gvsig.vectorediting.lib.api.EditingService; |
|
75 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
76 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
77 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
78 |
import org.gvsig.vectorediting.lib.api.exceptions.CreateEditingBehaviorException; |
|
79 |
import org.gvsig.vectorediting.lib.api.exceptions.EndEditingException; |
|
80 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
81 |
import org.gvsig.vectorediting.lib.api.exceptions.ParsePointException; |
|
82 |
import org.gvsig.vectorediting.lib.api.exceptions.ParseValueException; |
|
83 |
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException; |
|
84 |
import org.gvsig.vectorediting.lib.api.exceptions.StartEditingException; |
|
85 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
|
86 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
|
87 |
import org.gvsig.vectorediting.lib.api.exceptions.VectorEditingException; |
|
88 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
|
89 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator; |
|
90 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
|
91 |
import org.gvsig.vectorediting.swing.api.console.EditingConsole; |
|
92 |
import org.gvsig.vectorediting.swing.impl.console.DefaultEditingConsole; |
|
93 |
import org.gvsig.fmap.geom.primitive.Point; |
|
94 |
|
|
95 |
import org.apache.commons.lang3.StringUtils; |
|
96 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
97 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
|
98 |
import org.gvsig.fmap.dal.DataTypes; |
|
99 |
|
|
100 |
import org.gvsig.fmap.dal.EditingNotification; |
|
101 |
import org.gvsig.fmap.dal.EditingNotificationManager; |
|
102 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
|
103 |
import org.gvsig.temporarystorage.TemporaryStorageGroup; |
|
104 |
import org.gvsig.temporarystorage.TemporaryStorageLocator; |
|
105 |
import org.gvsig.temporarystorage.TemporaryStorageManager; |
|
106 |
import org.gvsig.tools.dataTypes.Coercion; |
|
107 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
108 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
109 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
|
110 |
|
|
111 |
import org.slf4j.Logger; |
|
112 |
import org.slf4j.LoggerFactory; |
|
113 |
|
|
114 |
public class DefaultEditingContext implements EditingContext { |
|
115 |
|
|
116 |
private static final Logger logger = LoggerFactory |
|
117 |
.getLogger(EditingManager.class); |
|
118 |
|
|
119 |
private WeakReference<MapControl> mapControlReference; |
|
120 |
|
|
121 |
private WeakReference<MapContext> mapContextReference; |
|
122 |
|
|
123 |
private EditingCompoundBehavior editingCompoundBehavior; |
|
124 |
|
|
125 |
private Behavior[] lastAdditionalBehaviors; |
|
126 |
|
|
127 |
private ObservableHelper observableHelper; |
|
128 |
|
|
129 |
private EditingConsole console; |
|
130 |
|
|
131 |
private JDockPanel dockConsole = null; |
|
132 |
|
|
133 |
private boolean isShowConsole = false; |
|
134 |
|
|
135 |
private Stack<EditingService> serviceStack; |
|
136 |
|
|
137 |
private FLyrVect currentLayer; |
|
138 |
|
|
139 |
private EditingServiceParameter currentParam; |
|
140 |
|
|
141 |
private Behavior[] defaultBehaviors; |
|
142 |
|
|
143 |
private LayerListener layerListener = new LayerListener() { |
|
144 |
|
|
145 |
@Override |
|
146 |
public void activationChanged(final LayerEvent e) { |
|
147 |
if( !SwingUtilities.isEventDispatchThread() ) { |
|
148 |
SwingUtilities.invokeLater(new Runnable() { |
|
149 |
|
|
150 |
@Override |
|
151 |
public void run() { |
|
152 |
activationChanged(e); |
|
153 |
} |
|
154 |
}); |
|
155 |
return; |
|
156 |
} |
|
157 |
|
|
158 |
FLayer layer = e.getSource(); |
|
159 |
|
|
160 |
FLayer[] activeLayers = |
|
161 |
layer.getMapContext().getLayers().getActives(); |
|
162 |
|
|
163 |
if ((activeLayers.length == 1) && (layer instanceof FLyrVect)) { |
|
164 |
if (layer.isActive() && layer.isEditing()) { |
|
165 |
getMapControl().setTool("VectorEditing"); |
|
166 |
setCurrentLayer((FLyrVect) layer); |
|
167 |
showConsole(); |
|
168 |
return; |
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
hideConsole(); |
|
173 |
if ((getMapControl().getCurrentTool() != null) |
|
174 |
&& getMapControl().getCurrentTool().equals("VectorEditing")) { |
|
175 |
getMapControl().setPrevTool(); |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
public void drawValueChanged(LayerEvent e) { |
|
180 |
} |
|
181 |
|
|
182 |
@Override |
|
183 |
public void editionChanged(final LayerEvent e) { |
|
184 |
if( !SwingUtilities.isEventDispatchThread() ) { |
|
185 |
SwingUtilities.invokeLater(new Runnable() { |
|
186 |
|
|
187 |
@Override |
|
188 |
public void run() { |
|
189 |
editionChanged(e); |
|
190 |
} |
|
191 |
}); |
|
192 |
return; |
|
193 |
} |
|
194 |
FLayer layer = e.getSource(); |
|
195 |
|
|
196 |
if (layer instanceof FLyrVect) { |
|
197 |
if (layer.isEditing()) { |
|
198 |
synchronized (DefaultEditingContext.this) { |
|
199 |
beginEdition((FLyrVect) layer); |
|
200 |
showConsole(); |
|
201 |
} |
|
202 |
} else { |
|
203 |
hideConsole(); |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
} |
|
208 |
|
|
209 |
public void nameChanged(LayerEvent e) { |
|
210 |
} |
|
211 |
|
|
212 |
public void visibilityChanged(LayerEvent e) { |
|
213 |
} |
|
214 |
}; |
|
215 |
|
|
216 |
private PreferenceChangeListener preferenceChangeListener = |
|
217 |
new PreferenceChangeListener() { |
|
218 |
|
|
219 |
public void preferenceChange(PreferenceChangeEvent evt) { |
|
220 |
String key = evt.getKey(); |
|
221 |
if (key.equalsIgnoreCase("apply-snappers")) { |
|
222 |
boolean newValue = Boolean.parseBoolean(evt.getNewValue()); |
|
223 |
getMapControl().setRefentEnabled(newValue); |
|
224 |
} |
|
225 |
} |
|
226 |
}; |
|
227 |
|
|
228 |
public DefaultEditingContext(MapControl mapControl) { |
|
229 |
|
|
230 |
this.mapControlReference = new WeakReference<MapControl>(mapControl); |
|
231 |
this.mapContextReference = |
|
232 |
new WeakReference<MapContext>(mapControl.getMapContext()); |
|
233 |
this.observableHelper = new ObservableHelper(); |
|
234 |
|
|
235 |
this.serviceStack = new Stack<EditingService>(); |
|
236 |
|
|
237 |
addLayerListeners(); |
|
238 |
addPreferenceListener(); |
|
239 |
} |
|
240 |
|
|
241 |
private void addPreferenceListener() { |
|
242 |
Preferences prefs = Preferences.userRoot().node("snappers"); |
|
243 |
prefs.addPreferenceChangeListener(preferenceChangeListener); |
|
244 |
} |
|
245 |
|
|
246 |
public void activateService(String name) { |
|
247 |
|
|
248 |
if ((getMapControl() != null) |
|
249 |
&& getMapControl().hasTool("VectorEditing")) { |
|
250 |
|
|
251 |
CompoundBehavior editingCompoundBehavior = |
|
252 |
getEditingCompoundBehavior(); |
|
253 |
getMapControl().setTool("VectorEditing"); |
|
254 |
editingCompoundBehavior.setDrawnBehavior( |
|
255 |
EditingCompoundBehavior.EDITING_INDEX, true); |
|
256 |
|
|
257 |
EditingManager manager = EditingLocator.getManager(); |
|
258 |
|
|
259 |
if (currentLayer != null) { |
|
260 |
|
|
261 |
EditingService service = |
|
262 |
manager.getEditingService(name, |
|
263 |
currentLayer.getFeatureStore(), |
|
264 |
mapContextReference.get()); |
|
265 |
|
|
266 |
if (service != null) { |
|
267 |
|
|
268 |
this.enableSelection(false); |
|
269 |
|
|
270 |
try { |
|
271 |
service.start(); |
|
272 |
} catch (StartServiceException e) { |
|
273 |
|
|
274 |
logger.info(String.format( |
|
275 |
"Can't start the service %1$s", service.getName()), |
|
276 |
e); |
|
277 |
cleanEditingContext(); |
|
278 |
return; |
|
279 |
|
|
280 |
} catch (InvalidEntryException e) { |
|
281 |
|
|
282 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
283 |
showConsoleMessage("\n" |
|
284 |
+ i18nManager.getTranslation("invalid_option")); |
|
285 |
} |
|
286 |
|
|
287 |
if (!serviceStack.isEmpty() |
|
288 |
&& !getActiveService().next().getTypes() |
|
289 |
.contains(TYPE.GEOMETRY)) { |
|
290 |
serviceStack.pop(); |
|
291 |
} |
|
292 |
|
|
293 |
setActiveService(service); |
|
294 |
|
|
295 |
getNextParameter(); |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
} |
|
300 |
|
|
301 |
private void addBehaviors(Behavior[] additionalBehavior) |
|
302 |
throws CreateEditingBehaviorException { |
|
303 |
|
|
304 |
DefaultEditingBehavior editingBehavior; |
|
305 |
EditingCompoundBehavior editingCompoundBehavior; |
|
306 |
|
|
307 |
if (!getMapControl().hasTool("VectorEditing")) { |
|
308 |
|
|
309 |
editingBehavior = new DefaultEditingBehavior(this); |
|
310 |
editingCompoundBehavior = |
|
311 |
new EditingCompoundBehavior(editingBehavior); |
|
312 |
setCompoundBehavior(editingCompoundBehavior); |
|
313 |
|
|
314 |
if (additionalBehavior != null) { |
|
315 |
|
|
316 |
Behavior[] behaviors = |
|
317 |
new Behavior[additionalBehavior.length + 1]; |
|
318 |
behaviors[0] = editingCompoundBehavior; |
|
319 |
|
|
320 |
for (int i = 0; i < additionalBehavior.length; i++) { |
|
321 |
behaviors[i + 1] = additionalBehavior[i]; |
|
322 |
} |
|
323 |
|
|
324 |
getMapControl().addBehavior("VectorEditing", behaviors); |
|
325 |
|
|
326 |
lastAdditionalBehaviors = additionalBehavior; |
|
327 |
|
|
328 |
} else { |
|
329 |
getMapControl().addBehavior("VectorEditing", |
|
330 |
editingCompoundBehavior); |
|
331 |
} |
|
332 |
|
|
333 |
} else { |
|
334 |
editingCompoundBehavior = getEditingCompoundBehavior(); |
|
335 |
editingBehavior = |
|
336 |
(DefaultEditingBehavior) editingCompoundBehavior |
|
337 |
.getBehavior(EditingCompoundBehavior.EDITING_INDEX); |
|
338 |
setCompoundBehavior(editingCompoundBehavior); |
|
339 |
cleanEditingContext(); |
|
340 |
} |
|
341 |
|
|
342 |
} |
|
343 |
|
|
344 |
private void addLayerListeners() { |
|
345 |
|
|
346 |
FLayers layers = mapContextReference.get().getLayers(); |
|
347 |
|
|
348 |
layers.addLayerListener(layerListener); |
|
349 |
|
|
350 |
layers.addLayerCollectionListener(new LayerCollectionListener() { |
|
351 |
|
|
352 |
public void addLayer(FLayer layer) { |
|
353 |
if (layer instanceof FLayers) { |
|
354 |
FLayers layers = (FLayers) layer; |
|
355 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
356 |
addLayer(layers.getLayer(i)); |
|
357 |
} |
|
358 |
} else if (layer instanceof FLyrVect) { |
|
359 |
((FLyrVect) layer).addLayerListener(layerListener); |
|
360 |
} |
|
361 |
} |
|
362 |
|
|
363 |
public void layerAdded(LayerCollectionEvent e) { |
|
364 |
addLayer(e.getLayers()); |
|
365 |
} |
|
366 |
|
|
367 |
public void layerAdding(LayerCollectionEvent e) |
|
368 |
throws CancelationException { |
|
369 |
} |
|
370 |
|
|
371 |
public void layerMoved(LayerPositionEvent e) { |
|
372 |
} |
|
373 |
|
|
374 |
public void layerMoving(LayerPositionEvent e) |
|
375 |
throws CancelationException { |
|
376 |
} |
|
377 |
|
|
378 |
public void removeLayer(FLayer layer) { |
|
379 |
if (layer instanceof FLayers) { |
|
380 |
FLayers layers = (FLayers) layer; |
|
381 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
382 |
addLayer(layers.getLayer(i)); |
|
383 |
} |
|
384 |
} else if (layer instanceof FLyrVect) { |
|
385 |
((FLyrVect) layer).removeLayerListener(layerListener); |
|
386 |
} |
|
387 |
} |
|
388 |
|
|
389 |
public void layerRemoved(LayerCollectionEvent e) { |
|
390 |
removeLayer(e.getLayers()); |
|
391 |
} |
|
392 |
|
|
393 |
public void layerRemoving(LayerCollectionEvent e) |
|
394 |
throws CancelationException { |
|
395 |
} |
|
396 |
|
|
397 |
public void visibilityChanged(LayerCollectionEvent e) |
|
398 |
throws CancelationException { |
|
399 |
} |
|
400 |
}); |
|
401 |
} |
|
402 |
|
|
403 |
public void addObserver(Observer o) { |
|
404 |
this.observableHelper.addObserver(o); |
|
405 |
} |
|
406 |
|
|
407 |
private void askQuestion(EditingServiceParameter param) { |
|
408 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
409 |
String translation = i18nManager.getTranslation(param.getDescription()); |
|
410 |
String activeServiceName = |
|
411 |
i18nManager.getTranslation(getActiveService().getName()); |
|
412 |
|
|
413 |
Object defaultValue = param.getDefaultValue(); |
|
414 |
String strDefaultValue; |
|
415 |
|
|
416 |
if (defaultValue != null) { |
|
417 |
if (defaultValue instanceof String) { |
|
418 |
strDefaultValue = (String) defaultValue; |
|
419 |
strDefaultValue = |
|
420 |
i18nManager.getTranslation((String) defaultValue); |
|
421 |
} else { |
|
422 |
if(defaultValue instanceof Point){ |
|
423 |
Point point = (Point)defaultValue; |
|
424 |
StringBuilder builder = new StringBuilder(); |
|
425 |
for(int i=0; i<point.getDimension(); i++){ |
|
426 |
builder.append(point.getCoordinateAt(i)); |
|
427 |
if(i < point.getDimension()-1){ |
|
428 |
builder.append(" , "); |
|
429 |
} |
|
430 |
} |
|
431 |
strDefaultValue = builder.toString(); |
|
432 |
} else { |
|
433 |
strDefaultValue = defaultValue.toString(); |
|
434 |
} |
|
435 |
} |
|
436 |
showConsoleMessage("\n" + activeServiceName + "# " + translation |
|
437 |
+ "<" + strDefaultValue + "> : "); |
|
438 |
} else { |
|
439 |
showConsoleMessage("\n" + activeServiceName + "# " + translation |
|
440 |
+ " : "); |
|
441 |
} |
|
442 |
} |
|
443 |
|
|
444 |
public synchronized void beginEdition(FLyrVect layer, |
|
445 |
Behavior[] additionalBehaviors) { |
|
446 |
|
|
447 |
try{ |
|
448 |
throw new Exception("Deprecated method"); |
|
449 |
} catch (Exception e){ |
|
450 |
logger.info("Deprecated method", e); |
|
451 |
} |
|
452 |
|
|
453 |
beginEdition(layer); |
|
454 |
try { |
|
455 |
addBehaviors(additionalBehaviors); |
|
456 |
} catch (CreateEditingBehaviorException e1) { |
|
457 |
logger.info("Problems adding behaviors to editing context", e1); |
|
458 |
getMapControl().setTool("pan"); |
|
459 |
return; |
|
460 |
} |
|
461 |
} |
|
462 |
|
|
463 |
public synchronized void beginEdition(FLyrVect layer) { |
|
464 |
|
|
465 |
EditingNotificationManager editingNotificationManager = |
|
466 |
DALSwingLocator.getEditingNotificationManager(); |
|
467 |
|
|
468 |
EditingNotification notification = |
|
469 |
editingNotificationManager.notifyObservers(this, |
|
470 |
EditingNotification.BEFORE_ENTER_EDITING_STORE, null, layer,layer.getFeatureStore()); |
|
471 |
|
|
472 |
if (notification.isCanceled()) { |
|
473 |
String msg = |
|
474 |
String.format("Edit layer %1$s canceled by somme observer.", |
|
475 |
layer.getName()); |
|
476 |
logger.info(msg, new StartEditingException(msg, null)); |
|
477 |
return; |
|
478 |
} |
|
479 |
|
|
480 |
setCurrentLayer(layer); |
|
481 |
|
|
482 |
FeatureStore featureStore = layer.getFeatureStore(); |
|
483 |
if (!featureStore.isEditing()) { |
|
484 |
try { |
|
485 |
featureStore.edit(); |
|
486 |
} catch (Exception e) { |
|
487 |
String msg = |
|
488 |
String.format("Can't set %1$s in edit mode", |
|
489 |
featureStore.getName()); |
|
490 |
logger.info(msg, new VectorEditingException(e)); |
|
491 |
cleanEditingContext(); |
|
492 |
return; |
|
493 |
} |
|
494 |
} |
|
495 |
|
|
496 |
featureStore.addObserver(getMapControl()); |
|
497 |
|
|
498 |
editingNotificationManager.notifyObservers(this, |
|
499 |
EditingNotification.AFTER_ENTER_EDITING_STORE, null, layer, layer.getFeatureStore()); |
|
500 |
|
|
501 |
enableSnapping(); |
|
502 |
} |
|
503 |
|
|
504 |
@SuppressWarnings({ "rawtypes", "unchecked" }) |
|
505 |
private void enableSnapping() { |
|
506 |
Preferences prefs = Preferences.userRoot().node("snappers"); |
|
507 |
getMapControl().setRefentEnabled(prefs.getBoolean("apply-snappers", false)); |
|
508 |
if (currentLayer != null) { |
|
509 |
ArrayList layersToSnap = |
|
510 |
getMapControl().getMapContext().getLayersToSnap(); |
|
511 |
if (!layersToSnap.contains(currentLayer)) { |
|
512 |
layersToSnap.add(currentLayer); |
|
513 |
} |
|
514 |
} |
|
515 |
} |
|
516 |
|
|
517 |
@SuppressWarnings("rawtypes") |
|
518 |
private void disableSnapping() { |
|
519 |
ArrayList layersToSnap = |
|
520 |
getMapControl().getMapContext().getLayersToSnap(); |
|
521 |
if (layersToSnap.contains(currentLayer)) { |
|
522 |
layersToSnap.remove(currentLayer); |
|
523 |
} |
|
524 |
} |
|
525 |
|
|
526 |
private void changeSelectedTool(String name) { |
|
527 |
if (name.equalsIgnoreCase(DEFAULT_TOOL)) { |
|
528 |
name = "selection-simple-select-view"; |
|
529 |
this.getMapControl().setTool("pointSelection"); |
|
530 |
} |
|
531 |
Notification notification = |
|
532 |
new BaseNotification( |
|
533 |
EditingContext.CHANGE_SELECTED_TOOL_NOTIFICATION, |
|
534 |
new Object[] { name }); |
|
535 |
this.observableHelper.notifyObservers(this, notification); |
|
536 |
} |
|
537 |
|
|
538 |
private void cleanEditingContext() { |
|
539 |
serviceStack.clear(); |
|
540 |
currentParam = null; |
|
541 |
this.enableSelection(false); |
|
542 |
refreshMenusAndToolBars(); |
|
543 |
|
|
544 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
545 |
showConsoleMessage("\n" + i18nManager.getTranslation("select_new_tool") |
|
546 |
+ "\n"); |
|
547 |
} |
|
548 |
|
|
549 |
public void deleteObserver(Observer o) { |
|
550 |
this.observableHelper.deleteObserver(o); |
|
551 |
} |
|
552 |
|
|
553 |
public void deleteObservers() { |
|
554 |
this.observableHelper.deleteObservers(); |
|
555 |
} |
|
556 |
|
|
557 |
private void discardChanges(FLyrVect layer) throws EndEditingException { |
|
558 |
FeatureStore featureStore = layer.getFeatureStore(); |
|
559 |
try { |
|
560 |
featureStore.cancelEditing(); |
|
561 |
} catch (Exception e) { |
|
562 |
throw new EndEditingException(e); |
|
563 |
} |
|
564 |
} |
|
565 |
|
|
566 |
private void doAction(FLyrVect layer, int option) { |
|
567 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
568 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
569 |
|
|
570 |
switch (option) { |
|
571 |
case SAVE_CHANGES: |
|
572 |
try { |
|
573 |
saveChanges(layer); |
|
574 |
} catch (VectorEditingException e) { |
|
575 |
String msg = |
|
576 |
String.format("Changes can not be saved in %1$s", |
|
577 |
layer.getName()); |
|
578 |
logger.info(msg, e); |
|
579 |
dialogs.messageDialog( |
|
580 |
i18n.getTranslation("_There_are_problems_saving_changes")+"\n\n"+ |
|
581 |
i18n.getTranslation("_See_error_log_for_more_information"), |
|
582 |
null, |
|
583 |
i18n.getTranslation("_Warning"), |
|
584 |
JOptionPane.WARNING_MESSAGE, |
|
585 |
"Vectorediting_cant_save_changes" |
|
586 |
); |
|
587 |
return; |
|
588 |
} |
|
589 |
break; |
|
590 |
|
|
591 |
case DISCARD_CHANGES: |
|
592 |
try { |
|
593 |
discardChanges(layer); |
|
594 |
} catch (VectorEditingException e) { |
|
595 |
String msg = |
|
596 |
String.format("Changes can not be discared in %1$s", |
|
597 |
layer.getName()); |
|
598 |
logger.info(msg, e); |
|
599 |
dialogs.messageDialog( |
|
600 |
i18n.getTranslation("_There_are_problems_discarding_changes")+"\n"+ |
|
601 |
// i18n.getTranslation("_The_layer_is_marked_as_temporary_to_avoid_possible_problems_when_trying_to_save_the_project")+"\n"+ |
|
602 |
"\n" + i18n.getTranslation("_See_error_log_for_more_information"), |
|
603 |
null, |
|
604 |
i18n.getTranslation("_Warning"), |
|
605 |
JOptionPane.WARNING_MESSAGE, |
|
606 |
"Vectorediting_cant_discard_changes" |
|
607 |
); |
|
608 |
return; |
|
609 |
} |
|
610 |
break; |
|
611 |
|
|
612 |
case EXPORT_LAYER: |
|
613 |
try { |
|
614 |
exportLayer(layer); |
|
615 |
} catch (VectorEditingException e) { |
|
616 |
String msg = |
|
617 |
String.format("Changes of %1$s can not be exported", |
|
618 |
layer.getName()); |
|
619 |
logger.info(msg, e); |
|
620 |
dialogs.messageDialog( |
|
621 |
i18n.getTranslation("_There_are_problems_exporting_changes")+"\n\n"+ |
|
622 |
i18n.getTranslation("_See_error_log_for_more_information"), |
|
623 |
null, |
|
624 |
i18n.getTranslation("_Warning"), |
|
625 |
JOptionPane.WARNING_MESSAGE, |
|
626 |
"Vectorediting_cant_export_changes" |
|
627 |
); |
|
628 |
return; |
|
629 |
} |
|
630 |
break; |
|
631 |
|
|
632 |
case CANCEL: |
|
633 |
return; |
|
634 |
} |
|
635 |
|
|
636 |
cleanEditingContext(); |
|
637 |
hideConsole(); |
|
638 |
disableSnapping(); |
|
639 |
changeSelectedTool(DEFAULT_TOOL); |
|
640 |
|
|
641 |
FeatureStore featureStore = layer.getFeatureStore(); |
|
642 |
featureStore.deleteObserver(getMapControl()); |
|
643 |
|
|
644 |
} |
|
645 |
|
|
646 |
private void enableSelection(boolean enableSelection) { |
|
647 |
this.editingCompoundBehavior.setDrawnBehavior( |
|
648 |
EditingCompoundBehavior.SELECTION_INDEX, enableSelection); |
|
649 |
} |
|
650 |
|
|
651 |
public void endEdition(FLyrVect layer) { |
|
652 |
if (layer.isEditing()) { |
|
653 |
EditingNotificationManager editingNotificationManager = |
|
654 |
DALSwingLocator.getEditingNotificationManager(); |
|
655 |
|
|
656 |
EditingNotification notification = |
|
657 |
editingNotificationManager.notifyObservers(this, |
|
658 |
EditingNotification.BEFORE_EXIT_EDITING_STORE, null, layer, layer.getFeatureStore()); |
|
659 |
|
|
660 |
if (notification.isCanceled()) { |
|
661 |
String msg = |
|
662 |
String.format( |
|
663 |
"Stop edit layer %1$s canceled by somme observer.", |
|
664 |
layer.getName()); |
|
665 |
logger.info(msg, new EndEditingException(msg, null)); |
|
666 |
|
|
667 |
} |
|
668 |
|
|
669 |
getMapControl().getCanceldraw().setCanceled(true); |
|
670 |
int option; |
|
671 |
EditingSwingManager swingManager = |
|
672 |
EditingSwingLocator.getSwingManager(); |
|
673 |
|
|
674 |
|
|
675 |
if (layer.isWritable() && getMapControl().getProjection().equals(layer.getProjection()) ) { |
|
676 |
option = |
|
677 |
swingManager.showPanelSaveOrDiscard(getMapControl(), |
|
678 |
layer.getName()); |
|
679 |
} else { |
|
680 |
option = |
|
681 |
swingManager.showPanelExportOrDiscard(getMapControl(), |
|
682 |
layer.getName()); |
|
683 |
} |
|
684 |
|
|
685 |
doAction(layer, option); |
|
686 |
|
|
687 |
editingNotificationManager.notifyObservers(this, |
|
688 |
EditingNotification.AFTER_EXIT_EDITING_STORE, null, layer, layer.getFeatureStore()); |
|
689 |
|
|
690 |
} |
|
691 |
|
|
692 |
} |
|
693 |
|
|
694 |
private void exportLayer(FLyrVect layer) throws EndEditingException { |
|
695 |
Notification notification = new BaseNotification(EditingContext.EXPORT_LAYER_NOTIFICATION,1); |
|
696 |
notification.setValue(layer); |
|
697 |
this.observableHelper.notifyObservers(this, notification); |
|
698 |
} |
|
699 |
|
|
700 |
protected void finishService() { |
|
701 |
EditingService lastService = serviceStack.pop(); |
|
702 |
try { |
|
703 |
|
|
704 |
if (!serviceStack.isEmpty() |
|
705 |
&& getActiveService().next().getTypes().contains(TYPE.GEOMETRY)) { |
|
706 |
Geometry geometry = lastService.finish(); |
|
707 |
if (geometry != null) { |
|
708 |
getActiveService().setValue(geometry); |
|
709 |
} |
|
710 |
} else { |
|
711 |
lastService.finishAndStore(); |
|
712 |
getMapControl().rePaintDirtyLayers(); |
|
713 |
|
|
714 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
715 |
showConsoleMessage("\n" |
|
716 |
+ i18nManager.getTranslation(lastService.getName()) + "# " |
|
717 |
+ i18nManager.getTranslation("finished") + "\n"); |
|
718 |
lastService.stop(); |
|
719 |
setActiveService(lastService); |
|
720 |
lastService.start(); |
|
721 |
changeSelectedTool(getActiveService().getName()); |
|
722 |
} |
|
723 |
|
|
724 |
} catch (InvalidEntryException ex) { |
|
725 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
726 |
showConsoleMessage("\n" |
|
727 |
+ i18nManager.getTranslation("invalid_option")); |
|
728 |
changeSelectedTool(getActiveService().getName()); |
|
729 |
} catch (VectorEditingException ex) { |
|
730 |
logger.info("Can't finish " + lastService.getName(), ex); |
|
731 |
cleanEditingContext(); |
|
732 |
return; |
|
733 |
} |
|
734 |
|
|
735 |
getNextParameter(); |
|
736 |
} |
|
737 |
|
|
738 |
protected EditingService getActiveService() { |
|
739 |
if (!serviceStack.isEmpty()) { |
|
740 |
return serviceStack.peek(); |
|
741 |
} |
|
742 |
return null; |
|
743 |
} |
|
744 |
|
|
745 |
private EditingConsole getConsolePanel() { |
|
746 |
if (console == null) { |
|
747 |
console = new DefaultEditingConsole(new ResponseListener() { |
|
748 |
|
|
749 |
public void acceptResponse(String response) { |
|
750 |
textEntered(response); |
|
751 |
} |
|
752 |
}); |
|
753 |
} |
|
754 |
return console; |
|
755 |
} |
|
756 |
|
|
757 |
protected FLyrVect getCurrentLayer() { |
|
758 |
return this.currentLayer; |
|
759 |
} |
|
760 |
|
|
761 |
protected EditingServiceParameter getCurrentParam() { |
|
762 |
return this.currentParam; |
|
763 |
} |
|
764 |
|
|
765 |
private Component getDockConsole() { |
|
766 |
if (dockConsole == null) { |
|
767 |
dockConsole = new JDockPanel((JComponent) getConsolePanel()); |
|
768 |
} |
|
769 |
return dockConsole; |
|
770 |
} |
|
771 |
|
|
772 |
private DefaultEditingBehavior getEditingBehavior() { |
|
773 |
if (editingCompoundBehavior != null) { |
|
774 |
return (DefaultEditingBehavior) editingCompoundBehavior |
|
775 |
.getBehavior(EditingCompoundBehavior.EDITING_INDEX); |
|
776 |
} |
|
777 |
return null; |
|
778 |
} |
|
779 |
|
|
780 |
private EditingCompoundBehavior getEditingCompoundBehavior() { |
|
781 |
if (editingCompoundBehavior != null) { |
|
782 |
return editingCompoundBehavior; |
|
783 |
} else { |
|
784 |
EditingCompoundBehavior editingCompoundBehavior; |
|
785 |
|
|
786 |
CompoundBehavior compoundBehavior = |
|
787 |
(CompoundBehavior) getMapControl().getMapTool("VectorEditing"); |
|
788 |
|
|
789 |
if (compoundBehavior instanceof EditingCompoundBehavior) { |
|
790 |
editingCompoundBehavior = |
|
791 |
(EditingCompoundBehavior) compoundBehavior; |
|
792 |
} else { |
|
793 |
editingCompoundBehavior = |
|
794 |
(EditingCompoundBehavior) compoundBehavior.getBehavior(0); |
|
795 |
} |
|
796 |
|
|
797 |
setCompoundBehavior(editingCompoundBehavior); |
|
798 |
return editingCompoundBehavior; |
|
799 |
} |
|
800 |
} |
|
801 |
|
|
802 |
public MapControl getMapControl() { |
|
803 |
return mapControlReference.get(); |
|
804 |
} |
|
805 |
|
|
806 |
protected void getNextParameter() { |
|
807 |
if ((getMapControl().getCurrentTool() != null) |
|
808 |
&& !getMapControl().getCurrentTool().equals("VectorEditing")) { |
|
809 |
getMapControl().setTool("VectorEditing"); |
|
810 |
} |
|
811 |
currentParam = getActiveService().next(); |
|
812 |
|
|
813 |
if (currentParam == null) { |
|
814 |
finishService(); |
|
815 |
} else { |
|
816 |
askQuestion(currentParam); |
|
817 |
if (currentParam.getTypes().contains(TYPE.SELECTION)) { |
|
818 |
enableSelection(true); |
|
819 |
} else if (currentParam.getTypes().contains(TYPE.GEOMETRY)) { |
|
820 |
refreshMenusAndToolBars(); |
|
821 |
} |
|
822 |
} |
|
823 |
} |
|
824 |
|
|
825 |
protected Stack<EditingService> getServiceStack() { |
|
826 |
return this.serviceStack; |
|
827 |
} |
|
828 |
|
|
829 |
private void hideConsole() { |
|
830 |
isShowConsole = false; |
|
831 |
if( !SwingUtilities.isEventDispatchThread() ) { |
|
832 |
try { |
|
833 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
834 |
|
|
835 |
@Override |
|
836 |
public void run() { |
|
837 |
hideConsole(); |
|
838 |
} |
|
839 |
}); |
|
840 |
return; |
|
841 |
} catch (InterruptedException | InvocationTargetException ex) { |
|
842 |
logger.warn("Can't hide editing console.",ex); |
|
843 |
} |
|
844 |
return; |
|
845 |
} |
|
846 |
getDockConsole().setVisible(false); |
Also available in: Unified diff