Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
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
00078
00079
00080
00081
00082
00083
00084
00085
00086
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 }