From 91c4164abf42bbfceb2c31948f3af09ef022843f Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 05 Jun 2007 14:56:34 +0000
Subject: [PATCH] Fix for issue 1634 (select text field content upon tab into).

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java
index 7da1f9d..afe891d 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java
@@ -34,6 +34,8 @@
 import java.awt.Insets;
 import java.awt.Rectangle;
 import java.awt.Toolkit;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.HashMap;
@@ -834,6 +836,7 @@
   {
     JTextField f = new JTextField();
     updateTextFieldComponent(f, text, tooltip, size, style);
+    f.addFocusListener(new TextFieldFocusListener(f));
     return f;
   }
 
@@ -852,6 +855,7 @@
   {
     JPasswordField f = new JPasswordField();
     updateTextFieldComponent(f, text, tooltip, size, style);
+    f.addFocusListener(new TextFieldFocusListener(f));
     return f;
   }
 
@@ -1775,3 +1779,44 @@
     }
   }
 }
+
+/**
+ * A class used to be able to select the contents of the text field when
+ * it gets the focus.
+ *
+ */
+class TextFieldFocusListener implements FocusListener
+{
+  private JTextField tf;
+  /**
+   * The constructor for this listener.
+   * @param tf the text field associated with this listener.
+   */
+  TextFieldFocusListener(JTextField tf)
+  {
+    this.tf = tf;
+  }
+  /**
+   * {@inheritDoc}
+   */
+  public void focusGained(FocusEvent e)
+  {
+    if ((tf.getText() == null) || "".equals(tf.getText()))
+    {
+      tf.setText(" ");
+      tf.selectAll();
+      tf.setText("");
+    }
+    else
+    {
+      tf.selectAll();
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public void focusLost(FocusEvent e)
+  {
+  }
+}

--
Gitblit v1.10.0