001 /*
002 * @(#)JLFAbstractAction.java 1.4 03/12/19
003 *
004 * Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved.
005 *
006 * Redistribution and use in source and binary forms, with or without
007 * modification, are permitted provided that the following conditions are met:
008 *
009 * -Redistribution of source code must retain the above copyright notice, this
010 * list of conditions and the following disclaimer.
011 *
012 * -Redistribution in binary form must reproduce the above copyright notice,
013 * this list of conditions and the following disclaimer in the documentation
014 * and/or other materials provided with the distribution.
015 *
016 * Neither the name of Sun Microsystems, Inc. or the names of contributors may
017 * be used to endorse or promote products derived from this software without
018 * specific prior written permission.
019 *
020 * This software is provided "AS IS," without a warranty of any kind. ALL
021 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
022 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
023 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
024 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
025 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
026 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
027 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
028 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
029 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
030 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
031 *
032 * You acknowledge that this software is not designed, licensed or intended
033 * for use in the design, construction, operation or maintenance of any
034 * nuclear facility.
035 */
036
037 package org.hd.d.pg2k.clApp.uploader;
038
039 import java.awt.event.ActionEvent;
040 import java.awt.event.ActionListener;
041
042 import javax.swing.AbstractAction;
043 import javax.swing.Action;
044 import javax.swing.event.EventListenerList;
045
046 /**
047 * Abstract Action for the JLF. Defines some useful methods.
048 *
049 */
050 abstract class JLFAbstractAction extends AbstractAction {
051
052 /**
053 *
054 */
055 private static final long serialVersionUID = -7453347349793809558L;
056
057 // The listener to action events (usually the main UI)
058 private EventListenerList listeners;
059
060 /**
061 * The key used for storing a large icon for the action,
062 * used for toolbar buttons.
063 * <p>
064 * Note: Eventually this key belongs in the javax.swing.Action interface.
065 */
066 public static final String LARGE_ICON = "LargeIcon";
067
068 //
069 // These next public methods may belong in the AbstractAction class.
070 //
071
072 /**
073 * Gets the value from the key Action.ACTION_COMMAND_KEY
074 */
075 public String getActionCommand() {
076 return (String)getValue(Action.ACTION_COMMAND_KEY);
077 }
078
079 /**
080 * Gets the value from the key Action.SHORT_DESCRIPTION
081 */
082 public String getShortDescription() {
083 return (String)getValue(Action.SHORT_DESCRIPTION);
084 }
085
086 /**
087 * Gets the value from the key Action.LONG_DESCRIPTION
088 */
089 public String getLongDescription() {
090 return (String)getValue(Action.LONG_DESCRIPTION);
091 }
092
093 /* Should finish the implementation and add get/set methods for all the
094 * javax.swing.Action keys:
095
096 Action.NAME
097 Action.SMALL_ICON
098 ActionConstants.LARGE_ICON
099 Action.MNEMONIC_KEY
100 */
101
102
103 // ActionListener registration and invocation.
104
105 /**
106 * Forwards the ActionEvent to the registered listener.
107 */
108 public void actionPerformed(final ActionEvent evt) {
109 if (listeners != null) {
110 final Object[] listenerList = listeners.getListenerList();
111
112 // Recreate the ActionEvent and stuff the value of the ACTION_COMMAND_KEY
113 final ActionEvent e = new ActionEvent(evt.getSource(), evt.getID(),
114 (String)getValue(Action.ACTION_COMMAND_KEY));
115 for (int i = 0; i <= listenerList.length-2; i += 2) {
116 ((ActionListener)listenerList[i+1]).actionPerformed(e);
117 }
118 }
119 }
120
121 public void addActionListener(final ActionListener l) {
122 if (listeners == null) {
123 listeners = new EventListenerList();
124 }
125 listeners.add(ActionListener.class, l);
126 }
127
128 public void removeActionListener(final ActionListener l) {
129 if (listeners == null) {
130 return;
131 }
132 listeners.remove(ActionListener.class, l);
133 }
134
135 }
136
137