VRangeDialog.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.Shell;
23 import org.eclipse.swt.widgets.Text;
24 
26 
27 
34 public class VRangeDialog extends Dialog {
35 
36  // -----------------------------------------------------------------
37  // インスタンス変数
38  double base_; // 基準値
39  double extent_; // 幅
40  boolean updated_; // 更新フラグ
41  String unit_; // 単位文字列
42  Text minField_; // 最小値フィールド
43  Text maxField_; // 最大値フィールド
44  Label minUnitLabel_; // 最小値単位ラベル
45  Label maxUnitLabel_; // 最大値単位ラベル
46  private Shell shell_;
47  private boolean minfirst_;
48  private boolean maxfirst_;
49 
50  // -----------------------------------------------------------------
51  // コンストラクタ
57  public VRangeDialog(Shell shell) {
58  super(shell);
59  shell_ = shell;
60  }
61 
62  protected void configureShell(Shell newShell) {
63  super.configureShell(newShell);
64  newShell.setText(MessageBundle.get("dialog.graph.vrange.title"));
65  }
66 
67  protected Control createDialogArea(Composite parent) {
68  Composite composite = (Composite)super.createDialogArea(parent);
69  composite.setLayout(new RowLayout(SWT.VERTICAL));
70  Composite comp0 = new Composite(composite, SWT.NONE);
71  comp0.setLayout(new RowLayout());
72 
73  Label label1 = new Label(comp0, SWT.NONE);
74  label1.setText(MessageBundle.get("dialog.graph.vrange.min"));
75 
76  minField_ = new Text(comp0, SWT.BORDER);
77  minField_.setText(String.format("%10.3f", base_));
78  minfirst_ = true;
79  minField_.addKeyListener(new KeyListener(){
80  public void keyPressed(KeyEvent e) {
81  if(minfirst_){
82  minField_.setText("");
83  minfirst_ = false;
84  }
85  }
86 
87  public void keyReleased(KeyEvent e) {
88  // TODO 自動生成されたメソッド・スタブ
89 
90  }
91 
92  });
93  minField_.setFocus();
94 
95  minUnitLabel_ = new Label(comp0, SWT.NONE);
96  minUnitLabel_.setText(unit_);
97 
98  Composite comp1 = new Composite(composite, SWT.NONE);
99  comp1.setLayout(new RowLayout());
100 
101  Label label3 = new Label(comp1, SWT.NONE);
102  label3.setText(MessageBundle.get("dialog.graph.vrange.max"));
103  maxField_ = new Text(comp1, SWT.BORDER);
104  maxField_.setText(String.format("%10.3f", base_+extent_));
105  maxfirst_ = true;
106  maxField_.addKeyListener(new KeyListener(){
107  public void keyPressed(KeyEvent e) {
108  if(maxfirst_){
109  maxField_.setText("");
110  maxfirst_ = false;
111  }
112  }
113 
114  public void keyReleased(KeyEvent e) {
115  // TODO 自動生成されたメソッド・スタブ
116 
117  }
118 
119  });
120 
121  maxUnitLabel_ = new Label(comp1, SWT.NONE);
122  maxUnitLabel_.setText(unit_);
123 
124  updated_ = false;
125  return composite;
126  }
127 
128  protected void buttonPressed(int buttonId) {
129  if (buttonId == IDialogConstants.OK_ID) {
130  double min, max;
131  try {
132  min = Double.parseDouble(minField_.getText());
133  max = Double.parseDouble(maxField_.getText());
134  } catch (NumberFormatException ex) {
135  MessageDialog.openError(shell_,
136  MessageBundle.get("dialog.graph.vrange.invalidinput.title"),
137  MessageBundle.get("dialog.graph.vrange.invalidinput.message"));
138  minField_.setFocus(); // フォーカス設定
139  return;
140  }
141  // 入力値チェック
142  if (min == max) {
143  MessageDialog.openError(shell_,
144  MessageBundle.get("dialog.graph.vrange.invalidrange.title"),
145  MessageBundle.get("dialog.graph.vrange.invalidrange.message"));
146  minField_.setFocus(); // フォーカス設定
147  return;
148  }
149  // 値更新
150  if (min < max) {
151  base_ = min;
152  extent_ = max - min;
153  } else {
154  base_ = max;
155  extent_ = min - max;
156  }
157  updated_ = true;
158  }
159  setReturnCode(buttonId);
160  close();
161  super.buttonPressed(buttonId);
162  }
163 
164  // -----------------------------------------------------------------
165  // メソッド
166 
172  public void setUnit(
173  String unit
174  ) {
175  unit_ = unit;
176  }
177 
183  public void setBase(
184  double base
185  ) {
186  base_ = base;
187  }
188 
194  public void setExtent(
195  double extent
196  ) {
197  extent_ = extent;
198  }
199 
205  public double getBase() {
206  return base_;
207  }
208 
214  public double getExtent() {
215  return extent_;
216  }
217 
223  public boolean isUpdated() {
224  return updated_;
225  }
226 }
static final String get(String key)
png_infop int * unit
Definition: png.h:2451
static int min(int a, int b)
org
static int max(int a, int b)


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