[Japi-cvs] SF.net SVN: japi: [289] libs/swing-about/trunk
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-01-14 13:12:59
|
Revision: 289 http://svn.sourceforge.net/japi/?rev=289&view=rev Author: christianhujer Date: 2007-01-14 05:12:51 -0800 (Sun, 14 Jan 2007) Log Message: ----------- Added AboutDialog source. Added Paths: ----------- libs/swing-about/trunk/libs-swing-about.iml libs/swing-about/trunk/src/net/sf/japi/swing/about/AboutDialog.java libs/swing-about/trunk/src/net/sf/japi/swing/about/action.properties Added: libs/swing-about/trunk/libs-swing-about.iml =================================================================== --- libs/swing-about/trunk/libs-swing-about.iml (rev 0) +++ libs/swing-about/trunk/libs-swing-about.iml 2007-01-14 13:12:51 UTC (rev 289) @@ -0,0 +1,188 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module version="4" relativePaths="true" type="JAVA_MODULE"> + <component name="ModuleRootManager" /> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="libs-swing-action" /> + <orderEntryProperties /> + </component> + <component name="copyright"> + <Base> + <setting name="state" value="2" /> + </Base> + <LanguageOptions name="$TEMPLATE$"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="4" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="CSS"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="HTML"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="JAVA"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="JSP"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="JavaScript"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="Properties"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="XML"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + </component> +</module> + Property changes on: libs/swing-about/trunk/libs-swing-about.iml ___________________________________________________________________ Name: svn:mime-type + text/xml Name: svn:eol-style + LF Added: libs/swing-about/trunk/src/net/sf/japi/swing/about/AboutDialog.java =================================================================== --- libs/swing-about/trunk/src/net/sf/japi/swing/about/AboutDialog.java (rev 0) +++ libs/swing-about/trunk/src/net/sf/japi/swing/about/AboutDialog.java 2007-01-14 13:12:51 UTC (rev 289) @@ -0,0 +1,281 @@ +package net.sf.japi.swing.about; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Font; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.Enumeration; +import java.util.Properties; +import java.util.ResourceBundle; +import java.util.SortedSet; +import java.util.TreeSet; +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.SwingConstants; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.Nullable; + +/** + * Class for constructing and showing About dialogs. + * It features: + * <ul> + * <li>logo</li> + * <li>about text - a descriptive text, maybe HTML, for instance to list the developers</li> + * <li>Showing the developer that built the software, the version, the date built</li> + * <li>All runtime properties</li> + * <li>All licenses the software uses</li> + * </ul> + * It requires the following properties to be available in the named ActionFactory: + * <ul> + * <li><code>about.logo</code> specifies the logo to display (optional)</li> + * <li><code>application.name</code> specifies the name of the application for the title of the about dialog (required)</li> + * <li> + * <code>about</code> specifies the format string for the about text in the about tab. + * It takes the following parameters: + * <ol> + * <li>The runtime's Java Version</li> + * <li>The build number</li> + * <li>The build developer</li> + * <li>The build timestamp</li> + * </ol> + * (See information on the build for how to specify the build information) + * </li> + * <li> + * Licenses: + * <ul> + * <li><code>license.<var>n</var>.title</code> specifies the title for license <var>n</var></li> + * <li><code>license.<var>n</var>.file</code> specifies the file for license <var>n</var></li> + * <li><var>n</var> starts with 1 and must be ascending without skips.</li> + * </ul> + * </li> + * <li><code>aboutBuildProperties.title</code> specifies the title for the build properties tab (optional - only required if the build properties tab is used)</li> + * <li><code>aboutRuntimeProperties.title</code> specifies the title for the runtime properties tab (required)</li> + * </ul> + * The information on the build is specified by: + * <ul> + * <li> + * A ResourceBundle <code>build</code> (optional, e.g. <code>build.properties</code> toplevel on classpath) + * <ul> + * <li><code>build.developer</code> The developer that made the build (optional)</li> + * <li><code>build.number</code> The build number, e.g. incremented by Ant or the Subversion revision (optional)</li> + * <li><code>build.tstamp</code> The timestamp when the build was made (optional)</li> + * </ul> + * </li> + * </ul> + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum + * @todo Allow configuring the build information + * @todo Allow reading the information from a specified bundle instead of an ActionFactory. + * @todo Allow passing a known ActionFactory instance + */ +public class AboutDialog extends JPanel { + + /** Action Factory to create Actions. */ + protected static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.swing.about"); + + /** Action Factory to create Actions. */ + protected final ActionFactory actionFactory; + + /** + * The main tabs. + */ + private final JTabbedPane tabs; + + /** + * The tabs in the license tab. + */ + private final JTabbedPane licensePane; + + /** + * Create an AboutDialog. + * @param actionFactoryName name of the ActionFactory to use. + */ + public AboutDialog(final String actionFactoryName) { + super(new BorderLayout()); + actionFactory = ActionFactory.getFactory(actionFactoryName); + tabs = new JTabbedPane(); + licensePane = buildLicenseTab(); + @Nullable final String logoURL = actionFactory.getString("about.logo"); + if (logoURL != null) { + add(new JLabel(new ImageIcon(getClass().getClassLoader().getResource(logoURL))), BorderLayout.NORTH); + } + add(tabs); + addTab(buildAboutTab()); + addTab(licensePane); + addTab(buildRuntimePropertiesTab()); + // TODO: Change this to use another way of configuration + if (actionFactoryName.equals("daieditor")) { + addTab(buildBuildPropertiesTab()); + } + } + + /** + * Show about dialog. + * @param parent Parent component to show dialog on + */ + public void showAboutDialog(final Component parent) { + tabs.setSelectedIndex(0); + licensePane.setSelectedIndex(0); + JOptionPane.showMessageDialog(parent, this, ACTION_FACTORY.format("about.title", actionFactory.getString("application.name")), JOptionPane.PLAIN_MESSAGE); + } + + /** + * Adds a tab. + * @param component Component to add as tab + */ + public void addTab(final Component component) { + tabs.add(component); + } + + /** + * Build the license tab. + * @return component for license tab + */ + private JTabbedPane buildLicenseTab() { + final JTabbedPane licensePane = new JTabbedPane(); + for (int i = 1; actionFactory.getString("license." + i + ".title") != null; i++) { + licensePane.add(buildLicenseSubTab(String.valueOf(i))); + } + licensePane.setName(actionFactory.getString("license.title")); + return licensePane; + } + + /** + * Build a XY license tab. + * @param number number of license + * @return component for XY license tab + */ + private JComponent buildLicenseSubTab(final String number) { + String licenseText; + try { + final Reader in = new InputStreamReader(new BufferedInputStream(getClass().getClassLoader().getResource(actionFactory.getString("license." + number + ".file")).openStream())); + try { + final StringBuilder sb = new StringBuilder(); + final char[] buf = new char[4096]; + for (int bytesRead; (bytesRead = in.read(buf)) != -1;) { + sb.append(buf, 0, bytesRead); + } + licenseText = sb.toString(); + } finally { + in.close(); + } + } catch (final NullPointerException e) { + licenseText = ACTION_FACTORY.getString("license.missing"); + } catch (final IOException e) { + licenseText = ACTION_FACTORY.getString("license.missing"); + } + final JTextArea license = new JTextArea(licenseText, 16, 80); + license.setLineWrap(true); + license.setWrapStyleWord(true); + license.setEditable(false); + license.setFont(new Font("Monospaced", Font.PLAIN, license.getFont().getSize())); + final JScrollPane scroller = new JScrollPane(license); + scroller.setFocusable(true); + scroller.setName(actionFactory.getString("license." + number + ".title")); + return scroller; + } + + /** + * Build the about tab. + * @return component for about tab + */ + private JComponent buildAboutTab() { + String buildNumber = "unknown"; + String buildDeveloper = "unknown"; + String buildTstamp = "unknown"; + try { + final ResourceBundle bundle = ResourceBundle.getBundle("build"); + try { + buildDeveloper = bundle.getString("build.developer"); + } catch (final Exception e) { + /* ignore */ + } + try { + buildNumber = bundle.getString("build.number"); + } catch (final Exception e) { + /* ignore */ + } + try { + buildTstamp = bundle.getString("build.tstamp"); + } catch (final Exception e) { + /* ignore */ + } + } catch (final Exception e) { + /* ignore */ + } + final JLabel aboutTab = new JLabel(actionFactory.format("about", System.getProperty("java.version"), buildNumber, buildDeveloper, buildTstamp), SwingConstants.CENTER); + aboutTab.setName(ACTION_FACTORY.getString("aboutTab.title")); + return aboutTab; + } + + /** + * Build the runtime properties tab. + * @return component for runtime properties tab + */ + private JComponent buildRuntimePropertiesTab() { + final StringBuilder propertiesText = new StringBuilder(); + final SortedSet<String> keys = new TreeSet<String>(); + final Properties props = System.getProperties(); + for (final Object key : props.keySet()) { + if (key instanceof String) { + keys.add((String) key); + } + } + for (final String key : keys) { + propertiesText + .append(key) + .append('=') + .append(props.getProperty(key)) + .append('\n'); + } + final JTextArea properties = new JTextArea(propertiesText.toString(), 16, 77); + properties.setEditable(false); + properties.setFont(new Font("Monospaced", Font.PLAIN, properties.getFont().getSize())); + final JScrollPane scroller = new JScrollPane(properties); + scroller.setName(ACTION_FACTORY.getString("aboutRuntimeProperties.title")); + scroller.setFocusable(true); + return scroller; + } + + /** + * Build the build properties tab. + * @return component for build properties tab + */ + private JComponent buildBuildPropertiesTab() { + final StringBuilder propertiesText = new StringBuilder(); + final SortedSet<String> keys = new TreeSet<String>(); + try { + final ResourceBundle bundle = ResourceBundle.getBundle("build"); + for (final Enumeration<String> uKeys = bundle.getKeys(); uKeys.hasMoreElements();) { + keys.add(uKeys.nextElement()); + } + for (final String key : keys) { + propertiesText + .append(key) + .append('=') + .append(bundle.getString(key)) + .append('\n'); + } + } catch (final Exception e) { + propertiesText.append(e.toString()); + } + final JTextArea properties = new JTextArea(propertiesText.toString(), 16, 77); + properties.setEditable(false); + properties.setFont(new Font("Monospaced", Font.PLAIN, properties.getFont().getSize())); + final JScrollPane scroller = new JScrollPane(properties); + scroller.setName(ACTION_FACTORY.getString("aboutBuildProperties.title")); + scroller.setFocusable(true); + return scroller; + } + +} // class AboutDialog + Property changes on: libs/swing-about/trunk/src/net/sf/japi/swing/about/AboutDialog.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/swing-about/trunk/src/net/sf/japi/swing/about/action.properties =================================================================== --- libs/swing-about/trunk/src/net/sf/japi/swing/about/action.properties (rev 0) +++ libs/swing-about/trunk/src/net/sf/japi/swing/about/action.properties 2007-01-14 13:12:51 UTC (rev 289) @@ -0,0 +1,6 @@ +about.title=About {0} +license.title=License +license.missing=Couldn''t load license text +aboutTab.title=About +aboutRuntimeProperties.title=Runtime Properties +aboutBuildProperties.title=Build Properties Property changes on: libs/swing-about/trunk/src/net/sf/japi/swing/about/action.properties ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |