001: /*
002: * Copyright 2005 Paul Hinds
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.antinstaller.renderer.swing;
017:
018: import java.awt.BorderLayout;
019: import java.io.BufferedReader;
020: import java.io.InputStream;
021: import java.io.InputStreamReader;
022:
023: import javax.swing.BorderFactory;
024: import javax.swing.JScrollPane;
025: import javax.swing.JTextArea;
026:
027: import org.tp23.antinstaller.ValidationException;
028: import org.tp23.antinstaller.page.LicensePage;
029: import org.tp23.antinstaller.renderer.AIResourceBundle;
030: import org.tp23.antinstaller.runtime.ConfigurationException;
031:
032: /**
033: *
034: * <p>Renders the license page </p>
035: * <p> </p>
036: * <p>Copyright: Copyright (c) 2004</p>
037: * <p>Company: tp23</p>
038: * @todo this could be an input type and simple renderer
039: * @author Paul Hinds
040: * @version $Id: LicensePageRenderer.java,v 1.5 2007/01/12 10:49:09 anothermwilson Exp $
041: */
042: public class LicensePageRenderer extends SwingPageRenderer {
043:
044: private static final AIResourceBundle res = new AIResourceBundle();
045:
046: private JTextArea licenseTextArea = new JTextArea();
047: private JScrollPane scrollPane = new JScrollPane();
048:
049: public LicensePageRenderer() {
050: }
051:
052: public boolean validateFields() throws ValidationException {
053: return true; // @todo option to force accepting or tick box to accept
054: }
055:
056: public void instanceInit() throws Exception {
057: String resource = ((LicensePage) page).getResource();
058: InputStream licensein = this .getClass().getResourceAsStream(
059: resource);
060: if (licensein == null) {
061: throw new ConfigurationException("License resource '"
062: + resource + "' is missing from installer");
063: }
064: BufferedReader reader = new BufferedReader(
065: new InputStreamReader(licensein));
066: StringBuffer sb = new StringBuffer();
067: String line;
068: while ((line = reader.readLine()) != null) {
069: sb.append(line);
070: sb.append('\n');
071: }
072:
073: licenseTextArea.setText(sb.toString());
074: licenseTextArea.setTabSize(4);
075: licenseTextArea.setAutoscrolls(true);
076: licenseTextArea.setCaretPosition(0);
077: licenseTextArea.setEditable(false);
078: licenseTextArea.setLineWrap(true);
079: licenseTextArea.setWrapStyleWord(true);
080: licenseTextArea.setBorder(BorderFactory.createEmptyBorder(2, 2,
081: 2, 2));
082: scrollPane.getViewport().add(licenseTextArea);
083: scrollPane
084: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
085: // scrollPane.setBorder(BorderFactory.createCompoundBorder(
086: // BorderFactory.createEmptyBorder(4, 4, 4, 4),
087: // BorderFactory.createEtchedBorder()));
088: dataPanel.add(scrollPane, BorderLayout.CENTER);
089: scrollPane.setBorder(BorderFactory.createEmptyBorder());
090:
091: getNextButton().setText(res.getString("button.license.next"));
092: getNextButton().setIcon(getImage("/resources/icons/ok.png"));
093: getCancelButton().setText(
094: res.getString("button.license.cancel"));
095:
096: }
097:
098: public void updateInputFields() {
099: ;
100: }
101:
102: /**
103: * updateDefaultValues
104: */
105: public void updateDefaultValues() {
106: }
107: }
|