Revision 711

View differences:

org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.17.1/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.31-SNAPSHOT</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.17.1/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.17.1/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.17.1/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.17.1/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.17.1/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.17.1/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.17.1/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.17.1/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();) {
220
                Status status = (Status) iterator.next();
221
                ISymbol symbol = status.getSymbol();
222
                if (symbol == null) {
223
                    symbol =
224
                        MapControlLocator.getMapControlManager()
225
                            .getAxisReferenceSymbol();
226
                }
227
                if (symbol instanceof ITextSymbol) {
228
                    ((ITextSymbol) symbol).setText(status.getText());
229
                }
230
                editingContext.getMapControl().getMapControlDrawer()
231
                    .draw(status.getGeometry(), symbol);
232
            }
233
        }
234
    }
235
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.17.1/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/EditingCompoundBehavior.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

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

  
27
import java.awt.Image;
28
import java.awt.event.MouseEvent;
29
import java.awt.event.MouseWheelEvent;
30

  
31
import org.gvsig.fmap.mapcontrol.MapControl;
32
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
33
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
34
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior;
35
import org.gvsig.fmap.mapcontrol.tools.PointSelectionListener;
36
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
37
import org.gvsig.fmap.mapcontrol.tools.Behavior.IBehavior;
38
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseWheelBehavior;
39
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
40
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener;
41

  
42
public class EditingCompoundBehavior extends CompoundBehavior {
43

  
44
    private enum Mode {
45
        EDITING, SELECTION
46
    };
47

  
48
    private Mode mode = Mode.EDITING;
49
    private IBehavior editing;
50
    private IBehavior selection;
51

  
52
    public final static int EDITING_INDEX = 0;
53
    public final static int SELECTION_INDEX = 1;
54

  
55
    public EditingCompoundBehavior(IBehavior editing) {
56
        super(new Behavior[0]);
57
        this.editing = editing;
58

  
59
        this.selection = null;
60
    }
61

  
62
    @Override
63
    public void addMapBehavior(Behavior mt, boolean draw) {
64
        if (mt instanceof MouseWheelBehavior) {
65
            return;
66
        }
67
        throw new UnsupportedOperationException();
68
    }
69

  
70
    @Override
71
    public void removeMapBehavior(Behavior mt) {
72
        throw new UnsupportedOperationException();
73
    }
74

  
75
    @Override
76
    public boolean containsBehavior(Behavior mt) {
77
        return ((mt == this.editing) || (mt == this.selection));
78
    }
79

  
80
    @Override
81
    public Behavior getBehavior(int index) {
82
        switch (index) {
83
        case EDITING_INDEX:
84
            return (Behavior) this.editing;
85
        case SELECTION_INDEX:
86
            return (Behavior) this.selection;
87
        default:
88
            throw new IndexOutOfBoundsException();
89
        }
90
    }
91

  
92
    @Override
93
    public boolean isDrawnBehavior(int index) {
94
        switch (mode) {
95
        case EDITING:
96
            return index == EDITING_INDEX;
97
        case SELECTION:
98
            return index == SELECTION_INDEX;
99
        default:
100
            return false;
101
        }
102
    }
103

  
104
    @Override
105
    public void setDrawnBehavior(int index, boolean draw) {
106
        switch (index) {
107
        case EDITING_INDEX:
108
            if (draw) {
109
                mode = Mode.EDITING;
110
            } else {
111
                mode = Mode.SELECTION;
112
            }
113
            break;
114
        case SELECTION_INDEX:
115
            if (draw) {
116
                mode = Mode.SELECTION;
117
            } else {
118
                mode = Mode.EDITING;
119
            }
120
            break;
121
        default:
122
            throw new IndexOutOfBoundsException();
123
        }
124
    }
125

  
126
    @Override
127
    public int size() {
128
        return 2;
129
    }
130

  
131
    @Override
132
    public Image getImageCursor() {
133
        switch (mode) {
134
        default:
135
        case EDITING:
136
            return this.editing.getImageCursor();
137
        case SELECTION:
138
            return this.selection.getImageCursor();
139
        }
140
    }
141

  
142
    @Override
143
    public void mouseClicked(MouseEvent e) throws BehaviorException {
144
        switch (mode) {
145
        default:
146
        case EDITING:
147
            this.editing.mouseClicked(e);
148
            break;
149
        case SELECTION:
150
            this.selection.mouseClicked(e);
151
        }
152
    }
153

  
154
    @Override
155
    public void mouseDragged(MouseEvent e) throws BehaviorException {
156
        switch (mode) {
157
        default:
158
        case EDITING:
159
            this.editing.mouseDragged(e);
160
            break;
161
        case SELECTION:
162
            this.selection.mouseDragged(e);
163
        }
164
    }
165

  
166
    @Override
167
    public void mouseEntered(MouseEvent e) throws BehaviorException {
168
        switch (mode) {
169
        default:
170
        case EDITING:
171
            this.editing.mouseEntered(e);
172
            break;
173
        case SELECTION:
174
            this.selection.mouseEntered(e);
175
        }
176
    }
177

  
178
    @Override
179
    public void mouseExited(MouseEvent e) throws BehaviorException {
180
        switch (mode) {
181
        default:
182
        case EDITING:
183
            this.editing.mouseExited(e);
184
            break;
185
        case SELECTION:
186
            this.selection.mouseExited(e);
187
        }
188
    }
189

  
190
    @Override
191
    public void mouseMoved(MouseEvent e) throws BehaviorException {
192
        switch (mode) {
193
        default:
194
        case EDITING:
195
            this.editing.mouseMoved(e);
196
            break;
197
        case SELECTION:
198
            this.selection.mouseMoved(e);
199
        }
200
    }
201

  
202
    @Override
203
    public void mousePressed(MouseEvent e) throws BehaviorException {
204
        switch (mode) {
205
        default:
206
        case EDITING:
207
            this.editing.mousePressed(e);
208
            break;
209
        case SELECTION:
210
            this.selection.mousePressed(e);
211
        }
212
    }
213

  
214
    @Override
215
    public void mouseReleased(MouseEvent e) throws BehaviorException {
216
        switch (mode) {
217
        default:
218
        case EDITING:
219
            this.editing.mouseReleased(e);
220
            break;
221
        case SELECTION:
222
            this.selection.mouseReleased(e);
223
        }
224
    }
225

  
226
    @Override
227
    public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException {
228
        switch (mode) {
229
        default:
230
        case EDITING:
231
            this.editing.mouseWheelMoved(e);
232
            break;
233
        case SELECTION:
234
            this.selection.mouseWheelMoved(e);
235
        }
236
    }
237

  
238

  
239
    public void paintComponent(MapControlDrawer renderer, boolean clean) {
240
        if(clean){
241
            clean(renderer);
242
        }
243
        paintComponent(renderer);
244
    }
245

  
246
    @Override
247
    public void paintComponent(MapControlDrawer renderer) {
248
        switch (mode) {
249
        default:
250
        case EDITING:
251
            this.editing.paintComponent(renderer);
252
            break;
253
        case SELECTION:
254
            this.selection.paintComponent(renderer);
255
        }
256
    }
257

  
258
    @Override
259
    public void setListener(ToolListener listener) {
260
        if (listener != null) {
261
            throw new UnsupportedOperationException(
262
                "CompoundBehavior does not have listeners");
263
        }
264
    }
265

  
266
    @Override
267
    public ToolListener getListener() {
268
        return null;
269
    }
270

  
271
    @Override
272
    public void setMapControl(MapControl mc) {
273
        this.editing.setMapControl(mc);
274

  
275
        if (this.selection == null) {
276
            if (mc != null) {
277
                PointSelectionListener psl = new PointSelectionListener(mc);
278
                this.selection =
279
                    new CompoundBehavior(
280
                        new Behavior[] { new PointBehavior(psl) });
281
                this.selection.setMapControl(mc);
282
            }
283
        } else {
284
            this.selection.setMapControl(mc);
285
        }
286
    }
287

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

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

  
27
import java.awt.Component;
28
import java.awt.event.ActionEvent;
29
import java.util.Map;
30

  
31
import javax.swing.AbstractAction;
32
import javax.swing.JComponent;
33
import javax.swing.JOptionPane;
34
import javax.swing.JSeparator;
35
import javax.swing.SwingConstants;
36
import javax.swing.SwingUtilities;
37

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

  
41
import org.gvsig.tools.ToolsLocator;
42
import org.gvsig.tools.i18n.I18nManager;
43
import org.gvsig.tools.task.RunnableWithParameters;
44
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
45
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE;
46
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener;
47
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu;
48

  
49
/**
50
 * @author llmarques
51
 *
52
 */
53
public class DefaultEditingContextMenu extends EditingContextMenuView implements
54
EditingContextMenu {
55

  
56
    private static Logger logger = LoggerFactory
57
        .getLogger(DefaultEditingContextMenu.class);
58

  
59
    private static final long serialVersionUID = -3207749321400180897L;
60

  
61
    private AcceptValueListener listener;
62

  
63
    private Component parent;
64

  
65
    private EditingServiceParameter parameter;
66

  
67
    public DefaultEditingContextMenu(Component parent,
68
        AcceptValueListener listener, EditingServiceParameter parameter) {
69

  
70
        super();
71
        this.listener = listener;
72
        this.parent = parent;
73
        this.parameter = parameter;
74
        initActions();
75
    }
76

  
77
    @SuppressWarnings("serial")
78
    private void initActions() {
79

  
80
        I18nManager i18nManager = ToolsLocator.getI18nManager();
81
        AbstractAction action = null;
82

  
83
        for (final TYPE type : parameter.getTypes()) {
84

  
85
            switch (type) {
86
            case OPTION:
87
                Map<String, String> options = parameter.getOptions();
88
                for (String key : options.keySet()) {
89
                    String value = i18nManager.getTranslation(options.get(key));
90
                    action = new AbstractAction(value) {
91

  
92
                        public void actionPerformed(ActionEvent e) {
93
                            String key = (String) this.getValue("key");
94
                            listener.acceptValue(key);
95
                        }
96
                    };
97
                    action.putValue("key", key);
98
                    this.add(action);
99
                }
100
                break;
101
            case VALUE:
102
                String name =
103
                i18nManager.getTranslation(parameter.getName()) + " ("
104
                    + i18nManager.getTranslation("value") + ")";
105
                ;
106
                action = new AbstractAction(name) {
107

  
108
                    public void actionPerformed(ActionEvent e) {
109
                        String value = showValueDialog(parameter);
110
                        if (value != null) {
111
                            listener.acceptValue(value);
112
                        }
113
                    }
114
                };
115
                this.add(action);
116
                break;
117

  
118
            case POSITION:
119
            case LIST_POSITIONS:
120
                name =
121
                i18nManager.getTranslation(parameter.getName()) + " ("
122
                    + i18nManager.getTranslation("point") + ")";
123
                action = new AbstractAction(name) {
124

  
125
                    public void actionPerformed(ActionEvent e) {
126
                        String value = showPointDialog(parameter);
127
                        if (value != null) {
128
                            listener.acceptValue(value);
129
                        }
130
                    }
131
                };
132
                this.add(action);
133
                break;
134

  
135
            case SELECTION:
136
            case GEOMETRY:
137
                break;
138
            }
139

  
140
        }
141

  
142
        this.add(new JSeparator(SwingConstants.HORIZONTAL));
143
        action = new AbstractAction(i18nManager.getTranslation("cancel")) {
144

  
145
            public void actionPerformed(ActionEvent e) {
146
                listener.acceptValue(null);
147
//                setVisible(false);
148
            }
149
        };
150
        this.add(action);
151

  
152
        ((JComponent) parent).add(this);
153

  
154
    }
155

  
156
    public JComponent asJComponent() {
157
        return this;
158
    }
159

  
160
    private String showPointDialog(EditingServiceParameter parameter) {
161

  
162
        final DefaultEditingPointPanel pointPanel =
163
            new DefaultEditingPointPanel();
164

  
165
        final String title =
166
            ToolsLocator.getI18nManager().getTranslation(parameter.getName());
167

  
168
        RunnableWithParameters runnable = new RunnableWithParameters() {
169

  
170
            public void run() {
171
                this.returnValue =
172
                    JOptionPane.showConfirmDialog(null, pointPanel, title,
173
                        JOptionPane.OK_CANCEL_OPTION);
174
            }
175
        };
176
        if (SwingUtilities.isEventDispatchThread()) {
177
            runnable.run();
178
        } else {
179
            try {
180
                SwingUtilities.invokeAndWait(runnable);
181
            } catch (Exception e) {
182
                logger.info("Can't show point dialog.", e);
183
            }
184
        }
185

  
186
        int result = ((Integer) runnable.getReturnValue());
187

  
188
        if (result == JOptionPane.OK_OPTION) {
189
            String x = pointPanel.getXValue();
190
            String y = pointPanel.getYValue();
191

  
192
            StringBuilder stb = new StringBuilder();
193
            stb.append(x);
194
            stb.append(",");
195
            stb.append(y);
196

  
197
            return stb.toString();
198
        }
199

  
200
        return null;
201
    }
202

  
203
    private String showValueDialog(EditingServiceParameter parameter) {
204

  
205
        final DefaultEditingValuePanel valuePanel =
206
            new DefaultEditingValuePanel();
207

  
208
        final String title =
209
            ToolsLocator.getI18nManager().getTranslation(parameter.getName());
210

  
211
        RunnableWithParameters runnable = new RunnableWithParameters() {
212

  
213
            public void run() {
214
                this.returnValue =
215
                    JOptionPane.showConfirmDialog(null, valuePanel, title,
216
                        JOptionPane.OK_CANCEL_OPTION);
217
            }
218
        };
219

  
220
        if (SwingUtilities.isEventDispatchThread()) {
221
            runnable.run();
222
        } else {
223
            try {
224
                SwingUtilities.invokeAndWait(runnable);
225
            } catch (Exception e) {
226
                logger.info("Can't show value dialog.", e);
227
            }
228
        }
229

  
230
        int result = ((Integer) runnable.getReturnValue());
231

  
232
        if (result == JOptionPane.OK_OPTION) {
233
            return valuePanel.getValue();
234
        }
235

  
236
        return null;
237

  
238
    }
239

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

  
25
/* gvSIG. Desktop Geographic Information System.
26
 *
27
 * Copyright ? 2007-2014 gvSIG Association
28
 *
29
 * This program is free software; you can redistribute it and/or
30
 * modify it under the terms of the GNU General Public License
31
 * as published by the Free Software Foundation; either version 2
32
 * of the License, or (at your option) any later version.
33
 *
34
 * This program is distributed in the hope that it will be useful,
35
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
 * GNU General Public License for more details.
38
 *
39
 * You should have received a copy of the GNU General Public License
40
 * along with this program; if not, write to the Free Software
41
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
42
 * MA  02110-1301, USA.
43
 *
44
 * For any additional information, do not hesitate to contact us
45
 * at info AT gvsig.com, or visit our website www.gvsig.com.
46
 */
47
package org.gvsig.vectorediting.swing.impl.contextmenu;
48

  
49
import javax.swing.JComponent;
50

  
51
/**
52
 * @author llmarques
53
 *
54
 */
55
public class DefaultEditingPointPanel extends EditingPointPanelView {
56

  
57
    private static final long serialVersionUID = 6598180137544454743L;
58

  
59
    public DefaultEditingPointPanel() {
60
        super();
61
    }
62

  
63
    public JComponent asJComponent() {
64
        return this;
65
    }
66

  
67
    public String getXValue() {
68
        return getXTextField().getText();
69
    }
70

  
71
    public String getYValue() {
72
        return getYTextField().getText();
73
    }
74

  
75
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.17.1/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/contextmenu/DefaultEditingValuePanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 gvSIG Association
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff