KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > panels > XInfoPanel


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2001 Johannes Lehtinen
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.panels;
23
24 import java.awt.GridBagConstraints JavaDoc;
25 import java.awt.GridBagLayout JavaDoc;
26 import java.awt.Insets JavaDoc;
27
28 import javax.swing.JLabel JavaDoc;
29 import javax.swing.JScrollPane JavaDoc;
30 import javax.swing.JTextArea JavaDoc;
31
32 import com.izforge.izpack.gui.LabelFactory;
33 import com.izforge.izpack.installer.InstallData;
34 import com.izforge.izpack.installer.InstallerFrame;
35 import com.izforge.izpack.installer.IzPanel;
36 import com.izforge.izpack.installer.ResourceManager;
37 import com.izforge.izpack.util.VariableSubstitutor;
38
39 /**
40  * The XInfo panel class - shows some adaptative text (ie by parsing for some variables.
41  *
42  * @author Julien Ponge
43  */

44 public class XInfoPanel extends IzPanel
45 {
46
47     /**
48      *
49      */

50     private static final long serialVersionUID = 3257009856274970416L;
51
52     /** The text area. */
53     private JTextArea JavaDoc textArea;
54
55     /** The info to display. */
56     private String JavaDoc info;
57
58     /**
59      * The constructor.
60      *
61      * @param parent The parent window.
62      * @param idata The installation data.
63      */

64     public XInfoPanel(InstallerFrame parent, InstallData idata)
65     {
66         super(parent, idata);
67
68         // We initialize our layout
69
GridBagLayout JavaDoc layout = new GridBagLayout JavaDoc();
70         GridBagConstraints JavaDoc gbConstraints = new GridBagConstraints JavaDoc();
71         setLayout(layout);
72
73         // We add the components
74

75         JLabel JavaDoc infoLabel = LabelFactory.create(parent.langpack.getString("InfoPanel.info"), parent.icons
76                 .getImageIcon("edit"), JLabel.TRAILING);
77         parent.buildConstraints(gbConstraints, 0, 0, 1, 1, 1.0, 0.0);
78         gbConstraints.insets = new Insets JavaDoc(5, 5, 5, 5);
79         gbConstraints.fill = GridBagConstraints.BOTH;
80         gbConstraints.anchor = GridBagConstraints.SOUTHWEST;
81         layout.addLayoutComponent(infoLabel, gbConstraints);
82         add(infoLabel);
83
84         textArea = new JTextArea JavaDoc();
85         textArea.setEditable(false);
86         JScrollPane JavaDoc scroller = new JScrollPane JavaDoc(textArea);
87         parent.buildConstraints(gbConstraints, 0, 1, 1, 1, 1.0, 0.9);
88         gbConstraints.anchor = GridBagConstraints.CENTER;
89         layout.addLayoutComponent(scroller, gbConstraints);
90         add(scroller);
91     }
92
93     /** Loads the info text. */
94     private void loadInfo()
95     {
96         try
97         {
98             // We read it
99
info = ResourceManager.getInstance().getTextResource("XInfoPanel.info");
100         }
101         catch (Exception JavaDoc err)
102         {
103             info = "Error : could not load the info text !";
104         }
105     }
106
107     /** Parses the text for special variables. */
108     private void parseText()
109     {
110         try
111         {
112             // Initialize the variable substitutor
113
VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
114
115             // Parses the info text
116
info = vs.substitute(info, null);
117         }
118         catch (Exception JavaDoc err)
119         {
120             err.printStackTrace();
121         }
122     }
123
124     /** Called when the panel becomes active. */
125     public void panelActivate()
126     {
127         // Text handling
128
loadInfo();
129         parseText();
130
131         // UI handling
132
textArea.setText(info);
133         textArea.setCaretPosition(0);
134     }
135
136     /**
137      * Indicates wether the panel has been validated or not.
138      *
139      * @return Always true.
140      */

141     public boolean isValidated()
142     {
143         return true;
144     }
145 }
146
Popular Tags