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.text;
17:
18: import java.io.BufferedReader;
19: import java.io.IOException;
20: import java.io.PrintStream;
21:
22: import org.tp23.antinstaller.InstallerContext;
23: import org.tp23.antinstaller.input.CheckboxInput;
24: import org.tp23.antinstaller.input.InputField;
25: import org.tp23.antinstaller.input.OutputField;
26: import org.tp23.antinstaller.renderer.AIResourceBundle;
27:
28: public class CheckboxInputRenderer implements TextOutputFieldRenderer {
29:
30: private static final AIResourceBundle res = new AIResourceBundle();
31:
32: protected InstallerContext ctx;
33:
34: public CheckboxInputRenderer() {
35: }
36:
37: public void setContext(InstallerContext ctx) {
38: this .ctx = ctx;
39: }
40:
41: public void renderOutput(OutputField field, BufferedReader reader,
42: PrintStream out) throws IOException {
43: CheckboxInput iField = (CheckboxInput) field;
44: out.print(iField.getDisplayText());
45: out.print(" [");
46: out.print(res.getString("selection.default"));
47: out.print(":");
48: out.print(iField.getDefaultValue());
49: out.print("]");
50: if (InputField.isTrue(iField.getForce())) {
51: out.println(res.getString("selection.required"));
52: iField.setValue(iField.getDefaultValue());
53: return;
54: } else {
55: out.println();
56: }
57:
58: String input = reader.readLine();
59: out.println();
60: if (input == null || input.trim().equals("")) {
61: input = iField.getDefaultValue();
62: }
63: if (InputField.isTrue(input)) {
64: iField.setValue("true");
65: }
66: //@TODO should accept true or false only and complain toher wise looping till sensible input
67: //else if (InputField.isFalse(input)){
68: // iField.setValue("false");
69: //}
70: else {
71: iField.setValue("false");
72: }
73: }
74:
75: public boolean isAbort() {
76: return false;
77: }
78:
79: /**
80: * renderError
81: *
82: * @param field InputField
83: * @param in InputStream
84: * @param out PrintStream
85: */
86: public void renderError(OutputField field, BufferedReader reader,
87: PrintStream out) {
88: }
89: }
|