001: /*
002: * Copyright 2005 Paul Hinds
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.antinstaller.renderer.swing;
017:
018: import java.awt.event.ActionEvent;
019: import java.awt.event.ActionListener;
020:
021: import javax.swing.JPanel;
022:
023: import org.tp23.antinstaller.input.InputField;
024: import org.tp23.antinstaller.input.OutputField;
025: import org.tp23.antinstaller.input.TargetInput;
026: import org.tp23.gui.GBCF;
027:
028: public class TargetInputRenderer extends SwingOutputFieldRenderer {
029:
030: protected TargetInput outputField;
031:
032: protected AILabel fieldLabel = new AILabel();
033: protected AICheckBox targetCheckBox = new AICheckBox();
034:
035: public TargetInputRenderer() {
036: }
037:
038: public void initComponent(JPanel parent) {
039: try {
040: jbInit();
041: } catch (Exception e) {
042: ctx.log(e.getMessage());
043: if (ctx.getInstaller().isVerbose()) {
044: ctx.log(e);
045: }
046:
047: }
048: }
049:
050: public void setOutputField(OutputField outputField) {
051: this .outputField = (TargetInput) outputField;
052: }
053:
054: public void updateInputField() {
055: String target = outputField.getTarget();
056: int targetIdx = outputField.getIdx();
057: boolean selected = targetCheckBox.isSelected();
058: outputField.setInputResult(String.valueOf(selected));
059: if (selected
060: && !ctx.getCurrentPage().getAllTargets().contains(
061: target)) {
062: ctx.getCurrentPage().addTarget(targetIdx, target);
063: } else if (!selected && ctx.getCurrentPage().isTarget(target)) {
064: ctx.getCurrentPage().removeTarget(targetIdx);
065: }
066: }
067:
068: public void updateDefaultValue() {
069: if (!outputField.isEditted()) {
070: targetCheckBox.setSelected(InputField.isTrue(outputField
071: .getDefaultValue()));
072: }
073: }
074:
075: private void jbInit() throws Exception {
076: fieldLabel.setText(outputField.getDisplayText());
077: targetCheckBox.setSelected(InputField.isTrue(outputField
078: .getDefaultValue()));
079: if (InputField.isTrue(outputField.getForce())) {
080: targetCheckBox.setEnabled(false);
081: }
082:
083: targetCheckBox.addActionListener(new ActionListener() {
084: public void actionPerformed(ActionEvent e) {
085: updateInputField();
086: outputField.setEditted(true);
087: }
088: });
089: }
090:
091: public int addSelf(JPanel content, GBCF cf, int row,
092: boolean overflow) {
093: content.add(fieldLabel, cf.getCell(row, 0));
094: content.add(targetCheckBox, cf.getCell(row, 1));
095: if (overflow) {
096: targetCheckBox
097: .setOverflow(SizeConstants.OVERFLOW_FIELD_SIZE);
098: }
099: return ++row;
100: }
101:
102: /**
103: * renderError
104: */
105: public void renderError() {
106: }
107: }
|