1 /*
2 * @(#)$Id: CommandExecutor.java 704 2009-07-28 11:39:37Z bsigner $
3 *
4 * Author : Michele Croci, mcroci@gmail.com
5 *
6 * Purpose : Class encapsulating the execution of a command.
7 *
8 * -----------------------------------------------------------------------
9 *
10 * Revision Information:
11 *
12 * Date Who Reason
13 *
14 * Dec 6, 2007 crocimi Initial Release
15 * Nov 11, 2008 bsigner Cleanup
16 *
17 * -----------------------------------------------------------------------
18 *
19 * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20 *
21 * This software is the proprietary information of ETH Zurich.
22 * Use is subject to license terms.
23 *
24 */
25
26
27 package org.ximtec.igesture.geco.action;
28
29 import java.io.IOException;
30
31 import org.sigtec.util.SystemTool;
32 import org.ximtec.igesture.core.ResultSet;
33 import org.ximtec.igesture.event.GestureAction;
34
35
36 /**
37 * Class encapsulating the execution of a command.
38 * @version 0.9, Dec 6, 2007
39 * @author Michele Croci, mcroci@gmail.com
40 * @author Beat Signer, signer@inf.ethz.ch
41 */
42 public class CommandExecutor implements GestureAction {
43
44 private final static String WIN_CONSOLE = "cmd /C ";
45
46 private String command;
47
48
49 /**
50 * Constructor.
51 *
52 * @param command the command to be executed
53 */
54 public CommandExecutor(String command) {
55 this.command = command;
56 }
57
58
59 /**
60 * Execute the action
61 *
62 */
63 public void actionPerformed(ResultSet resultSet) {
64 try {
65 if ((command != null) && (!command.isEmpty())) {
66
67 if (SystemTool.isWindowsPlatform()) {
68 Runtime.getRuntime().exec(WIN_CONSOLE + command);
69 }
70
71 }
72 }
73 catch (IOException ioe) {
74 ioe.printStackTrace();
75 }
76
77 } // run
78
79
80 public String getCommand() {
81 return command;
82 }
83
84
85 /**
86 * Returns a string representation of the command executor.
87 *
88 * @return string representation of the command executor.
89 */
90 public String toString() {
91 return command;
92 }// toString
93
94 }