OSDN Git Service

d10f634d0cb5b36567306fa01b556fb836e43524
[tainavi/TinyBannavi.git] / TinyBannavi / src / tainavi / JComboBoxPanel.java
1 package tainavi;\r
2 \r
3 import java.awt.ItemSelectable;\r
4 import java.awt.event.ActionListener;\r
5 import java.awt.event.ItemListener;\r
6 \r
7 import javax.swing.ComboBoxModel;\r
8 import javax.swing.JComboBox;\r
9 import javax.swing.JLabel;\r
10 import javax.swing.JPanel;\r
11 import javax.swing.SpringLayout;\r
12 \r
13 \r
14 public class JComboBoxPanel extends JPanel implements ItemSelectable,WideComponent {\r
15 \r
16         private static final long serialVersionUID = 1L;\r
17 \r
18         private JComboBoxWithPopup jcombobox = null;\r
19         private JLabel jlabel = null;\r
20         \r
21         // 旧版\r
22         public JComboBoxPanel(String s, int labelWidth, int comboboxWidth) {\r
23                 super();\r
24                 makeComboBoxPanel(s, labelWidth, false);\r
25         }\r
26 \r
27         // 新版\r
28         public JComboBoxPanel(String s, int labelWidth, int comboboxWidth, boolean horizontal) {\r
29                 super();\r
30                 makeComboBoxPanel(s, labelWidth, horizontal);\r
31         }\r
32         \r
33         private void makeComboBoxPanel(String s, int labelWidth, boolean horizontal) {\r
34                 \r
35                 SpringLayout layout = new SpringLayout();\r
36                 setLayout(layout);\r
37                 \r
38                 jlabel = new JLabel(s);\r
39                 jcombobox = new JComboBoxWithPopup();\r
40 \r
41                 this.add(jlabel);\r
42                 this.add(jcombobox);\r
43                 \r
44                 if ( horizontal == true ) {\r
45                         // 左・右\r
46                         layout.putConstraint(SpringLayout.NORTH, jlabel, 1, SpringLayout.NORTH, this);\r
47                         layout.putConstraint(SpringLayout.WEST, jlabel, 1, SpringLayout.WEST, this);\r
48                         layout.putConstraint(SpringLayout.SOUTH, jlabel, -1, SpringLayout.SOUTH, this);\r
49                         layout.putConstraint(SpringLayout.EAST, jlabel, labelWidth, SpringLayout.WEST, this);\r
50                         \r
51                         layout.putConstraint(SpringLayout.NORTH, jcombobox, 1, SpringLayout.NORTH, this);\r
52                         layout.putConstraint(SpringLayout.WEST, jcombobox, 0, SpringLayout.EAST, jlabel);\r
53                         layout.putConstraint(SpringLayout.SOUTH, jcombobox, -1, SpringLayout.SOUTH, this);\r
54                         layout.putConstraint(SpringLayout.EAST, jcombobox, -1, SpringLayout.EAST, this);\r
55                 }\r
56                 else {\r
57                         // 上・下\r
58                         layout.putConstraint(SpringLayout.NORTH, jlabel, 1, SpringLayout.NORTH, this);\r
59                         layout.putConstraint(SpringLayout.WEST, jlabel, 1, SpringLayout.WEST, this);\r
60                         //\r
61                         layout.putConstraint(SpringLayout.EAST, jlabel, -1, SpringLayout.EAST, this);\r
62                         \r
63                         layout.putConstraint(SpringLayout.NORTH, jcombobox, 1, SpringLayout.SOUTH, jlabel);\r
64                         layout.putConstraint(SpringLayout.WEST, jcombobox, 5, SpringLayout.NORTH, this);\r
65                         layout.putConstraint(SpringLayout.SOUTH, jcombobox, -1, SpringLayout.SOUTH, this);\r
66                         layout.putConstraint(SpringLayout.EAST, jcombobox, -1, SpringLayout.EAST, this);\r
67                 }\r
68         }\r
69 \r
70         public void removeAllItems() {\r
71                 this.jcombobox.removeAllItems();\r
72         }\r
73         \r
74         public void removeItemAt(int anIndex) {\r
75                 this.jcombobox.removeItemAt(anIndex);\r
76         }\r
77         \r
78         public void insertItemAt(Object anObject, int index) {\r
79                 this.jcombobox.insertItemAt(anObject, index);\r
80         }\r
81         \r
82         public void addItem(Object o) {\r
83                 this.jcombobox.addItem(o);\r
84         }\r
85         \r
86         public int getSelectedIndex() {\r
87                 return this.jcombobox.getSelectedIndex();\r
88         }\r
89         public Object getSelectedItem() {\r
90                 return this.jcombobox.getSelectedItem();\r
91         }\r
92         public Object getItemAt(int index) {\r
93                 return this.jcombobox.getItemAt(index);\r
94         }\r
95         \r
96         public int getItemCount() {\r
97                 return this.jcombobox.getItemCount();\r
98         }\r
99         \r
100         public int indexOf(Object o) {\r
101                 return this.jcombobox.indexOf(o);\r
102         }\r
103         \r
104         public void setSelectedItem(Object o) {\r
105                 this.jcombobox.setSelectedItem(o);\r
106         }\r
107         public void setSelectedIndex(int anIndex) {\r
108                 this.jcombobox.setSelectedIndex(anIndex);\r
109         }\r
110         \r
111         public void setEditable(boolean b) {\r
112                 this.jcombobox.setEditable(b);\r
113         }\r
114         \r
115         @Override\r
116         public void setEnabled(boolean b) {\r
117                 this.jlabel.setEnabled(b);\r
118                 this.jcombobox.setEnabled(b);\r
119         }\r
120         @Override\r
121         public boolean isEnabled() {\r
122                 return this.jcombobox.isEnabled();\r
123         }\r
124         \r
125         public void setToolTipText(String s) {\r
126                 this.jlabel.setToolTipText(s);\r
127         }\r
128         \r
129         public void setText(String s) {\r
130                 this.jlabel.setText(s);\r
131         }\r
132         \r
133         public ComboBoxModel getModel() {\r
134                 return this.jcombobox.getModel();\r
135         }\r
136 \r
137         public JComboBox getJComboBox() { return jcombobox; }\r
138 \r
139         // オーバーライドではない\r
140         \r
141         public void addActionListener(ActionListener l) {\r
142                 this.jcombobox.addActionListener(l);\r
143         }\r
144         \r
145         /*\r
146         public ActionListener[] getActionListeners() {\r
147                 return this.jcombobox.getActionListeners();\r
148         }\r
149         */\r
150         \r
151         public void removeActionListener(ActionListener l) {\r
152                 this.jcombobox.removeActionListener(l);\r
153         }\r
154         \r
155         // オーバーライド\r
156 \r
157         @Override\r
158         public void addPopupWidth(int w) {\r
159                 this.jcombobox.addPopupWidth(w);\r
160         }\r
161         \r
162         @Override\r
163         public void addItemListener(ItemListener l) {\r
164                 this.jcombobox.addItemListener(l);\r
165         }\r
166 \r
167         @Override\r
168         public Object[] getSelectedObjects() {\r
169                 return this.jcombobox.getSelectedObjects();\r
170         }\r
171 \r
172         @Override\r
173         public void removeItemListener(ItemListener l) {\r
174                 this.jcombobox.removeItemListener(l);\r
175         }\r
176 }\r