View Javadoc

1   /*
2    * $Id: SelectAllAction.java,v 1.7 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) 2005 - 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.JComponent;
27  import javax.swing.KeyStroke;
28  import javax.swing.text.JTextComponent;
29  
30  import org.bounce.RunnableAction;
31  import org.xmlhammer.gui.XMLHammer;
32  
33  /***
34   * An action that can be used to select all content in the selected component.
35   *
36   * @version	$Revision: 1.7 $, $Date: 2007/07/04 19:42:49 $
37   * @author Edwin Dankert <edankert@gmail.com>
38   */
39   public class SelectAllAction extends RunnableAction {
40      private static final long serialVersionUID = 4492842981937751317L;
41      
42      private XMLHammer parent = null;
43  	
44   	/***
45  	 * The constructor for the action which allows for selecting all content for a component.
46       * 
47       * @param parent the XML Hammer parent.
48  	 */
49   	public SelectAllAction( XMLHammer parent) {
50  		super( "Select All");
51          
52          this.parent = parent;
53  		
54  		putValue( MNEMONIC_KEY, new Integer( 'A'));
55  		putValue( ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
56  		
57  		setEnabled( false);
58   	}
59   	
60  	/***
61  	 * The implementation of the select all action, called 
62  	 * after a user action.
63  	 */
64   	public void run() {
65          JComponent component = parent.getLastSelectedComponent();
66          
67          if ( component instanceof JTextComponent) {
68              ((JTextComponent)component).selectAll();
69          }
70   	}
71  }