1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.ui; |
17 | |
18 | import java.net.URL; |
19 | import java.util.Date; |
20 | |
21 | import javax.swing.Icon; |
22 | import javax.swing.event.HyperlinkEvent; |
23 | import javax.swing.event.HyperlinkListener; |
24 | |
25 | import net.roydesign.ui.StandardMacAboutFrame; |
26 | import net.sf.jomic.common.JomicTools; |
27 | import net.sf.jomic.common.Version; |
28 | import net.sf.jomic.tools.ErrorTools; |
29 | import net.sf.jomic.tools.LocaleTools; |
30 | import net.sf.jomic.tools.StringTools; |
31 | import net.sf.jomic.tools.SystemTools; |
32 | |
33 | /** |
34 | * AboutFrame is a frame with an icon, a text using a Mac OS X Cocoa style. |
35 | * |
36 | * @author Thomas Aglassinger |
37 | */ |
38 | public class AboutFrame extends StandardMacAboutFrame implements HyperlinkListener |
39 | { |
40 | private static final String[] APPLICATION_CREDITS = new String[]{ |
41 | "ant", "http://ant.apache.org/", |
42 | "BareBonesBrowserLaunch", "http://www.centerkey.com/java/browser/", |
43 | "commons", "http://commons.apache.org/", |
44 | "Crystal icons", "http://www.everaldo.com/crystal.html", |
45 | "gnu.regexp", "http://www.cacas.org/java/gnu/regexp/", |
46 | "IzPack", "http://izpack.org/", |
47 | "JavaHelp", "http://java.sun.com/products/javahelp/", |
48 | "JDOM", "http://www.jdom.org/", |
49 | "JH Labs", "http://www.jhlabs.com/ip/filters/index.html", |
50 | "JSAP", "http://www.martiansoftware.com/jsap/", |
51 | "junrar", "https://github.com/edmund-wagner/junrar", |
52 | "Log4j", "http://logging.apache.org/log4j/", |
53 | "MRJAdapter", "http://homepage.mac.com/sroy/mrjadapter/", |
54 | "pdfbox", "http://pdfbox.apache.org/", |
55 | "Quaqua", "http://www.randelshofer.ch/quaqua/", |
56 | "Xalan-J", "http://xml.apache.org/xalan-j/", |
57 | "Xerces", "http://xml.apache.org/" |
58 | }; |
59 | |
60 | private static final String[] DEVELOPMENT_CREDITS = new String[]{ |
61 | "Abbot", "http://abbot.sourceforge.net/", |
62 | "Batik", "http://xml.apache.org/batik/", |
63 | "Checkstyle", "http://checkstyle.sourceforge.net/", |
64 | "eclipse", "http://www.eclipse.org/", |
65 | "EMMA", "http://emma.sourceforge.net/", |
66 | "FindBugs", "http://findbugs.sourceforge.net/", |
67 | "FOP", "http://xmlgraphics.apache.org/fop/", |
68 | "gnuplot", "http://www.gnuplot.info/", |
69 | "JAI", "http://java.sun.com/products/java-media/jai/", |
70 | "JDepend", "http://clarkware.com/software/JDepend.html", |
71 | "JRefactory", "http://jrefactory.sourceforge.net/", |
72 | "JUnit", "http://www.junit.org/", |
73 | "Subversion", "http://subversion.tigris.org/" |
74 | }; |
75 | |
76 | private ErrorTools errorTools; |
77 | private JomicTools jomicTools; |
78 | private LocaleTools localeTools; |
79 | private StringTools stringTools; |
80 | private SystemTools systemTools; |
81 | |
82 | /** |
83 | * Creates an AboutBox with a given title, message and icon and centers it over the parent |
84 | * component. |
85 | */ |
86 | public AboutFrame() { |
87 | super("Jomic", null); |
88 | |
89 | assert APPLICATION_CREDITS.length % 2 == 0; |
90 | assert DEVELOPMENT_CREDITS.length % 2 == 0; |
91 | |
92 | errorTools = ErrorTools.instance(); |
93 | jomicTools = JomicTools.instance(); |
94 | localeTools = LocaleTools.instance(); |
95 | stringTools = StringTools.instance(); |
96 | systemTools = SystemTools.instance(); |
97 | |
98 | Icon icon = JomicTools.instance().getJomicLogo(); |
99 | String descriptionText = localeTools.getMessage("dialogs.about.description"); |
100 | String licenseText = localeTools.getMessage("dialogs.about.license"); |
101 | Date versionDate = JomicTools.instance().getVersionDate(); |
102 | Object[] versionOptions = new Object[]{Version.VERSION_TAG, versionDate}; |
103 | String version = localeTools.getMessage("dialogs.about.version", versionOptions); |
104 | |
105 | setApplicationVersion(version); |
106 | setApplicationIcon(icon); |
107 | setCopyright(Version.COPYRIGHT); |
108 | setCredits("<p>" + stringTools.asHtmlEscaped(descriptionText) + "</p>" |
109 | + getLinks("application", APPLICATION_CREDITS) |
110 | + getLinks("development", DEVELOPMENT_CREDITS) |
111 | + getHeading("license") |
112 | + licenseText, |
113 | "text/html"); |
114 | setHyperlinkListener(this); |
115 | jomicTools.setIconToJomicLogo(this); |
116 | } |
117 | |
118 | private String getHeading(String headingLocalizationKeySuffix) { |
119 | assert headingLocalizationKeySuffix != null; |
120 | String title = localeTools.getMessage("dialogs.about.heading." + headingLocalizationKeySuffix); |
121 | String result = "<p><b>" + stringTools.asHtmlEscaped(title) + "</b></p>"; |
122 | |
123 | return result; |
124 | } |
125 | |
126 | private String getLinks(String headingLocalizationKeySuffix, String[] credits) { |
127 | assert headingLocalizationKeySuffix != null; |
128 | assert credits != null; |
129 | assert credits.length % 2 == 0; |
130 | |
131 | String result = getHeading(headingLocalizationKeySuffix); |
132 | boolean isFirst = true; |
133 | |
134 | result += "<p>"; |
135 | for (int i = 0; i < credits.length; i += 2) { |
136 | String product = credits[i]; |
137 | String link = credits[i + 1]; |
138 | |
139 | if (isFirst) { |
140 | isFirst = false; |
141 | } else { |
142 | result += " \u00b7 "; |
143 | } |
144 | result += "<a href=\"" + stringTools.asHtmlEscaped(link) + "\">" |
145 | + stringTools.asHtmlEscaped(product) + "</a>"; |
146 | } |
147 | result += "</p>"; |
148 | return result; |
149 | } |
150 | |
151 | public void dispose() { |
152 | setHyperlinkListener(null); |
153 | super.dispose(); |
154 | } |
155 | |
156 | public void hyperlinkUpdate(HyperlinkEvent linkEvent) { |
157 | URL siteToOpen = null; |
158 | |
159 | try { |
160 | assert linkEvent != null; |
161 | |
162 | if (linkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
163 | siteToOpen = linkEvent.getURL(); |
164 | systemTools.openURL(siteToOpen.toExternalForm()); |
165 | } |
166 | } catch (Throwable error) { |
167 | errorTools.showErrorMessage(this, localeTools.getMessage("errors.cannotOpenLink", siteToOpen), error); |
168 | } |
169 | } |
170 | } |