View Javadoc

1   /*
2    * $Id$
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  
22  package org.xmlhammer.gui.actions;
23  
24  import javax.swing.ImageIcon;
25  
26  import org.bounce.RunnableAction;
27  import org.xmlhammer.ModuleThread;
28  import org.xmlhammer.ModuleThreadListener;
29  
30  /***
31   * An action that can be used to stop an executed Project.
32   *
33   * @version	$Revision$, $Date$
34   * @author Edwin Dankert <edankert@gmail.com>
35   */
36   public class StopAction extends RunnableAction implements ModuleThreadListener {
37      private static final long serialVersionUID = 2367273710156615661L;
38  
39   	private ModuleThread thread = null;
40  
41   	/***
42  	 * The constructor for the action which stops an execution.
43  	 *
44  	 * @param parent the parent frame.
45  	 */
46   	public StopAction() {
47   		super( "Stop");
48  		
49  		putValue( SMALL_ICON, new ImageIcon( getClass().getResource( "/org/xmlhammer/gui/icons/elcl16/progress_stop.gif")));
50  		putValue( SHORT_DESCRIPTION, "Stop Execution");
51  		
52  		setEnabled( false);
53   	}
54  	
55  	/***
56  	 * The implementation of the stop execution action.
57  	 */
58   	public void run() {
59          thread.cancel();
60  	}
61   	
62   	public void setModuleThread( ModuleThread thread) {
63   		if ( this.thread != null) {
64   			this.thread.removeListener( this);
65   		}
66   		
67   		this.thread = thread;
68  
69   		if (thread != null) {
70   			setEnabled( true);
71   			thread.addListener( this);
72   		} else {
73              setEnabled( false);
74          }
75   	}
76   	
77      public void threadStarted( ModuleThread thread) {
78          setEnabled(true);
79      }
80  
81      public void threadFinished( ModuleThread thread) {
82   		setEnabled( false);
83   		thread.removeListener( this);
84   	}
85  }