root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / XInfoPanel.java @ 15280
History | View | Annotate | Download (4.4 KB)
1 |
/*
|
---|---|
2 |
* $Id: XInfoPanel.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
3 |
* IzPack
|
4 |
* Copyright (C) 2001-2004 Julien Ponge
|
5 |
*
|
6 |
* File : XInfoPanel.java
|
7 |
* Description : A panel to show some adaptative textual information.
|
8 |
* Author's email : julien@izforge.com
|
9 |
* Author's Website : http://www.izforge.com
|
10 |
*
|
11 |
* Portions are Copyright (c) 2001 Johannes Lehtinen
|
12 |
* johannes.lehtinen@iki.fi
|
13 |
* http://www.iki.fi/jle/
|
14 |
*
|
15 |
* This program is free software; you can redistribute it and/or
|
16 |
* modify it under the terms of the GNU General Public License
|
17 |
* as published by the Free Software Foundation; either version 2
|
18 |
* of the License, or any later version.
|
19 |
*
|
20 |
* This program is distributed in the hope that it will be useful,
|
21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
* GNU General Public License for more details.
|
24 |
*
|
25 |
* You should have received a copy of the GNU General Public License
|
26 |
* along with this program; if not, write to the Free Software
|
27 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
28 |
*/
|
29 |
package com.izforge.izpack.panels; |
30 |
|
31 |
import java.awt.GridBagConstraints; |
32 |
import java.awt.GridBagLayout; |
33 |
import java.awt.Insets; |
34 |
|
35 |
import javax.swing.JLabel; |
36 |
import javax.swing.JScrollPane; |
37 |
import javax.swing.JTextArea; |
38 |
|
39 |
import com.izforge.izpack.gui.LabelFactory; |
40 |
import com.izforge.izpack.installer.InstallData; |
41 |
import com.izforge.izpack.installer.InstallerFrame; |
42 |
import com.izforge.izpack.installer.IzPanel; |
43 |
import com.izforge.izpack.installer.ResourceManager; |
44 |
import com.izforge.izpack.installer.VariableSubstitutor; |
45 |
|
46 |
/**
|
47 |
* The XInfo panel class - shows some adaptative text (ie by parsing for some
|
48 |
* variables.
|
49 |
*
|
50 |
* @author Julien Ponge
|
51 |
*/
|
52 |
public class XInfoPanel extends IzPanel |
53 |
{ |
54 |
/** The layout. */
|
55 |
private GridBagLayout layout; |
56 |
|
57 |
/** The layout constraints. */
|
58 |
private GridBagConstraints gbConstraints; |
59 |
|
60 |
/** The info label. */
|
61 |
private JLabel infoLabel; |
62 |
|
63 |
/** The text area. */
|
64 |
private JTextArea textArea; |
65 |
|
66 |
/** The info to display. */
|
67 |
private String info; |
68 |
|
69 |
/**
|
70 |
* The constructor.
|
71 |
*
|
72 |
* @param parent The parent window.
|
73 |
* @param idata The installation data.
|
74 |
*/
|
75 |
public XInfoPanel(InstallerFrame parent, InstallData idata)
|
76 |
{ |
77 |
super(parent, idata);
|
78 |
|
79 |
// We initialize our layout
|
80 |
layout = new GridBagLayout(); |
81 |
gbConstraints = new GridBagConstraints(); |
82 |
setLayout(layout); |
83 |
|
84 |
// We add the components
|
85 |
|
86 |
infoLabel = |
87 |
LabelFactory.create( |
88 |
parent.langpack.getString("InfoPanel.info"),
|
89 |
parent.icons.getImageIcon("edit"),
|
90 |
JLabel.TRAILING);
|
91 |
parent.buildConstraints(gbConstraints, 0, 0, 1, 1, 1.0, 0.0); |
92 |
gbConstraints.insets = new Insets(5, 5, 5, 5); |
93 |
gbConstraints.fill = GridBagConstraints.BOTH;
|
94 |
gbConstraints.anchor = GridBagConstraints.SOUTHWEST;
|
95 |
layout.addLayoutComponent(infoLabel, gbConstraints); |
96 |
add(infoLabel); |
97 |
|
98 |
textArea = new JTextArea(); |
99 |
textArea.setEditable(false);
|
100 |
JScrollPane scroller = new JScrollPane(textArea); |
101 |
parent.buildConstraints(gbConstraints, 0, 1, 1, 1, 1.0, 0.9); |
102 |
gbConstraints.anchor = GridBagConstraints.CENTER;
|
103 |
layout.addLayoutComponent(scroller, gbConstraints); |
104 |
add(scroller); |
105 |
} |
106 |
|
107 |
/** Loads the info text. */
|
108 |
private void loadInfo() |
109 |
{ |
110 |
try
|
111 |
{ |
112 |
// We read it
|
113 |
info = ResourceManager.getInstance().getTextResource("XInfoPanel.info");
|
114 |
} catch (Exception err) |
115 |
{ |
116 |
info = "Error : could not load the info text !";
|
117 |
} |
118 |
} |
119 |
|
120 |
/** Parses the text for special variables. */
|
121 |
private void parseText() |
122 |
{ |
123 |
try
|
124 |
{ |
125 |
// Initialize the variable substitutor
|
126 |
VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
|
127 |
|
128 |
// Parses the info text
|
129 |
info = vs.substitute(info, null);
|
130 |
} catch (Exception err) |
131 |
{ |
132 |
err.printStackTrace(); |
133 |
} |
134 |
} |
135 |
|
136 |
/** Called when the panel becomes active. */
|
137 |
public void panelActivate() |
138 |
{ |
139 |
// Text handling
|
140 |
loadInfo(); |
141 |
parseText(); |
142 |
|
143 |
// UI handling
|
144 |
textArea.setText(info); |
145 |
textArea.setCaretPosition(0);
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* Indicates wether the panel has been validated or not.
|
150 |
*
|
151 |
* @return Always true.
|
152 |
*/
|
153 |
public boolean isValidated() |
154 |
{ |
155 |
return true; |
156 |
} |
157 |
} |