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