KickJava   Java API By Example, From Geeks To Geeks.

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


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.KeyStroke JavaDoc;
34 import javax.swing.JOptionPane JavaDoc;
35
36 /**
37  * An action that just calls the {@link
38  * org.objectweb.fractal.gui.clipboard.model.Clipboard#cut cut} method on a
39  * {@link org.objectweb.fractal.gui.clipboard.model.Clipboard}.
40  */

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

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

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

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