[Japi-cvs] SF.net SVN: japi: [268] libs/swing-action/trunk/src
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2006-12-17 15:02:34
|
Revision: 268
http://svn.sourceforge.net/japi/?rev=268&view=rev
Author: christianhujer
Date: 2006-12-17 07:02:29 -0800 (Sun, 17 Dec 2006)
Log Message:
-----------
Improved tests and documentation.
Modified Paths:
--------------
libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java
libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java
Added Paths:
-----------
libs/swing-action/trunk/src/net/sf/japi/swing/action.properties
libs/swing-action/trunk/src/net/sf/japi/swing/action_de.properties
libs/swing-action/trunk/src/net/sf/japi/swing/package.html
libs/swing-action/trunk/src/test/net/sf/japi/swing/ActionFactoryTest.java
libs/swing-action/trunk/src/test/net/sf/japi/swing/action.properties
Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java
===================================================================
--- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2006-12-17 14:48:01 UTC (rev 267)
+++ libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2006-12-17 15:02:29 UTC (rev 268)
@@ -52,6 +52,7 @@
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JToolBar;
+import javax.swing.KeyStroke;
import static javax.swing.KeyStroke.getKeyStroke;
import static net.sf.japi.swing.IconManager.getDefaultIconManager;
import static net.sf.japi.swing.ReflectionAction.REFLECTION_MESSAGE_PROVIDER;
@@ -272,6 +273,14 @@
* @throws NullPointerException if <var>menu</var> or <var>action</var> is <code>null</code>
*/
@Nullable public static JMenuItem find(@NotNull final JMenu menu, @NotNull final Action action) {
+ //noinspection ConstantConditions
+ if (menu == null) {
+ throw new NullPointerException("null JMenuBar not allowed");
+ }
+ //noinspection ConstantConditions
+ if (action == null) {
+ throw new NullPointerException("null Action not allowed");
+ }
for (int i = 0; i < menu.getItemCount(); i++) {
final JMenuItem item = menu.getItem(i);
if (item == null) {
@@ -288,11 +297,14 @@
return null;
}
- /** Create an ActionFactory.
- * This constructor is private to force users to use the method {@link #getFactory(String)} for recycling ActionFactories and profit of easy
+ /**
+ * Create an ActionFactory.
+ * Usually you wouldn't create an ActionFactory yourself but use {@link #getFactory(String)} for recycling ActionFactories and profit of easy
* access to the same ActionFactory from within the whole application without passing around ActionFactory references.
+ * Don't use this constructor without knowing what you're doing.
+ * It's mainly there for testing purposes.
*/
- private ActionFactory() {
+ public ActionFactory() {
}
/** Get the ActionMap.
@@ -403,19 +415,34 @@
* @throws NullPointerException in case <var>key</var> was <code>null</code>
*/
@SuppressWarnings({"NestedAssignment"})
- public Action initAction(final boolean store, @NotNull final Action action, @NotNull final String key) throws NullPointerException {
+ @NotNull public Action initAction(final boolean store, @NotNull final Action action, @NotNull final String key) throws NullPointerException {
if (key == null) { throw new NullPointerException("null key for Action initialization not allowed."); }
action.putValue(ACTION_ID, key);
String value;
- if ((value = getString(key + ".text" )) != null) { action.putValue(NAME, value); }
+ final String text = getString(key + ".text");
+ if ((value = text) != null) { action.putValue(NAME, value); }
if ((value = getString(key + ".shortdescription")) != null) { action.putValue(SHORT_DESCRIPTION, value); }
if ((value = getString(key + ".longdescription" )) != null) { action.putValue(LONG_DESCRIPTION, value); }
if ((value = getString(key + ".accel" )) != null) { action.putValue(ACCELERATOR_KEY, getKeyStroke(value)); }
if ((value = getString(key + ".accel2" )) != null) { action.putValue(ACCELERATOR_KEY_2, getKeyStroke(value)); }
- if ((value = getString(key + ".mnemonic" )) != null) { action.putValue(MNEMONIC_KEY, getKeyStroke(value).getKeyCode()); }
+ if ((value = getString(key + ".mnemonic" )) != null) {
+ final KeyStroke keyStroke = getKeyStroke(value);
+ if (keyStroke != null) {
+ action.putValue(MNEMONIC_KEY, keyStroke.getKeyCode());
+ } else {
+ System.err.println("Warning: Action key " + key + " has " + key + ".mnemonic value " + value + " which is a null KeyStroke.");
+ }
+ if (text == null) {
+ System.err.println("Warning: Action key " + key + " has " + key + ".mnemonic value " + value + " but no text. Either define " + key + ".text or remove " + key + ".mnemonic.");
+ }
+ }
if ((value = getString(key + ".icon" )) != null) {
final Icon image = getDefaultIconManager().getIcon(value);
- if (image != null) { action.putValue(SMALL_ICON, image); }
+ if (image != null) {
+ action.putValue(SMALL_ICON, image);
+ } else {
+ System.err.println("Warning: Action key " + key + " has " + key + ".icon value " + value + " but no corresponding icon was found.");
+ }
}
action.putValue(REFLECTION_MESSAGE_PROVIDER, this);
if (store) {
Copied: libs/swing-action/trunk/src/net/sf/japi/swing/action.properties (from rev 245, historic/trunk/src/app/net/sf/japi/swing/action.properties)
===================================================================
--- libs/swing-action/trunk/src/net/sf/japi/swing/action.properties (rev 0)
+++ libs/swing-action/trunk/src/net/sf/japi/swing/action.properties 2006-12-17 15:02:29 UTC (rev 268)
@@ -0,0 +1,23 @@
+# JAPI - (Yet another (hopefully) useful) Java API
+#
+# Copyright (C) 2004-2006 Christian Hujer
+#
+# This program 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 of the
+# License, or (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+#
+
+
+dialogDontShowAgain=Show this dialog again next time.
+ReflectionAction.nonPublicMethod=Action Methods must be accessible public. That means the declaring class as well as the method must be public.\n{0}
\ No newline at end of file
Copied: libs/swing-action/trunk/src/net/sf/japi/swing/action_de.properties (from rev 245, historic/trunk/src/app/net/sf/japi/swing/action_de.properties)
===================================================================
--- libs/swing-action/trunk/src/net/sf/japi/swing/action_de.properties (rev 0)
+++ libs/swing-action/trunk/src/net/sf/japi/swing/action_de.properties 2006-12-17 15:02:29 UTC (rev 268)
@@ -0,0 +1,22 @@
+# JAPI - (Yet another (hopefully) useful) Java API
+#
+# Copyright (C) 2004-2006 Christian Hujer
+#
+# This program 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 of the
+# License, or (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+#
+
+
+dialogDontShowAgain=Show this dialog again next time.
Copied: libs/swing-action/trunk/src/net/sf/japi/swing/package.html (from rev 245, historic/trunk/src/app/net/sf/japi/swing/package.html)
===================================================================
--- libs/swing-action/trunk/src/net/sf/japi/swing/package.html (rev 0)
+++ libs/swing-action/trunk/src/net/sf/japi/swing/package.html 2006-12-17 15:02:29 UTC (rev 268)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- JAPI - (Yet another (hopefully) useful) Java API
+ -
+ - Copyright (C) 2004-2006 Christian Hujer
+ -
+ - This program 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 of the
+ - License, or (at your option) any later version.
+ -
+ - This program 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 this program; if not, write to the Free Software
+ - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ - 02111-1307, USA.
+ -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
+ <head>
+ <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
+ <meta name="Date" content="$Date: 2006-04-03 23:00:14 +0200 (Mon, 03 Apr 2006) $" />
+ <title>net.sf.japi.swing</title>
+ </head>
+ <body>
+ <p>
+ This package contains classes for supporting creation and use of Swing Actions.
+ </p>
+ </body>
+</html>
Added: libs/swing-action/trunk/src/test/net/sf/japi/swing/ActionFactoryTest.java
===================================================================
--- libs/swing-action/trunk/src/test/net/sf/japi/swing/ActionFactoryTest.java (rev 0)
+++ libs/swing-action/trunk/src/test/net/sf/japi/swing/ActionFactoryTest.java 2006-12-17 15:02:29 UTC (rev 268)
@@ -0,0 +1,99 @@
+package test.net.sf.japi.swing;
+
+import javax.swing.Action;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import net.sf.japi.swing.ActionFactory;
+import net.sf.japi.swing.DummyAction;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Assert;
+
+/**
+ * Test for {@link ActionFactory}.
+ *
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class ActionFactoryTest {
+
+ private ActionFactory actionFactory;
+
+ /**
+ * Creates an ActionFactory.
+ * @throws Exception (unexpected)
+ */
+ @Before
+ public void setUp() throws Exception {
+ actionFactory = new ActionFactory();
+ }
+
+ /**
+ * Tests whether {@link ActionFactory#find(JMenuBar, Action)} works.
+ * @throws Exception (unexpected)
+ */
+ @Test(expected=NullPointerException.class)
+ public void testFindNullBar() throws Exception {
+ //noinspection ConstantConditions
+ ActionFactory.find((JMenuBar) null, createSimple("item"));
+ }
+
+ /**
+ * Tests whether {@link ActionFactory#find(JMenuBar, Action)} works.
+ * @throws Exception (unexpected)
+ */
+ @Test(expected=NullPointerException.class)
+ public void testFindNullActionInMenuBar() throws Exception {
+ //noinspection ConstantConditions
+ ActionFactory.find(new JMenuBar(), (Action) null);
+ }
+
+ /**
+ * Tests whether {@link ActionFactory#find(JMenuBar, Action)} works.
+ * @throws Exception (unexpected)
+ */
+ @Test(expected=NullPointerException.class)
+ public void testFindNullMenu() throws Exception {
+ //noinspection ConstantConditions
+ ActionFactory.find((JMenu) null, createSimple("item"));
+ }
+
+ /**
+ * Tests whether {@link ActionFactory#find(JMenuBar, Action)} works.
+ * @throws Exception (expected)
+ */
+ @Test(expected=NullPointerException.class)
+ public void testFindNullActionInMenu() throws Exception {
+ //noinspection ConstantConditions
+ ActionFactory.find(new JMenu(), null);
+ }
+ /**
+ * Tests whether {@link ActionFactory#find(JMenuBar, Action)} works.
+ * @throws Exception (unexpected)
+ */
+ @Test
+ public void testFind() throws Exception {
+ final JMenuBar menuBar = new JMenuBar();
+ final JMenu menu = new JMenu(createSimple("menu"));
+ final Action action1 = createSimple("item1");
+ final Action action2 = createSimple("item2");
+ final JMenuItem item1 = new JMenu(action1);
+ final JMenuItem item2 = new JMenu(action2);
+ menuBar.add(menu);
+ menu.add(item1);
+ menu.add(item2);
+ Assert.assertSame(item1, ActionFactory.find(menuBar, action1));
+ Assert.assertSame(item2, ActionFactory.find(menuBar, action2));
+ }
+
+ /**
+ * Creates a simple action that performs nothing.
+ * @param key Key for the action
+ * @return A simple action that performs nothing.
+ */
+ private Action createSimple(final String key) {
+ final Action action = new DummyAction();
+ action.putValue(Action.ACTION_COMMAND_KEY, key);
+ return action;
+ }
+} // class ActionFactoryTest
\ No newline at end of file
Property changes on: libs/swing-action/trunk/src/test/net/sf/japi/swing/ActionFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Modified: libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java
===================================================================
--- libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java 2006-12-17 14:48:01 UTC (rev 267)
+++ libs/swing-action/trunk/src/test/net/sf/japi/swing/ReflectionActionTest.java 2006-12-17 15:02:29 UTC (rev 268)
@@ -2,9 +2,9 @@
import java.awt.event.ActionEvent;
import java.lang.reflect.Method;
+import net.sf.japi.swing.ActionFactory;
import net.sf.japi.swing.ActionMethod;
import net.sf.japi.swing.ReflectionAction;
-import net.sf.japi.swing.ActionFactory;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Added: libs/swing-action/trunk/src/test/net/sf/japi/swing/action.properties
===================================================================
Property changes on: libs/swing-action/trunk/src/test/net/sf/japi/swing/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.
|