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 */ 00017 package com.generalrobotix.ui.view.graph; 00018 00019 import java.util.StringTokenizer; 00020 00021 public class SEEnumeration implements StringExchangeable { 00022 String[] item_; 00023 int selection_; 00024 00025 public SEEnumeration(String[] s, int selection) { 00026 item_ = s; 00027 selection_ = selection; 00028 } 00029 00033 public SEEnumeration(String str) { 00034 StringTokenizer tokenizer = new StringTokenizer(str, ","); 00035 item_ = new String[tokenizer.countTokens()]; 00036 for (int i = 0; tokenizer.hasMoreTokens(); i ++) { 00037 item_[i] = tokenizer.nextToken(); 00038 } 00039 selection_ = 0; 00040 } 00041 00047 public String toString() { 00048 return item_[selection_]; 00049 } 00050 00057 public Object fromString(String str) { 00058 if (str == null) { 00059 selection_ = 0; 00060 return item_[selection_]; 00061 } 00062 00063 for(int i =0; i < item_.length; i ++) { 00064 if (str.equals(item_[i])) { 00065 selection_ = i; 00066 break; 00067 } 00068 } 00069 return item_[selection_]; 00070 } 00071 00078 public void setValue(Object value) { 00079 fromString((String)value); 00080 } 00081 00087 public void setValue(String str) { 00088 fromString((String)str); 00089 } 00090 00096 public Object getValue() { 00097 return item_[selection_]; 00098 } 00099 00105 public String[] getSelectionNames() { 00106 return item_; 00107 } 00113 public int getSelectedIndex() { 00114 return selection_; 00115 } 00116 }