KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package com.izforge.izpack.panels;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.net.URL JavaDoc;
25
26 import javax.swing.ButtonGroup JavaDoc;
27 import javax.swing.JEditorPane JavaDoc;
28 import javax.swing.JRadioButton JavaDoc;
29 import javax.swing.JScrollPane JavaDoc;
30 import javax.swing.event.HyperlinkEvent JavaDoc;
31 import javax.swing.event.HyperlinkListener JavaDoc;
32
33 import com.izforge.izpack.gui.IzPanelLayout;
34 import com.izforge.izpack.gui.LabelFactory;
35 import com.izforge.izpack.installer.InstallData;
36 import com.izforge.izpack.installer.InstallerFrame;
37 import com.izforge.izpack.installer.IzPanel;
38 import com.izforge.izpack.installer.ResourceManager;
39
40 /**
41  * The IzPack HTML license panel.
42  *
43  * @author Julien Ponge
44  */

45 public class HTMLLicencePanel extends IzPanel implements HyperlinkListener JavaDoc, ActionListener JavaDoc
46 {
47
48     /**
49      *
50      */

51     private static final long serialVersionUID = 3256728385458746416L;
52
53     /** The text area. */
54     private JEditorPane JavaDoc textArea;
55
56     /** The radio buttons. */
57     private JRadioButton JavaDoc yesRadio;
58     private JRadioButton JavaDoc noRadio;
59
60     /**
61      * The constructor.
62      *
63      * @param idata The installation data.
64      * @param parent Description of the Parameter
65      */

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

74         add(LabelFactory.create(parent.langpack.getString("LicencePanel.info"),
75                 parent.icons.getImageIcon("history"), LEADING), NEXT_LINE);
76         try
77         {
78             textArea = new JEditorPane JavaDoc();
79             textArea.setEditable(false);
80             textArea.addHyperlinkListener(this);
81             JScrollPane JavaDoc scroller = new JScrollPane JavaDoc(textArea);
82             textArea.setPage(loadLicence());
83             add(scroller, NEXT_LINE);
84         }
85         catch (Exception JavaDoc err)
86         {
87             err.printStackTrace();
88         }
89
90         ButtonGroup JavaDoc group = new ButtonGroup JavaDoc();
91
92         yesRadio = new JRadioButton JavaDoc(parent.langpack.getString("LicencePanel.agree"), false);
93         group.add(yesRadio);
94         add(yesRadio, NEXT_LINE);
95         yesRadio.addActionListener(this);
96
97         noRadio = new JRadioButton JavaDoc(parent.langpack.getString("LicencePanel.notagree"), true);
98         group.add(noRadio);
99         add(noRadio, NEXT_LINE);
100         noRadio.addActionListener(this);
101         setInitialFocus(textArea);
102         getLayoutHelper().completeLayout();
103     }
104
105     /**
106      * Loads the license text.
107      *
108      * @return The license text URL.
109      */

110     private URL JavaDoc loadLicence()
111     {
112         String JavaDoc resNamePrifix = "HTMLLicencePanel.licence";
113         try
114         {
115             return ResourceManager.getInstance().getURL(resNamePrifix);
116         }
117         catch (Exception JavaDoc ex)
118         {
119             ex.printStackTrace();
120         }
121         return null;
122     }
123
124     /**
125      * Actions-handling method (here it launches the installation).
126      *
127      * @param e The event.
128      */

129     public void actionPerformed(ActionEvent JavaDoc e)
130     {
131         if (yesRadio.isSelected())
132             parent.unlockNextButton();
133         else
134             parent.lockNextButton();
135     }
136
137     /**
138      * Indicates wether the panel has been validated or not.
139      *
140      * @return true if the user agrees with the license, false otherwise.
141      */

142     public boolean isValidated()
143     {
144         if (noRadio.isSelected())
145         {
146             parent.exit();
147             return false;
148         }
149         return (yesRadio.isSelected());
150     }
151
152     /**
153      * Hyperlink events handler.
154      *
155      * @param e The event.
156      */

157     public void hyperlinkUpdate(HyperlinkEvent JavaDoc e)
158     {
159         try
160         {
161             if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
162                 textArea.setPage(e.getURL());
163         }
164         catch (Exception JavaDoc err)
165         {
166             // TODO: Extend exception handling.
167
}
168     }
169
170     /** Called when the panel becomes active. */
171     public void panelActivate()
172     {
173         if (!yesRadio.isSelected()) parent.lockNextButton();
174     }
175 }
176
Popular Tags