001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.core.gui.globalactions;
017:
018: import java.awt.KeyboardFocusManager;
019: import java.awt.Toolkit;
020: import java.awt.event.ActionEvent;
021: import java.awt.event.KeyEvent;
022: import java.beans.PropertyChangeEvent;
023: import java.beans.PropertyChangeListener;
024:
025: import javax.swing.Action;
026: import javax.swing.JComponent;
027: import javax.swing.KeyStroke;
028: import javax.swing.TransferHandler;
029:
030: import org.columba.api.gui.frame.IFrameMediator;
031: import org.columba.core.gui.action.AbstractColumbaAction;
032: import org.columba.core.resourceloader.GlobalResourceLoader;
033: import org.columba.core.resourceloader.IconKeys;
034: import org.columba.core.resourceloader.ImageLoader;
035:
036: public class PasteAction extends AbstractColumbaAction implements
037: PropertyChangeListener {
038:
039: private JComponent focusOwner = null;
040:
041: public PasteAction(IFrameMediator controller) {
042: super (controller, GlobalResourceLoader.getString(null, null,
043: "menu_edit_paste"));
044:
045: // tooltip text
046: putValue(SHORT_DESCRIPTION, GlobalResourceLoader.getString(
047: null, null, "menu_edit_paste_tooltip").replaceAll("&",
048: ""));
049:
050: // small icon for menu
051: putValue(SMALL_ICON, ImageLoader
052: .getSmallIcon(IconKeys.EDIT_PASTE));
053:
054: // large icon for toolbar
055: putValue(LARGE_ICON, ImageLoader.getIcon(IconKeys.EDIT_PASTE));
056:
057: // shortcut key
058: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V,
059: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
060:
061: // disable toolbar text
062: setShowToolBarText(false);
063:
064: setEnabled(true);
065:
066: putValue(Action.ACTION_COMMAND_KEY, (String) TransferHandler
067: .getPasteAction().getValue(Action.NAME));
068:
069: KeyboardFocusManager manager = KeyboardFocusManager
070: .getCurrentKeyboardFocusManager();
071: manager.addPropertyChangeListener("permanentFocusOwner", this );
072: }
073:
074: public void propertyChange(PropertyChangeEvent e) {
075: Object o = e.getNewValue();
076: if (o instanceof JComponent)
077: focusOwner = (JComponent) o;
078: else
079: focusOwner = null;
080:
081: }
082:
083: /**
084: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
085: */
086: public void actionPerformed(ActionEvent e) {
087:
088: if (focusOwner == null)
089: return;
090:
091: String action = (String) e.getActionCommand();
092: Action a = focusOwner.getActionMap().get(action);
093: if (a != null)
094: a.actionPerformed(new ActionEvent(focusOwner,
095: ActionEvent.ACTION_PERFORMED, null));
096:
097: }
098:
099: /**
100: * @see org.columba.core.gui.action.AbstractColumbaAction#isSingleton()
101: */
102: public boolean isSingleton() {
103: return true;
104: }
105:
106: // public boolean isEnabled() {
107: //
108: // Transferable contents = Toolkit.getDefaultToolkit()
109: // .getSystemClipboard().getContents(this);
110: //
111: // if ( focusOwner == null ) return false;
112: //
113: // if ( focusOwner.getTransferHandler() == null ) return false;
114: //
115: // return focusOwner.getTransferHandler().canImport(focusOwner,
116: // contents.getTransferDataFlavors());
117: //
118: // }
119: }
|