OSDN Git Service

version 2010-03-19
[cardregister/CardRegister.git] / src / hayashi / yuu / register / DeviceItem.java
1 package hayashi.yuu.register;
2
3 import java.awt.Dimension;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6
7 import javax.swing.JComponent;
8 import javax.swing.JLabel;
9 import javax.swing.JPanel;
10
11 /**
12  * public class PropertyItem extends JPanel implements ActionListener
13  * @author hayashi
14  *
15  */
16 public abstract class DeviceItem extends JPanel implements ActionListener
17 {
18         JLabel label;
19         JComponent field;
20         String value;           // 設定データを保持する領域
21         public static final int ITEM_WIDTH_1 = 120;
22         public static final int ITEM_WIDTH_2 = 80;
23     public static final int LINE_WIDTH = ITEM_WIDTH_1 + ITEM_WIDTH_2;
24     public static final int LINE_HEIGHT = 18;
25     
26     /**
27      * コンストラクタ
28      * @param prop2
29      * @param name
30      * @param editable
31      */
32         public DeviceItem(String name) {
33                 super(null);
34                 this.value = new String("");
35         }
36         
37         void createItem(String name, String value) {
38                 this.value = value;
39                 setupLabel(name, value);
40                 setupField(value);
41                 
42                 label.setBounds(0, 0, ITEM_WIDTH_1 - 6, LINE_HEIGHT);
43                 field.setBounds(ITEM_WIDTH_1, 0, ITEM_WIDTH_2, LINE_HEIGHT);
44                 setPreferredSize(new Dimension(ITEM_WIDTH_1, LINE_HEIGHT));
45         }
46         
47         JLabel setupLabel(String name, String value) {
48                 label = new JLabel(name, JLabel.RIGHT);
49                 add(label);
50                 return label;
51         }
52         
53         /**
54          * コーディング例:
55          * 
56          *      void setupField(String name, String value) {
57          *              this.value = value;
58          *              ((JTextField)field).setText(value);
59          *              field.setFont(new Font("MS UI Gothic", Font.PLAIN, 12));
60          *              add(field);
61          *      }
62          */
63         abstract void setupField(String value);
64
65         /**
66          * [反映]ボタンがクリックされたときの処理
67          *      
68          *      public void actionPerformed(ActionEvent e) {
69          *              GuardixMonitor.logger.fine("[反映] "+ label.getText() +" = "+ text.getText());
70          *              prop.setProperty(label.getText(), text.getText());
71          *      }
72          * @param e
73          */
74         public abstract void actionPerformed(ActionEvent e);
75 }