Revision 1161

View differences:

org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.61/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.61</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>
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.61/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.61/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.61/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.61/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.61/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.61/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.61/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.61/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
}
0 78

  
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.61/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.61</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.61/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/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.impl</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.vectorediting.swing.impl</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.vectorediting.swing</artifactId>
10
		<version>1.0.61</version>
11
	</parent>
12
	<dependencies>
13
		<dependency>
14
			<groupId>org.gvsig</groupId>
15
			<artifactId>org.gvsig.vectorediting.swing.api</artifactId>
16
		</dependency>
17
    <dependency>
18
      <groupId>org.gvsig</groupId>
19
      <artifactId>org.gvsig.vectorediting.lib.spi</artifactId>
20
    </dependency>
21
	</dependencies>
22
</project>
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.61/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.61/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.61/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/console/DefaultEditingConsoleView.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.impl.console;
26

  
27
import java.awt.BorderLayout;
28
import java.awt.Dimension;
29
import java.awt.Font;
30

  
31
import javax.swing.JPanel;
32
import javax.swing.JScrollPane;
33
import javax.swing.JTextArea;
34

  
35
/**
36
 * Default view implementation of EditingConsole
37
 * 
38
 * @author llmarques
39
 */
40
public class DefaultEditingConsoleView extends JPanel {
41

  
42
    private static final long serialVersionUID = -843733609032093530L;
43

  
44
    private JTextArea textArea;
45

  
46
    public DefaultEditingConsoleView() {
47
        this.textArea = new JTextArea();
48
        this.textArea.setLineWrap(true);
49
        this.textArea.setWrapStyleWord(true);
50
        this.textArea.setFont(new Font("Monospaced", Font.PLAIN, 14));
51

  
52
        JScrollPane scroll = new JScrollPane(textArea);
53
        scroll
54
            .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
55

  
56
        initialize(scroll);
57
    }
58

  
59
    private void initialize(JScrollPane scroll) {
60
        this.setLayout(new BorderLayout());
61
        this.setSize(300, 150);
62
        this.setPreferredSize(new Dimension(300, 150));
63
        this.add(scroll, java.awt.BorderLayout.CENTER);
64
    }
65

  
66
    protected JTextArea getTextArea() {
67
        return textArea;
68
    }
69

  
70
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.61/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/console/DefaultEditingConsole.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.impl.console;
26

  
27
import java.awt.event.ActionEvent;
28
import java.util.List;
29

  
30
import javax.swing.AbstractAction;
31
import javax.swing.Action;
32
import javax.swing.KeyStroke;
33
import javax.swing.event.AncestorEvent;
34
import javax.swing.event.AncestorListener;
35

  
36
import org.gvsig.utils.console.ResponseListener;
37
import org.gvsig.utils.console.ResponseListenerSupport;
38
import org.gvsig.vectorediting.swing.api.console.EditingConsole;
39

  
40
/**
41
 * Default implementation of EditingConsole
42
 *
43
 * @author llmarques
44
 */
45
public class DefaultEditingConsole extends DefaultEditingConsoleView implements
46
    EditingConsole {
47

  
48
    private static final long serialVersionUID = -1068129558465010049L;
49

  
50
    private ResponseListenerSupport responseListenerSupport;
51
    private int startingCaretPosition = 0;
52

  
53
    public DefaultEditingConsole(ResponseListener listener) {
54
        super();
55

  
56
        // Add ancestor listener to request focus when an ancestor becomes
57
        // visible
58
        addAncestorListenerToSetCaretPosition();
59

  
60
        this.responseListenerSupport = new ResponseListenerSupport();
61
        this.responseListenerSupport.addResponseListener(listener);
62

  
63
        getTextArea().setNavigationFilter(
64
            new DefaultEditingNavigationFilter(startingCaretPosition));
65

  
66
        addKeyBindings();
67
    }
68

  
69
    public DefaultEditingConsole(List<ResponseListener> listeners) {
70
        super();
71

  
72
        // Add ancestor listener to request focus when an ancestor becomes
73
        // visible
74
        addAncestorListenerToSetCaretPosition();
75

  
76
        this.responseListenerSupport = new ResponseListenerSupport();
77
        for (ResponseListener responseListener : listeners) {
78
            this.responseListenerSupport.addResponseListener(responseListener);
79
        }
80

  
81
        // Add navigation filter to control caret position
82
        getTextArea().setNavigationFilter(
83
            new DefaultEditingNavigationFilter(startingCaretPosition));
84

  
85
        addKeyBindings();
86
    }
87

  
88
    private void addAncestorListenerToSetCaretPosition() {
89
        this.addAncestorListener(new AncestorListener() {
90

  
91
            public void ancestorRemoved(AncestorEvent event) {
92
            }
93

  
94
            public void ancestorMoved(AncestorEvent event) {
95
            }
96

  
97
            public void ancestorAdded(AncestorEvent event) {
98
                getTextArea().requestFocusInWindow();
99
                getTextArea().setCaretPosition(startingCaretPosition);
100
            }
101
        });
102
    }
103

  
104
    private void addKeyBindings() {
105

  
106
        // Enter binding
107
        getTextArea().getInputMap().put(KeyStroke.getKeyStroke("ENTER"),
108
            "enterAction");
109
        getTextArea().getActionMap().put("enterAction", enterAction);
110

  
111
        // Esc binding
112
        getTextArea().getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"),
113
            "escAction");
114
        getTextArea().getActionMap().put("escAction", escAction);
115

  
116
        // BackSpace binding
117
        getTextArea().getInputMap().put(KeyStroke.getKeyStroke("BACK_SPACE"),
118
            "backSpaceAction");
119
        getTextArea().getActionMap().put("backSpaceAction", backSpaceAction);
120
        // Del binding
121
        getTextArea().getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "none");
122
    }
123

  
124
    public String getResponseText() {
125
        return getTextArea().getText().substring(startingCaretPosition,
126
            getTextArea().getText().length());
127
    }
128

  
129
    public void addText(String text) {
130
        getTextArea().setText(getTextArea().getText() + text);
131
        getTextArea().setCaretPosition(getTextArea().getText().length());
132
        startingCaretPosition = getTextArea().getText().length();
133
        getTextArea().setNavigationFilter(
134
            new DefaultEditingNavigationFilter(startingCaretPosition));
135
    }
136

  
137
    public void addResponseText(String responseText) {
138
        getTextArea().setText(getTextArea().getText() + responseText);
139
        getTextArea().setCaretPosition(getTextArea().getText().length());
140
    }
141

  
142
    public void addResponseListener(ResponseListener listener) {
143
        this.responseListenerSupport.addResponseListener(listener);
144
    }
145

  
146
    public void removeResponseListener(ResponseListener listener) {
147
        this.responseListenerSupport.removeResponseListener(listener);
148
    }
149

  
150
    private void callResponseListener(String response) {
151
        this.responseListenerSupport.callAcceptResponse(response);
152
    }
153

  
154
    public void clear() {
155
        getTextArea().setText(null);
156
    }
157

  
158
    @SuppressWarnings("serial")
159
    private Action enterAction = new AbstractAction() {
160

  
161
        public void actionPerformed(ActionEvent e) {
162
            callResponseListener(getResponseText() + "\n");
163
        }
164
    };
165

  
166
    @SuppressWarnings("serial")
167
    private Action escAction = new AbstractAction() {
168

  
169
        public void actionPerformed(ActionEvent e) {
170
            callResponseListener(null);
171
        }
172
    };
173

  
174
    @SuppressWarnings("serial")
175
    private Action backSpaceAction = new AbstractAction() {
176

  
177
        public void actionPerformed(ActionEvent e) {
178
            if (getTextArea().getCaretPosition() > startingCaretPosition) {
179
                StringBuilder stb = new StringBuilder(getTextArea().getText());
180
                stb.deleteCharAt(getTextArea().getText().length() - 1);
181
                getTextArea().setText(stb.toString());
182
            }
183
        }
184
    };
185

  
186
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.61/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/console/DefaultEditingNavigationFilter.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.impl.console;
26

  
27
import javax.swing.text.NavigationFilter;
28
import javax.swing.text.Position.Bias;
29

  
30
/**
31
 * Default implementation of Navigation filter. This implementation doesn't let
32
 * caret to move behind of a determinate position.
33
 * 
34
 * @author llmarques
35
 *
36
 */
37
public class DefaultEditingNavigationFilter extends NavigationFilter {
38

  
39
    private int startCaretPosition;
40

  
41
    public DefaultEditingNavigationFilter(int theStartPosition) {
42
        startCaretPosition = theStartPosition;
43
    }
44

  
45
    @Override
46
    public void setDot(FilterBypass fb, int dot, Bias bias) {
47
        if (dot > startCaretPosition) {
48
            fb.setDot(dot, bias);
49
        } else {
50
            fb.setDot(startCaretPosition, bias);
51
        }
52
    }
53

  
54
    @Override
55
    public void moveDot(FilterBypass fb, int dot, Bias bias) {
56
        if (dot > startCaretPosition) {
57
            fb.moveDot(dot, bias);
58
        } else {
59
            fb.moveDot(startCaretPosition, bias);
60
        }
61
    }
62
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.61/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.61/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.61/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingBehavior.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.vectorediting.swing.impl;
26

  
27
import java.awt.Color;
28
import java.awt.Graphics;
29
import java.awt.Image;
30
import java.awt.event.MouseEvent;
31
import java.awt.geom.Point2D;
32
import java.awt.image.BufferedImage;
33
import java.util.Iterator;
34
import java.util.Set;
35

  
36
import javax.swing.SwingUtilities;
37

  
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

  
41
import org.gvsig.fmap.geom.Geometry;
42
import org.gvsig.fmap.geom.GeometryLocator;
43
import org.gvsig.fmap.geom.primitive.Point;
44
import org.gvsig.fmap.mapcontext.ViewPort;
45
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
46
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
47
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
48
import org.gvsig.fmap.mapcontrol.MapControlLocator;
49
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
50
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
51
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener;
52
import org.gvsig.tools.ToolsLocator;
53
import org.gvsig.tools.exception.BaseException;
54
import org.gvsig.tools.i18n.I18nManager;
55
import org.gvsig.vectorediting.lib.api.DrawingStatus;
56
import org.gvsig.vectorediting.lib.api.DrawingStatus.Status;
57
import org.gvsig.vectorediting.lib.api.EditingService;
58
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
59
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE;
60
import org.gvsig.vectorediting.lib.api.exceptions.CreateEditingBehaviorException;
61
import org.gvsig.vectorediting.lib.api.exceptions.VectorEditingException;
62
import org.gvsig.vectorediting.swing.api.EditingSwingLocator;
63
import org.gvsig.vectorediting.swing.api.EditingSwingManager;
64
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener;
65
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu;
66

  
67
public class DefaultEditingBehavior extends Behavior {
68

  
69
    private static final Logger logger = LoggerFactory
70
        .getLogger(DefaultEditingBehavior.class);
71

  
72
    private DefaultEditingContext editingContext;
73

  
74
    private Point adjustedPoint;
75

  
76
    private static final Image imageCursor = new BufferedImage(32, 32,
77
        BufferedImage.TYPE_INT_ARGB);
78
    static {
79
        Graphics g = imageCursor.getGraphics();
80
        int size1 = 15;
81
        int x = 16;
82
        int y = 16;
83
        g.setColor(Color.MAGENTA);
84
        g.drawLine((x - size1), (y), (x + size1), (y));
85
        g.drawLine((x), (y - size1), (x), (y + size1));
86
        g.drawRect((x - 6), (y - 6), 12, 12);
87
        g.drawRect((x - 3), (y - 3), 6, 6);
88
    }
89

  
90
    public DefaultEditingBehavior(DefaultEditingContext editingContext)
91
        throws CreateEditingBehaviorException {
92

  
93
        if (editingContext.getMapControl() != null) {
94
            this.editingContext = editingContext;
95
            setMapControl(editingContext.getMapControl());
96
        }
97
    }
98

  
99
    @Override
100
    public ToolListener getListener() {
101
        return new ToolListener() {
102

  
103
            public boolean cancelDrawing() {
104
                return false;
105
            }
106

  
107
            public Image getImageCursor() {
108
                return imageCursor;
109
            }
110
        };
111
    }
112

  
113
    @Override
114
    public void mouseClicked(MouseEvent e) {
115
        ViewPort vp = editingContext.getMapControl().getViewPort();
116
        EditingServiceParameter currentParam = editingContext.getCurrentParam();
117
        EditingService activeService = editingContext.getActiveService();
118

  
119
        if ((activeService != null) && (currentParam != null)) {
120

  
121
            if (SwingUtilities.isLeftMouseButton(e)) {
122

  
123
                Set<TYPE> typesOfParam = currentParam.getTypes();
124

  
125
                if (typesOfParam.contains(TYPE.LIST_POSITIONS)) {
126
                    if (e.getClickCount() == 2) {
127
                        editingContext.finishService();
128
                        return;
129
                    }
130
                }
131

  
132
                Point point = null;
133
                Point2D point2D = getMapControl().getMapAdjustedPoint();
134
                if (point2D == null) {
135
                    point2D = getMapControl().getAdjustedPoint();
136
                    point = vp.convertToMapPoint(point2D);
137
                } else {
138
                    try {
139
                        point =
140
                            GeometryLocator.getGeometryManager().createPoint(
141
                                point2D.getX(), point2D.getY(),
142
                                Geometry.SUBTYPES.GEOM2D);
143
                    } catch (BaseException ex) {
144
                        logger.warn("Can't create point geometry from "
145
                            + point2D.toString());
146
                    }
147
                }
148

  
149
                try {
150
                    editingContext.getActiveService().setValue(point);
151
                } catch (VectorEditingException ex) {
152
                    I18nManager i18nManager = ToolsLocator.getI18nManager();
153
                    editingContext.showConsoleMessage(i18nManager
154
                        .getTranslation("invalid_option"));
155
                }
156

  
157
                editingContext.getNextParameter();
158

  
159
            } else if (SwingUtilities.isRightMouseButton(e)) {
160

  
161
                EditingSwingManager swingManager =
162
                    EditingSwingLocator.getSwingManager();
163

  
164
                EditingContextMenu contextMenu =
165
                    swingManager.getContextualMenu(getMapControl(),
166
                        new AcceptValueListener() {
167

  
168
                            public void acceptValue(Object value) {
169
                                editingContext.textEntered((String) value);
170

  
171
                            }
172
                        }, currentParam);
173

  
174
                contextMenu.show(getMapControl(), e.getX(), e.getY());
175
            }
176
        }
177
    }
178

  
179
    @Override
180
    public void mouseEntered(MouseEvent e) throws BehaviorException {
181
    }
182

  
183
    @Override
184
    public void mouseMoved(MouseEvent e) throws BehaviorException {
185
        ViewPort vp = editingContext.getMapControl().getViewPort();
186
        adjustedPoint = vp.convertToMapPoint(e.getX(), e.getY());
187
    }
188

  
189
    @Override
190
    public void mousePressed(MouseEvent e) throws BehaviorException {
191
    }
192

  
193
    @Override
194
    public void mouseReleased(MouseEvent e) throws BehaviorException {
195
    }
196

  
197
    @Override
198
    @SuppressWarnings("rawtypes")
199
    public void paintComponent(MapControlDrawer mapControlDrawer) {
200
        super.paintComponent(mapControlDrawer);
201

  
202
        if ((editingContext.getActiveService() == null)
203
            || (adjustedPoint == null)) {
204
            return;
205
        }
206

  
207
        DrawingStatus helperGeo = null;
208

  
209
        try {
210
            helperGeo =
211
                editingContext.getActiveService().getDrawingStatus(
212
                    adjustedPoint);
213
        } catch (VectorEditingException e) {
214
            logger.info("An error ocurred when draw service geometries", e);
215
        }
216

  
217
        if (helperGeo != null) {
218
            for (Iterator iterator = helperGeo.getStatus().iterator(); iterator
219
                .hasNext();) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff