diff options
author | Jiri Vanek <[email protected]> | 2012-08-13 15:52:03 +0200 |
---|---|---|
committer | Jiri Vanek <[email protected]> | 2012-08-13 15:52:03 +0200 |
commit | 94049c8dd94caec6f2178e729893b2ba8cafbe74 (patch) | |
tree | 1f20174c59f6bd0e98d6549f07857afab19e7a19 /netx/net/sourceforge/jnlp/splashscreen/parts | |
parent | a0e3685615521759e08246d348dc6fbf58f8a6bc (diff) |
Added splashscreen implementation
Diffstat (limited to 'netx/net/sourceforge/jnlp/splashscreen/parts')
6 files changed, 1083 insertions, 0 deletions
diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentErrorSplashScreen.java b/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentErrorSplashScreen.java new file mode 100644 index 0000000..6210de9 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentErrorSplashScreen.java @@ -0,0 +1,85 @@ +/* BasicComponentSplashScreen.java +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +package net.sourceforge.jnlp.splashscreen.parts; + +import net.sourceforge.jnlp.splashscreen.SplashErrorPanel; + +public abstract class BasicComponentErrorSplashScreen extends BasicComponentSplashScreen implements SplashErrorPanel { + + /** + * When applet loading fails, then dying stacktrace can be stted, and is then shown to user on demand. + */ + private Throwable loadingException; + + + /** + * @return the loadingException + */ + @Override + public Throwable getLoadingException() { + return loadingException; + } + + /** + * @param loadingException the loadingException to set + */ + @Override + public void setLoadingException(Throwable loadingException) { + this.loadingException = loadingException; + } + + + + protected void raiseExceptionDialogNOW() { + JEditorPaneBasedExceptionDialog dialog = new JEditorPaneBasedExceptionDialog(null, true, getLoadingException(), getInformationElement(), createAditionalInfo()); + dialog.setVisible(true); + } + + protected void raiseExceptionDialogQUEUED() { + java.awt.EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + raiseExceptionDialogNOW(); + } + }); + } + + protected void raiseExceptionDialog() { + raiseExceptionDialogQUEUED(); + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentSplashScreen.java b/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentSplashScreen.java new file mode 100644 index 0000000..eaadf39 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentSplashScreen.java @@ -0,0 +1,156 @@ +/* BasicComponentSplashScreen.java +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +package net.sourceforge.jnlp.splashscreen.parts; + +import javax.swing.JComponent; +import net.sourceforge.jnlp.splashscreen.SplashPanel; +import net.sourceforge.jnlp.splashscreen.SplashUtils.SplashReason; + +public abstract class BasicComponentSplashScreen extends JComponent implements SplashPanel { + //scaling 100% + public static final double ORIGINAL_W = 635; + public static final double ORIGINAL_H = 480; + /** Width of the plugin window */ + protected int pluginWidth; + /** Height of the plugin window */ + protected int pluginHeight; + /** The project name to display */ + private SplashReason splashReason; + private boolean animationRunning = false; + private InformationElement content; + private String version; + + @Override + public JComponent getSplashComponent() { + return this; + } + + @Override + public boolean isAnimationRunning() { + return animationRunning; + } + + public void setAnimationRunning(boolean b){ + animationRunning=b; + } + + @Override + public void setInformationElement(InformationElement content) { + this.content = content; + } + + @Override + public InformationElement getInformationElement() { + return content; + } + + + /** + * @return the pluginWidth + */ + @Override + public int getSplashWidth() { + return pluginWidth; + } + + /** + * @param pluginWidth the pluginWidth to set + */ + @Override + public void setSplashWidth(int pluginWidth) { + this.pluginWidth = pluginWidth; + } + + /** + * @return the pluginHeight + */ + @Override + public int getSplashHeight() { + return pluginHeight; + } + + /** + * @param pluginHeight the pluginHeight to set + */ + @Override + public void setSplashHeight(int pluginHeight) { + this.pluginHeight = pluginHeight; + } + + /** + * @return the splashReason + */ + @Override + public SplashReason getSplashReason() { + return splashReason; + } + + /** + * @param splashReason the splashReason to set + */ + @Override + public void setSplashReason(SplashReason splashReason) { + this.splashReason = splashReason; + } + + /** + * @return the version + */ + @Override + public String getVersion() { + return version; + } + + /** + * @param version the version to set + */ + @Override + public void setVersion(String version) { + this.version = version; + } + + + protected String createAditionalInfo() { + if (getVersion() != null) { + return getSplashReason().toString() + " version: " + getVersion(); + } else { + return null; + } + } + + +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/DescriptionInfoItem.java b/netx/net/sourceforge/jnlp/splashscreen/parts/DescriptionInfoItem.java new file mode 100644 index 0000000..6af7562 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/DescriptionInfoItem.java @@ -0,0 +1,126 @@ +/* DescriptionInfoItem.java +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +package net.sourceforge.jnlp.splashscreen.parts; + +/** + *description element: A short statement about the application. Description + * elements are optional. The kind attribute defines how the description should + * be used. It can have one of the following values: + * + * * one-line: If a reference to the application is going to appear on one row + * in a list or a table, this description will be used. + * * short: If a reference to the application is going to be displayed in a + * situation where there is room for a paragraph, this description is used. + * * tooltip: If a reference to the application is going to appear in a + * tooltip, this description is used. + * + * Only one description element of each kind can be specified. A description + * element without a kind is used as a default value. Thus, if Java Web Start + * needs a description of kind short, and it is not specified in the JNLP file, + * then the text from the description without an attribute is used. + * + * All descriptions contain plain text. No formatting, such as with HTML tags, + * is supported. + */ +public class DescriptionInfoItem extends InfoItem { + + protected String kind; + + public DescriptionInfoItem(String value, String kind) { + super(InfoItem.description, value); + this.kind = kind; + } + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + + public boolean isOfSameKind(DescriptionInfoItem o) { + if (o.getKind() == null && getKind() == null) { + return true; + } + if (o.getKind() == null && getKind() != null) { + return false; + } + if (o.getKind() != null && getKind() == null) { + return false; + } + return (o.getKind().equals(getKind())); + } + + public boolean isSame(DescriptionInfoItem o) { + return isOfSameKind(o) && isofSameType(o); + + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof DescriptionInfoItem)) { + return false; + } + DescriptionInfoItem o = (DescriptionInfoItem) obj; + return super.equals(o) && isOfSameKind(o); + + + } + + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + (this.kind != null ? this.kind.hashCode() : 0); + hash = 59 * hash + (this.getType() != null ? this.getType().hashCode() : 0); + hash = 59 * hash + (this.getValue() != null ? this.getValue().hashCode() : 0); + return hash; + } + + @Override + public String toString() { + return super.toString() + " (" + getKind() + ")"; + } + + + + @Override + public String toNiceString() { + return super.toNiceString(); + } + +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/InfoItem.java b/netx/net/sourceforge/jnlp/splashscreen/parts/InfoItem.java new file mode 100644 index 0000000..8dea28b --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/InfoItem.java @@ -0,0 +1,145 @@ +/* InfoItem.java +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +package net.sourceforge.jnlp.splashscreen.parts; + +import net.sourceforge.jnlp.InformationDesc; +import net.sourceforge.jnlp.runtime.Translator; + +/** + * The optional kind="splash" attribute may be used in an icon element to + * indicate that the image is to be used as a "splash" screen during the launch + * of an application. If the JNLP file does not contain an icon element with + * kind="splash" attribute, Java Web Start will construct a splash screen using + * other items from the information Element. + * If the JNLP file does not contain any icon images, the splash image will + * consist of the application's title and vendor, as taken from the JNLP file. + * + * items not used inside + */ +public class InfoItem { + + public static final String SPLASH = "SPLASH"; + public static final String title = "title"; + public static final String vendor = "vendor"; + public static final String homepage = "homepage"; + public static final String homepageHref = "href"; + public static final String description = "description"; + public static final String descriptionKind = "kind"; + public static final String descriptionKindOneLine = (String) InformationDesc.ONE_LINE; + //when no kind is specified, then it should behave as short + public static final String descriptionKindShort = (String) InformationDesc.SHORT; + public static final String descriptionKindToolTip = (String) InformationDesc.TOOLTIP; + protected String type; + protected String value; + + + public InfoItem(String type, String value) { + this.type = type; + this.value = value; + } + + /** + * @return the type + */ + public String getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + + /** + * @return the value + */ + public String getValue() { + return value; + } + + /** + * @param value the value to set + */ + public void setValue(String value) { + this.value = value; + } + + public boolean isofSameType(InfoItem o) { + return ((getType().equals(o.getType()))); + + + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof InfoItem)) { + return false; + } + InfoItem o = (InfoItem) obj; + return isofSameType(o) && (getValue().equals(o.getValue())); + + + + } + + @Override + public String toString() { + return type + ": " + value; + } + + + + + public String toNiceString() { + String key = SPLASH + type; + return localise(key, value); + } + + public static String localise(String key, String s) { + return Translator.R(key) + ": " + s; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + (this.getType() != null ? this.getType().hashCode() : 0); + hash = 59 * hash + (this.getValue() != null ? this.getValue().hashCode() : 0); + return hash; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/InformationElement.java b/netx/net/sourceforge/jnlp/splashscreen/parts/InformationElement.java new file mode 100644 index 0000000..9e5101a --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/InformationElement.java @@ -0,0 +1,214 @@ +/* InformationElement.java +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +/** +http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html + */ +package net.sourceforge.jnlp.splashscreen.parts; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import net.sourceforge.jnlp.InformationDesc; +import net.sourceforge.jnlp.JNLPFile; + +/** + * This class is wrapper arround <information> tag which should + * javaws provide from source jnlp file + */ +public class InformationElement { + + private InfoItem title; + private InfoItem vendor; + private InfoItem homepage; + private List<DescriptionInfoItem> descriptions = new ArrayList<DescriptionInfoItem>(5); + + public void setTitle(String title) { + if (title == null) { + return; + } + this.title = new InfoItem(InfoItem.title, title); + } + + public void setvendor(String vendor) { + if (vendor == null) { + return; + } + this.vendor = new InfoItem(InfoItem.vendor, vendor); + } + + public void setHomepage(String homepage) { + if (homepage == null) { + return; + } + this.homepage = new InfoItem(InfoItem.homepage, homepage); + } + + public void addDescription(String description) { + addDescription(description, null); + } + + /** + * Just one description of each kind (4 including null) are allowed in information element. + * This method should throw exception when trying to add second description of same kind + * But I do not consider it as good idea to force this behaviour for somesing like psalsh screen, + * so I jsut replace the previous one with new one. without any warning + */ + public void addDescription(String description, String kind) { + if (description == null) { + return; + } + DescriptionInfoItem d = new DescriptionInfoItem(description, kind); + for (DescriptionInfoItem descriptionInfoItem : descriptions) { + if (descriptionInfoItem.isOfSameKind(d)) { + descriptions.remove(descriptionInfoItem); + descriptions.add(d); + return; + } + } + descriptions.add(d); + + } + + public InfoItem getBestMatchingDescriptionForSplash() { + for (DescriptionInfoItem d : descriptions) { + if (InfoItem.descriptionKindOneLine.equals(d.getKind())) { + return d; + } + } + for (DescriptionInfoItem d : descriptions) { + if (d.getKind() == null) { + return d; + } + } + return null; + } + + public InfoItem getLongestDescriptionForSplash() { + for (DescriptionInfoItem d : descriptions) { + if (InfoItem.descriptionKindShort.equals(d.getKind())) { + return d; + } + } + for (DescriptionInfoItem d : descriptions) { + if (d.getKind() == null) { + return d; + } + } + for (DescriptionInfoItem d : descriptions) { + if (InfoItem.descriptionKindOneLine.equals(d.getKind())) { + return d; + } + } + for (DescriptionInfoItem d : descriptions) { + if (InfoItem.descriptionKindToolTip.equals(d.getKind())) { + return d; + } + } + return null; + } + + public String getTitle() { + if (title == null) { + return null; + } + return title.toNiceString(); + } + + public String getVendor() { + if (vendor == null) { + return null; + } + return vendor.toNiceString(); + } + + public String getHomepage() { + if (homepage == null) { + return null; + } + return homepage.toNiceString(); + } + + List<DescriptionInfoItem> getDescriptions() { + return Collections.unmodifiableList(descriptions); + } + + public String getDescription() { + InfoItem i = getBestMatchingDescriptionForSplash(); + if (i == null) { + return null; + } + return i.toNiceString(); + } + + public List<String> getHeader() { + List<String> r = new ArrayList<String>(4); + String t = getTitle(); + String v = getVendor(); + String h = getHomepage(); + if (t != null) { + r.add(t); + } + if (v != null) { + r.add(v); + } + if (h != null) { + r.add(h); + } + + return r; + } + + public static InformationElement createFromJNLP(JNLPFile file) { + if (file == null) { + return null; + } + try { + InformationElement ie = new InformationElement(); + ie.setHomepage(file.getInformation().getHomepage().toString()); + ie.setTitle(file.getInformation().getTitle()); + ie.setvendor(file.getInformation().getVendor()); + ie.addDescription(file.getInformation().getDescriptionStrict((String) (InformationDesc.DEFAULT))); + ie.addDescription(file.getInformation().getDescriptionStrict(InfoItem.descriptionKindOneLine), InfoItem.descriptionKindOneLine); + ie.addDescription(file.getInformation().getDescriptionStrict(InfoItem.descriptionKindShort), InfoItem.descriptionKindShort); + ie.addDescription(file.getInformation().getDescriptionStrict(InfoItem.descriptionKindToolTip), InfoItem.descriptionKindToolTip); + return ie; + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java b/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java new file mode 100644 index 0000000..8cc6070 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java @@ -0,0 +1,357 @@ +/* JeditorPaneBasedExceptionDialog.java +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +package net.sourceforge.jnlp.splashscreen.parts; + +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.awt.event.WindowEvent; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.List; +import javax.swing.BorderFactory; +import javax.swing.GroupLayout; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JEditorPane; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.LayoutStyle; +import javax.swing.SwingConstants; +import javax.swing.WindowConstants; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import net.sourceforge.jnlp.runtime.Translator; + +public class JEditorPaneBasedExceptionDialog extends JDialog implements HyperlinkListener { + + // components + private JButton closeButton; + private JButton closeAndCopyButton; + private JButton homeButton; + private JEditorPane htmlErrorAndHelpPanel; + private JLabel exceptionLabel; + private JLabel iconLabel; + private JPanel mainPanel; + private JPanel topPanel; + private JPanel bottomPanel; + private JScrollPane htmlPaneScroller; + // End of components declaration + private final String message; + private final Throwable exception; + + /** Creates new form JEditorPaneBasedExceptionDialog */ + public JEditorPaneBasedExceptionDialog(java.awt.Frame parent, boolean modal, Throwable ex, InformationElement information, String anotherInfo) { + super(parent, modal); + initComponents(); + htmlErrorAndHelpPanel.setContentType("text/html"); + htmlErrorAndHelpPanel.setEditable(false); + List<String> l = infoElementToList(information); + this.message = getText(ex, l, anotherInfo); + this.exception = ex; + if (exception == null) { + closeAndCopyButton.setVisible(false); + } + htmlErrorAndHelpPanel.setText(message); + //htmlPaneScroller.getVerticalScrollBar().setValue(1); + htmlErrorAndHelpPanel.setCaretPosition(0); + try { + Icon icon = new ImageIcon(this.getClass().getResource("/net/sourceforge/jnlp/resources/warning.png")); + iconLabel.setIcon(icon); + } catch (Exception lex) { + lex.printStackTrace(); + } + htmlErrorAndHelpPanel.addHyperlinkListener(this); + homeButton.setVisible(false); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + + } + + static List<String> infoElementToList(InformationElement information) { + List<String> l = null; + if (information != null) { + l = information.getHeader(); + InfoItem ii = information.getLongestDescriptionForSplash(); + if (ii != null) { + l.add(ii.toNiceString()); + } + } + return l; + } + + private void initComponents() { + + topPanel = new JPanel(); + closeButton = new JButton(); + closeAndCopyButton = new JButton(); + mainPanel = new JPanel(); + exceptionLabel = new JLabel(); + iconLabel = new JLabel(); + bottomPanel = new JPanel(); + htmlPaneScroller = new JScrollPane(); + htmlErrorAndHelpPanel = new JEditorPane(); + homeButton = new JButton(); + + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + + closeButton.setText(Translator.R(InfoItem.SPLASH + "Close")); + closeButton.addActionListener(new java.awt.event.ActionListener() { + + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + closeWindowButtonActionPerformed(evt); + } + }); + + closeAndCopyButton.setText(Translator.R(InfoItem.SPLASH + "closewAndCopyException")); + closeAndCopyButton.addActionListener(new java.awt.event.ActionListener() { + + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + copyAndCloseButtonActionPerformed(evt); + } + }); + + GroupLayout jPanel2Layout = new GroupLayout(topPanel); + topPanel.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(closeButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 314, Short.MAX_VALUE).addComponent(closeAndCopyButton).addContainerGap())); + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addContainerGap(24, Short.MAX_VALUE).addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(closeButton).addComponent(closeAndCopyButton)).addContainerGap())); + + exceptionLabel.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N + exceptionLabel.setHorizontalAlignment(SwingConstants.CENTER); + exceptionLabel.setText(Translator.R(InfoItem.SPLASH + "exOccured")); + + bottomPanel.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); + bottomPanel.setLayout(new java.awt.BorderLayout()); + + htmlPaneScroller.setViewportView(htmlErrorAndHelpPanel); + + bottomPanel.add(htmlPaneScroller, java.awt.BorderLayout.CENTER); + + homeButton.setText(Translator.R(InfoItem.SPLASH + "Home")); + homeButton.addActionListener(new java.awt.event.ActionListener() { + + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + homeButtonActionPerformed(evt); + } + }); + + GroupLayout jPanel1Layout = new GroupLayout(mainPanel); + mainPanel.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(exceptionLabel, GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(homeButton, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE).addContainerGap()).addComponent(bottomPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 723, Short.MAX_VALUE)); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE).addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(exceptionLabel, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE).addComponent(homeButton, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE))).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(bottomPanel, GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))); + + GroupLayout layout = new GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING).addComponent(mainPanel, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(topPanel, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap())); + layout.setVerticalGroup( + layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(topPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap())); + + pack(); + } + + private void copyAndCloseButtonActionPerformed(java.awt.event.ActionEvent evt) { + if (exception != null) { + try { + StringSelection data = new StringSelection(getExceptionStackTraceAsString(exception)); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(data, data); + } catch (Exception ex) { + JOptionPane.showMessageDialog(this, Translator.R(InfoItem.SPLASH + "cantCopyEx")); + ex.printStackTrace(); + } + } else { + JOptionPane.showMessageDialog(this, Translator.R(InfoItem.SPLASH + "noExRecorded")); + } + close(); + } + + private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) { + htmlErrorAndHelpPanel.setText(message); + homeButton.setVisible(false); + } + + private void closeWindowButtonActionPerformed(java.awt.event.ActionEvent evt) { + close(); + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + Exception ex = new RuntimeException("dsgsfdg"); + JEditorPaneBasedExceptionDialog dialog = new JEditorPaneBasedExceptionDialog(new JFrame(), true, ex, null, "uaaa: aaa\nwqdeweq:sdsds"); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + static String getText(Throwable ex, List<String> l, String anotherInfo) { + StringBuilder s = new StringBuilder("<html><body>"); + String info = "<p>" + + Translator.R(InfoItem.SPLASH + "mainL1", createLink()) + + " </p> \n"; + String t = "<p>" + + Translator.R(InfoItem.SPLASH + "mainL3") + + "</p> \n" + + info + formatListInfoList(l) + formatInfo(anotherInfo); + Object[] options = new String[2]; + options[0] = Translator.R(InfoItem.SPLASH + "Close"); + options[1] = Translator.R(InfoItem.SPLASH + "closeAndCopyShorter"); + if (ex != null) { + t = "<p>" + + Translator.R(InfoItem.SPLASH + "mainL4") + + " </p>\n" + + info + formatListInfoList(l) + formatInfo(anotherInfo) + + "<p>" + + Translator.R(InfoItem.SPLASH + "exWas") + + " <br/>\n" + "<pre>" + getExceptionStackTraceAsString(ex) + "</pre>"; + + + } else { + t += formatListInfoList(l); + } + s.append(t); + s.append("</body></html>"); + return s.toString(); + } + + public static String getExceptionStackTraceAsString(Throwable exception) { + if (exception == null) { + return ""; + } + StringWriter sw = new StringWriter(); + exception.printStackTrace(new PrintWriter(sw)); + return sw.toString(); + } + + public static String[] getExceptionStackTraceAsStrings(Throwable exception) { + if (exception == null) { + return new String[0]; + } + StringWriter sw = new StringWriter(); + exception.printStackTrace(new PrintWriter(sw)); + return sw.toString().split("\n"); + } + + @Override + public void hyperlinkUpdate(HyperlinkEvent event) { + if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + try { + htmlErrorAndHelpPanel.setPage(event.getURL()); + homeButton.setVisible(true); + + } catch (Exception ioe) { + JOptionPane.showMessageDialog(this, Translator.R(InfoItem.SPLASH + "cfl") + " " + + event.getURL().toExternalForm() + ": " + ioe); + } + } + } + + private void close() { + processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); + } + + static String formatListInfoList(List<String> l) { + if (l == null) { + return ""; + } + StringBuilder sb = new StringBuilder(); + sb.append("<p>"); + sb.append("<h3>"). + append(Translator.R(InfoItem.SPLASH + "vendorsInfo")).append(":</h3>"); + sb.append("<pre>"); + for (int i = 0; i < l.size(); i++) { + String string = l.get(i); + sb.append(string).append("\n"); + } + sb.append("</pre>"); + sb.append("</p>"); + return sb.toString(); + } + + static String formatInfo(String l) { + if (l == null) { + return ""; + } + StringBuilder sb = new StringBuilder(); + sb.append("<p>"); + sb.append("<h3>"). + append(Translator.R(InfoItem.SPLASH + "anotherInfo")).append(": </h3>"); + sb.append("<pre>"); + sb.append(l); + sb.append("</pre>"); + sb.append("</p>"); + return sb.toString(); + } + + Throwable getException() { + return exception; + } + + String getMessage() { + return message; + } + + private static String createLink() { + return "<a href=\"" + Translator.R(InfoItem.SPLASH + "url") + "\">" + + Translator.R(InfoItem.SPLASH + "urlLooks") + "</a>"; + } + + +} |