01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.gui.explorer;
19:
20: import java.awt.datatransfer.Clipboard;
21: import java.awt.datatransfer.Transferable;
22: import java.awt.dnd.DnDConstants;
23: import java.awt.event.ActionEvent;
24: import java.awt.event.InputEvent;
25: import java.awt.event.KeyEvent;
26:
27: import javax.swing.Action;
28: import javax.swing.KeyStroke;
29: import javax.swing.TransferHandler;
30: import javax.swing.tree.DefaultMutableTreeNode;
31:
32: import de.finix.contelligent.client.gui.ContelligentAction;
33: import de.finix.contelligent.client.i18n.Resources;
34: import de.finix.contelligent.client.util.MnemonicAbstractAction;
35:
36: public class PasteComponentAction extends MnemonicAbstractAction
37: implements ContelligentAction {
38: /**
39: *
40: */
41: private final ExplorerEditor editor;
42:
43: public PasteComponentAction(ExplorerEditor editor) {
44: super ("paste_component_action", Resources.pasteIcon);
45: this .editor = editor;
46: putValue(ROLLOVER_ICON, Resources.pasteIconRollOver);
47: putValue(TYPE, PUSH_ACTION);
48: putValue(ACTION_TYPE, EDIT_ACTION);
49: putValue(ACTION_GROUP, EDIT_COPYPASTE_GROUP);
50: putValue(ACTION_POS, EDIT_COPYPASTE_PASTE);
51: putValue(MENU_TARGET, MENU);
52: putValue(BUTTON_TARGET, TOOLBAR);
53:
54: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
55: KeyEvent.VK_V, InputEvent.CTRL_MASK));
56:
57: this .editor.canAccessSystemClipboard = true;
58: this .editor.canAccessSystemClipboard();
59: putValue(POPUP_TARGET, POPUP_MENU);
60: }
61:
62: public void actionPerformed(ActionEvent e) {
63: DefaultMutableTreeNode node = (DefaultMutableTreeNode) this .editor.tree
64: .getLastSelectedPathComponent();
65: TransferHandler th = this .editor.tree.getTransferHandler();
66: Clipboard clipboard = this .editor
67: .getClipboard(this .editor.tree);
68: if ((clipboard != null) && (th != null)) {
69: Transferable transferable = clipboard.getContents(null);
70: if (transferable != null) {
71: th.importData(this.editor.tree, transferable);
72: }
73: if (transferable != null) {
74: this.editor.tree.insert(node, transferable,
75: DnDConstants.ACTION_COPY);
76: }
77: }
78: }
79: }
|