View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program 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
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.util.launcher;
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.net.URL;
25  
26  /***
27   * Provides a default implementation for the {@link Launcher} interface.
28   */
29  public class DefaultLauncher implements Launcher {
30  
31      //--- Constant(s) ---
32  
33      //--- Data field(s) ---
34  
35      private String command;
36      private String key;
37      private String name;
38  
39      //--- Constructor(s) ---
40  
41      public DefaultLauncher(String key, String name, String command)
42      {
43  		this.key = key;
44  		this.name = name;
45  		this.command = command;
46      }
47  
48      //--- Method(s) ---
49  
50      /***
51       * Returns the command of the launcher.
52       */
53      public String getCommand()
54      {
55  		return command;
56      }
57  
58      /***
59       * Returns the key.
60       */
61      public String getKey()
62      {
63  		return key;
64      }
65  
66      /***
67       * Returns the name of the launcher.
68       */
69      public String getName()
70      {
71  		return name;
72      }
73  
74      /***
75       * Returns true.
76       */
77      public boolean isEditable()
78      {
79  		return true;
80      }
81  
82      /***
83       * Returns true.
84       */
85      public boolean isEnabled()
86      {
87  		return true;
88      }
89  
90      /***
91       * Launches <code>file</code>.
92       */
93      public void open(File file) throws IOException
94      {
95  		LauncherManager.exec(getCommand(), new File[] { file });
96      }
97  
98  
99      /***
100      * Sets command to <code>command</code>.
101      */
102     public void setCommand(String command)
103     {
104 		this.command = command;
105     }
106 
107 	/*
108 	 * @see org.xnap.util.launcher.Launcher#open(java.net.URL)
109 	 */
110 	public void open(URL url) throws IOException 
111 	{
112 		LauncherManager.exec(new String[] { getCommand(), url.toExternalForm() });
113 	}
114 
115 }