1 | /*
|
---|
2 | * Copyright 2005 Paul Hinds
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
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 java.awt.FlowLayout;
|
---|
22 | import java.awt.GridLayout;
|
---|
23 | import java.awt.BorderLayout;
|
---|
24 | import javax.swing.JLabel;
|
---|
25 | import javax.swing.JPanel;
|
---|
26 | import java.awt.Dimension;
|
---|
27 | import java.awt.Insets;
|
---|
28 | import javax.swing.JTextField;
|
---|
29 |
|
---|
30 |
|
---|
31 | import org.tp23.antinstaller.input.CheckboxInput;
|
---|
32 | import org.tp23.antinstaller.input.InputField;
|
---|
33 | import org.tp23.antinstaller.input.OutputField;
|
---|
34 | import org.tp23.gui.GBCF;
|
---|
35 |
|
---|
36 | public class CheckboxInputRenderer
|
---|
37 | extends SwingOutputFieldRenderer {
|
---|
38 |
|
---|
39 | protected CheckboxInput inputField;
|
---|
40 |
|
---|
41 | protected JLabel fieldLabel = new AILabel();
|
---|
42 | protected AICheckBox checkBox = new AICheckBox();
|
---|
43 |
|
---|
44 | public CheckboxInputRenderer() {
|
---|
45 | }
|
---|
46 | public void initComponent(JPanel parent){
|
---|
47 | try {
|
---|
48 | jbInit();
|
---|
49 | }
|
---|
50 | catch(Exception e) {
|
---|
51 | e.printStackTrace();
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | public void setOutputField(OutputField inputField) {
|
---|
58 | this.inputField = (CheckboxInput)inputField;
|
---|
59 | }
|
---|
60 | public void updateInputField(){
|
---|
61 | boolean selected = checkBox.isSelected();
|
---|
62 | if(selected)inputField.setValue("true");
|
---|
63 | else inputField.setValue("false");
|
---|
64 | }
|
---|
65 | public void updateDefaultValue(){
|
---|
66 | if(!inputField.isEditted()){
|
---|
67 | String newDefault = inputField.getDefaultValue();
|
---|
68 | checkBox.setSelected(InputField.isTrue(newDefault));
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | private void jbInit() throws Exception {
|
---|
73 | fieldLabel.setText(inputField.getDisplayText());
|
---|
74 | checkBox.setSelected(OutputField.isTrue(inputField.getDefaultValue()));
|
---|
75 | checkBox.setEnabled(!OutputField.isTrue(inputField.getForce()));
|
---|
76 | checkBox.addActionListener(new ActionListener() {
|
---|
77 | public void actionPerformed(ActionEvent e) {
|
---|
78 | updateInputField();
|
---|
79 | inputField.setEditted(true);
|
---|
80 | }
|
---|
81 | });
|
---|
82 | }
|
---|
83 | public int addSelf(JPanel content, GBCF cf, int row, boolean overflow) {
|
---|
84 | JPanel p;
|
---|
85 |
|
---|
86 | //p = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
---|
87 | BorderLayout l = new BorderLayout();
|
---|
88 | p = new JPanel(l);
|
---|
89 | p.add( fieldLabel, BorderLayout.WEST );
|
---|
90 | p.add( checkBox, BorderLayout.CENTER );
|
---|
91 | content.add(p);
|
---|
92 |
|
---|
93 | p = new JPanel();
|
---|
94 | p.setMinimumSize( new Dimension(0,1) );
|
---|
95 | content.add(p);
|
---|
96 | return ++row;
|
---|
97 | /*
|
---|
98 | JPanel p = new JPanel();
|
---|
99 | p.add(fieldLabel);
|
---|
100 | p.add(checkBox);
|
---|
101 | if(overflow){
|
---|
102 | checkBox.setOverflow(SizeConstants.OVERFLOW_FIELD_SIZE);
|
---|
103 | }
|
---|
104 | content.add(p);
|
---|
105 |
|
---|
106 | */
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * renderError
|
---|
111 | */
|
---|
112 | public void renderError() {
|
---|
113 | }
|
---|
114 | }
|
---|