Revision 376
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/console/EditingConsole.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2015 gvSIG Association |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.vectorediting.swing.api.console; |
|
26 |
|
|
27 |
import org.gvsig.utils.console.ResponseListener; |
|
28 |
|
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @author llmarques |
|
33 |
* |
|
34 |
*/ |
|
35 |
public interface EditingConsole { |
|
36 |
|
|
37 |
/** |
|
38 |
* Gets response text typed by user |
|
39 |
* |
|
40 |
* @return |
|
41 |
*/ |
|
42 |
public String getResponseText(); |
|
43 |
|
|
44 |
/** |
|
45 |
* Clears console |
|
46 |
*/ |
|
47 |
public void clear(); |
|
48 |
|
|
49 |
/** |
|
50 |
* Adds text to console |
|
51 |
* |
|
52 |
* @param text |
|
53 |
*/ |
|
54 |
public void addText(String text); |
|
55 |
|
|
56 |
/** |
|
57 |
* Add text that is taken like text typed by user |
|
58 |
* |
|
59 |
* @param responseText |
|
60 |
*/ |
|
61 |
public void addResponseText(String responseText); |
|
62 |
|
|
63 |
/** |
|
64 |
* Adds the listener |
|
65 |
* |
|
66 |
* @param listener |
|
67 |
*/ |
|
68 |
public void addResponseListener(ResponseListener listener); |
|
69 |
|
|
70 |
/** |
|
71 |
* Removes the listener |
|
72 |
* |
|
73 |
* @param listener |
|
74 |
*/ |
|
75 |
public void removeResponseListener(ResponseListener listener); |
|
76 |
|
|
77 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingSwingManager.java | ||
---|---|---|
25 | 25 |
package org.gvsig.vectorediting.swing.api; |
26 | 26 |
|
27 | 27 |
import java.awt.Component; |
28 |
import java.util.List; |
|
28 | 29 |
|
29 | 30 |
import org.gvsig.fmap.mapcontrol.MapControl; |
30 | 31 |
import org.gvsig.tools.service.Manager; |
32 |
import org.gvsig.utils.console.ResponseListener; |
|
31 | 33 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
34 |
import org.gvsig.vectorediting.swing.api.console.EditingConsole; |
|
32 | 35 |
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener; |
33 | 36 |
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu; |
34 | 37 |
|
... | ... | |
76 | 79 |
EditingContextMenu getContextualMenu(Component parent, |
77 | 80 |
AcceptValueListener listener, EditingServiceParameter parameter); |
78 | 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); |
|
79 | 103 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingSwingManager.java | ||
---|---|---|
31 | 31 |
import java.awt.GridBagLayout; |
32 | 32 |
import java.awt.Insets; |
33 | 33 |
import java.util.HashMap; |
34 |
import java.util.List; |
|
34 | 35 |
import java.util.Map; |
35 | 36 |
|
36 | 37 |
import javax.swing.JLabel; |
... | ... | |
45 | 46 |
import org.gvsig.tools.service.AbstractManager; |
46 | 47 |
import org.gvsig.tools.service.Service; |
47 | 48 |
import org.gvsig.tools.service.ServiceException; |
49 |
import org.gvsig.utils.console.ResponseListener; |
|
48 | 50 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
49 | 51 |
import org.gvsig.vectorediting.lib.impl.DefaultEditingProviderManager; |
50 | 52 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
51 | 53 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
54 |
import org.gvsig.vectorediting.swing.api.console.EditingConsole; |
|
52 | 55 |
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener; |
53 | 56 |
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu; |
57 |
import org.gvsig.vectorediting.swing.impl.console.DefaultEditingConsole; |
|
54 | 58 |
import org.gvsig.vectorediting.swing.impl.contextmenu.DefaultEditingContextMenu; |
55 | 59 |
|
56 | 60 |
public class DefaultEditingSwingManager extends AbstractManager implements |
... | ... | |
219 | 223 |
|
220 | 224 |
return contextMenu; |
221 | 225 |
} |
226 |
|
|
227 |
public EditingConsole getEditingConsole(ResponseListener listener) { |
|
228 |
return new DefaultEditingConsole(listener); |
|
229 |
} |
|
230 |
|
|
231 |
public EditingConsole getEditingConsole(List<ResponseListener> listeners) { |
|
232 |
return new DefaultEditingConsole(listeners); |
|
233 |
} |
|
222 | 234 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingContext.java | ||
---|---|---|
34 | 34 |
import java.util.prefs.PreferenceChangeListener; |
35 | 35 |
import java.util.prefs.Preferences; |
36 | 36 |
|
37 |
import javax.swing.JComponent; |
|
38 |
|
|
37 | 39 |
import org.slf4j.Logger; |
38 | 40 |
import org.slf4j.LoggerFactory; |
39 | 41 |
|
... | ... | |
66 | 68 |
import org.gvsig.tools.observer.Notification; |
67 | 69 |
import org.gvsig.tools.observer.ObservableHelper; |
68 | 70 |
import org.gvsig.tools.observer.Observer; |
69 |
import org.gvsig.utils.console.JConsole; |
|
70 | 71 |
import org.gvsig.utils.console.JDockPanel; |
71 | 72 |
import org.gvsig.utils.console.ResponseListener; |
72 |
import org.gvsig.utils.console.jedit.JEditTextArea; |
|
73 | 73 |
import org.gvsig.vectorediting.lib.api.EditingLocator; |
74 | 74 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
75 | 75 |
import org.gvsig.vectorediting.lib.api.EditingService; |
... | ... | |
89 | 89 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
90 | 90 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator; |
91 | 91 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
92 |
import org.gvsig.vectorediting.swing.api.console.EditingConsole; |
|
93 |
import org.gvsig.vectorediting.swing.impl.console.DefaultEditingConsole; |
|
92 | 94 |
|
93 | 95 |
public class DefaultEditingContext implements EditingContext { |
94 | 96 |
|
... | ... | |
105 | 107 |
|
106 | 108 |
private ObservableHelper observableHelper; |
107 | 109 |
|
108 |
private JConsole console;
|
|
110 |
private EditingConsole console;
|
|
109 | 111 |
|
110 | 112 |
private JDockPanel dockConsole = null; |
111 | 113 |
|
... | ... | |
131 | 133 |
try { |
132 | 134 |
getMapControl().setTool("VectorEditing"); |
133 | 135 |
} catch (RuntimeException e2) { |
134 |
logger |
|
135 |
.warn( |
|
136 |
"Can't set tool VectorEditing. Perhaps the old edition has begun.", |
|
137 |
e2); |
|
136 |
logger.warn( |
|
137 |
"Can't set tool VectorEditing. Perhaps the old" |
|
138 |
+ " edition has begun.", e2); |
|
138 | 139 |
return; |
139 | 140 |
} |
140 | 141 |
showConsole(); |
... | ... | |
185 | 186 |
|
186 | 187 |
addLayerListeners(); |
187 | 188 |
addPreferenceListener(); |
188 |
addConsolePanelListeners(getConsolePanel()); |
|
189 | 189 |
} |
190 | 190 |
|
191 | 191 |
private void addPreferenceListener() { |
... | ... | |
229 | 229 |
} catch (InvalidEntryException e) { |
230 | 230 |
|
231 | 231 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
232 |
showConsoleMessage(i18nManager
|
|
233 |
.getTranslation("invalid_option")); |
|
232 |
showConsoleMessage("\n"
|
|
233 |
+ i18nManager.getTranslation("invalid_option"));
|
|
234 | 234 |
} |
235 | 235 |
|
236 | 236 |
if (!serviceStack.isEmpty() |
... | ... | |
290 | 290 |
|
291 | 291 |
} |
292 | 292 |
|
293 |
private void addConsolePanelListeners(JConsole jConsole) { |
|
294 |
jConsole.addResponseListener(new ResponseListener() { |
|
295 |
|
|
296 |
public void acceptResponse(String response) { |
|
297 |
textEntered(response); |
|
298 |
} |
|
299 |
}); |
|
300 |
} |
|
301 |
|
|
302 | 293 |
private void addLayerListeners() { |
303 | 294 |
|
304 | 295 |
FLayers layers = mapContext.getLayers(); |
... | ... | |
615 | 606 |
|
616 | 607 |
} catch (InvalidEntryException ex) { |
617 | 608 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
618 |
showConsoleMessage(i18nManager.getTranslation("invalid_option")); |
|
609 |
showConsoleMessage("\n" |
|
610 |
+ i18nManager.getTranslation("invalid_option")); |
|
619 | 611 |
changeSelectedTool(getActiveService().getName()); |
620 | 612 |
} catch (VectorEditingException ex) { |
621 | 613 |
logger.info("Can't finish " + lastService.getName(), ex); |
... | ... | |
633 | 625 |
return null; |
634 | 626 |
} |
635 | 627 |
|
636 |
private JConsole getConsolePanel() {
|
|
628 |
private EditingConsole getConsolePanel() {
|
|
637 | 629 |
if (console == null) { |
638 |
console = new JConsole(true); |
|
639 |
// Para distinguir cuando se est? escribiendo sobre la consola y |
|
640 |
// cuando no. |
|
641 |
console.setJTextName("VectorEditingConsole"); |
|
630 |
console = new DefaultEditingConsole(new ResponseListener() { |
|
631 |
|
|
632 |
public void acceptResponse(String response) { |
|
633 |
textEntered(response); |
|
634 |
} |
|
635 |
}); |
|
642 | 636 |
} |
643 | 637 |
return console; |
644 | 638 |
} |
... | ... | |
653 | 647 |
|
654 | 648 |
private Component getDockConsole() { |
655 | 649 |
if (dockConsole == null) { |
656 |
dockConsole = new JDockPanel(getConsolePanel()); |
|
650 |
dockConsole = new JDockPanel((JComponent) getConsolePanel());
|
|
657 | 651 |
} |
658 | 652 |
return dockConsole; |
659 | 653 |
} |
... | ... | |
859 | 853 |
serviceStack.add(service); |
860 | 854 |
} |
861 | 855 |
|
862 |
private void setCaretPosition() { |
|
863 |
JEditTextArea jeta = getConsolePanel().getTxt(); |
|
864 |
jeta.requestFocusInWindow(); |
|
865 |
jeta.setCaretPosition(jeta.getText().length()); |
|
866 |
} |
|
867 |
|
|
868 | 856 |
private void setCompoundBehavior(EditingCompoundBehavior compoundBehavior) { |
869 | 857 |
this.editingCompoundBehavior = compoundBehavior; |
870 | 858 |
} |
... | ... | |
905 | 893 |
getMapControl().setLayout(new BorderLayout()); |
906 | 894 |
getMapControl().add(getDockConsole(), BorderLayout.SOUTH); |
907 | 895 |
getDockConsole().setVisible(true); |
908 |
setCaretPosition(); |
|
909 | 896 |
} |
910 | 897 |
|
911 | 898 |
protected void showConsoleMessage(String text) { |
912 |
getConsolePanel().addText(text, JConsole.MESSAGE);
|
|
899 |
getConsolePanel().addText(text); |
|
913 | 900 |
} |
914 | 901 |
|
915 | 902 |
protected void textEntered(String response) { |
... | ... | |
1010 | 997 |
} catch (InvalidEntryException e) { |
1011 | 998 |
I18nManager i18nManager = |
1012 | 999 |
ToolsLocator.getI18nManager(); |
1013 |
showConsoleMessage(i18nManager
|
|
1014 |
.getTranslation("invalid_option")); |
|
1000 |
showConsoleMessage("\n"
|
|
1001 |
+ i18nManager.getTranslation("invalid_option"));
|
|
1015 | 1002 |
} catch (Exception e) { |
1016 | 1003 |
logger.info("Can't access to selecction.", e); |
1017 | 1004 |
cleanEditingContext(); |
... | ... | |
1021 | 1008 |
} |
1022 | 1009 |
if (!insertedValue) { |
1023 | 1010 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
1024 |
showConsoleMessage(i18nManager
|
|
1025 |
.getTranslation("invalid_option")); |
|
1011 |
showConsoleMessage("\n"
|
|
1012 |
+ i18nManager.getTranslation("invalid_option"));
|
|
1026 | 1013 |
} |
1027 | 1014 |
getNextParameter(); |
1028 | 1015 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/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 |
|
|
121 |
} |
|
122 |
|
|
123 |
public String getResponseText() { |
|
124 |
return getTextArea().getText().substring(startingCaretPosition, |
|
125 |
getTextArea().getText().length()); |
|
126 |
} |
|
127 |
|
|
128 |
public void addText(String text) { |
|
129 |
getTextArea().setText(getTextArea().getText() + text); |
|
130 |
getTextArea().setCaretPosition(getTextArea().getText().length()); |
|
131 |
startingCaretPosition = getTextArea().getText().length(); |
|
132 |
getTextArea().setNavigationFilter( |
|
133 |
new DefaultEditingNavigationFilter(startingCaretPosition)); |
|
134 |
} |
|
135 |
|
|
136 |
public void addResponseText(String responseText) { |
|
137 |
getTextArea().setText(getTextArea().getText() + responseText); |
|
138 |
getTextArea().setCaretPosition(getTextArea().getText().length()); |
|
139 |
} |
|
140 |
|
|
141 |
public void addResponseListener(ResponseListener listener) { |
|
142 |
this.responseListenerSupport.addResponseListener(listener); |
|
143 |
} |
|
144 |
|
|
145 |
public void removeResponseListener(ResponseListener listener) { |
|
146 |
this.responseListenerSupport.removeResponseListener(listener); |
|
147 |
} |
|
148 |
|
|
149 |
private void callResponseListener(String response) { |
|
150 |
this.responseListenerSupport.callAcceptResponse(response); |
|
151 |
} |
|
152 |
|
|
153 |
public void clear() { |
|
154 |
getTextArea().setText(null); |
|
155 |
} |
|
156 |
|
|
157 |
@SuppressWarnings("serial") |
|
158 |
private Action enterAction = new AbstractAction() { |
|
159 |
|
|
160 |
public void actionPerformed(ActionEvent e) { |
|
161 |
callResponseListener(getResponseText() + "\n"); |
|
162 |
} |
|
163 |
}; |
|
164 |
|
|
165 |
@SuppressWarnings("serial") |
|
166 |
private Action escAction = new AbstractAction() { |
|
167 |
|
|
168 |
public void actionPerformed(ActionEvent e) { |
|
169 |
callResponseListener(null); |
|
170 |
} |
|
171 |
}; |
|
172 |
|
|
173 |
@SuppressWarnings("serial") |
|
174 |
private Action backSpaceAction = new AbstractAction() { |
|
175 |
|
|
176 |
public void actionPerformed(ActionEvent e) { |
|
177 |
if (getTextArea().getCaretPosition() > startingCaretPosition) { |
|
178 |
StringBuilder stb = new StringBuilder(getTextArea().getText()); |
|
179 |
stb.deleteCharAt(getTextArea().getText().length() - 1); |
|
180 |
getTextArea().setText(stb.toString()); |
|
181 |
} |
|
182 |
} |
|
183 |
}; |
|
184 |
|
|
185 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/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/trunk/org.gvsig.vectorediting/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 |
} |
Also available in: Unified diff