GrxControllerView.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, 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;
00018 
00019 import java.util.ArrayList;
00020 import java.util.Iterator;
00021 import java.util.List;
00022 
00023 import org.eclipse.swt.SWT;
00024 import org.eclipse.swt.widgets.Composite;
00025 
00026 import com.generalrobotix.ui.GrxBaseItem;
00027 import com.generalrobotix.ui.GrxBasePlugin;
00028 import com.generalrobotix.ui.GrxBaseView;
00029 import com.generalrobotix.ui.GrxBaseViewPart;
00030 import com.generalrobotix.ui.GrxPluginManager;
00031 import com.generalrobotix.ui.item.GrxCollisionPairItem;
00032 import com.generalrobotix.ui.item.GrxModelItem;
00033 import com.generalrobotix.ui.view.simulation.ControllerPanel;
00034 
00035 @SuppressWarnings("serial")
00036 public class GrxControllerView extends GrxBaseView {
00037     private ControllerPanel controllerPane_;
00038     private List<GrxModelItem> currentModels_ = new ArrayList<GrxModelItem>();
00039     private List<GrxCollisionPairItem> currentCollisionPairs_ = new ArrayList<GrxCollisionPairItem>();
00040 
00041     public GrxControllerView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent) {
00042         super(name, manager, vp, parent);
00043         
00044         controllerPane_ = new ControllerPanel(composite_, SWT.NONE, manager_);
00045         currentModels_ = manager_.<GrxModelItem>getSelectedItemList(GrxModelItem.class);
00046         controllerPane_.updateRobots(currentModels_);
00047         controllerPane_.setEnabled(true);
00048         
00049         currentCollisionPairs_ = manager_.<GrxCollisionPairItem>getSelectedItemList(GrxCollisionPairItem.class);
00050 
00051         Iterator<GrxModelItem> it = currentModels_.iterator();
00052         while(it.hasNext()) {
00053             it.next().addObserver(this);
00054         }
00055         manager_.registerItemChangeListener(this, GrxModelItem.class);
00056         manager_.registerItemChangeListener(this, GrxCollisionPairItem.class);
00057     }
00058     
00059     public void setUp(){
00060         Iterator<GrxModelItem> it = currentModels_.iterator();
00061         while(it.hasNext())     
00062                 it.next().deleteObserver(this);
00063         currentModels_ = manager_.<GrxModelItem>getSelectedItemList(GrxModelItem.class);
00064         currentCollisionPairs_ = manager_.<GrxCollisionPairItem>getSelectedItemList(GrxCollisionPairItem.class);
00065         controllerPane_.updateRobots(currentModels_);
00066         it = currentModels_.iterator();
00067         while(it.hasNext())     
00068                 it.next().addObserver(this);
00069         
00070     }
00071     
00072     public void registerItemChange(GrxBaseItem item, int event){
00073         if(item instanceof GrxModelItem){
00074             GrxModelItem mitem = (GrxModelItem)item;
00075             switch(event){
00076             case GrxPluginManager.SELECTED_ITEM:
00077                 if(!currentModels_.contains(mitem)){
00078                     currentModels_.add(mitem);
00079                     controllerPane_.updateRobots(currentModels_);
00080                     mitem.addObserver(this);
00081                 }
00082                 break;
00083             case GrxPluginManager.REMOVE_ITEM:
00084             case GrxPluginManager.NOTSELECTED_ITEM:
00085                 if(currentModels_.contains(mitem)){
00086                     currentModels_.remove(mitem);
00087                     controllerPane_.updateRobots(currentModels_);
00088                     mitem.deleteObserver(this);
00089                 }
00090                 break;
00091             default:
00092                 break;  
00093             }
00094         }else if(item instanceof GrxCollisionPairItem){
00095             GrxCollisionPairItem citem = (GrxCollisionPairItem)item;
00096             switch(event){
00097             case GrxPluginManager.SELECTED_ITEM:
00098             case GrxPluginManager.ADD_ITEM:
00099                 if(!currentCollisionPairs_.contains(citem)){
00100                     currentCollisionPairs_.add(citem);
00101                     controllerPane_.updateRobots(currentModels_);
00102                 }
00103                 break;
00104             case GrxPluginManager.REMOVE_ITEM:
00105             case GrxPluginManager.NOTSELECTED_ITEM:
00106                 if(currentCollisionPairs_.contains(citem)){
00107                     currentCollisionPairs_.remove(citem);
00108                     controllerPane_.updateRobots(currentModels_);
00109                 }
00110                 break;
00111             default:
00112                 break;  
00113             }
00114         }
00115     }
00116 
00117     public void update(GrxBasePlugin plugin, Object... arg) {
00118         
00119         if(currentModels_.contains(plugin)){
00120             if((String)arg[0]=="PropertyChange"){ //$NON-NLS-1$
00121                 if((String)arg[1]=="isRobot")
00122                     controllerPane_.updateRobots(currentModels_);
00123             }
00124         }
00125     }
00126     
00127     public void shutdown() {
00128         Iterator<GrxModelItem> it = currentModels_.iterator();
00129         while(it.hasNext()) {
00130             it.next().deleteObserver(this);
00131         }
00132 
00133         manager_.removeItemChangeListener(this, GrxModelItem.class);
00134         manager_.removeItemChangeListener(this, GrxCollisionPairItem.class);
00135     }
00136 
00137     public void updateTableFont(){
00138         controllerPane_.updateTableFont();
00139     }
00140 }


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