01: /*
02: * Copyright 2005 Paul Hinds
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.tp23.antinstaller.renderer.swing;
17:
18: import java.awt.event.ActionEvent;
19: import java.awt.event.ActionListener;
20:
21: import javax.swing.JLabel;
22: import javax.swing.JPanel;
23:
24: import org.tp23.antinstaller.input.CheckboxInput;
25: import org.tp23.antinstaller.input.InputField;
26: import org.tp23.antinstaller.input.OutputField;
27: import org.tp23.gui.GBCF;
28:
29: public class CheckboxInputRenderer extends SwingOutputFieldRenderer {
30:
31: protected CheckboxInput inputField;
32:
33: protected JLabel fieldLabel = new AILabel();
34: protected AICheckBox checkBox = new AICheckBox();
35:
36: public CheckboxInputRenderer() {
37: }
38:
39: public void initComponent(JPanel parent) {
40: try {
41: jbInit();
42: } catch (Exception e) {
43: e.printStackTrace();
44: }
45: }
46:
47: public void setOutputField(OutputField inputField) {
48: this .inputField = (CheckboxInput) inputField;
49: }
50:
51: public void updateInputField() {
52: boolean selected = checkBox.isSelected();
53: if (selected)
54: inputField.setValue("true");
55: else
56: inputField.setValue("false");
57: }
58:
59: public void updateDefaultValue() {
60: if (!inputField.isEditted()) {
61: String newDefault = inputField.getDefaultValue();
62: checkBox.setSelected(InputField.isTrue(newDefault));
63: }
64: }
65:
66: private void jbInit() throws Exception {
67: fieldLabel.setText(inputField.getDisplayText());
68: checkBox.setSelected(OutputField.isTrue(inputField
69: .getDefaultValue()));
70: checkBox.setEnabled(!OutputField.isTrue(inputField.getForce()));
71: checkBox.addActionListener(new ActionListener() {
72: public void actionPerformed(ActionEvent e) {
73: updateInputField();
74: inputField.setEditted(true);
75: }
76: });
77: }
78:
79: public int addSelf(JPanel content, GBCF cf, int row,
80: boolean overflow) {
81: content.add(fieldLabel, cf.getCell(row, 0));
82: content.add(checkBox, cf.getCell(row, 1));
83: if (overflow) {
84: checkBox.setOverflow(SizeConstants.OVERFLOW_FIELD_SIZE);
85: }
86: return ++row;
87: }
88:
89: /**
90: * renderError
91: */
92: public void renderError() {
93: }
94: }
|