KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > clipboard > control > PasteAsSharedAction


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

23
24 package org.objectweb.fractal.gui.clipboard.control;
25
26 import org.objectweb.fractal.gui.model.Component;
27 import org.objectweb.fractal.gui.model.IllegalOperationException;
28
29 import java.net.URL JavaDoc;
30 import java.awt.event.ActionEvent JavaDoc;
31
32 import javax.swing.ImageIcon JavaDoc;
33 import javax.swing.JOptionPane JavaDoc;
34 import javax.swing.KeyStroke JavaDoc;
35
36 /**
37  * An action that just calls the {@link
38  * org.objectweb.fractal.gui.clipboard.model.Clipboard#pasteAsShared
39  * pasteAsShared} method on a {@link
40  * org.objectweb.fractal.gui.clipboard.model.Clipboard}.
41  */

42
43 public class PasteAsSharedAction extends ClipboardAction {
44
45   /**
46    * Constructs a new {@link PasteAsSharedAction} component.
47    */

48
49   public PasteAsSharedAction () {
50     putValue(NAME, "Paste as shared");
51     putValue(SHORT_DESCRIPTION, "Paste as shared");
52     putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control shift V"));
53     URL JavaDoc url = getClass().getResource(
54       "/org/objectweb/fractal/gui/resources/empty.gif");
55     putValue(SMALL_ICON, new ImageIcon JavaDoc(url));
56     setEnabled(false);
57   }
58
59   // -------------------------------------------------------------------------
60
// Implementation of the SelectionListener interface
61
// -------------------------------------------------------------------------
62

63   public void selectionChanged () {
64     Object JavaDoc o = selection.getSelection();
65     if (o instanceof Component) {
66       setEnabled(clipboard.canPasteAsShared((Component)o));
67     } else {
68       setEnabled(clipboard.canPasteAsShared(null));
69     }
70   }
71
72   // -------------------------------------------------------------------------
73
// Implementation of the ActionListener interface
74
// -------------------------------------------------------------------------
75

76   public void actionPerformed (final ActionEvent JavaDoc e) {
77     Object JavaDoc o = selection.getSelection();
78     try {
79       clipboard.pasteAsShared((Component)o, graph, factory);
80     } catch (IllegalOperationException ioe) {
81       JOptionPane.showMessageDialog(
82         null, ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
83     }
84   }
85 }
86
Popular Tags