Thread: [Japi-cvs] SF.net SVN: japi: [317] libs/swing-tod/trunk/src/net/sf/japi/swing/tod/ TipOfTheDayManag
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-01-20 14:49:58
|
Revision: 317 http://svn.sourceforge.net/japi/?rev=317&view=rev Author: christianhujer Date: 2007-01-20 06:49:57 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Corrected ActionFactory package. Modified Paths: -------------- libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java Modified: libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java =================================================================== --- libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java 2007-01-20 14:44:32 UTC (rev 316) +++ libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java 2007-01-20 14:49:57 UTC (rev 317) @@ -81,7 +81,7 @@ public final class TipOfTheDayManager extends JOptionPane { /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.swing"); + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.swing.tod"); /** Random number generator for random tods. */ private static final Random RND = new Random(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-06-30 12:39:00
|
Revision: 476 http://svn.sourceforge.net/japi/?rev=476&view=rev Author: christianhujer Date: 2007-06-30 05:38:58 -0700 (Sat, 30 Jun 2007) Log Message: ----------- Improved I/O code. Added missing @ActionMethod annotations. Modified Paths: -------------- libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java Modified: libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java =================================================================== --- libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java 2007-06-30 12:20:08 UTC (rev 475) +++ libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java 2007-06-30 12:38:58 UTC (rev 476) @@ -22,6 +22,12 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.Font; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.List; import java.util.MissingResourceException; @@ -30,12 +36,6 @@ import static java.util.ResourceBundle.getBundle; import java.util.prefs.Preferences; import static java.util.prefs.Preferences.userNodeForPackage; -import java.io.InputStream; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.security.PrivilegedAction; -import java.security.AccessController; import javax.swing.Action; import static javax.swing.Action.ACCELERATOR_KEY; import javax.swing.JButton; @@ -47,10 +47,11 @@ import javax.swing.JScrollPane; import javax.swing.KeyStroke; import static javax.swing.SwingConstants.TRAILING; -import org.jetbrains.annotations.Nullable; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.swing.ActionMethod; import static net.sf.japi.swing.ActionFactory.ACCELERATOR_KEY_2; import static net.sf.japi.swing.IconManager.getDefaultIconManager; -import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.Nullable; /** Class that manages tips of the day. * The tips of the day are read from a property file. @@ -158,22 +159,19 @@ * @return first line of resource, or <code>null</code> */ @Nullable private static String getServiceValue(final ClassLoader classLoader) { - BufferedReader rd = null; - try { - final String serviceId = "META-INF/services/net.sf.japi.swing.tod"; - final InputStream in = getResourceAsStream(classLoader, serviceId); - if (in != null) { + final String serviceId = "META-INF/services/net.sf.japi.swing.tod"; + final InputStream in = getResourceAsStream(classLoader, serviceId); + if (in != null) { + try { + final BufferedReader rd = new BufferedReader(new InputStreamReader(in, "UTF-8")); try { - rd = new BufferedReader(new InputStreamReader(in, "UTF-8")); - } catch (final UnsupportedEncodingException e) { - rd = new BufferedReader(new InputStreamReader(in)); + return rd.readLine(); + } finally { + rd.close(); } - return rd.readLine(); + } catch (final IOException ignore) { + /* ignore. */ } - } catch (final Exception e) { - /* ignore. */ - } finally { - try { rd.close(); } catch (final Exception e) { /* ignore */ } finally { rd = null; } } return null; } @@ -304,7 +302,7 @@ } /** Action method for close. */ - public void todClose() { + @ActionMethod public void todClose() { setValue(closeButton); PREFS.putBoolean("showTipOfTheDayAtStartup", showAtStartup.isSelected()); PREFS.putInt("lastTipOfTheDayNumber", todIndex); @@ -314,17 +312,17 @@ } /** Action method for next. */ - public void todNext() { + @ActionMethod public void todNext() { setTodIndex(todIndex + 1); } /** Action method for previous. */ - public void todPrev() { + @ActionMethod public void todPrev() { setTodIndex(todIndex - 1); } /** Action method for random. */ - public void todRand() { + @ActionMethod public void todRand() { setTodIndex(RND.nextInt(todTexts.size())); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-06-30 16:10:33
|
Revision: 477 http://svn.sourceforge.net/japi/?rev=477&view=rev Author: christianhujer Date: 2007-06-30 09:10:29 -0700 (Sat, 30 Jun 2007) Log Message: ----------- Added missing @NotNull / @Nullable annotations. Introduced constants for magic numbers. Fixed possible NPE in close action. Modified Paths: -------------- libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java Modified: libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java =================================================================== --- libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java 2007-06-30 12:38:58 UTC (rev 476) +++ libs/swing-tod/trunk/src/net/sf/japi/swing/tod/TipOfTheDayManager.java 2007-06-30 16:10:29 UTC (rev 477) @@ -22,10 +22,11 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.Font; +import java.awt.Dialog; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.IOException; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; @@ -48,9 +49,10 @@ import javax.swing.KeyStroke; import static javax.swing.SwingConstants.TRAILING; import net.sf.japi.swing.ActionFactory; +import static net.sf.japi.swing.ActionFactory.ACCELERATOR_KEY_2; import net.sf.japi.swing.ActionMethod; -import static net.sf.japi.swing.ActionFactory.ACCELERATOR_KEY_2; import static net.sf.japi.swing.IconManager.getDefaultIconManager; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** Class that manages tips of the day. @@ -81,37 +83,46 @@ public final class TipOfTheDayManager extends JOptionPane { /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.swing.tod"); + @NotNull private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.swing.tod"); /** Random number generator for random tods. */ - private static final Random RND = new Random(); + @NotNull private static final Random RND = new Random(); /** Preferences. */ - private static final Preferences PREFS = userNodeForPackage(TipOfTheDayManager.class); + @NotNull private static final Preferences PREFS = userNodeForPackage(TipOfTheDayManager.class); /** The Action keys used for accelerators. */ - private static final String[] ACCELERATOR_KEYS = new String[] { ACCELERATOR_KEY, ACCELERATOR_KEY_2 }; + @NotNull private static final String[] ACCELERATOR_KEYS = new String[] { ACCELERATOR_KEY, ACCELERATOR_KEY_2 }; /** The static instance. */ - private static final TipOfTheDayManager INSTANCE = new TipOfTheDayManager(); + @NotNull private static final TipOfTheDayManager INSTANCE = new TipOfTheDayManager(); + /** Width of the scroll region. */ + private static final int SCROLLER_WIDTH = 512; + + /** Height of the scroll region. */ + private static final int SCROLLER_HEIGHT = 128; + + /** Scale of the heading font. */ + private static final double HEADING_SCALE = 1.5; + /** JButton for close. */ - private JButton closeButton; + @NotNull private JButton closeButton; /** JDialog. */ - private JDialog dialog; + @Nullable private JDialog dialog; /** JCheckBox for showing at startup. */ - private JCheckBox showAtStartup = new JCheckBox(ACTION_FACTORY.createAction(false, "todShowAtStartup", null)); + @NotNull private JCheckBox showAtStartup = new JCheckBox(ACTION_FACTORY.createAction(false, "todShowAtStartup", null)); /** The JLabel showing the current number of the tod. */ - private JLabel currentTodIndex = new JLabel(); + @NotNull private JLabel currentTodIndex = new JLabel(); /** The JEditorPane displaying the tod text. */ - private JEditorPane todText = new JEditorPane("text/html", ""); + @NotNull private JEditorPane todText = new JEditorPane("text/html", ""); /** List with tod texts. */ - private List<String> todTexts = new ArrayList<String>(); + @NotNull private List<String> todTexts = new ArrayList<String>(); /** Number of current Tip of the day. * In visible state, the index must range between 0 and the number of tods available - 1, inclusive. @@ -123,7 +134,7 @@ * If the user chose not to see TipOfTheDays this method simply returns. * @param parentComponent the parent component of this dialog. */ - public static void showAtStartup(final Component parentComponent) { + public static void showAtStartup(@Nullable final Component parentComponent) { if (PREFS.getBoolean("showTipOfTheDayAtStartup", true)) { show(parentComponent); } @@ -132,7 +143,7 @@ /** Show a Tip Of The Day. * @param parentComponent the parent component of this dialog. */ - public static void show(final Component parentComponent) { + public static void show(@Nullable final Component parentComponent) { if (INSTANCE.dialog == null) { INSTANCE.dialog = INSTANCE.createDialog(parentComponent, ACTION_FACTORY.getString("tipOfTheDay.windowTitle")); } @@ -146,7 +157,7 @@ /** Finds the bundle name. * @return bundle name */ - private static String getBundleName() { + @Nullable private static String getBundleName() { String bundleName = System.getProperty("net.sf.japi.swing.tod"); if (bundleName == null) { bundleName = getServiceValue(getClassLoader()); @@ -158,7 +169,7 @@ * @param classLoader ClassLoader, may not be <code>null</code>. * @return first line of resource, or <code>null</code> */ - @Nullable private static String getServiceValue(final ClassLoader classLoader) { + @Nullable private static String getServiceValue(@Nullable final ClassLoader classLoader) { final String serviceId = "META-INF/services/net.sf.japi.swing.tod"; final InputStream in = getResourceAsStream(classLoader, serviceId); if (in != null) { @@ -181,7 +192,7 @@ * @param serviceId service file to get stream from * @return stream for resource <var>serviceId</var> in <var>classLoader</var> */ - private static InputStream getResourceAsStream(final ClassLoader classLoader, final String serviceId) { + @Nullable private static InputStream getResourceAsStream(@Nullable final ClassLoader classLoader, @NotNull final String serviceId) { return AccessController.doPrivileged(new PrivilegedAction<InputStream>() { /** {@inheritDoc} */ @@ -197,7 +208,7 @@ /** Get the ClassLoader. * @return ClassLoader */ - private static ClassLoader getClassLoader() { + @Nullable private static ClassLoader getClassLoader() { try { final ClassLoader contextClassLoader = getContextClassLoader(); if (contextClassLoader != null) { @@ -212,7 +223,7 @@ /** Get the context ClassLoader. * @return context ClassLoader */ - private static ClassLoader getContextClassLoader() { + @Nullable private static ClassLoader getContextClassLoader() { return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { /** {@inheritDoc} */ @@ -246,7 +257,7 @@ } } } - final Dimension size = new Dimension(512, 128); + final Dimension size = new Dimension(SCROLLER_WIDTH, SCROLLER_HEIGHT); showAtStartup.setSelected(PREFS.getBoolean("showTipOfTheDayAtStartup", true)); final JScrollPane todTextScroller = new JScrollPane(todText); todTextScroller.setMinimumSize(size); @@ -261,7 +272,7 @@ setIcon(getDefaultIconManager().getIcon(ACTION_FACTORY.getString("tipOfTheDay.icon"))); final JLabel heading = new JLabel(ACTION_FACTORY.getString("todHeading")); final Font oldFont = heading.getFont(); - heading.setFont(oldFont.deriveFont((float) (oldFont.getSize2D() * 1.5))); + heading.setFont(oldFont.deriveFont((float) (oldFont.getSize2D() * HEADING_SCALE))); setMessage(new Object[] { heading, todTextScroller, currentTodIndex, showAtStartup }); setMessageType(INFORMATION_MESSAGE); setOptions(newOptions); @@ -306,9 +317,12 @@ setValue(closeButton); PREFS.putBoolean("showTipOfTheDayAtStartup", showAtStartup.isSelected()); PREFS.putInt("lastTipOfTheDayNumber", todIndex); - dialog.setVisible(false); - dialog.dispose(); - dialog = null; + final Dialog dialog = this.dialog; + if (dialog != null) { + dialog.setVisible(false); + dialog.dispose(); + this.dialog = null; + } } /** Action method for next. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |