ViewHandler.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  */
00017 package com.generalrobotix.ui.view.tdview;
00018 
00019 import java.util.*;
00020 import java.awt.event.*;
00021 
00022 abstract class ViewHandler implements BehaviorHandler {
00023     protected static final int MOUSE_BUTTON_LEFT   = 0;
00024     protected static final int MOUSE_BUTTON_CENTER = 1;
00025     protected static final int MOUSE_BUTTON_RIGHT  = 2;
00026 
00027     protected static final int ROTATION_MODE    = 1;
00028     protected static final int TRANSLATION_MODE = 2;
00029     protected static final int ZOOM_MODE        = 3;
00030 
00031     protected int[] mode_;
00032     protected Map<String, int[]> modeMap_;
00033 
00034     ViewHandler() {
00035         modeMap_ = new HashMap<String, int[]>();
00036 
00037         modeMap_.put(
00038             "default_mode",
00039             new int[] { ROTATION_MODE, ZOOM_MODE, TRANSLATION_MODE }
00040         );
00041 
00042         modeMap_.put(
00043             "button_mode_rotation",
00044             new int[] { ROTATION_MODE, ZOOM_MODE, TRANSLATION_MODE }
00045         );
00046 
00047         modeMap_.put(
00048             "button_mode_translation",
00049             new int[] { TRANSLATION_MODE, ZOOM_MODE, TRANSLATION_MODE }
00050         );
00051 
00052         modeMap_.put(
00053             "button_mode_zoom",
00054             new int[] { ZOOM_MODE, ZOOM_MODE, TRANSLATION_MODE }
00055         );
00056 
00057         modeMap_.put(
00058             "ctrl_pressed",
00059             new int[] { ZOOM_MODE, ZOOM_MODE, ZOOM_MODE }
00060         );
00061 
00062         modeMap_.put(
00063             "alt_pressed",
00064             new int[] { TRANSLATION_MODE, TRANSLATION_MODE, TRANSLATION_MODE }
00065         );
00066 
00067         setMode("default_mode");
00068     }
00069 
00070     void setMode(String mode) {
00071         mode_ = (int[])modeMap_.get(mode);
00072     }
00073 
00074     protected int getMouseButtonMode(MouseEvent evt) {
00075         // マウスイベントからマウスボタンの識別子に変換。
00076 /*
00077         switch (evt.getModifiers()) {
00078         case MouseEvent.BUTTON1_MASK:
00079             return MOUSE_BUTTON_LEFT;
00080         case MouseEvent.BUTTON2_MASK:
00081             return MOUSE_BUTTON_CENTER;
00082         case MouseEvent.BUTTON3_MASK:
00083             return MOUSE_BUTTON_RIGHT;
00084         default:
00085             return 3;
00086             //return MOUSE_BUTTON_RIGHT;
00087         }
00088 */
00089 
00090         if (evt.isMetaDown()) {
00091             return MOUSE_BUTTON_RIGHT;
00092         } else if (evt.isAltDown()) {
00093             return MOUSE_BUTTON_CENTER;
00094         } else {
00095             return MOUSE_BUTTON_LEFT;
00096         }
00097     }
00098 }


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