source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/text/SelectInputRenderer.java@ 17514

Last change on this file since 17514 was 17514, checked in by oranfry, 16 years ago

changes to the way ant-installer loads and reloads the language packs, and a new attribute to the select input which triggers it to change the language to the input value

File size: 2.6 KB
Line 
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 */
16package org.tp23.antinstaller.renderer.text;
17
18import java.io.BufferedReader;
19import java.io.IOException;
20import java.io.PrintStream;
21import java.util.ResourceBundle;
22
23import org.tp23.antinstaller.InstallerContext;
24import org.tp23.antinstaller.input.OutputField;
25import org.tp23.antinstaller.input.SelectInput;
26
27
28public class SelectInputRenderer
29 implements TextOutputFieldRenderer {
30
31 protected InstallerContext ctx;
32 public SelectInputRenderer() {
33 }
34
35 public void setContext(InstallerContext ctx) {
36 this.ctx = ctx;
37 }
38
39 public void renderOutput(OutputField field, BufferedReader reader, PrintStream out) throws IOException {
40 SelectInput iField = (SelectInput) field;
41 printText(iField,out);
42
43 String input = reader.readLine();
44 out.println();
45 if(input == null || input.equals("")){
46 input = iField.getDefaultValue();
47 }
48 else {
49 try {
50 int idx = Integer.parseInt(input.trim());
51 input = iField.getOptions()[idx - 1].value;
52 } catch(Exception numFormatOrIndexOutOfBounds){
53 return;
54 }
55 }
56 iField.setInputResult(input);
57 }
58 public boolean isAbort(){
59 return false;
60 }
61 private void printText(SelectInput iField, PrintStream out) throws IOException{
62 out.println(iField.getDisplayText());
63 SelectInput.Option[] options = iField.getOptions();
64 out.print(" ");
65 out.println(org.tp23.antinstaller.Installer.langPack.getString("enterNumber"));
66 for (int i = 0; i < options.length; i++) {
67 out.print(" ");
68 out.print(i+1);
69 out.print(") ");
70 out.print(options[i].getText());
71 if(iField.getDefaultValue().equals(options[i].value)){
72 out.print(" [");
73 out.print(org.tp23.antinstaller.Installer.langPack.getString("_default_"));
74 out.print("]");
75 }
76 out.println();
77 }
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) throws IOException {
90 ctx.getMessageRenderer().printMessage("Not a valid selection");
91 renderOutput(field, reader, out);
92 }
93}
Note: See TracBrowser for help on using the repository browser.