Newer
Older
CardRegister / src / hayashi / yuu / register / DeviceItem.java
@yuuhayashi yuuhayashi on 26 Jan 2014 1 KB version 2010-03-19
  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. * @param prop2
  28. * @param name
  29. * @param editable
  30. */
  31. public DeviceItem(String name) {
  32. super(null);
  33. this.value = new String("");
  34. }
  35. void createItem(String name, String value) {
  36. this.value = value;
  37. setupLabel(name, value);
  38. setupField(value);
  39. label.setBounds(0, 0, ITEM_WIDTH_1 - 6, LINE_HEIGHT);
  40. field.setBounds(ITEM_WIDTH_1, 0, ITEM_WIDTH_2, LINE_HEIGHT);
  41. setPreferredSize(new Dimension(ITEM_WIDTH_1, LINE_HEIGHT));
  42. }
  43. JLabel setupLabel(String name, String value) {
  44. label = new JLabel(name, JLabel.RIGHT);
  45. add(label);
  46. return label;
  47. }
  48. /**
  49. * コーディング例:
  50. *
  51. * void setupField(String name, String value) {
  52. * this.value = value;
  53. * ((JTextField)field).setText(value);
  54. * field.setFont(new Font("MS UI Gothic", Font.PLAIN, 12));
  55. * add(field);
  56. * }
  57. */
  58. abstract void setupField(String value);
  59.  
  60. /**
  61. * [反映]ボタンがクリックされたときの処理
  62. *
  63. * public void actionPerformed(ActionEvent e) {
  64. * GuardixMonitor.logger.fine("[反映] "+ label.getText() +" = "+ text.getText());
  65. * prop.setProperty(label.getText(), text.getText());
  66. * }
  67. * @param e
  68. */
  69. public abstract void actionPerformed(ActionEvent e);
  70. }