Thread: [Japi-cvs] SF.net SVN: japi: [269] libs/swing-action/trunk/src/net/sf/japi/swing/ ActionFactory.jav
Status: Beta
Brought to you by:
christianhujer
[Japi-cvs] SF.net SVN: japi: [269]
libs/swing-action/trunk/src/net/sf/japi/swing/ ActionFactory.java
From: <chr...@us...> - 2007-01-06 03:09:22
|
Revision: 269 http://svn.sourceforge.net/japi/?rev=269&view=rev Author: christianhujer Date: 2007-01-05 19:09:18 -0800 (Fri, 05 Jan 2007) Log Message: ----------- Added handling of parent factories in #getAction(String). Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 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 15:02:29 UTC (rev 268) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2007-01-06 03:09:18 UTC (rev 269) @@ -629,6 +629,15 @@ } } } + if (action == null) { + for (final ActionFactory parent : parents) { + action = parent.getAction(key); + if (action != null) { + actionMap.put(key, action); + break; + } + } + } return action; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[Japi-cvs] SF.net SVN: japi: [318]
libs/swing-action/trunk/src/net/sf/japi/swing/ ActionFactory.java
From: <chr...@us...> - 2007-01-20 22:40:13
|
Revision: 318 http://svn.sourceforge.net/japi/?rev=318&view=rev Author: christianhujer Date: 2007-01-20 14:40:12 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Added constructor that creates a new ActionFactory for a key (bundle). This might be useful for developing SDI applications or per-document actions in MDI applications. Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2007-01-20 14:49:57 UTC (rev 317) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2007-01-20 22:40:12 UTC (rev 318) @@ -206,14 +206,8 @@ @NotNull public static ActionFactory getFactory(@Nullable final String key) { ActionFactory factory = FACTORIES.get(key); if (factory == null) { - factory = new ActionFactory(); + factory = new ActionFactory(key); FACTORIES.put(key, factory); - try { - factory.addBundle(key + ".action"); - } catch (final MissingResourceException e) { - /* ignore */ - } - // eventually initialize factory here } return factory; } @@ -307,6 +301,21 @@ public ActionFactory() { } + /** + * 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. + * Use this constructor if you explicitely need a new ActionFactory that doesn't share information (especially the action cache) with other ActionFactory instances. + * @param key name of ActionFactory. + */ + public ActionFactory(final String key) { + try { + addBundle(key + ".action"); + } catch (final MissingResourceException e) { + /* ignore */ + } + } + /** Get the ActionMap. * @return ActionMap */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[Japi-cvs] SF.net SVN: japi: [559]
libs/swing-action/trunk/src/net/sf/japi/swing/ ActionFactory.java
From: <chr...@us...> - 2007-07-30 20:13:52
|
Revision: 559 http://japi.svn.sourceforge.net/japi/?rev=559&view=rev Author: christianhujer Date: 2007-07-30 13:13:50 -0700 (Mon, 30 Jul 2007) Log Message: ----------- Added TODO: ActionFactory should be Serializable. Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2007-07-30 20:10:49 UTC (rev 558) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2007-07-30 20:13:50 UTC (rev 559) @@ -159,6 +159,7 @@ * @todo think about toolbar configuration * @todo eventually rename this ActionBuilder and provide an ActionBuilderFactory. * @todo whether a dialog is a onetime dialog should be a property and user configurable + * @todo Implement serialization. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public final class ActionFactory { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[Japi-cvs] SF.net SVN: japi: [568]
libs/swing-action/trunk/src/net/sf/japi/swing/ ActionFactory.java
From: <chr...@us...> - 2007-08-11 17:36:10
|
Revision: 568 http://japi.svn.sourceforge.net/japi/?rev=568&view=rev Author: christianhujer Date: 2007-08-11 10:36:04 -0700 (Sat, 11 Aug 2007) Log Message: ----------- Made ActionFactory non-final to override for test purposes (e.g. creating mocks). Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2007-08-09 21:06:39 UTC (rev 567) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2007-08-11 17:36:04 UTC (rev 568) @@ -162,7 +162,7 @@ * @todo Implement serialization. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class ActionFactory { +public class ActionFactory { /** The key used for storing a somewhat unique id for this Action. */ @NotNull public static final String ACTION_ID = "ActionID"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[Japi-cvs] SF.net SVN: japi: [569]
libs/swing-action/trunk/src/net/sf/japi/swing/ ActionFactory.java
From: <chr...@us...> - 2007-08-11 18:42:08
|
Revision: 569 http://japi.svn.sourceforge.net/japi/?rev=569&view=rev Author: christianhujer Date: 2007-08-11 11:42:06 -0700 (Sat, 11 Aug 2007) Log Message: ----------- Improved handling of null values in factory methods. Modified Paths: -------------- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java Modified: libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java =================================================================== --- libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2007-08-11 17:36:04 UTC (rev 568) +++ libs/swing-action/trunk/src/net/sf/japi/swing/ActionFactory.java 2007-08-11 18:42:06 UTC (rev 569) @@ -426,7 +426,6 @@ */ @SuppressWarnings({"NestedAssignment"}) @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; final String text = getString(key + ".text"); @@ -502,9 +501,6 @@ * @throws NullPointerException if <var>key</var> is <code>null</code> */ @Nullable public String getStringFromPrefs(@NotNull final String key) throws NullPointerException { - if (key == null) { - throw new NullPointerException("null key not allowed"); - } String value = null; for (final Preferences pref : prefs) { value = pref.get(key, value); @@ -608,7 +604,7 @@ } else { final Action action = getAction(key); if (action == null) { - throw new Error("No Action for key " + key); + throw new MissingResourceException(this + " has no definitin for action " + key, getClass().getName(), key); } if (action instanceof ToggleAction) { menu.add(((ToggleAction) action).createCheckBoxMenuItem()); @@ -668,15 +664,19 @@ } /** Method for creating a popup menu. - * @param store whether to store the initialized Actions in the ActionMap of this ActionFactory - * @param popupKey Action key of popup menu to create + * @param store Whether to store the initialized Actions in the ActionMap of this ActionFactory. + * @param popupKey Action key of popup menu to create. * @return JPopupMenu created for <var>popupKey</var> - * @throws NullPointerException if no menubar definition was found + * @throws MissingResourceException if no menubar definition was found. * @todo make error handling consistent (see createMenu and others) */ - @NotNull public JPopupMenu createPopupMenu(final boolean store, final String popupKey) throws NullPointerException { + @NotNull public JPopupMenu createPopupMenu(final boolean store, final String popupKey) throws MissingResourceException { final JPopupMenu menu = new JPopupMenu(); - for (final String key : getString(popupKey + ".menu").split("\\s+")) { + final String popupDefinition = getString(popupKey + ".menu"); + if (popupDefinition == null) { + throw new MissingResourceException(this + " has no definition for popup " + popupKey, getClass().getName(), popupKey + ".menu"); + } + for (final String key : popupDefinition.split("\\s+")) { if (key != null && key.length() == 0) { /* ignore this for empty menus */ } else if (key == null || "-".equals(key) || "|".equals(key)) { @@ -686,7 +686,7 @@ } else { final Action action = getAction(key); if (action == null) { - throw new Error("No Action for key " + key); + throw new MissingResourceException(this + " has no definitin for action " + key, getClass().getName(), key); } if (action instanceof ToggleAction) { menu.add(((ToggleAction) action).createCheckBoxMenuItem()); @@ -701,14 +701,18 @@ /** Method for creating a Menu. * This method assumes that the underlying properties contain an entry like <code>key + ".menu"</code> which lists the menu element's keys. * Submenus are build recursively. - * @param store whether to store the initialized Action in the ActionMap of this ActionFactory - * @param menuKey action key for menu - * @return menu created from the menu definition found - * @throws Error in case a menu definition for <var>menuKey</var> wasn't found + * @param store Whether to store the initialized Action in the ActionMap of this ActionFactory. + * @param menuKey Action key for menu. + * @return menu created from the menu definition found. + * @throws MissingResourceException In case a menu definition for <var>menuKey</var> wasn't found */ - public JMenu createMenu(final boolean store, final String menuKey) throws Error { + public JMenu createMenu(final boolean store, final String menuKey) throws MissingResourceException { final JMenu menu = new JMenu(createAction(store, menuKey)); - for (final String key : getString(menuKey + ".menu").split("\\s+")) { + final String menuDefinition = getString(menuKey + ".menu"); + if (menuDefinition == null) { + throw new MissingResourceException(this + " has no definition for menu " + menuKey, getClass().getName(), menuKey + ".menu"); + } + for (final String key : menuDefinition.split("\\s+")) { if (key != null && key.length() == 0) { /* ignore this for empty menus */ } else if (key == null || "-".equals(key) || "|".equals(key)) { @@ -718,7 +722,7 @@ } else { final Action action = getAction(key); if (action == null) { - throw new Error("No Action for key " + key); + throw new MissingResourceException(this + " has no definitin for action " + key, getClass().getName(), key); } if (action instanceof ToggleAction) { menu.add(((ToggleAction) action).createCheckBoxMenuItem()); @@ -735,14 +739,15 @@ * @param barKey Action key of menu to create * @param target Target object * @return JMenuBar created for <var>barKey</var> + * @throws MissingResourceException In case a menu or menubar definition was not found. */ - public JMenuBar createMenuBar(final boolean store, final String barKey, final Object target) { + public JMenuBar createMenuBar(final boolean store, final String barKey, final Object target) throws MissingResourceException { final JMenuBar menuBar = new JMenuBar(); - final String menuBarSpec = getString(barKey + ".menubar"); - if (menuBarSpec == null) { - throw new RuntimeException("Missing Resource for " + barKey + ".menubar"); + final String menuBarDefinition = getString(barKey + ".menubar"); + if (menuBarDefinition == null) { + throw new MissingResourceException(this + " has no definitin for menubar " + barKey, getClass().getName(), barKey); } - for (final String key : menuBarSpec.split("\\s+")) { + for (final String key : menuBarDefinition.split("\\s+")) { menuBar.add(createMenu(store, key, target)); } return menuBar; @@ -753,10 +758,15 @@ * @param popupKey Action key of popup menu to create * @param target Target object * @return JPopupMenu created for <var>barKey</var> + * @throws MissingResourceException In case a menu definition was not found. */ - public JPopupMenu createPopupMenu(final boolean store, final String popupKey, final Object target) { + public JPopupMenu createPopupMenu(final boolean store, final String popupKey, final Object target) throws MissingResourceException { final JPopupMenu menu = new JPopupMenu(); - for (final String key : getString(popupKey + ".menu").split("\\s+")) { + final String popupDefinition = getString(popupKey + ".menu"); + if (popupDefinition == null) { + throw new MissingResourceException(this + " has no definition for popup " + popupKey, getClass().getName(), popupKey + ".menu"); + } + for (final String key : popupDefinition.split("\\s+")) { if (key != null && key.length() == 0) { /* ignore this for empty menus */ } else if (key == null || "-".equals(key) || "|".equals(key)) { @@ -772,7 +782,7 @@ action = createAction(store, key, target); } if (action == null) { - throw new Error("No Action for key " + key); + throw new MissingResourceException(this + " has no definitin for action " + key, getClass().getName(), key); } if (action instanceof ToggleAction) { menu.add(((ToggleAction) action).createCheckBoxMenuItem()); @@ -795,7 +805,11 @@ */ public JMenu createMenu(final boolean store, final String menuKey, final Object target) throws Error { final JMenu menu = new JMenu(createAction(store, menuKey)); - for (final String key : getString(menuKey + ".menu").split("\\s+")) { + final String menuDefinition = getString(menuKey + ".menu"); + if (menuDefinition == null) { + throw new MissingResourceException(this + " has no definition for menu " + menuKey, getClass().getName(), menuKey + ".menu"); + } + for (final String key : menuDefinition.split("\\s+")) { if (key != null && key.length() == 0) { /* ignore this for empty menus */ } else if (key == null || "-".equals(key) || "|".equals(key)) { @@ -811,7 +825,7 @@ action = createAction(store, key, target); } if (action == null) { - throw new Error("No Action for key " + key); + throw new MissingResourceException(this + " has no definitin for action " + key, getClass().getName(), key); } if (action instanceof ToggleAction) { menu.add(((ToggleAction) action).createCheckBoxMenuItem()); @@ -878,7 +892,7 @@ } else { final Action action = getAction(key); if (action == null) { - throw new Error("No Action for key " + key); + throw new MissingResourceException(this + " has no definitin for action " + key, getClass().getName(), key); } toolBar.add(action); } @@ -889,9 +903,14 @@ /** Method for creating a toolbar. * @param barKey Action keys of toolbar to create * @return JToolBar created for <var>barKey</var> + * @throws MissingResourceException In case there is no definition for the requested toolbar. */ - public JToolBar createToolBar(final String barKey) { - return createToolBar(getString(barKey + ".toolbar").split("\\s+")); + public JToolBar createToolBar(final String barKey) throws MissingResourceException { + final String toolbarDefinition = getString(barKey + ".toolbar"); + if (toolbarDefinition == null) { + throw new MissingResourceException(this + " has no definition for toolbar " + barKey, getClass().getName(), barKey); + } + return createToolBar(toolbarDefinition.split("\\s+")); } /** Method for creating a toolbar. @@ -919,9 +938,14 @@ * @param object Instance to invoke method on if the Action was activated ({@link Action#actionPerformed(ActionEvent)}) * @param barKey Action keys of toolbar to create * @return JToolBar created for <var>barKey</var> + * @throws MissingResourceException In case there is no definition for the requested toolbar. */ - public JToolBar createToolBar(final Object object, final String barKey) { - return createToolBar(object, getString(barKey + ".toolbar").split("\\s+")); + public JToolBar createToolBar(final Object object, final String barKey) throws MissingResourceException { + final String toolbarDefinition = getString(barKey + ".toolbar"); + if (toolbarDefinition == null) { + throw new MissingResourceException(this + " has no definition for toolbar " + barKey, getClass().getName(), barKey); + } + return createToolBar(object, toolbarDefinition.split("\\s+")); } /** Method to find the JMenuItem for a specific Action key. @@ -1116,6 +1140,7 @@ * @note the label text will be the key if no String for the key was found */ public JLabel createLabel(final String key, final Object... args) { + //noinspection RedundantCast return createLabel((Component) null, key, args); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |