HRangeDialog.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  */
10 package com.generalrobotix.ui.view.graph;
11 
12 import org.eclipse.jface.dialogs.Dialog;
13 import org.eclipse.jface.dialogs.IDialogConstants;
14 import org.eclipse.jface.dialogs.MessageDialog;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.KeyEvent;
17 import org.eclipse.swt.events.KeyListener;
18 import org.eclipse.swt.layout.RowLayout;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Scale;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.swt.widgets.Text;
25 
27 
28 
35 public class HRangeDialog extends Dialog {
36 
37  // -----------------------------------------------------------------
38  // 定数
39  // 更新フラグ
40  public static final int RANGE_UPDATED = 1; // レンジ変更
41  public static final int POS_UPDATED = 2; // マーカ位置変更
42 
43  private static final int MARKER_POS_STEPS = 100; // マーカ位置段階数
44 
45  // -----------------------------------------------------------------
46  // インスタンス変数
47  int updateFlag_; // 更新フラグ
48  double hRange_; // レンジ値
49  double maxHRange_; // 最大レンジ
50  double minHRange_; // 最小レンジ
51  double markerPos_; // マーカ位置
52  Text hRangeField_; // レンジ入力フィールド
53  Scale markerSlider_; // マーカ位置設定スライダ
54  private boolean first_;
55  private Shell shell_;
56  // -----------------------------------------------------------------
57  // コンストラクタ
63  public HRangeDialog(Shell shell) {
64  super(shell);
65  shell_ = shell;
66  }
67 
68  protected void configureShell(Shell newShell) {
69  super.configureShell(newShell);
70  newShell.setText(MessageBundle.get("dialog.graph.hrange.title")); //$NON-NLS-1$
71  }
72 
73  protected Control createDialogArea(Composite parent) {
74  Composite composite = (Composite)super.createDialogArea(parent);
75  composite.setLayout(new RowLayout(SWT.VERTICAL));
76  Composite comp0 = new Composite(composite, SWT.NONE);
77  comp0.setLayout(new RowLayout());
78 
79  Label label1 = new Label(comp0, SWT.NONE);
80  label1.setText(MessageBundle.get("dialog.graph.hrange.hrange")); //$NON-NLS-1$
81 
82  hRangeField_ = new Text(comp0, SWT.BORDER);
83  hRangeField_.setText(String.format("%10.3f", hRange_)); //$NON-NLS-1$
84  first_ = true;
85  hRangeField_.addKeyListener(new KeyListener(){
86  public void keyPressed(KeyEvent e) {
87  if(first_){
88  hRangeField_.setText(""); //$NON-NLS-1$
89  first_ = false;
90  }
91  }
92  public void keyReleased(KeyEvent e) {
93  }
94  });
95  hRangeField_.setFocus();
96 
97  Label label2 = new Label(comp0, SWT.NONE);
98  label2.setText(MessageBundle.get("dialog.graph.hrange.unit")); //$NON-NLS-1$
99 
100  Composite comp1 = new Composite(composite, SWT.NONE);
101  comp1.setLayout(new RowLayout());
102 
103  Label label3 = new Label(comp1, SWT.NONE);
104  label3.setText(MessageBundle.get("dialog.graph.hrange.markerpos")); //$NON-NLS-1$
105 
106  markerSlider_ = new Scale(comp1, SWT.HORIZONTAL);
107  markerSlider_.setMinimum(0);
108  markerSlider_.setMaximum(MARKER_POS_STEPS);
109  markerSlider_.setIncrement(10);
110  markerSlider_.setSelection((int)(markerPos_ * MARKER_POS_STEPS));
111 
112  updateFlag_ = 0;
113  return composite;
114  }
115 
116  protected void buttonPressed(int buttonId) {
117  if (buttonId == IDialogConstants.OK_ID) {
118  double range;
119  try {
120  range = Double.parseDouble(hRangeField_.getText());
121  } catch (NumberFormatException ex) {
122  // エラー表示
123  MessageDialog.openError(shell_,
124  MessageBundle.get("dialog.graph.hrange.invalidinput.title"), //$NON-NLS-1$
125  MessageBundle.get("dialog.graph.hrange.invalidinput.message")); //$NON-NLS-1$
126 
127  hRangeField_.setFocus(); // フォーカス設定
128  return;
129  }
130  // 入力値チェック
131  if (range < minHRange_ || range > maxHRange_) {
132  // エラー表示
133  MessageDialog.openError(shell_,
134  MessageBundle.get("dialog.graph.hrange.invalidrange.title"), //$NON-NLS-1$
135  MessageBundle.get("dialog.graph.hrange.invalidrange.message") //$NON-NLS-1$
136  + "\n(" + minHRange_ + " - " + maxHRange_ + ")" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
137  hRangeField_.setFocus(); // フォーカス設定
138  return;
139  }
140  double pos = markerSlider_.getSelection() / (double)MARKER_POS_STEPS;
141  // 更新チェック
142  updateFlag_ = 0;
143  if (range != hRange_) { // レンジ更新?
144  hRange_ = range;
145  updateFlag_ += RANGE_UPDATED;
146  }
147  if (pos != markerPos_) { // マーカ更新?
148  markerPos_ = pos;
149  updateFlag_ += POS_UPDATED;
150  }
151  }
152  setReturnCode(buttonId);
153  close();
154  super.buttonPressed(buttonId);
155  }
156 
157  // -----------------------------------------------------------------
158  // メソッド
159 
165  public void setHRange(
166  double hRange
167  ) {
168  hRange_ = hRange;
169  }
170 
176  public void setMaxHRange(
177  double maxHRange
178  ) {
179  maxHRange_ = maxHRange;
180  }
181 
187  public void setMinHRange(
188  double minHRange
189  ) {
190  minHRange_ = minHRange;
191  }
192 
198  public void setMarkerPos(
199  double markerPos
200  ) {
201  markerPos_ = markerPos;
202  }
203 
209  public double getHRange() {
210  return hRange_;
211  }
212 
218  public double getMarkerPos() {
219  return markerPos_;
220  }
221 
227  public int getUpdateFlag() {
228  return updateFlag_;
229  }
230 
231 }
static final String get(String key)
org


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:38