VRangeDialog.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  */
00010 package com.generalrobotix.ui.view.graph;
00011 
00012 import org.eclipse.jface.dialogs.Dialog;
00013 import org.eclipse.jface.dialogs.IDialogConstants;
00014 import org.eclipse.jface.dialogs.MessageDialog;
00015 import org.eclipse.swt.SWT;
00016 import org.eclipse.swt.events.KeyEvent;
00017 import org.eclipse.swt.events.KeyListener;
00018 import org.eclipse.swt.layout.RowLayout;
00019 import org.eclipse.swt.widgets.Composite;
00020 import org.eclipse.swt.widgets.Control;
00021 import org.eclipse.swt.widgets.Label;
00022 import org.eclipse.swt.widgets.Shell;
00023 import org.eclipse.swt.widgets.Text;
00024 
00025 import com.generalrobotix.ui.util.MessageBundle;
00026 
00027 
00034 public class VRangeDialog extends Dialog {
00035 
00036     // -----------------------------------------------------------------
00037     // インスタンス変数
00038     double base_;       // 基準値
00039     double extent_;     // 幅
00040     boolean updated_;   // 更新フラグ
00041     String unit_;       // 単位文字列
00042     Text minField_;   // 最小値フィールド
00043     Text maxField_;   // 最大値フィールド
00044     Label minUnitLabel_;   // 最小値単位ラベル
00045     Label maxUnitLabel_;   // 最大値単位ラベル
00046     private Shell shell_;
00047     private boolean minfirst_;
00048     private boolean maxfirst_;
00049     
00050     // -----------------------------------------------------------------
00051     // コンストラクタ
00057     public VRangeDialog(Shell shell) {
00058         super(shell);
00059         shell_ = shell;
00060     }
00061     
00062     protected void configureShell(Shell newShell) {   
00063         super.configureShell(newShell);
00064         newShell.setText(MessageBundle.get("dialog.graph.vrange.title"));
00065     }
00066     
00067     protected Control createDialogArea(Composite parent) {
00068         Composite composite = (Composite)super.createDialogArea(parent);
00069         composite.setLayout(new RowLayout(SWT.VERTICAL));
00070         Composite comp0 = new Composite(composite, SWT.NONE);
00071         comp0.setLayout(new RowLayout());
00072         
00073         Label label1 = new Label(comp0, SWT.NONE);
00074         label1.setText(MessageBundle.get("dialog.graph.vrange.min"));
00075         
00076         minField_ = new Text(comp0, SWT.BORDER);
00077         minField_.setText(String.format("%10.3f", base_));
00078         minfirst_ = true;
00079         minField_.addKeyListener(new KeyListener(){
00080                         public void keyPressed(KeyEvent e) {
00081                                 if(minfirst_){
00082                                         minField_.setText("");
00083                                         minfirst_ = false;
00084                                 }
00085                         }
00086 
00087                         public void keyReleased(KeyEvent e) {
00088                                 // TODO 自動生成されたメソッド・スタブ
00089                                 
00090                         }
00091                 
00092         });
00093         minField_.setFocus();
00094         
00095         minUnitLabel_ = new Label(comp0, SWT.NONE);
00096         minUnitLabel_.setText(unit_);
00097         
00098         Composite comp1 = new Composite(composite, SWT.NONE);
00099         comp1.setLayout(new RowLayout());
00100         
00101         Label label3 = new Label(comp1, SWT.NONE);
00102         label3.setText(MessageBundle.get("dialog.graph.vrange.max"));
00103         maxField_ = new Text(comp1, SWT.BORDER);
00104         maxField_.setText(String.format("%10.3f", base_+extent_));
00105         maxfirst_ = true;
00106         maxField_.addKeyListener(new KeyListener(){
00107                         public void keyPressed(KeyEvent e) {
00108                                 if(maxfirst_){
00109                                         maxField_.setText("");
00110                                         maxfirst_ = false;
00111                                 }
00112                         }
00113 
00114                         public void keyReleased(KeyEvent e) {
00115                                 // TODO 自動生成されたメソッド・スタブ
00116                                 
00117                         }
00118                 
00119         });
00120         
00121         maxUnitLabel_ = new Label(comp1, SWT.NONE);
00122         maxUnitLabel_.setText(unit_);
00123         
00124         updated_ = false; 
00125         return composite;
00126     }
00127     
00128     protected void buttonPressed(int buttonId) {
00129         if (buttonId == IDialogConstants.OK_ID) {
00130                 double min, max;
00131             try {
00132                 min = Double.parseDouble(minField_.getText());
00133                 max = Double.parseDouble(maxField_.getText());
00134             } catch (NumberFormatException ex) {
00135                  MessageDialog.openError(shell_, 
00136                                  MessageBundle.get("dialog.graph.vrange.invalidinput.title"),
00137                          MessageBundle.get("dialog.graph.vrange.invalidinput.message"));               
00138                  minField_.setFocus();    // フォーカス設定
00139                 return;
00140             }
00141             // 入力値チェック
00142             if (min == max) {
00143                 MessageDialog.openError(shell_, 
00144                                 MessageBundle.get("dialog.graph.vrange.invalidrange.title"),
00145                                 MessageBundle.get("dialog.graph.vrange.invalidrange.message"));
00146                  minField_.setFocus();    // フォーカス設定
00147                 return;
00148             }
00149             // 値更新
00150             if (min < max) {
00151                 base_ = min;
00152                 extent_ = max - min;
00153             } else {
00154                 base_ = max;
00155                 extent_ = min - max;
00156             }
00157             updated_ = true;            
00158         }
00159         setReturnCode(buttonId);
00160         close();
00161         super.buttonPressed(buttonId);
00162     }
00163   
00164     // -----------------------------------------------------------------
00165     // メソッド
00166     
00172     public void setUnit(
00173         String unit
00174     ) {
00175         unit_ = unit;
00176     }
00177 
00183     public void setBase(
00184         double base
00185     ) {
00186         base_ = base;
00187     }
00188 
00194     public void setExtent(
00195         double extent
00196     ) {
00197         extent_ = extent;
00198     }
00199 
00205     public double getBase() {
00206         return base_;
00207     }
00208 
00214     public double getExtent() {
00215         return extent_;
00216     }
00217 
00223     public boolean isUpdated() {
00224         return updated_;
00225     }
00226 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:19