GrxBaseItem.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST)
00009  */
00010 /*
00011  *  GrxBaseItem.java
00012  *
00013  *  Copyright (C) 2007 GeneralRobotix, Inc.
00014  *  All Rights Reserved
00015  *
00016  *  @author Yuichiro Kawasumi (General Robotix, Inc.)
00017  */
00018 package com.generalrobotix.ui;
00019 
00020 import java.io.File;
00021 
00022 import org.eclipse.jface.action.Action;
00023 import org.eclipse.jface.dialogs.MessageDialog;
00024 import org.eclipse.swt.SWT;
00025 import org.eclipse.swt.widgets.FileDialog;
00026 import org.eclipse.osgi.util.NLS;
00027 
00028 import com.generalrobotix.ui.util.MessageBundle;
00029 
00030 @SuppressWarnings("serial") //$NON-NLS-1$
00031 
00032 
00035 public class GrxBaseItem extends GrxBasePlugin {
00036         private   Object value_ = null;
00037         private   File defaultFileDir_;
00038         protected File file_;
00039         private   String ext_;
00040         protected String clipValue_ = ""; //$NON-NLS-1$
00041 
00042     protected static final String[] modeComboItem_ = new String[] { "Torque", "HighGain" };
00043     protected static final String[] jointTypeComboItem_ = new String[] { "fixed", "rotate", "free", "slide" };
00044     protected static final String[] methodComboItem_ = new String[] { "EULER",  "RUNGE_KUTTA" };
00045 
00051         protected GrxBaseItem(String name, GrxPluginManager manager) {
00052                 super(name, manager);
00053                 // delete
00054                 Action item = new Action(){
00055                                 public String getText(){
00056                                         return MessageBundle.get("GrxBaseItem.menu.delete"); //$NON-NLS-1$
00057                                 }
00058                                 public void run(){
00059                     String mes = MessageBundle.get("GrxBaseItem.dialog.message.delete"); //$NON-NLS-1$
00060                     mes = NLS.bind(mes, new String[]{GrxBaseItem.this.getName()});
00061 
00062                                         if( MessageDialog.openQuestion( null, MessageBundle.get("GrxBaseItem.dialog.title.delete"), //$NON-NLS-1$
00063                                                         mes) )
00064                                                 delete();
00065                                 }
00066                         };
00067                 setMenuItem(item);
00068         }
00069 
00074         public boolean create() {
00075                 return true;
00076         };
00077 
00083         public boolean load(File file) {
00084                 file_ = file;
00085                 return true;
00086         };
00087 
00088 
00092         public void delete() {
00093                 //System.out.println("GrxBaseItem.delete("+getName()+") is called");
00094                 manager_.removeItem(this);
00095         };
00096 
00101         public String getFileExtention() {
00102                 if (ext_ == null)
00103                         ext_ = (String)GrxBasePlugin.getField(this.getClass(), "FILE_EXTENSION", ""); //$NON-NLS-1$ //$NON-NLS-2$
00104                 return ext_;
00105         }
00106 
00111         public File getDefaultDir() {
00112         if (defaultFileDir_ == null)
00113             defaultFileDir_ = new File(manager_.getHomePath().getPath() + GrxBasePlugin.getField(this.getClass(), "DEFAULT_DIR", "")); //$NON-NLS-1$ //$NON-NLS-2$
00114                 return defaultFileDir_;
00115         }
00116 
00121         public Object getValue() {
00122                 return value_;
00123         }
00124 
00129         protected void setFileExtension(String ext) {
00130                 ext_ = ext;
00131         }
00132 
00137         protected void setDefaultDirectory(String dir) {
00138                 defaultFileDir_ = new File(dir);
00139                 if (!defaultFileDir_.isDirectory())
00140                         defaultFileDir_ = manager_.getHomePath();
00141         }
00142 
00147         public void setValue(Object o) {
00148                 value_ = o;
00149         }
00150 
00155         public File chooseSaveFile() {
00156                 FileDialog openDialog = new FileDialog(null,SWT.SAVE);
00157                 String openFile = openDialog.open();
00158                 if( openFile != null )
00159                         return new File(openFile);
00160                 else
00161                         return null;
00162         }
00163 
00167     public void paste(String clipVal) {
00168         clipValue_ = clipVal;
00169     };
00170 
00175     public GrxBaseItem clone() {
00176         GrxBaseItem ret = (GrxBaseItem) super.clone();
00177         ret.setValue(value_);
00178 /*      
00179  *              Deep copy suspension list
00180         ret.defaultFileDir_ = new File(defaultFileDir_.getPath());
00181         ret.file_ = new File(file_.getPath());
00182         ret.ext_ = new String(ext_);
00183         ret.clipValue_ = new String(clipValue_);
00184 */
00185         return ret;
00186     }
00187 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:53