001/* 002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved. 003 * 004 * http://www.izforge.com/izpack/ 005 * http://developer.berlios.de/projects/izpack/ 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 022package com.izforge.izpack.panels; 023 024import java.awt.Dimension; 025import java.awt.Insets; 026import java.awt.event.ActionEvent; 027import java.awt.event.ActionListener; 028 029import javax.swing.Box; 030import javax.swing.BoxLayout; 031import javax.swing.ButtonGroup; 032import javax.swing.JLabel; 033import javax.swing.JRadioButton; 034import javax.swing.JScrollPane; 035import javax.swing.JTextArea; 036 037import com.izforge.izpack.gui.LabelFactory; 038import com.izforge.izpack.installer.InstallData; 039import com.izforge.izpack.installer.InstallerFrame; 040import com.izforge.izpack.installer.IzPanel; 041import com.izforge.izpack.installer.ResourceManager; 042 043/** 044 * The license panel. 045 * 046 * @author Julien Ponge 047 */ 048public class LicencePanel extends IzPanel implements ActionListener 049{ 050 051 /** 052 * 053 */ 054 private static final long serialVersionUID = 3691043187997552948L; 055 056 /** The license text. */ 057 private String licence; 058 059 /** The text area. */ 060 private JTextArea textArea; 061 062 /** The radio buttons. */ 063 private JRadioButton yesRadio, noRadio; 064 065 /** The scrolling container. */ 066 private JScrollPane scroller; 067 068 /** 069 * The constructor. 070 * 071 * @param parent The parent window. 072 * @param idata The installation data. 073 */ 074 public LicencePanel(InstallerFrame parent, InstallData idata) 075 { 076 super(parent, idata); 077 078 // We initialize our layout 079 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 080 081 // We load the licence 082 loadLicence(); 083 084 // We put our components 085 086 JLabel infoLabel = LabelFactory.create(parent.langpack.getString("LicencePanel.info"), 087 parent.icons.getImageIcon("history"), JLabel.TRAILING); 088 add(infoLabel); 089 090 add(Box.createRigidArea(new Dimension(0, 3))); 091 092 textArea = new JTextArea(licence); 093 textArea.setMargin(new Insets(2, 2, 2, 2)); 094 textArea.setCaretPosition(0); 095 textArea.setEditable(false); 096 textArea.setLineWrap(true); 097 textArea.setWrapStyleWord(true); 098 scroller = new JScrollPane(textArea); 099 scroller.setAlignmentX(LEFT_ALIGNMENT); 100 add(scroller); 101 102 ButtonGroup group = new ButtonGroup(); 103 104 yesRadio = new JRadioButton(parent.langpack.getString("LicencePanel.agree"), false); 105 group.add(yesRadio); 106 add(yesRadio); 107 yesRadio.addActionListener(this); 108 109 noRadio = new JRadioButton(parent.langpack.getString("LicencePanel.notagree"), true); 110 group.add(noRadio); 111 add(noRadio); 112 noRadio.addActionListener(this); 113 } 114 115 /** Loads the licence text. */ 116 private void loadLicence() 117 { 118 try 119 { 120 // We read it 121 String resNamePrifix = "LicencePanel.licence"; 122 licence = ResourceManager.getInstance().getTextResource(resNamePrifix); 123 } 124 catch (Exception err) 125 { 126 licence = "Error : could not load the licence text !"; 127 } 128 } 129 130 /** 131 * Actions-handling method (here it allows the installation). 132 * 133 * @param e The event. 134 */ 135 public void actionPerformed(ActionEvent e) 136 { 137 if (yesRadio.isSelected()) 138 parent.unlockNextButton(); 139 else 140 parent.lockNextButton(); 141 } 142 143 /** 144 * Indicates wether the panel has been validated or not. 145 * 146 * @return true if the user has agreed. 147 */ 148 public boolean isValidated() 149 { 150 if (noRadio.isSelected()) 151 { 152 parent.exit(); 153 return false; 154 } 155 else 156 return (yesRadio.isSelected()); 157 } 158 159 /** Called when the panel becomes active. */ 160 public void panelActivate() 161 { 162 if (!yesRadio.isSelected()) parent.lockNextButton(); 163 } 164}