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.net.URL;
023:
024: import javax.swing.JEditorPane;
025: import javax.swing.JScrollPane;
026: import javax.swing.event.HyperlinkEvent;
027: import javax.swing.event.HyperlinkListener;
028:
029: import com.izforge.izpack.gui.IzPanelLayout;
030: import com.izforge.izpack.gui.LabelFactory;
031: import com.izforge.izpack.installer.InstallData;
032: import com.izforge.izpack.installer.InstallerFrame;
033: import com.izforge.izpack.installer.IzPanel;
034: import com.izforge.izpack.installer.ResourceManager;
035:
036: /**
037: * The HTML info panel.
038: *
039: * @author Julien Ponge
040: */
041: public class HTMLInfoPanel extends IzPanel implements HyperlinkListener {
042:
043: private static final long serialVersionUID = 3257008769514025270L;
044:
045: /** The text area. */
046: private JEditorPane textArea;
047:
048: /**
049: * The constructor.
050: *
051: * @param parent The parent.
052: * @param idata The installation data.
053: */
054: public HTMLInfoPanel(InstallerFrame parent, InstallData idata) {
055: super (parent, idata, new IzPanelLayout());
056: // We add the components
057:
058: add(LabelFactory.create(parent.langpack
059: .getString("InfoPanel.info"), parent.icons
060: .getImageIcon("edit"), LEADING), NEXT_LINE);
061: try {
062: textArea = new JEditorPane();
063: textArea.setContentType("text/html; charset=utf-8");
064: textArea.setEditable(false);
065: textArea.addHyperlinkListener(this );
066: JScrollPane scroller = new JScrollPane(textArea);
067: textArea.setPage(loadInfo());
068: add(scroller, NEXT_LINE);
069: } catch (Exception err) {
070: err.printStackTrace();
071: }
072: getLayoutHelper().completeLayout();
073: }
074:
075: /**
076: * Loads the info.
077: *
078: * @return The info URL.
079: */
080: private URL loadInfo() {
081: String resNamePrifix = "HTMLInfoPanel.info";
082: try {
083: return ResourceManager.getInstance().getURL(resNamePrifix);
084: } catch (Exception ex) {
085: ex.printStackTrace();
086: }
087: return null;
088: }
089:
090: /**
091: * Indicates wether the panel has been validated or not.
092: *
093: * @return Always true.
094: */
095: public boolean isValidated() {
096: return true;
097: }
098:
099: /**
100: * Hyperlink events handler.
101: *
102: * @param e The event.
103: */
104: public void hyperlinkUpdate(HyperlinkEvent e) {
105: try {
106: if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
107: String urls = e.getURL().toExternalForm();
108: // if the link points to a chapter in the same page
109: // don't open a browser
110: if (urls.contains("HTMLInfoPanel.info#"))
111: textArea.setPage(e.getURL());
112: else {
113: if (com.izforge.izpack.util.OsVersion.IS_OSX) {
114: Runtime.getRuntime().exec("open " + urls);
115: } else if (com.izforge.izpack.util.OsVersion.IS_UNIX) {
116: String[] launchers = { "htmlview QqzURL",
117: "xdg-open QqzURL", "gnome-open QqzURL",
118: "kfmclient openURL QqzURL",
119: "call-browser QqzURL",
120: "firefox QqzURL", "opera QqzURL",
121: "konqueror QqzURL", "epiphany QqzURL",
122: "mozilla QqzURL", "netscape QqzURL" };
123: //String launchers = "/bin/sh -c \"htmlview QqzURL || xdg-open QqzURL || gnome-open QqzURL || kfmclient openURL QqzURL || call-browser QqzURL || firefox QqzURL || opera QqzURL || konqueror QqzURL || epiphany QqzURL || mozilla QqzURL || netscape QqzURL\"";
124: for (String launcher : launchers) {
125:
126: try {
127: Runtime.getRuntime().exec(
128: launcher.replaceAll("QqzURL",
129: urls));
130: System.out.println("OK");
131: break;
132: } catch (Exception ignore) {
133: System.out
134: .println(launcher + " NOT OK");
135: }
136: }
137: } else // windows
138: {
139: Runtime.getRuntime().exec(
140: "cmd /C start " + urls);
141: }
142: }
143: }
144: } catch (Exception err) {
145: //TODO: Handle exception.
146: }
147: }
148: }
|