KickJava   Java API By Example, From Geeks To Geeks.

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


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 2002 Jan Blok
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.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26
27 import javax.swing.ButtonGroup JavaDoc;
28 import javax.swing.JRadioButton JavaDoc;
29 import javax.swing.JScrollPane JavaDoc;
30 import javax.swing.JTextArea JavaDoc;
31
32 import com.izforge.izpack.gui.IzPanelLayout;
33 import com.izforge.izpack.gui.LabelFactory;
34 import com.izforge.izpack.installer.InstallData;
35 import com.izforge.izpack.installer.InstallerFrame;
36 import com.izforge.izpack.installer.IzPanel;
37 import com.izforge.izpack.installer.ResourceManager;
38
39 /**
40  * The license panel.
41  *
42  * @author Julien Ponge
43  */

44 public class LicencePanel extends IzPanel implements ActionListener JavaDoc
45 {
46
47     /**
48      *
49      */

50     private static final long serialVersionUID = 3691043187997552948L;
51
52     /** The license text. */
53     private String JavaDoc licence;
54
55     /** The radio buttons. */
56     private JRadioButton JavaDoc yesRadio;
57     private JRadioButton JavaDoc noRadio;
58
59     /**
60      * The constructor.
61      *
62      * @param parent The parent window.
63      * @param idata The installation data.
64      */

65     public LicencePanel(InstallerFrame parent, InstallData idata)
66     {
67         super(parent, idata, new IzPanelLayout());
68         // We load the licence
69
loadLicence();
70
71         // We put our components
72

73         add(LabelFactory.create(parent.langpack.getString("LicencePanel.info"),
74                 parent.icons.getImageIcon("history"), LEADING), NEXT_LINE);
75         JTextArea JavaDoc textArea = new JTextArea JavaDoc(licence);
76         textArea.setCaretPosition(0);
77         textArea.setEditable(false);
78         textArea.setLineWrap(true);
79         textArea.setWrapStyleWord(true);
80         JScrollPane JavaDoc scroller = new JScrollPane JavaDoc(textArea);
81         scroller.setAlignmentX(LEFT_ALIGNMENT);
82         add(scroller, NEXT_LINE);
83
84         ButtonGroup JavaDoc group = new ButtonGroup JavaDoc();
85
86         yesRadio = new JRadioButton JavaDoc(parent.langpack.getString("LicencePanel.agree"), false);
87         group.add(yesRadio);
88         add(yesRadio, NEXT_LINE);
89         yesRadio.addActionListener(this);
90
91         noRadio = new JRadioButton JavaDoc(parent.langpack.getString("LicencePanel.notagree"), true);
92         group.add(noRadio);
93         add(noRadio, NEXT_LINE);
94         noRadio.addActionListener(this);
95         
96         setInitialFocus(noRadio);
97         getLayoutHelper().completeLayout();
98     }
99
100     /** Loads the licence text. */
101     private void loadLicence()
102     {
103         try
104         {
105             // We read it
106
String JavaDoc resNamePrifix = "LicencePanel.licence";
107             licence = ResourceManager.getInstance().getTextResource(resNamePrifix);
108         }
109         catch (Exception JavaDoc err)
110         {
111             licence = "Error : could not load the licence text !";
112         }
113     }
114
115     /**
116      * Actions-handling method (here it allows the installation).
117      *
118      * @param e The event.
119      */

120     public void actionPerformed(ActionEvent JavaDoc e)
121     {
122         if (yesRadio.isSelected())
123             parent.unlockNextButton();
124         else
125             parent.lockNextButton();
126     }
127
128     /**
129      * Indicates wether the panel has been validated or not.
130      *
131      * @return true if the user has agreed.
132      */

133     public boolean isValidated()
134     {
135         if (noRadio.isSelected())
136         {
137             parent.exit();
138             return false;
139         }
140         return (yesRadio.isSelected());
141     }
142
143     /** Called when the panel becomes active. */
144     public void panelActivate()
145     {
146         if (!yesRadio.isSelected()) parent.lockNextButton();
147     }
148 }
149
Popular Tags