You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2006/03/05 19:58:14 UTC
svn commit: r383367 -
/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/PasswordEditor.java
Author: sebb
Date: Sun Mar 5 10:58:11 2006
New Revision: 383367
URL: http://svn.apache.org/viewcvs?rev=383367&view=rev
Log:
Add Password editor for TestBean support
Added:
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/PasswordEditor.java (with props)
Added: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/PasswordEditor.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/PasswordEditor.java?rev=383367&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/PasswordEditor.java (added)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/PasswordEditor.java Sun Mar 5 10:58:11 2006
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jmeter.testbeans.gui;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.beans.PropertyEditorSupport;
+
+import javax.swing.JPasswordField;
+
+/**
+ * This class implements a property editor for non-null String properties that
+ * supports custom editing (i.e.: provides a GUI component) based on a text
+ * field.
+ * <p>
+ * The provided GUI is a simple password field.
+ *
+ */
+public class PasswordEditor extends PropertyEditorSupport implements ActionListener, FocusListener {
+
+ private JPasswordField textField;
+
+ /**
+ * Value on which we started the editing. Used to avoid firing
+ * PropertyChanged events when there's not been such change.
+ */
+ private String initialValue = "";
+
+ protected PasswordEditor() {
+ super();
+
+ textField = new JPasswordField();
+ textField.addActionListener(this);
+ textField.addFocusListener(this);
+ }
+
+ public String getAsText() {
+ return textField.getPassword().toString();
+ }
+
+ public void setAsText(String value) {
+ initialValue = value;
+ textField.setText(value);
+ }
+
+ public Object getValue() {
+ return getAsText();
+ }
+
+ public void setValue(Object value) {
+ if (value instanceof String)
+ setAsText((String) value);
+ else
+ throw new IllegalArgumentException();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.beans.PropertyEditor#getCustomEditor()
+ */
+ public Component getCustomEditor() {
+ return textField;
+ }
+
+ public boolean supportsCustomEditor() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc) Avoid needlessly firing PropertyChanged events.
+ */
+ public void firePropertyChange() {
+ String newValue = getAsText();
+
+ if (initialValue.equals(newValue))
+ return;
+ initialValue = newValue;
+
+ super.firePropertyChange();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent e) {
+ firePropertyChange();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
+ */
+ public void focusGained(FocusEvent e) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
+ */
+ public void focusLost(FocusEvent e) {
+ firePropertyChange();
+ }
+}
\ No newline at end of file
Propchange: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/PasswordEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/PasswordEditor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/testbeans/gui/PasswordEditor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org