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