[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.InstallException;
|
---|
| 24 | import org.tp23.antinstaller.InstallerContext;
|
---|
| 25 | import org.tp23.antinstaller.page.Page;
|
---|
| 26 | import 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 | */
|
---|
| 34 | public 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 |
|
---|
[17514] | 86 | private static final char[] affimativeChars = parseChars(org.tp23.antinstaller.Installer.langPack.getString("affirmativeChars"));
|
---|
[14982] | 87 |
|
---|
| 88 | private static char[] parseChars(String commaSeparated){
|
---|
| 89 | char[] input = commaSeparated.toCharArray();
|
---|
| 90 | char[] theChars = new char[input.length];
|
---|
| 91 | int j = 0;
|
---|
| 92 | for (int i = 0; i < input.length; i++) {
|
---|
| 93 | if(Character.isWhitespace(input[i]))continue;
|
---|
| 94 | if(',' == input[i]) {
|
---|
| 95 | continue;
|
---|
| 96 | }
|
---|
| 97 | else theChars[j++] = input[i];
|
---|
| 98 | }
|
---|
| 99 | char[] toReturn = new char[j];
|
---|
| 100 | System.arraycopy(theChars,0,toReturn,0,j);
|
---|
| 101 | return toReturn;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /**
|
---|
| 105 | * does the string represent true default = true
|
---|
| 106 | * @param entered String
|
---|
| 107 | * @return boolean
|
---|
| 108 | */
|
---|
| 109 | protected boolean isTrue(String entered){
|
---|
| 110 | if(entered.length() == 0) {
|
---|
| 111 | return true;
|
---|
| 112 | }
|
---|
| 113 | char first = entered.charAt(0);
|
---|
| 114 | boolean isTrue= false;
|
---|
| 115 | for (int i = 0; i < affimativeChars.length; i++) {
|
---|
| 116 | isTrue |= Character.toUpperCase(first) == affimativeChars[i];
|
---|
| 117 | }
|
---|
| 118 | return isTrue;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|