OSDN Git Service

2019-02-11
[hayashilib/hayashi.git] / src / hayashi / yuu / tools / properties / PropertyPasswordItem.java
1 package hayashi.yuu.tools.properties;\r
2 \r
3 import java.awt.event.ActionEvent;\r
4 import java.awt.event.FocusEvent;\r
5 import java.awt.event.FocusListener;\r
6 import javax.swing.JPasswordField;\r
7 \r
8 @SuppressWarnings("serial")\r
9 public class PropertyPasswordItem extends PropertyItem implements FocusListener\r
10 {\r
11         public PropertyPasswordItem(hayashi.yuu.tools.properties.Properties prop, String name, String title, boolean editable) {\r
12                 super(prop, name, title);\r
13                 field = new JPasswordField(value, 20);\r
14                 ((JPasswordField)field).addFocusListener(this);\r
15                 createItem(name, title, prop.getProperty(name), editable);\r
16         }\r
17 \r
18         @Override\r
19         void setupField(String name, String value, boolean editable) {\r
20                 this.value = value;\r
21                 ((JPasswordField)field).setText(value);\r
22                 if (!editable) {\r
23                         field.setEnabled(editable);\r
24                 }\r
25                 add(field);\r
26         }\r
27         \r
28         @Override\r
29         public void actionPerformed(ActionEvent e) {\r
30                 char[] chars = ((JPasswordField)this.field).getPassword();\r
31                 this.value = new String(chars);\r
32                 logger.info("[反映] "+ propertyName +" = "+ this.value);\r
33                 prop.setProperty(propertyName, this.value);\r
34         }\r
35 \r
36         /**\r
37          * このフィールドにカーソルが移ったときの処理\r
38          */\r
39         public void focusGained(FocusEvent arg0) {\r
40                 // 何もしない\r
41         }\r
42 \r
43         /**\r
44          * このフィールドから他のフィールドへカーソルが移った時の処理。\r
45          */\r
46         public void focusLost(FocusEvent arg0) {\r
47                 actionPerformed(null);\r
48         }\r
49 }\r