Revision 18795
trunk/libraries/libUIComponent/src-test-ui/org/gvsig/gui/beans/comboboxconfigurablelookup/programmertests/SampleComboBoxEditor.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
*/ |
|
19 |
|
|
20 |
package org.gvsig.gui.beans.comboboxconfigurablelookup.programmertests; |
|
21 |
|
|
22 |
import java.awt.Component; |
|
23 |
import java.awt.event.ActionListener; |
|
24 |
import java.awt.event.FocusEvent; |
|
25 |
import java.awt.event.FocusListener; |
|
26 |
import java.lang.reflect.Method; |
|
27 |
|
|
28 |
import javax.swing.ComboBoxEditor; |
|
29 |
import javax.swing.JTextField; |
|
30 |
import javax.swing.border.Border; |
|
31 |
import javax.swing.plaf.basic.BasicComboBoxEditor; |
|
32 |
|
|
33 |
import org.gvsig.gui.beans.editabletextcomponent.JEditableTextField; |
|
34 |
|
|
35 |
/** |
|
36 |
* The default editor for editable combo boxes. The editor is implemented as a JTextField. |
|
37 |
* |
|
38 |
* @version 12/02/08 |
|
39 |
* @author Arnaud Weber |
|
40 |
* @author Mark Davidson |
|
41 |
* @author Pablo Piqueras Bartolom? |
|
42 |
*/ |
|
43 |
public class SampleComboBoxEditor implements ComboBoxEditor, FocusListener { |
|
44 |
protected JTextField editor; |
|
45 |
private Object oldValue; |
|
46 |
|
|
47 |
public SampleComboBoxEditor() { |
|
48 |
editor = new BorderlessTextField("",9); |
|
49 |
editor.setBorder(null); |
|
50 |
} |
|
51 |
|
|
52 |
public Component getEditorComponent() { |
|
53 |
return editor; |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Sets the item that should be edited. |
|
58 |
* |
|
59 |
* @param anObject the displayed value of the editor |
|
60 |
*/ |
|
61 |
public void setItem(Object anObject) { |
|
62 |
if ( anObject != null ) { |
|
63 |
editor.setText(anObject.toString()); |
|
64 |
|
|
65 |
oldValue = anObject; |
|
66 |
} else { |
|
67 |
editor.setText(""); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
public Object getItem() { |
|
72 |
Object newValue = editor.getText(); |
|
73 |
|
|
74 |
if (oldValue != null && !(oldValue instanceof String)) { |
|
75 |
// The original value is not a string. Should return the value in it's |
|
76 |
// original type. |
|
77 |
if (newValue.equals(oldValue.toString())) { |
|
78 |
return oldValue; |
|
79 |
} else { |
|
80 |
// Must take the value from the editor and get the value and cast it to the new type. |
|
81 |
Class cls = oldValue.getClass(); |
|
82 |
try { |
|
83 |
Method method = cls.getMethod("valueOf", new Class[]{String.class}); |
|
84 |
newValue = method.invoke(oldValue, new Object[] { editor.getText()}); |
|
85 |
} catch (Exception ex) { |
|
86 |
// Fail silently and return the newValue (a String object) |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
return newValue; |
|
91 |
} |
|
92 |
|
|
93 |
public void selectAll() { |
|
94 |
editor.selectAll(); |
|
95 |
editor.requestFocus(); |
|
96 |
} |
|
97 |
|
|
98 |
// This used to do something but now it doesn't. It couldn't be |
|
99 |
// removed because it would be an API change to do so. |
|
100 |
public void focusGained(FocusEvent e) {} |
|
101 |
|
|
102 |
// This used to do something but now it doesn't. It couldn't be |
|
103 |
// removed because it would be an API change to do so. |
|
104 |
public void focusLost(FocusEvent e) {} |
|
105 |
|
|
106 |
public void addActionListener(ActionListener l) { |
|
107 |
editor.addActionListener(l); |
|
108 |
} |
|
109 |
|
|
110 |
public void removeActionListener(ActionListener l) { |
|
111 |
editor.removeActionListener(l); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Inner text field editable as a component of a ComboBox editor. |
|
116 |
* |
|
117 |
* @see JEditableTextField |
|
118 |
* |
|
119 |
* @version 12/02/08 |
|
120 |
* @author Arnaud Weber |
|
121 |
* @author Mark Davidson |
|
122 |
* @author Pablo Piqueras Bartolom? |
|
123 |
*/ |
|
124 |
private class BorderlessTextField extends JEditableTextField { |
|
125 |
private static final long serialVersionUID = -3333236529430569318L; |
|
126 |
|
|
127 |
public BorderlessTextField(String value,int n) { |
|
128 |
super(value,n); |
|
129 |
} |
|
130 |
|
|
131 |
// workaround for 4530952 |
|
132 |
public void setText(String s) { |
|
133 |
if (getText().equals(s)) { |
|
134 |
return; |
|
135 |
} |
|
136 |
super.setText(s); |
|
137 |
} |
|
138 |
|
|
139 |
public void setBorder(Border b) {} |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* A subclass of BasicComboBoxEditor that implements UIResource. |
|
144 |
* BasicComboBoxEditor doesn't implement UIResource |
|
145 |
* directly so that applications can safely override the |
|
146 |
* cellRenderer property with BasicListCellRenderer subclasses. |
|
147 |
* <p> |
|
148 |
* <strong>Warning:</strong> |
|
149 |
* Serialized objects of this class will not be compatible with |
|
150 |
* future Swing releases. The current serialization support is |
|
151 |
* appropriate for short term storage or RMI between applications running |
|
152 |
* the same version of Swing. As of 1.4, support for long term storage |
|
153 |
* of all JavaBeans<sup><font size="-2">TM</font></sup> |
|
154 |
* has been added to the <code>java.beans</code> package. |
|
155 |
* Please see {@link java.beans.XMLEncoder}. |
|
156 |
*/ |
|
157 |
public static class UIResource extends BasicComboBoxEditor |
|
158 |
implements javax.swing.plaf.UIResource { |
|
159 |
} |
|
160 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/editabletextcomponent/event/UndoRedoEditEvent.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
*/ |
|
19 |
|
|
20 |
package org.gvsig.gui.beans.editabletextcomponent.event; |
|
21 |
|
|
22 |
|
|
23 |
/** |
|
24 |
* <p>An event indicating the kind of operation occurred: undo or redo.</p> |
|
25 |
* |
|
26 |
* @version 12/02/2008 |
|
27 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
28 |
*/ |
|
29 |
public class UndoRedoEditEvent extends java.util.EventObject { |
|
30 |
public static final short UNDO = 0; |
|
31 |
public static final short REDO = 1; |
|
32 |
|
|
33 |
private short myType; |
|
34 |
private String myOldText; |
|
35 |
private String myNewText; |
|
36 |
|
|
37 |
/** |
|
38 |
* Constructs an UndoableEditEvent object. |
|
39 |
* |
|
40 |
* @param source the Object that originated the event |
|
41 |
* (typically <code>this</code>) |
|
42 |
* @param type type of operation done <i>(undo or redo)</i> |
|
43 |
* @param oldText text before the operation |
|
44 |
* @param newText text after the operation |
|
45 |
*/ |
|
46 |
public UndoRedoEditEvent(Object source, short type, String oldText, String newText) { |
|
47 |
super(source); |
|
48 |
myType = type; |
|
49 |
myOldText = oldText; |
|
50 |
myNewText = newText; |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* Returns the edit operation identifier value. |
|
55 |
* |
|
56 |
* @return the UndoableEdit object encapsulating the edit |
|
57 |
*/ |
|
58 |
public short getType() { |
|
59 |
return myType; |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Returns the previous text. |
|
64 |
* |
|
65 |
* @return the previous text |
|
66 |
*/ |
|
67 |
public String getOldText() { |
|
68 |
return myOldText; |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Returns the new text. |
|
73 |
* |
|
74 |
* @return the new text |
|
75 |
*/ |
|
76 |
public String getNewText() { |
|
77 |
return myNewText; |
|
78 |
} |
|
79 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/editabletextcomponent/event/UndoRedoEditListener.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
*/ |
|
19 |
|
|
20 |
package org.gvsig.gui.beans.editabletextcomponent.event; |
|
21 |
|
|
22 |
import java.util.EventListener; |
|
23 |
|
|
24 |
/** |
|
25 |
* <p>The listener interface for receiving events from undo or redo operations on a text edition.</p> |
|
26 |
* |
|
27 |
* <p>The listener object created from that class is then registered with a |
|
28 |
* component using the component's <code>addUndoRedoEditListener</code> |
|
29 |
* method. An event of this kind of operations is generated when an <code>EditableTextDecorator</code> |
|
30 |
* executes an <code>undo</code> or <code>redo</code> operation. The relevant method in the listener |
|
31 |
* object is then invoked, and the <code>UndoRedoEditEvent</code> is passed to it.</p> |
|
32 |
* |
|
33 |
* @see UndoRedoEditEvent |
|
34 |
* |
|
35 |
* @version 12/02/2008 |
|
36 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
37 |
*/ |
|
38 |
public interface UndoRedoEditListener extends EventListener { |
|
39 |
/** |
|
40 |
* Invoked when an <i>undo</i> or <i>redo</i> operation has been executed. |
|
41 |
* See the class description for {@link UndoRedoEditEvent UndoRedoEditEvent} for a notification of |
|
42 |
* an <i>undo</i> or <i>redo</i> operation executed on an editable text component. |
|
43 |
*/ |
|
44 |
public void operationExecuted(UndoRedoEditEvent e); |
|
45 |
} |
Also available in: Unified diff