ViewToolBar.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  */
00016 package com.generalrobotix.ui.view.tdview;
00017 
00018 import java.awt.*;
00019 import javax.swing.*;
00020 
00021 import org.eclipse.swt.widgets.Display;
00022 
00023 import com.generalrobotix.ui.util.IconProperties;
00024 import com.generalrobotix.ui.util.MessageBundle;
00025 import com.generalrobotix.ui.view.Grx3DView;
00026 
00027 
00028 import java.awt.event.*;
00029 
00030 
00036 @SuppressWarnings("serial")
00037 public class ViewToolBar extends JToolBar implements ItemListener, BehaviorHandler {
00038     //--------------------------------------------------------------------
00039     // Constant Variables
00040     public static final int DISABLE_MODE  = 0;
00041     public static final int ROOM_MODE     = 1;
00042     public static final int WALK_MODE     = 2;
00043     public static final int PARALLEL_MODE = 3;
00044 
00045     public static final String COMBO_SELECT_ROOM   = "Room";
00046     public static final String COMBO_SELECT_WALK   = "Walk";
00047     public static final String COMBO_SELECT_FRONT  = "Front";
00048     public static final String COMBO_SELECT_BACK   = "Back";
00049     public static final String COMBO_SELECT_LEFT   = "Left";
00050     public static final String COMBO_SELECT_RIGHT  = "Right";
00051     public static final String COMBO_SELECT_TOP    = "Top";
00052     public static final String COMBO_SELECT_BOTTOM = "Bottom";
00053     public static final String[] VIEW_MODE = {COMBO_SELECT_ROOM, COMBO_SELECT_WALK, COMBO_SELECT_FRONT, COMBO_SELECT_BACK, COMBO_SELECT_LEFT,
00054         COMBO_SELECT_RIGHT, COMBO_SELECT_TOP, COMBO_SELECT_BOTTOM};
00055 
00056     public static final int PAN    = 1;
00057     public static final int ZOOM   = 2;
00058     public static final int ROTATE = 3;
00059 
00060     //--------------------------------------------------------------------
00061     // Instance Variables
00062     protected int operation_;
00063     protected int mode_;
00064 
00065     protected JComboBox cmb_;
00066     protected JToggleButton pan_;
00067     protected JToggleButton zoom_;
00068     protected JToggleButton rotate_;
00069     protected JToggleButton wireFrame_;
00070     //protected JToggleButton gamen_;
00071     protected JButton bgColor_;
00072     protected JButton capture_;
00073     protected JToggleButton selectedButton_;
00074 
00075     protected ButtonGroup group_;
00076 
00077     private Grx3DView view_=null;
00078     //--------------------------------------------------------------------
00079     // Constructor
00080     public ViewToolBar(Grx3DView view) {
00081         super(MessageBundle.get("tool.view.title"));
00082         view_ = view;
00083         Dimension size = new Dimension(IconProperties.WIDTH, IconProperties.HEIGHT);
00084         
00085         group_ = new ButtonGroup();
00086 
00087         cmb_ = new JComboBox();
00088         cmb_.setToolTipText(MessageBundle.get("toolTipText.type"));
00089         cmb_.setLightWeightPopupEnabled(false);
00090         cmb_.addItem(GUIAction.ROOM_VIEW = new GUIAction("roomView"));
00091         cmb_.addItem(GUIAction.WALK_VIEW = new GUIAction("walkView"));
00092         cmb_.addItem(GUIAction.FRONT_VIEW = new GUIAction("frontView"));
00093         cmb_.addItem(GUIAction.BACK_VIEW = new GUIAction("backView"));
00094         cmb_.addItem(GUIAction.LEFT_VIEW = new GUIAction("leftView"));
00095         cmb_.addItem(GUIAction.RIGHT_VIEW = new GUIAction("rightView"));
00096         cmb_.addItem(GUIAction.TOP_VIEW = new GUIAction("topView"));
00097         cmb_.addItem(GUIAction.BOTTOM_VIEW = new GUIAction("bottomView"));
00098 
00099         cmb_.setMinimumSize(cmb_.getPreferredSize());
00100         cmb_.setMaximumSize(cmb_.getPreferredSize());
00101 
00102         cmb_.addItemListener(this);
00103         add(cmb_);
00104         
00105         addSeparator();
00106 
00107         rotate_ = new JToggleButton(GUIAction.VIEW_ROTATION_MODE = new GUIAction("rotationMode"));
00108         rotate_.setPreferredSize(size);
00109         rotate_.setMaximumSize(size);
00110         rotate_.setMinimumSize(size);
00111         rotate_.setSelectedIcon(IconProperties.get("icon.rotationModeOn"));
00112 
00113         add(rotate_);
00114         group_.add(rotate_);
00115 
00116         zoom_ = new JToggleButton(GUIAction.VIEW_ZOOM_MODE = new GUIAction("zoomMode"));
00117         zoom_.setPreferredSize(size);
00118         zoom_.setMaximumSize(size);
00119         zoom_.setMinimumSize(size);
00120         zoom_.setSelectedIcon(IconProperties.get("icon.zoomModeOn"));
00121         add(zoom_);
00122         group_.add(zoom_);
00123 
00124         pan_ = new JToggleButton(GUIAction.VIEW_PAN_MODE = new GUIAction("panMode"));
00125         pan_.setPreferredSize(size);
00126         pan_.setMaximumSize(size);
00127         pan_.setMinimumSize(size);
00128         pan_.setSelectedIcon(IconProperties.get("icon.panModeOn"));
00129         add(pan_);
00130         group_.add(pan_);
00131 
00132         addSeparator();
00133 
00134         wireFrame_ = new JToggleButton(GUIAction.WIRE_FRAME = new GUIAction("wireFrame"));
00135         wireFrame_.setPreferredSize(size);
00136         wireFrame_.setMaximumSize(size);
00137         wireFrame_.setMinimumSize(size);
00138         add(wireFrame_);
00139 
00140         //gamen_ = new JToggleButton(GUIAction.SPLIT_MODE);
00141         //gamen_.setPreferredSize(size);
00142         //gamen_.setMaximumSize(size);
00143         //gamen_.setMinimumSize(size);
00144        // add(gamen_);
00145 
00146 
00147         bgColor_ = new JButton(GUIAction.BG_COLOR = new GUIAction("bgColor"));
00148         bgColor_.setPreferredSize(size);
00149         bgColor_.setMaximumSize(size);
00150         bgColor_.setMinimumSize(size);
00151         add(bgColor_);
00152         
00153         addSeparator();
00154         
00155         capture_ = new JButton(GUIAction.CAPTURE = new GUIAction("capture"));
00156         capture_.setPreferredSize(size);
00157         capture_.setMaximumSize(size);
00158         capture_.setMinimumSize(size);
00159         add(capture_);
00160 
00161         setMode(mode_);
00162         
00163         setOperation(ROTATE);
00164     }
00165 
00166     //--------------------------------------------------------------------
00167     // Public Methods
00168     public void setEnabled(boolean enabled) {
00169         if (!enabled) {
00170             mode_ = DISABLE_MODE;
00171         }
00172 
00173         //cmb_.setEnabled(enabled);
00174         pan_.setEnabled(enabled);
00175         zoom_.setEnabled(enabled);
00176         rotate_.setEnabled(enabled);
00177         wireFrame_.setEnabled(enabled);
00178         //gamen_.setEnabled(enabled);
00179     }
00180 
00181     public void setMode(int mode) {
00182         switch (mode) {
00183         case DISABLE_MODE:
00184             cmb_.setEnabled(false);
00185             pan_.setEnabled(false);
00186             zoom_.setEnabled(false);
00187             rotate_.setEnabled(false);
00188             wireFrame_.setEnabled(false);
00189             //gamen_.setEnabled(false);
00190             break;
00191         case ROOM_MODE:
00192             cmb_.setEnabled(true);
00193             pan_.setEnabled(true);    
00194             zoom_.setEnabled(true);    
00195             rotate_.setEnabled(true);    
00196                 if (pan_.isSelected()){
00197                         rotate_.doClick();
00198                 }
00199             wireFrame_.setEnabled(true);
00200             //gamen_.setEnabled(true);
00201             break;
00202         case WALK_MODE:
00203             cmb_.setEnabled(true);
00204             pan_.setEnabled(true);    
00205             zoom_.setEnabled(true);    
00206             rotate_.setEnabled(true);    
00207             wireFrame_.setEnabled(true);
00208             //gamen_.setEnabled(true);
00209             break;
00210         case PARALLEL_MODE:
00211             if (rotate_.isSelected()) {
00212                 pan_.doClick();
00213             }
00214             cmb_.setEnabled(true);
00215             pan_.setEnabled(true);    
00216             zoom_.setEnabled(true);    
00217             rotate_.setEnabled(false);    
00218             wireFrame_.setEnabled(true);
00219             //gamen_.setEnabled(true);
00220             break;
00221         default:
00222             return;
00223         }
00224         mode_ = mode;
00225     }
00226 
00227     public final int getMode() { return mode_; }
00228 
00229     public void setOperation(int operation) {
00230         switch (operation) {
00231         case PAN:
00232             pan_.setSelected(true);
00233             break;
00234         case ZOOM:
00235             zoom_.setSelected(true);
00236             break;
00237         case ROTATE:
00238             rotate_.setSelected(true);
00239             break;
00240         default:
00241             return;
00242         }
00243         operation_ = operation;
00244     }
00245 
00246     public final int getOperation() { return operation_; }
00247 
00248     public final void setComboSelection(int index) {
00249         cmb_.setSelectedIndex(index);
00250     }
00251 
00252     public void itemStateChanged(ItemEvent evt) {
00253         if (evt.getStateChange() == ItemEvent.SELECTED) {
00254                 Display display = Display.getDefault();
00255             if (display != null && !display.isDisposed())
00256                 display.syncExec(new Runnable(){
00257                         public void run(){
00258                                 view_.setProperty("view.mode", VIEW_MODE[cmb_.getSelectedIndex()]);
00259                         }
00260                 });
00261             GUIAction action = (GUIAction)evt.getItem();
00262             action.fireAction();
00263         }
00264     }
00265 
00266     public boolean isWireFrameSelected() {
00267         return wireFrame_.isSelected();
00268     }
00269 /*
00270     public boolean isGamenSelected() {
00271         return gamen_.isSelected();
00272     }
00273     
00274     public void setGamen(boolean flag){
00275         gamen_.setSelected(flag);
00276     }
00277 */
00278     //--------------------------------------------------------------------
00279     // Implementation of BehaviorHandler
00280     public void processPicking(MouseEvent evt, BehaviorInfo info) {
00281         if (zoom_.isSelected()) {
00282             selectedButton_ = zoom_;
00283         } else if (pan_.isSelected()) {
00284             selectedButton_ = pan_;
00285         } else if (rotate_.isSelected()) {
00286             selectedButton_ = rotate_;
00287         }
00288 
00289         if (evt.isMetaDown()) {
00290             pan_.setSelected(true);
00291         } else if (evt.isAltDown()) {
00292             zoom_.setSelected(true);
00293         }
00294     }
00295 
00296     public void processStartDrag(MouseEvent evt, BehaviorInfo info) {}
00297 
00298     public void processDragOperation(MouseEvent evt, BehaviorInfo info) {}
00299 
00300     public void processReleased(MouseEvent evt, BehaviorInfo info) {
00301         selectedButton_.setSelected(true);
00302     }
00303 
00304     public boolean processTimerOperation(BehaviorInfo info) {
00305                 return true;}
00306     
00307     public String selectViewMode(String mode){
00308         for(int i=0; i<VIEW_MODE.length; i++)
00309                 if(VIEW_MODE[i].equals(mode)){
00310                         cmb_.setSelectedIndex(i);
00311                         return mode;
00312                 }
00313         // old version
00314         try{
00315                 int i = Integer.valueOf(mode.trim());
00316                 cmb_.setSelectedIndex(i);
00317                 return VIEW_MODE[i];
00318         }catch(NumberFormatException e){
00319                 
00320         }
00321                 return null;
00322     }
00323 }


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:19