GrxCollisionPairView.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.CollisionPairPanel;
00034 
00035 @SuppressWarnings("serial")
00036 public class GrxCollisionPairView extends GrxBaseView {
00037 
00038     private CollisionPairPanel collisionPane_;
00039     private List<GrxModelItem> currentModels_ = new ArrayList<GrxModelItem>();
00040     private List<GrxCollisionPairItem> currentCollisionPairs_ = new ArrayList<GrxCollisionPairItem>();;
00041 
00042     public GrxCollisionPairView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent) {
00043         super(name, manager, vp, parent);
00044         collisionPane_ = new CollisionPairPanel(composite_, SWT.NONE, manager_);
00045 
00046         setUp();
00047         collisionPane_.setEnabled(true);
00048         
00049         manager_.registerItemChangeListener(this, GrxModelItem.class);
00050         manager_.registerItemChangeListener(this, GrxCollisionPairItem.class);
00051     }
00052     
00053     public void setUp(){
00054         Iterator<GrxCollisionPairItem> it = currentCollisionPairs_.iterator();
00055         while(it.hasNext()) {
00056             it.next().deleteObserver(this);
00057         }
00058         currentModels_ = manager_.<GrxModelItem>getSelectedItemList(GrxModelItem.class);
00059         currentCollisionPairs_ = manager_.<GrxCollisionPairItem>getSelectedItemList(GrxCollisionPairItem.class);
00060         collisionPane_.updateCollisionPairs(currentCollisionPairs_, currentModels_);
00061         it = currentCollisionPairs_.iterator();
00062         while(it.hasNext()) {
00063             it.next().addObserver(this);
00064         }
00065     }
00066     
00067     public void registerItemChange(GrxBaseItem item, int event){
00068         if(item instanceof GrxModelItem){
00069             GrxModelItem mitem = (GrxModelItem)item;
00070             switch(event){
00071             case GrxPluginManager.SELECTED_ITEM:
00072                 if(!currentModels_.contains(mitem)){
00073                     currentModels_.add(mitem);
00074                     collisionPane_.updateCollisionPairs(currentCollisionPairs_, currentModels_);
00075                 }
00076                 break;
00077             case GrxPluginManager.REMOVE_ITEM:
00078             case GrxPluginManager.NOTSELECTED_ITEM:
00079                 if(currentModels_.contains(mitem)){
00080                     currentModels_.remove(mitem);
00081                     collisionPane_.updateCollisionPairs(currentCollisionPairs_, currentModels_);
00082                 }
00083                 break;
00084             default:
00085                 break;  
00086             }
00087         }else if(item instanceof GrxCollisionPairItem){
00088             GrxCollisionPairItem citem = (GrxCollisionPairItem)item;
00089             switch(event){
00090             case GrxPluginManager.SELECTED_ITEM:
00091             case GrxPluginManager.ADD_ITEM:
00092                 if(!currentCollisionPairs_.contains(citem)){
00093                     currentCollisionPairs_.add(citem);
00094                     collisionPane_.updateCollisionPairs(currentCollisionPairs_, currentModels_);
00095                     citem.addObserver(this);
00096                 }
00097                 break;
00098             case GrxPluginManager.REMOVE_ITEM:
00099             case GrxPluginManager.NOTSELECTED_ITEM:
00100                 if(currentCollisionPairs_.contains(citem)){
00101                     currentCollisionPairs_.remove(citem);
00102                     collisionPane_.updateCollisionPairs(currentCollisionPairs_, currentModels_);
00103                     citem.deleteObserver(this);
00104                 }
00105                 break;
00106             default:
00107                 break;  
00108             }
00109         }
00110     }
00111 
00112     public void update(GrxBasePlugin plugin, Object... arg) {
00113         if(currentCollisionPairs_.contains(plugin)){
00114             if((String)arg[0]=="PropertyChange"){
00115                 collisionPane_.updateCollisionPairs(currentCollisionPairs_, currentModels_);
00116             }
00117         }
00118     }
00119     
00120     public void shutdown() {
00121         Iterator<GrxCollisionPairItem> it = currentCollisionPairs_.iterator();
00122         while(it.hasNext()) {
00123             it.next().deleteObserver(this);
00124         }
00125 
00126         manager_.removeItemChangeListener(this, GrxModelItem.class);
00127         manager_.removeItemChangeListener(this, GrxCollisionPairItem.class);
00128     }
00129 
00130     public void updateTableFont(){
00131         collisionPane_.updateTableFont();
00132     }
00133 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16