source: release-kits/lirk3/bin/ant-installer/src/org/tp23/antinstaller/renderer/text/AbstractTextPageRenderer.java@ 14982

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

initial import of LiRK3

File size: 3.2 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.InstallException;
24import org.tp23.antinstaller.InstallerContext;
25import org.tp23.antinstaller.page.Page;
26import org.tp23.antinstaller.renderer.PageRenderer;
27/**
28 * renamed from TextPageRenderer in version 0.8 to enable
29 * the use of the page type TextPage, TextPageRenderer is now
30 * the renderer for these page types
31 * @author teknopaul
32 *
33 */
34public abstract class AbstractTextPageRenderer
35 implements PageRenderer {
36
37 public static final int PAGE_BLANK_LINES = 20;
38 public static final int PAGE_DECO_WIDTH = 80;
39
40 protected BufferedReader reader;
41 protected PrintStream out;
42 private InstallerContext ctx;
43
44
45 public AbstractTextPageRenderer() {
46 }
47
48 public void setContext(InstallerContext ctx){
49 this.ctx = ctx;
50 }
51 public InstallerContext getContext(){
52 return ctx;
53 }
54
55 public void init( BufferedReader reader, PrintStream out){
56 this.out = out;
57 this.reader = reader;
58 }
59 /**
60 *
61 * @param page Page
62 * @throws InstallException
63 * @return boolean false implys user aborted
64 */
65 public abstract boolean renderPage(Page page) throws InstallException;
66
67 protected void printHeader(Page page) throws IOException{
68 for (int i = 0; i < PAGE_BLANK_LINES; i++) {
69 out.println();
70 }
71
72
73 for (int i = 0; i < PAGE_DECO_WIDTH; i++) {
74 out.print('~');
75 }
76 out.println();
77 out.println(" " + page.getDisplayText());
78 for (int i = 0; i < PAGE_DECO_WIDTH; i++) {
79 out.print('~');
80 }
81 out.println();
82 out.println();
83 out.println();
84 }
85
86 private static final ResourceBundle res = ResourceBundle.getBundle("org.tp23.antinstaller.renderer.text.Res");
87 private static final char[] affimativeChars = parseChars(res.getString("affirmativeChars"));
88
89 private static char[] parseChars(String commaSeparated){
90 char[] input = commaSeparated.toCharArray();
91 char[] theChars = new char[input.length];
92 int j = 0;
93 for (int i = 0; i < input.length; i++) {
94 if(Character.isWhitespace(input[i]))continue;
95 if(',' == input[i]) {
96 continue;
97 }
98 else theChars[j++] = input[i];
99 }
100 char[] toReturn = new char[j];
101 System.arraycopy(theChars,0,toReturn,0,j);
102 return toReturn;
103 }
104
105 /**
106 * does the string represent true default = true
107 * @param entered String
108 * @return boolean
109 */
110 protected boolean isTrue(String entered){
111 if(entered.length() == 0) {
112 return true;
113 }
114 char first = entered.charAt(0);
115 boolean isTrue= false;
116 for (int i = 0; i < affimativeChars.length; i++) {
117 isTrue |= Character.toUpperCase(first) == affimativeChars[i];
118 }
119 return isTrue;
120 }
121}
Note: See TracBrowser for help on using the repository browser.