source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/text/TargetSelectInputRenderer.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.4 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds, Mark Anderson
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.input.OutputField;
24import org.tp23.antinstaller.input.TargetSelectInput;
25
26/**
27 *
28 * @author Paul Hinds, Mark Anderson
29 * @version $Id: TargetSelectInputRenderer.java,v 1.3 2007/01/09 22:41:40 teknopaul Exp $
30 */
31public class TargetSelectInputRenderer
32 extends SelectInputRenderer {
33
34 public TargetSelectInputRenderer() {
35 }
36
37 public void renderOutput(OutputField field, BufferedReader reader, PrintStream out) throws IOException {
38 TargetSelectInput iField = (TargetSelectInput) field;
39 printText(iField,out);
40
41 String input = reader.readLine();
42 out.println();
43 if(input == null || input.equals(""))
44 input = iField.getDefaultValue();
45 else{
46 try{
47 int idx = Integer.parseInt(input.trim());
48 input = iField.getOptions()[idx - 1].value;
49 } catch(Exception numFormatOrIndexOutOfBounds) {
50 return;
51 }
52 }
53 ctx.getCurrentPage().removeTarget(iField.getIdx());
54 ctx.getCurrentPage().addTarget(iField.getIdx(), input);
55 iField.setInputResult(input);
56 }
57
58 private void printText(TargetSelectInput iField, PrintStream out) throws IOException{
59 out.println(iField.getDisplayText());
60 TargetSelectInput.Option[] options = iField.getOptions();
61 out.print(" ");
62 out.println(org.tp23.antinstaller.Installer.langPack.getString("enterNumber"));
63 for (int i = 0; i < options.length; i++) {
64 out.print(" ");
65 out.print(i+1);
66 out.print(") ");
67 out.print(options[i].getText());
68 if(iField.getDefaultValue().equals(options[i].value)){
69 out.print(" [");
70 out.print(org.tp23.antinstaller.Installer.langPack.getString("_default_"));
71 out.print("]");
72 }
73 out.println();
74 }
75 }
76
77}
Note: See TracBrowser for help on using the repository browser.