sample/JoystickControl/JoystickComponent-project/src/jp/go/aist/hrp/joystick/Activator.java
Go to the documentation of this file.
1 package jp.go.aist.hrp.joystick;
2 
3 import java.io.File;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.OutputStream;
8 import java.net.URL;
9 
10 import org.eclipse.core.runtime.FileLocator;
11 import org.eclipse.jface.resource.ImageDescriptor;
12 import org.eclipse.ui.plugin.AbstractUIPlugin;
13 import org.osgi.framework.BundleContext;
14 
15 
19 public class Activator extends AbstractUIPlugin {
20  // The plug-in ID
21  public static final String PLUGIN_ID = "JoystickPlugin";
22 
23  // The shared instance
24  private static Activator plugin;
25 
26  private static final String LINUX_HOME_DIR = System.getenv("HOME") + File.separator ;
27  private static final String WIN_HOME_DIR = System.getenv("APPDATA") + File.separator;
28  private static final String LINUX_TMP_DIR = LINUX_HOME_DIR + ".Joystick_aist" + File.separator;
29  private static final String WIN_TMP_DIR = WIN_HOME_DIR + "Joystick_aist" + File.separator;
30  private static final File TMP_DIR = initTempDir();
31 
35  public Activator() {
36  plugin = this;
37  }
38 
39  /*
40  * (non-Javadoc)
41  * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
42  */
43  public void start(BundleContext context) throws Exception {
44  super.start(context);
45  }
46 
47  /*
48  * (non-Javadoc)
49  * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
50  */
51  public void stop(BundleContext context) throws Exception {
52  plugin = null;
53  super.stop(context);
54  }
55 
61  public static String getPath() {
62  URL entry = getDefault().getBundle().getEntry("/");
63  String pluginDirectory = "";
64  try {
65  pluginDirectory = FileLocator.resolve(entry).getPath();
66  } catch (IOException e) {
67  e.printStackTrace();
68  }
69  return pluginDirectory;
70  }
71 
78  public File getTempDir(){
79  return TMP_DIR;
80  }
81 
87  public static Activator getDefault() {
88  return plugin;
89  }
90 
91 
100  public static void resourceToFile(Class<jp.go.aist.hrp.joystick.Activator> pluginManager, String srcName, File destFile)
101  throws IOException {
102  InputStream in = pluginManager.getResourceAsStream(srcName.toString());
103  OutputStream out = new FileOutputStream(destFile.toString());
104  try {
105  byte[] buf = new byte[1024];
106  int len;
107  while ((len = in.read(buf)) > 0) {
108  out.write(buf, 0, len);
109  }
110  } catch (IOException e) {
111  e.printStackTrace();
112  } finally {
113  in.close();
114  out.close();
115  }
116  }
117 
122  private static File createConfigFile() {
123  File rtcFile = new File( Activator.getDefault().getTempDir(),"rtc.conf");
124  if (!rtcFile.exists()){
125  try{
126  resourceToFile(Activator.class, "/default_rtc.conf", rtcFile);
127  }catch (IOException ex){
128  ex.printStackTrace();
129  }
130  }
131  return rtcFile;
132  }
133 
138  public static String getConfigFilePath(){
139  String confPath=""; //$NON-NLS-1$
140  File defualtRtcFile = new File(Activator.getDefault().getTempDir() + File.separator + "rtc.conf");
141  if( defualtRtcFile.isFile() ){
142  confPath = defualtRtcFile.getPath();
143  } else {
144  confPath = createConfigFile().getPath();
145  }
146  System.out.println("[Joystick] default Config File path="+confPath); //$NON-NLS-1$
147  return confPath;
148  }
149 
157  public static ImageDescriptor getImageDescriptor(String path) {
158  return imageDescriptorFromPlugin(PLUGIN_ID, path);
159  }
160 
161 
162  static private File initTempDir() {
163  File ret = null;
164 
165  if ( System.getProperty("os.name").equals("Linux") ||
166  System.getProperty("os.name").equals("Mac OS X")) {
167  ret = new File(LINUX_TMP_DIR);
168  } else { //Windows と 仮定
169  ret = new File(WIN_TMP_DIR);
170  }
171  if( !ret.exists() ){
172  ret.mkdirs();
173  }
174 
175  return ret;
176  }
177 
178 }
#define null
our own NULL pointer
Definition: IceTypes.h:57
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
png_bytep buf
Definition: png.h:2729
static void resourceToFile(Class< jp.go.aist.hrp.joystick.Activator > pluginManager, String srcName, File destFile)
org


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:36