jsalvata 2004/01/14 06:11:20
Modified: src/core/org/apache/jmeter/testbeans/gui Tag:
testbeans_experimental_branch
ComboStringEditor.java
Log:
Fixed process of entering into Edit mode.
Revision Changes Path
No revision
No revision
1.1.2.2 +27 -24
jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/ComboStringEditor.java
Index: ComboStringEditor.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/ComboStringEditor.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- ComboStringEditor.java 14 Jan 2004 12:53:28 -0000 1.1.2.1
+++ ComboStringEditor.java 14 Jan 2004 14:11:20 -0000 1.1.2.2
@@ -112,11 +112,10 @@
private JComboBox combo;
private DefaultComboBoxModel model;
- private boolean processingItemEvent= false;
+ private boolean startingEdit= false;
/* True iif we're currently processing an event triggered by the user
- * selecting or entering a new value. Used to prevent touching at
- * GUI states outside of the event handling method -- otherwise it's
- * a mess.
+ * selecting the "Edit" option. Used to prevent reverting the combo
+ * to non-editable during processing of secondary events.
*/
private static final Object UNDEFINED=
@@ -185,14 +184,14 @@
*/
public void setAsText(String value)
{
- if (! processingItemEvent) combo.setEditable(true);
+ combo.setEditable(true);
if (value == null) combo.setSelectedItem(UNDEFINED);
else combo.setSelectedItem(value);
- if (combo.getSelectedIndex() >= 0)
+ if (! startingEdit && combo.getSelectedIndex() >= 0)
{
- if (! processingItemEvent) combo.setEditable(false);
+ combo.setEditable(false);
}
}
@@ -201,22 +200,23 @@
*/
public void itemStateChanged(ItemEvent e)
{
- processingItemEvent= true;
-
if (e.getStateChange() == ItemEvent.SELECTED)
{
if (e.getItem() == EDIT) {
- combo.setEditable(true);
+ startingEdit= true;
startEditing();
- }
- else if (combo.getSelectedIndex() >= 0)
+ startingEdit= false;
+ }
+ else
{
- combo.setEditable(false);
+ if (!startingEdit && combo.getSelectedIndex() >= 0)
+ {
+ combo.setEditable(false);
+ }
+
+ firePropertyChange();
}
- firePropertyChange();
}
-
- processingItemEvent= false;
}
private void startEditing()
@@ -224,15 +224,18 @@
JTextComponent textField=
(JTextComponent)combo.getEditor().getEditorComponent();
+ combo.setEditable(true);
+
textField.requestFocus();
- if (initialEditValue != null)
- {
- textField.setText(initialEditValue);
- int i= initialEditValue.indexOf("${}");
- if (i != -1) textField.setCaretPosition(i+2);
- else textField.selectAll();
- }
+ String text= initialEditValue;
+ if (initialEditValue == null) text= ""; // will revert to last valid
value if invalid
+
+ combo.setSelectedItem(text);
+
+ int i= text.indexOf("${}");
+ if (i != -1) textField.setCaretPosition(i+2);
+ else textField.selectAll();
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]