| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| CutAction |
|
| 1.5;1.5 |
| 1 | /* |
|
| 2 | * $Id: CutAction.java,v 1.8 2007/07/04 19:42:49 edankert Exp $ |
|
| 3 | * |
|
| 4 | * The contents of this file are subject to the Mozilla Public License |
|
| 5 | * Version 1.1 (the "License"); you may not use this file except in |
|
| 6 | * compliance with the License. You may obtain a copy of the License at |
|
| 7 | * http://www.mozilla.org/MPL/ |
|
| 8 | * |
|
| 9 | * Software distributed under the License is distributed on an "AS IS" basis, |
|
| 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
|
| 11 | * for the specific language governing rights and limitations under the License. |
|
| 12 | * |
|
| 13 | * The Original Code is XML Hammer code. (org.xmlhammer.*) |
|
| 14 | * |
|
| 15 | * The Initial Developer of the Original Code is Edwin Dankert. Portions created |
|
| 16 | * by the Initial Developer are Copyright (C) 2002 - 2006 the Initial Developer. |
|
| 17 | * All Rights Reserved. |
|
| 18 | * |
|
| 19 | * Contributor(s): Edwin Dankert <edankert@gmail.com> |
|
| 20 | */ |
|
| 21 | package org.xmlhammer.gui.actions; |
|
| 22 | ||
| 23 | import java.awt.Toolkit; |
|
| 24 | import java.awt.event.KeyEvent; |
|
| 25 | ||
| 26 | import javax.swing.ImageIcon; |
|
| 27 | import javax.swing.JComponent; |
|
| 28 | import javax.swing.KeyStroke; |
|
| 29 | import javax.swing.text.JTextComponent; |
|
| 30 | ||
| 31 | import org.bounce.RunnableAction; |
|
| 32 | import org.xmlhammer.gui.XMLHammer; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * An action that can be used to cut content. |
|
| 36 | * |
|
| 37 | * @version $Revision: 1.8 $, $Date: 2007/07/04 19:42:49 $ |
|
| 38 | * @author Edwin Dankert <edankert@gmail.com> |
|
| 39 | */ |
|
| 40 | public class CutAction extends RunnableAction { |
|
| 41 | private static final long serialVersionUID = 939638802470121637L; |
|
| 42 | ||
| 43 | 220 | private XMLHammer parent = null; |
| 44 | ||
| 45 | /** |
|
| 46 | * The constructor for the action which allows cutting content. |
|
| 47 | * |
|
| 48 | * @param parent the XML Hammer |
|
| 49 | */ |
|
| 50 | public CutAction( XMLHammer parent) { |
|
| 51 | 220 | super( "Cut"); |
| 52 | ||
| 53 | 220 | this.parent = parent; |
| 54 | ||
| 55 | 220 | putValue( MNEMONIC_KEY, new Integer( 't')); |
| 56 | 220 | putValue( ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)); |
| 57 | 220 | putValue( SMALL_ICON, new ImageIcon( getClass().getResource( "/org/xmlhammer/gui/icons/etool16/cut_edit.gif"))); |
| 58 | 220 | putValue( SHORT_DESCRIPTION, "Cut"); |
| 59 | ||
| 60 | 220 | setEnabled( false); |
| 61 | 220 | } |
| 62 | ||
| 63 | /** |
|
| 64 | * The implementation of the cut action, called |
|
| 65 | * after a user action. |
|
| 66 | */ |
|
| 67 | public void run() { |
|
| 68 | 0 | JComponent component = parent.getLastSelectedComponent(); |
| 69 | ||
| 70 | 0 | if ( component instanceof JTextComponent) { |
| 71 | 0 | ((JTextComponent)component).cut(); |
| 72 | } |
|
| 73 | 0 | } |
| 74 | } |