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 * 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 020package com.izforge.izpack.panels; 021 022import java.awt.GridBagConstraints; 023import java.awt.GridBagLayout; 024import java.awt.Insets; 025import java.net.URL; 026 027import javax.swing.JEditorPane; 028import javax.swing.JLabel; 029import javax.swing.JScrollPane; 030import javax.swing.event.HyperlinkEvent; 031import javax.swing.event.HyperlinkListener; 032 033import com.izforge.izpack.gui.LabelFactory; 034import com.izforge.izpack.installer.InstallData; 035import com.izforge.izpack.installer.InstallerFrame; 036import com.izforge.izpack.installer.IzPanel; 037import com.izforge.izpack.installer.ResourceManager; 038 039/** 040 * The HTML info panel. 041 * 042 * @author Julien Ponge 043 */ 044public class HTMLInfoPanel extends IzPanel implements HyperlinkListener 045{ 046 047 private static final long serialVersionUID = 3257008769514025270L; 048 049 /** The layout. */ 050 private GridBagLayout layout; 051 052 /** The layout constraints. */ 053 private GridBagConstraints gbConstraints; 054 055 /** The info label. */ 056 private JLabel infoLabel; 057 058 /** The text area. */ 059 private JEditorPane textArea; 060 061 /** 062 * The constructor. 063 * 064 * @param parent The parent. 065 * @param idata The installation data. 066 */ 067 public HTMLInfoPanel(InstallerFrame parent, InstallData idata) 068 { 069 super(parent, idata); 070 071 // We initialize our layout 072 layout = new GridBagLayout(); 073 gbConstraints = new GridBagConstraints(); 074 setLayout(layout); 075 076 // We add the components 077 078 infoLabel = LabelFactory.create(parent.langpack.getString("InfoPanel.info"), parent.icons 079 .getImageIcon("edit"), JLabel.TRAILING); 080 parent.buildConstraints(gbConstraints, 0, 0, 1, 1, 1.0, 0.0); 081 gbConstraints.insets = new Insets(5, 5, 5, 5); 082 gbConstraints.fill = GridBagConstraints.NONE; 083 gbConstraints.anchor = GridBagConstraints.SOUTHWEST; 084 layout.addLayoutComponent(infoLabel, gbConstraints); 085 add(infoLabel); 086 087 try 088 { 089 textArea = new JEditorPane(); 090 textArea.setEditable(false); 091 textArea.addHyperlinkListener(this); 092 JScrollPane scroller = new JScrollPane(textArea); 093 textArea.setPage(loadInfo()); 094 parent.buildConstraints(gbConstraints, 0, 1, 1, 1, 1.0, 1.0); 095 gbConstraints.anchor = GridBagConstraints.CENTER; 096 gbConstraints.fill = GridBagConstraints.BOTH; 097 layout.addLayoutComponent(scroller, gbConstraints); 098 add(scroller); 099 } 100 catch (Exception err) 101 { 102 err.printStackTrace(); 103 } 104 } 105 106 /** 107 * Loads the info. 108 * 109 * @return The info URL. 110 */ 111 private URL loadInfo() 112 { 113 String resNamePrifix = "HTMLInfoPanel.info"; 114 try 115 { 116 return ResourceManager.getInstance().getURL(resNamePrifix); 117 } 118 catch (Exception ex) 119 { 120 ex.printStackTrace(); 121 } 122 return null; 123 } 124 125 /** 126 * Indicates wether the panel has been validated or not. 127 * 128 * @return Always true. 129 */ 130 public boolean isValidated() 131 { 132 return true; 133 } 134 135 /** 136 * Hyperlink events handler. 137 * 138 * @param e The event. 139 */ 140 public void hyperlinkUpdate(HyperlinkEvent e) 141 { 142 try 143 { 144 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) 145 textArea.setPage(e.getURL()); 146 } 147 catch (Exception err) 148 {} 149 } 150}