1 19 20 package com.izforge.izpack.panels; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.net.URL ; 25 26 import javax.swing.ButtonGroup ; 27 import javax.swing.JEditorPane ; 28 import javax.swing.JRadioButton ; 29 import javax.swing.JScrollPane ; 30 import javax.swing.event.HyperlinkEvent ; 31 import javax.swing.event.HyperlinkListener ; 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 45 public class HTMLLicencePanel extends IzPanel implements HyperlinkListener , ActionListener 46 { 47 48 51 private static final long serialVersionUID = 3256728385458746416L; 52 53 54 private JEditorPane textArea; 55 56 57 private JRadioButton yesRadio; 58 private JRadioButton noRadio; 59 60 66 public HTMLLicencePanel(InstallerFrame parent, InstallData idata) 67 { 68 super(parent, idata, new IzPanelLayout()); 69 loadLicence(); 71 72 74 add(LabelFactory.create(parent.langpack.getString("LicencePanel.info"), 75 parent.icons.getImageIcon("history"), LEADING), NEXT_LINE); 76 try 77 { 78 textArea = new JEditorPane (); 79 textArea.setEditable(false); 80 textArea.addHyperlinkListener(this); 81 JScrollPane scroller = new JScrollPane (textArea); 82 textArea.setPage(loadLicence()); 83 add(scroller, NEXT_LINE); 84 } 85 catch (Exception err) 86 { 87 err.printStackTrace(); 88 } 89 90 ButtonGroup group = new ButtonGroup (); 91 92 yesRadio = new JRadioButton (parent.langpack.getString("LicencePanel.agree"), false); 93 group.add(yesRadio); 94 add(yesRadio, NEXT_LINE); 95 yesRadio.addActionListener(this); 96 97 noRadio = new JRadioButton (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 110 private URL loadLicence() 111 { 112 String resNamePrifix = "HTMLLicencePanel.licence"; 113 try 114 { 115 return ResourceManager.getInstance().getURL(resNamePrifix); 116 } 117 catch (Exception ex) 118 { 119 ex.printStackTrace(); 120 } 121 return null; 122 } 123 124 129 public void actionPerformed(ActionEvent e) 130 { 131 if (yesRadio.isSelected()) 132 parent.unlockNextButton(); 133 else 134 parent.lockNextButton(); 135 } 136 137 142 public boolean isValidated() 143 { 144 if (noRadio.isSelected()) 145 { 146 parent.exit(); 147 return false; 148 } 149 return (yesRadio.isSelected()); 150 } 151 152 157 public void hyperlinkUpdate(HyperlinkEvent e) 158 { 159 try 160 { 161 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) 162 textArea.setPage(e.getURL()); 163 } 164 catch (Exception err) 165 { 166 } 168 } 169 170 171 public void panelActivate() 172 { 173 if (!yesRadio.isSelected()) parent.lockNextButton(); 174 } 175 } 176 | Popular Tags |