001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2001 Johannes Lehtinen
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package com.izforge.izpack.panels;
023:
024: import java.awt.GridBagConstraints;
025: import java.awt.GridBagLayout;
026: import java.awt.Insets;
027:
028: import javax.swing.JLabel;
029: import javax.swing.JScrollPane;
030: import javax.swing.JTextArea;
031:
032: import com.izforge.izpack.gui.LabelFactory;
033: import com.izforge.izpack.installer.InstallData;
034: import com.izforge.izpack.installer.InstallerFrame;
035: import com.izforge.izpack.installer.IzPanel;
036: import com.izforge.izpack.installer.ResourceManager;
037: import com.izforge.izpack.util.VariableSubstitutor;
038:
039: /**
040: * The XInfo panel class - shows some adaptative text (ie by parsing for some variables.
041: *
042: * @author Julien Ponge
043: */
044: public class XInfoPanel extends IzPanel {
045:
046: /**
047: *
048: */
049: private static final long serialVersionUID = 3257009856274970416L;
050:
051: /** The text area. */
052: private JTextArea textArea;
053:
054: /** The info to display. */
055: private String info;
056:
057: /**
058: * The constructor.
059: *
060: * @param parent The parent window.
061: * @param idata The installation data.
062: */
063: public XInfoPanel(InstallerFrame parent, InstallData idata) {
064: super (parent, idata);
065:
066: // We initialize our layout
067: GridBagLayout layout = new GridBagLayout();
068: GridBagConstraints gbConstraints = new GridBagConstraints();
069: setLayout(layout);
070:
071: // We add the components
072:
073: JLabel infoLabel = LabelFactory.create(parent.langpack
074: .getString("InfoPanel.info"), parent.icons
075: .getImageIcon("edit"), JLabel.TRAILING);
076: parent.buildConstraints(gbConstraints, 0, 0, 1, 1, 1.0, 0.0);
077: gbConstraints.insets = new Insets(5, 5, 5, 5);
078: gbConstraints.fill = GridBagConstraints.BOTH;
079: gbConstraints.anchor = GridBagConstraints.SOUTHWEST;
080: layout.addLayoutComponent(infoLabel, gbConstraints);
081: add(infoLabel);
082:
083: textArea = new JTextArea();
084: textArea.setEditable(false);
085: JScrollPane scroller = new JScrollPane(textArea);
086: parent.buildConstraints(gbConstraints, 0, 1, 1, 1, 1.0, 0.9);
087: gbConstraints.anchor = GridBagConstraints.CENTER;
088: layout.addLayoutComponent(scroller, gbConstraints);
089: add(scroller);
090: }
091:
092: /** Loads the info text. */
093: private void loadInfo() {
094: try {
095: // We read it
096: info = ResourceManager.getInstance().getTextResource(
097: "XInfoPanel.info");
098: } catch (Exception err) {
099: info = "Error : could not load the info text !";
100: }
101: }
102:
103: /** Parses the text for special variables. */
104: private void parseText() {
105: try {
106: // Initialize the variable substitutor
107: VariableSubstitutor vs = new VariableSubstitutor(idata
108: .getVariables());
109:
110: // Parses the info text
111: info = vs.substitute(info, null);
112: } catch (Exception err) {
113: err.printStackTrace();
114: }
115: }
116:
117: /** Called when the panel becomes active. */
118: public void panelActivate() {
119: // Text handling
120: loadInfo();
121: parseText();
122:
123: // UI handling
124: textArea.setText(info);
125: textArea.setCaretPosition(0);
126: }
127:
128: /**
129: * Indicates wether the panel has been validated or not.
130: *
131: * @return Always true.
132: */
133: public boolean isValidated() {
134: return true;
135: }
136: }
|