source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/text/LargeSelectInputRenderer.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: 3.4 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.LargeSelectInput;
25import org.tp23.antinstaller.input.OutputField;
26
27
28public class LargeSelectInputRenderer
29 implements TextOutputFieldRenderer {
30
31 private static final String nextChar = org.tp23.antinstaller.Installer.langPack.getString("nextChar");
32
33 protected InstallerContext ctx;
34 public LargeSelectInputRenderer() {
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 LargeSelectInput iField = (LargeSelectInput) field;
43
44 printText(iField,out,reader);
45 String input = reader.readLine();
46 out.println();
47 if(input == null || input.equals("")) {
48 input = iField.getDefaultValue();
49 }
50 else {
51 try {
52 int idx = Integer.parseInt(input.trim());
53 input = iField.getOptions()[idx - 1].value;
54 } catch(Exception numFormatOrIndexOutOfBounds) {
55 return;
56 }
57 }
58 iField.setInputResult(input);
59 }
60
61 public boolean isAbort(){
62 return false;
63 }
64 private void printText(LargeSelectInput iField, PrintStream out,BufferedReader reader) throws IOException{
65 out.println(iField.getDisplayText());
66 LargeSelectInput.Option[] options = iField.getOptions();
67 out.print(" ");
68 out.println(org.tp23.antinstaller.Installer.langPack.getString("availableOptions"));
69 StringBuffer optionsData = new StringBuffer();
70 for (int i = 0; i < options.length; i++) {
71 optionsData.append(" ");
72 optionsData.append(i+1);
73 optionsData.append(") ");
74 optionsData.append(options[i].getText());
75 if(iField.getDefaultValue().equals(options[i].value)){
76 optionsData.append(" [");
77 optionsData.append(org.tp23.antinstaller.Installer.langPack.getString("_default_"));
78 optionsData.append("]");
79 }
80 optionsData.append("\n");
81 }
82 optionsData.append(" ");
83 optionsData.append(org.tp23.antinstaller.Installer.langPack.getString("enterNumber")).append("\n");
84 Pager pager = new Pager(optionsData.toString());
85 String command = null;
86 do {
87 if (!pager.next(out)) {
88 break;
89 }
90 out.println();
91 out.println(getNextInstructions());
92 command = reader.readLine();
93 }
94 while (command.toUpperCase().startsWith( nextChar ));
95 pager.rest(out);
96
97 }
98
99
100
101 /**
102 * renderError
103 *
104 * @param field InputField
105 * @param out PrintStream
106 */
107 public void renderError(OutputField field, BufferedReader reader, PrintStream out) throws IOException {
108 ctx.getMessageRenderer().printMessage("Not a valid selection");
109 renderOutput(field, reader, out);
110 }
111 private String getNextInstructions() {
112 return org.tp23.antinstaller.Installer.langPack.getString("large_select_next");
113 }
114}
Note: See TracBrowser for help on using the repository browser.