svn-gvsig-desktop / trunk / build / distribution / IzPack / src / lib / com / izforge / izpack / panels / LicencePanel.java @ 21757
History | View | Annotate | Download (4.62 KB)
1 |
/*
|
---|---|
2 |
* $Id: LicencePanel.java 5819 2006-06-14 07:29:09Z cesar $
|
3 |
* IzPack
|
4 |
* Copyright (C) 2001-2004 Julien Ponge
|
5 |
*
|
6 |
* File : LicencePanel.java
|
7 |
* Description : A panel to prompt the user for a licence agreement.
|
8 |
* Author's email : julien@izforge.com
|
9 |
* Author's Website : http://www.izforge.com
|
10 |
*
|
11 |
* Portions are Copyright (C) 2002 Jan Blok (jblok@profdata.nl - PDM - www.profdata.nl)
|
12 |
*
|
13 |
* This program is free software; you can redistribute it and/or
|
14 |
* modify it under the terms of the GNU General Public License
|
15 |
* as published by the Free Software Foundation; either version 2
|
16 |
* of the License, or any later version.
|
17 |
*
|
18 |
* This program is distributed in the hope that it will be useful,
|
19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
* GNU General Public License for more details.
|
22 |
*
|
23 |
* You should have received a copy of the GNU General Public License
|
24 |
* along with this program; if not, write to the Free Software
|
25 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
26 |
*/
|
27 |
package com.izforge.izpack.panels; |
28 |
|
29 |
import java.awt.Dimension; |
30 |
import java.awt.Insets; |
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
|
34 |
import javax.swing.Box; |
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.ButtonGroup; |
37 |
import javax.swing.JLabel; |
38 |
import javax.swing.JRadioButton; |
39 |
import javax.swing.JScrollPane; |
40 |
import javax.swing.JTextArea; |
41 |
|
42 |
import com.izforge.izpack.gui.LabelFactory; |
43 |
import com.izforge.izpack.installer.InstallData; |
44 |
import com.izforge.izpack.installer.InstallerFrame; |
45 |
import com.izforge.izpack.installer.IzPanel; |
46 |
import com.izforge.izpack.installer.ResourceManager; |
47 |
|
48 |
/**
|
49 |
* The license panel.
|
50 |
*
|
51 |
* @author Julien Ponge
|
52 |
*/
|
53 |
public class LicencePanel extends IzPanel implements ActionListener |
54 |
{ |
55 |
/** The license text. */
|
56 |
private String licence; |
57 |
|
58 |
/** The text area. */
|
59 |
private JTextArea textArea; |
60 |
|
61 |
/** The radio buttons. */
|
62 |
private JRadioButton yesRadio, noRadio; |
63 |
|
64 |
/** The scrolling container. */
|
65 |
private JScrollPane scroller; |
66 |
|
67 |
/**
|
68 |
* The constructor.
|
69 |
*
|
70 |
* @param parent The parent window.
|
71 |
* @param idata The installation data.
|
72 |
*/
|
73 |
public LicencePanel(InstallerFrame parent, InstallData idata)
|
74 |
{ |
75 |
super(parent, idata);
|
76 |
|
77 |
// We initialize our layout
|
78 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
79 |
|
80 |
// We load the licence
|
81 |
loadLicence(); |
82 |
|
83 |
// We put our components
|
84 |
|
85 |
JLabel infoLabel =
|
86 |
LabelFactory.create( |
87 |
parent.langpack.getString("LicencePanel.info"),
|
88 |
parent.icons.getImageIcon("history"),
|
89 |
JLabel.TRAILING);
|
90 |
add(infoLabel); |
91 |
|
92 |
add(Box.createRigidArea(new Dimension(0, 3))); |
93 |
|
94 |
textArea = new JTextArea(licence); |
95 |
textArea.setMargin(new Insets(2, 2, 2, 2)); |
96 |
textArea.setCaretPosition(0);
|
97 |
textArea.setEditable(false);
|
98 |
textArea.setLineWrap(true);
|
99 |
textArea.setWrapStyleWord(true);
|
100 |
scroller = new JScrollPane(textArea); |
101 |
scroller.setAlignmentX(LEFT_ALIGNMENT); |
102 |
add(scroller); |
103 |
|
104 |
ButtonGroup group = new ButtonGroup(); |
105 |
|
106 |
yesRadio = |
107 |
new JRadioButton(parent.langpack.getString("LicencePanel.agree"), false); |
108 |
group.add(yesRadio); |
109 |
add(yesRadio); |
110 |
yesRadio.addActionListener(this);
|
111 |
|
112 |
noRadio = |
113 |
new JRadioButton( |
114 |
parent.langpack.getString("LicencePanel.notagree"),
|
115 |
true);
|
116 |
group.add(noRadio); |
117 |
add(noRadio); |
118 |
noRadio.addActionListener(this);
|
119 |
} |
120 |
|
121 |
/** Loads the licence text. */
|
122 |
private void loadLicence() |
123 |
{ |
124 |
try
|
125 |
{ |
126 |
// We read it
|
127 |
String resNamePrifix = "LicencePanel.licence"; |
128 |
licence = ResourceManager.getInstance().getTextResource(resNamePrifix); |
129 |
} catch (Exception err) |
130 |
{ |
131 |
licence = "Error : could not load the licence text !";
|
132 |
} |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Actions-handling method (here it allows the installation).
|
137 |
*
|
138 |
* @param e The event.
|
139 |
*/
|
140 |
public void actionPerformed(ActionEvent e) |
141 |
{ |
142 |
if (yesRadio.isSelected())
|
143 |
parent.unlockNextButton(); |
144 |
else
|
145 |
parent.lockNextButton(); |
146 |
} |
147 |
|
148 |
/**
|
149 |
* Indicates wether the panel has been validated or not.
|
150 |
*
|
151 |
* @return true if the user has agreed.
|
152 |
*/
|
153 |
public boolean isValidated() |
154 |
{ |
155 |
if (noRadio.isSelected())
|
156 |
{ |
157 |
parent.exit(); |
158 |
return false; |
159 |
} else
|
160 |
return (yesRadio.isSelected());
|
161 |
} |
162 |
|
163 |
/** Called when the panel becomes active. */
|
164 |
public void panelActivate() |
165 |
{ |
166 |
if (!yesRadio.isSelected())
|
167 |
parent.lockNextButton(); |
168 |
} |
169 |
} |