ViewToolBar.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
16 package com.generalrobotix.ui.view.tdview;
17 
18 import java.awt.*;
19 import javax.swing.*;
20 
21 import org.eclipse.swt.widgets.Display;
22 
26 
27 
28 import java.awt.event.*;
29 
30 
36 @SuppressWarnings("serial")
37 public class ViewToolBar extends JToolBar implements ItemListener, BehaviorHandler {
38  //--------------------------------------------------------------------
39  // Constant Variables
40  public static final int DISABLE_MODE = 0;
41  public static final int ROOM_MODE = 1;
42  public static final int WALK_MODE = 2;
43  public static final int PARALLEL_MODE = 3;
44 
45  public static final String COMBO_SELECT_ROOM = "Room";
46  public static final String COMBO_SELECT_WALK = "Walk";
47  public static final String COMBO_SELECT_FRONT = "Front";
48  public static final String COMBO_SELECT_BACK = "Back";
49  public static final String COMBO_SELECT_LEFT = "Left";
50  public static final String COMBO_SELECT_RIGHT = "Right";
51  public static final String COMBO_SELECT_TOP = "Top";
52  public static final String COMBO_SELECT_BOTTOM = "Bottom";
53  public static final String[] VIEW_MODE = {COMBO_SELECT_ROOM, COMBO_SELECT_WALK, COMBO_SELECT_FRONT, COMBO_SELECT_BACK, COMBO_SELECT_LEFT,
54  COMBO_SELECT_RIGHT, COMBO_SELECT_TOP, COMBO_SELECT_BOTTOM};
55 
56  public static final int PAN = 1;
57  public static final int ZOOM = 2;
58  public static final int ROTATE = 3;
59 
60  //--------------------------------------------------------------------
61  // Instance Variables
62  protected int operation_;
63  protected int mode_;
64 
65  protected JComboBox cmb_;
66  protected JToggleButton pan_;
67  protected JToggleButton zoom_;
68  protected JToggleButton rotate_;
69  protected JToggleButton wireFrame_;
70  //protected JToggleButton gamen_;
71  protected JButton bgColor_;
72  protected JButton capture_;
73  protected JToggleButton selectedButton_;
74 
75  protected ButtonGroup group_;
76 
77  private Grx3DView view_=null;
78  //--------------------------------------------------------------------
79  // Constructor
81  super(MessageBundle.get("tool.view.title"));
82  view_ = view;
83  Dimension size = new Dimension(IconProperties.WIDTH, IconProperties.HEIGHT);
84 
85  group_ = new ButtonGroup();
86 
87  cmb_ = new JComboBox();
88  cmb_.setToolTipText(MessageBundle.get("toolTipText.type"));
89  cmb_.setLightWeightPopupEnabled(false);
90  cmb_.addItem(GUIAction.ROOM_VIEW = new GUIAction("roomView"));
91  cmb_.addItem(GUIAction.WALK_VIEW = new GUIAction("walkView"));
92  cmb_.addItem(GUIAction.FRONT_VIEW = new GUIAction("frontView"));
93  cmb_.addItem(GUIAction.BACK_VIEW = new GUIAction("backView"));
94  cmb_.addItem(GUIAction.LEFT_VIEW = new GUIAction("leftView"));
95  cmb_.addItem(GUIAction.RIGHT_VIEW = new GUIAction("rightView"));
96  cmb_.addItem(GUIAction.TOP_VIEW = new GUIAction("topView"));
97  cmb_.addItem(GUIAction.BOTTOM_VIEW = new GUIAction("bottomView"));
98 
99  cmb_.setMinimumSize(cmb_.getPreferredSize());
100  cmb_.setMaximumSize(cmb_.getPreferredSize());
101 
102  cmb_.addItemListener(this);
103  add(cmb_);
104 
105  addSeparator();
106 
107  rotate_ = new JToggleButton(GUIAction.VIEW_ROTATION_MODE = new GUIAction("rotationMode"));
108  rotate_.setPreferredSize(size);
109  rotate_.setMaximumSize(size);
110  rotate_.setMinimumSize(size);
111  rotate_.setSelectedIcon(IconProperties.get("icon.rotationModeOn"));
112 
113  add(rotate_);
114  group_.add(rotate_);
115 
116  zoom_ = new JToggleButton(GUIAction.VIEW_ZOOM_MODE = new GUIAction("zoomMode"));
117  zoom_.setPreferredSize(size);
118  zoom_.setMaximumSize(size);
119  zoom_.setMinimumSize(size);
120  zoom_.setSelectedIcon(IconProperties.get("icon.zoomModeOn"));
121  add(zoom_);
122  group_.add(zoom_);
123 
124  pan_ = new JToggleButton(GUIAction.VIEW_PAN_MODE = new GUIAction("panMode"));
125  pan_.setPreferredSize(size);
126  pan_.setMaximumSize(size);
127  pan_.setMinimumSize(size);
128  pan_.setSelectedIcon(IconProperties.get("icon.panModeOn"));
129  add(pan_);
130  group_.add(pan_);
131 
132  addSeparator();
133 
134  wireFrame_ = new JToggleButton(GUIAction.WIRE_FRAME = new GUIAction("wireFrame"));
135  wireFrame_.setPreferredSize(size);
136  wireFrame_.setMaximumSize(size);
137  wireFrame_.setMinimumSize(size);
138  add(wireFrame_);
139 
140  //gamen_ = new JToggleButton(GUIAction.SPLIT_MODE);
141  //gamen_.setPreferredSize(size);
142  //gamen_.setMaximumSize(size);
143  //gamen_.setMinimumSize(size);
144  // add(gamen_);
145 
146 
147  bgColor_ = new JButton(GUIAction.BG_COLOR = new GUIAction("bgColor"));
148  bgColor_.setPreferredSize(size);
149  bgColor_.setMaximumSize(size);
150  bgColor_.setMinimumSize(size);
151  add(bgColor_);
152 
153  addSeparator();
154 
155  capture_ = new JButton(GUIAction.CAPTURE = new GUIAction("capture"));
156  capture_.setPreferredSize(size);
157  capture_.setMaximumSize(size);
158  capture_.setMinimumSize(size);
159  add(capture_);
160 
161  setMode(mode_);
162 
163  setOperation(ROTATE);
164  }
165 
166  //--------------------------------------------------------------------
167  // Public Methods
168  public void setEnabled(boolean enabled) {
169  if (!enabled) {
170  mode_ = DISABLE_MODE;
171  }
172 
173  //cmb_.setEnabled(enabled);
174  pan_.setEnabled(enabled);
175  zoom_.setEnabled(enabled);
176  rotate_.setEnabled(enabled);
177  wireFrame_.setEnabled(enabled);
178  //gamen_.setEnabled(enabled);
179  }
180 
181  public void setMode(int mode) {
182  switch (mode) {
183  case DISABLE_MODE:
184  cmb_.setEnabled(false);
185  pan_.setEnabled(false);
186  zoom_.setEnabled(false);
187  rotate_.setEnabled(false);
188  wireFrame_.setEnabled(false);
189  //gamen_.setEnabled(false);
190  break;
191  case ROOM_MODE:
192  cmb_.setEnabled(true);
193  pan_.setEnabled(true);
194  zoom_.setEnabled(true);
195  rotate_.setEnabled(true);
196  if (pan_.isSelected()){
197  rotate_.doClick();
198  }
199  wireFrame_.setEnabled(true);
200  //gamen_.setEnabled(true);
201  break;
202  case WALK_MODE:
203  cmb_.setEnabled(true);
204  pan_.setEnabled(true);
205  zoom_.setEnabled(true);
206  rotate_.setEnabled(true);
207  wireFrame_.setEnabled(true);
208  //gamen_.setEnabled(true);
209  break;
210  case PARALLEL_MODE:
211  if (rotate_.isSelected()) {
212  pan_.doClick();
213  }
214  cmb_.setEnabled(true);
215  pan_.setEnabled(true);
216  zoom_.setEnabled(true);
217  rotate_.setEnabled(false);
218  wireFrame_.setEnabled(true);
219  //gamen_.setEnabled(true);
220  break;
221  default:
222  return;
223  }
224  mode_ = mode;
225  }
226 
227  public final int getMode() { return mode_; }
228 
229  public void setOperation(int operation) {
230  switch (operation) {
231  case PAN:
232  pan_.setSelected(true);
233  break;
234  case ZOOM:
235  zoom_.setSelected(true);
236  break;
237  case ROTATE:
238  rotate_.setSelected(true);
239  break;
240  default:
241  return;
242  }
243  operation_ = operation;
244  }
245 
246  public final int getOperation() { return operation_; }
247 
248  public final void setComboSelection(int index) {
249  cmb_.setSelectedIndex(index);
250  }
251 
252  public void itemStateChanged(ItemEvent evt) {
253  if (evt.getStateChange() == ItemEvent.SELECTED) {
254  Display display = Display.getDefault();
255  if (display != null && !display.isDisposed())
256  display.syncExec(new Runnable(){
257  public void run(){
258  view_.setProperty("view.mode", VIEW_MODE[cmb_.getSelectedIndex()]);
259  }
260  });
261  GUIAction action = (GUIAction)evt.getItem();
262  action.fireAction();
263  }
264  }
265 
266  public boolean isWireFrameSelected() {
267  return wireFrame_.isSelected();
268  }
269 /*
270  public boolean isGamenSelected() {
271  return gamen_.isSelected();
272  }
273 
274  public void setGamen(boolean flag){
275  gamen_.setSelected(flag);
276  }
277 */
278  //--------------------------------------------------------------------
279  // Implementation of BehaviorHandler
280  public void processPicking(MouseEvent evt, BehaviorInfo info) {
281  if (zoom_.isSelected()) {
282  selectedButton_ = zoom_;
283  } else if (pan_.isSelected()) {
284  selectedButton_ = pan_;
285  } else if (rotate_.isSelected()) {
286  selectedButton_ = rotate_;
287  }
288 
289  if (evt.isMetaDown()) {
290  pan_.setSelected(true);
291  } else if (evt.isAltDown()) {
292  zoom_.setSelected(true);
293  }
294  }
295 
296  public void processStartDrag(MouseEvent evt, BehaviorInfo info) {}
297 
298  public void processDragOperation(MouseEvent evt, BehaviorInfo info) {}
299 
300  public void processReleased(MouseEvent evt, BehaviorInfo info) {
301  selectedButton_.setSelected(true);
302  }
303 
304  public boolean processTimerOperation(BehaviorInfo info) {
305  return true;}
306 
307  public String selectViewMode(String mode){
308  for(int i=0; i<VIEW_MODE.length; i++)
309  if(VIEW_MODE[i].equals(mode)){
310  cmb_.setSelectedIndex(i);
311  return mode;
312  }
313  // old version
314  try{
315  int i = Integer.valueOf(mode.trim());
316  cmb_.setSelectedIndex(i);
317  return VIEW_MODE[i];
318  }catch(NumberFormatException e){
319 
320  }
321  return null;
322  }
323 }
static final String get(String key)
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_uint_32 size
Definition: png.h:1521
png_uint_32 i
Definition: png.h:2735
void processStartDrag(MouseEvent evt, BehaviorInfo info)
boolean processTimerOperation(BehaviorInfo info)
void processReleased(MouseEvent evt, BehaviorInfo info)
def run(tree, args)
Object setProperty(String key, String value)
set property value associated with a keyword
void processDragOperation(MouseEvent evt, BehaviorInfo info)
backing_store_ptr info
Definition: jmemsys.h:181
org
void processPicking(MouseEvent evt, BehaviorInfo info)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:26