001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: package com.izforge.izpack.panels;
021:
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.net.URL;
025:
026: import javax.swing.ButtonGroup;
027: import javax.swing.JEditorPane;
028: import javax.swing.JRadioButton;
029: import javax.swing.JScrollPane;
030: import javax.swing.event.HyperlinkEvent;
031: import javax.swing.event.HyperlinkListener;
032:
033: import com.izforge.izpack.gui.IzPanelLayout;
034: import com.izforge.izpack.gui.LabelFactory;
035: import com.izforge.izpack.installer.InstallData;
036: import com.izforge.izpack.installer.InstallerFrame;
037: import com.izforge.izpack.installer.IzPanel;
038: import com.izforge.izpack.installer.ResourceManager;
039:
040: /**
041: * The IzPack HTML license panel.
042: *
043: * @author Julien Ponge
044: */
045: public class HTMLLicencePanel extends IzPanel implements
046: HyperlinkListener, ActionListener {
047:
048: /**
049: *
050: */
051: private static final long serialVersionUID = 3256728385458746416L;
052:
053: /** The text area. */
054: private JEditorPane textArea;
055:
056: /** The radio buttons. */
057: private JRadioButton yesRadio;
058: private JRadioButton noRadio;
059:
060: /**
061: * The constructor.
062: *
063: * @param idata The installation data.
064: * @param parent Description of the Parameter
065: */
066: public HTMLLicencePanel(InstallerFrame parent, InstallData idata) {
067: super (parent, idata, new IzPanelLayout());
068: // We load the licence
069: loadLicence();
070:
071: // We put our components
072:
073: add(LabelFactory.create(parent.langpack
074: .getString("LicencePanel.info"), parent.icons
075: .getImageIcon("history"), LEADING), NEXT_LINE);
076: try {
077: textArea = new JEditorPane();
078: textArea.setEditable(false);
079: textArea.addHyperlinkListener(this );
080: JScrollPane scroller = new JScrollPane(textArea);
081: textArea.setPage(loadLicence());
082: add(scroller, NEXT_LINE);
083: } catch (Exception err) {
084: err.printStackTrace();
085: }
086:
087: ButtonGroup group = new ButtonGroup();
088:
089: yesRadio = new JRadioButton(parent.langpack
090: .getString("LicencePanel.agree"), false);
091: group.add(yesRadio);
092: add(yesRadio, NEXT_LINE);
093: yesRadio.addActionListener(this );
094:
095: noRadio = new JRadioButton(parent.langpack
096: .getString("LicencePanel.notagree"), true);
097: group.add(noRadio);
098: add(noRadio, NEXT_LINE);
099: noRadio.addActionListener(this );
100: setInitialFocus(textArea);
101: getLayoutHelper().completeLayout();
102: }
103:
104: /**
105: * Loads the license text.
106: *
107: * @return The license text URL.
108: */
109: private URL loadLicence() {
110: String resNamePrifix = "HTMLLicencePanel.licence";
111: try {
112: return ResourceManager.getInstance().getURL(resNamePrifix);
113: } catch (Exception ex) {
114: ex.printStackTrace();
115: }
116: return null;
117: }
118:
119: /**
120: * Actions-handling method (here it launches the installation).
121: *
122: * @param e The event.
123: */
124: public void actionPerformed(ActionEvent e) {
125: if (yesRadio.isSelected())
126: parent.unlockNextButton();
127: else
128: parent.lockNextButton();
129: }
130:
131: /**
132: * Indicates wether the panel has been validated or not.
133: *
134: * @return true if the user agrees with the license, false otherwise.
135: */
136: public boolean isValidated() {
137: if (noRadio.isSelected()) {
138: parent.exit();
139: return false;
140: }
141: return (yesRadio.isSelected());
142: }
143:
144: /**
145: * Hyperlink events handler.
146: *
147: * @param e The event.
148: */
149: public void hyperlinkUpdate(HyperlinkEvent e) {
150: try {
151: if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
152: textArea.setPage(e.getURL());
153: } catch (Exception err) {
154: // TODO: Extend exception handling.
155: }
156: }
157:
158: /** Called when the panel becomes active. */
159: public void panelActivate() {
160: if (!yesRadio.isSelected())
161: parent.lockNextButton();
162: }
163: }
|