components/visual-panels/core/src/java/util/com/oracle/solaris/vp/util/swing/property/PasswordFieldPropertySynchronizer.java
equal
deleted
inserted
replaced
18 * |
18 * |
19 * CDDL HEADER END |
19 * CDDL HEADER END |
20 */ |
20 */ |
21 |
21 |
22 /* |
22 /* |
23 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
23 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
24 */ |
24 */ |
25 |
25 |
26 package com.oracle.solaris.vp.util.swing.property; |
26 package com.oracle.solaris.vp.util.swing.property; |
27 |
27 |
28 import javax.swing.JPasswordField; |
28 import javax.swing.JPasswordField; |
34 * The {@code PasswordFieldPropertySynchronizer} class synchronizes a {@link |
34 * The {@code PasswordFieldPropertySynchronizer} class synchronizes a {@link |
35 * MutableProperty} with a {@code JPasswordField} so that changes in one will |
35 * MutableProperty} with a {@code JPasswordField} so that changes in one will |
36 * automatically be reflected in the other. |
36 * automatically be reflected in the other. |
37 */ |
37 */ |
38 public class PasswordFieldPropertySynchronizer |
38 public class PasswordFieldPropertySynchronizer |
39 extends PropertySynchronizer<char[], JPasswordField> { |
39 extends PropertySynchronizer<String, JPasswordField> { |
40 |
40 |
41 // |
41 // |
42 // Instance data |
42 // Instance data |
43 // |
43 // |
44 |
44 |
52 |
52 |
53 // |
53 // |
54 // Constructors |
54 // Constructors |
55 // |
55 // |
56 |
56 |
57 public PasswordFieldPropertySynchronizer(MutableProperty<char[]> property, |
57 public PasswordFieldPropertySynchronizer(MutableProperty<String> property, |
58 JPasswordField field, boolean initFromProp) { |
58 JPasswordField field, boolean initFromProp) { |
59 |
59 |
60 super(property, field, initFromProp); |
60 super(property, field, initFromProp); |
61 field.getDocument().addDocumentListener(listener); |
61 field.getDocument().addDocumentListener(listener); |
62 } |
62 } |
63 |
63 |
64 /** |
64 /** |
65 * Constructs a {@code PasswordFieldPropertySynchronizer} with initial |
65 * Constructs a {@code PasswordFieldPropertySynchronizer} with initial |
66 * synchronization from the property to the {@code JPasswordField}. |
66 * synchronization from the property to the {@code JPasswordField}. |
67 */ |
67 */ |
68 public PasswordFieldPropertySynchronizer(MutableProperty<char[]> property, |
68 public PasswordFieldPropertySynchronizer(MutableProperty<String> property, |
69 JPasswordField field) { |
69 JPasswordField field) { |
70 |
70 |
71 this(property, field, true); |
71 this(property, field, true); |
72 } |
72 } |
73 |
73 |
80 super.desynchronize(); |
80 super.desynchronize(); |
81 getObject().getDocument().removeDocumentListener(listener); |
81 getObject().getDocument().removeDocumentListener(listener); |
82 } |
82 } |
83 |
83 |
84 @Override |
84 @Override |
85 public char[] getValue() { |
85 public String getValue() { |
86 return getObject().getPassword(); |
86 return new String(getObject().getPassword()); |
87 } |
87 } |
88 |
88 |
89 @Override |
89 @Override |
90 public void setValue(char[] value) { |
90 public void setValue(String value) { |
91 String text = value == null ? "" : new String(value); |
91 String text = value == null ? "" : new String(value); |
92 getObject().setText(text); |
92 getObject().setText(text); |
93 } |
93 } |
94 } |
94 } |