Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / HTMLLicencePanel.java @ 15280

History | View | Annotate | Download (6.11 KB)

1
/*
2
 *  $Id: HTMLLicencePanel.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
3
 *  IzPack
4
 *  Copyright (C) 2001-2004 Julien Ponge
5
 *
6
 *  File :               HTMLLicencePanel.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
 *  This program is free software; you can redistribute it and/or
12
 *  modify it under the terms of the GNU General Public License
13
 *  as published by the Free Software Foundation; either version 2
14
 *  of the License, or any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program; if not, write to the Free Software
23
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
 */
25
package com.izforge.izpack.panels;
26

    
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.Insets;
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32
import java.net.URL;
33

    
34
import javax.swing.ButtonGroup;
35
import javax.swing.JEditorPane;
36
import javax.swing.JLabel;
37
import javax.swing.JRadioButton;
38
import javax.swing.JScrollPane;
39
import javax.swing.event.HyperlinkEvent;
40
import javax.swing.event.HyperlinkListener;
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 IzPack HTML license panel.
50
 *
51
 * @author     Julien Ponge
52
 */
53
public class HTMLLicencePanel
54
  extends IzPanel
55
  implements HyperlinkListener, ActionListener
56
{
57
  /**  The layout. */
58
  private GridBagLayout layout;
59

    
60
  /**  The layout constraints. */
61
  private GridBagConstraints gbConstraints;
62

    
63
  /**  The info label. */
64
  private JLabel infoLabel;
65

    
66
  /**  The text area. */
67
  private JEditorPane textArea;
68

    
69
  /**  The radio buttons. */
70
  private JRadioButton yesRadio, noRadio;
71

    
72
  /**
73
   *  The constructor.
74
   *
75
   * @param  idata   The installation data.
76
   * @param  parent  Description of the Parameter
77
   */
78
  public HTMLLicencePanel(InstallerFrame parent, InstallData idata)
79
  {
80
    super(parent, idata);
81

    
82
    // We initialize our layout
83
    layout = new GridBagLayout();
84
    gbConstraints = new GridBagConstraints();
85
    setLayout(layout);
86

    
87
    // We load the licence
88
    loadLicence();
89

    
90
    // We put our components
91

    
92
    infoLabel =
93
      LabelFactory.create(
94
        parent.langpack.getString("LicencePanel.info"),
95
        parent.icons.getImageIcon("history"),
96
        JLabel.TRAILING);
97
    parent.buildConstraints(gbConstraints, 0, 0, 2, 1, 1.0, 0.0);
98
    gbConstraints.insets = new Insets(5, 5, 5, 5);
99
    gbConstraints.fill = GridBagConstraints.NONE;
100
    gbConstraints.anchor = GridBagConstraints.WEST;
101
    layout.addLayoutComponent(infoLabel, gbConstraints);
102
    add(infoLabel);
103

    
104
    try
105
    {
106
      textArea = new JEditorPane();
107
      textArea.setEditable(false);
108
      textArea.addHyperlinkListener(this);
109
      JScrollPane scroller = new JScrollPane(textArea);
110
      textArea.setPage(loadLicence());
111
      parent.buildConstraints(gbConstraints, 0, 1, 2, 1, 1.0, 1.0);
112
      gbConstraints.anchor = GridBagConstraints.CENTER;
113
      gbConstraints.fill = GridBagConstraints.BOTH;
114
      layout.addLayoutComponent(scroller, gbConstraints);
115
      add(scroller);
116
    } catch (Exception err)
117
    {
118
      err.printStackTrace();
119
    }
120

    
121

    
122
    ButtonGroup group = new ButtonGroup();
123

    
124
    yesRadio =
125
      new JRadioButton(parent.langpack.getString("LicencePanel.agree"), false);
126
    group.add(yesRadio);
127
    parent.buildConstraints(gbConstraints, 0, 2, 1, 1, 1.0, 0.0);
128
    gbConstraints.anchor = GridBagConstraints.WEST;
129
    gbConstraints.fill = GridBagConstraints.NONE;
130
    layout.addLayoutComponent(yesRadio, gbConstraints);
131
    add(yesRadio);
132
    yesRadio.addActionListener(this);
133

    
134
    noRadio =
135
      new JRadioButton(
136
      parent.langpack.getString("LicencePanel.notagree"), 
137
      true);
138
    group.add(noRadio);
139
    parent.buildConstraints(gbConstraints, 0, 3, 1, 1, 1.0, 0.0);
140
    gbConstraints.anchor = GridBagConstraints.WEST;
141
    gbConstraints.fill = GridBagConstraints.NONE;
142
    gbConstraints.insets = new Insets(0, 5, 5, 5);
143
    layout.addLayoutComponent(noRadio, gbConstraints);
144
    add(noRadio);
145
    noRadio.addActionListener(this);
146
    setInitialFocus(textArea);
147
  }
148

    
149
  /**
150
   *  Loads the license text.
151
   *
152
   * @return    The license text URL.
153
   */
154
  private URL loadLicence()
155
  {
156
    String resNamePrifix = "HTMLLicencePanel.licence";
157
    try
158
    {
159
      return ResourceManager.getInstance().getURL(resNamePrifix);
160
    } catch (Exception ex)
161
    {
162
      ex.printStackTrace();
163
    }
164
    return null;
165
  }
166

    
167
  /**
168
   *  Actions-handling method (here it launches the installation).
169
   *
170
   * @param  e  The event.
171
   */
172
  public void actionPerformed(ActionEvent e)
173
  {
174
    if (yesRadio.isSelected())
175
      parent.unlockNextButton();
176
    else
177
      parent.lockNextButton();
178
  }
179

    
180
  /**
181
   *  Indicates wether the panel has been validated or not.
182
   *
183
   * @return    true if the user agrees with the license, false otherwise.
184
   */
185
  public boolean isValidated()
186
  {
187
    if (noRadio.isSelected())
188
    {
189
      parent.exit();
190
      return false;
191
    } else
192
      return (yesRadio.isSelected());
193
  }
194

    
195
  /**
196
   *  Hyperlink events handler.
197
   *
198
   * @param  e  The event.
199
   */
200
  public void hyperlinkUpdate(HyperlinkEvent e)
201
  {
202
    try
203
    {
204
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
205
        textArea.setPage(e.getURL());
206
    } catch (Exception err)
207
    {
208
    }
209
  }
210

    
211
  /**  Called when the panel becomes active.  */
212
  public void panelActivate()
213
  {
214
    if (!yesRadio.isSelected())
215
      parent.lockNextButton();
216
  }
217
}