HRangeDialog.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.Scale;
00023 import org.eclipse.swt.widgets.Shell;
00024 import org.eclipse.swt.widgets.Text;
00025 
00026 import com.generalrobotix.ui.util.MessageBundle;
00027 
00028 
00035 public class HRangeDialog extends Dialog {
00036 
00037     // -----------------------------------------------------------------
00038     // 定数
00039     // 更新フラグ
00040     public static final int RANGE_UPDATED = 1;  // レンジ変更
00041     public static final int POS_UPDATED = 2;    // マーカ位置変更
00042        
00043     private static final int MARKER_POS_STEPS = 100;         // マーカ位置段階数
00044 
00045     // -----------------------------------------------------------------
00046     // インスタンス変数
00047     int updateFlag_;    // 更新フラグ
00048     double hRange_;     // レンジ値
00049     double maxHRange_;  // 最大レンジ
00050     double minHRange_;  // 最小レンジ
00051     double markerPos_;  // マーカ位置
00052     Text hRangeField_;    // レンジ入力フィールド
00053     Scale markerSlider_;      // マーカ位置設定スライダ
00054     private boolean first_;
00055     private Shell shell_;
00056     // -----------------------------------------------------------------
00057     // コンストラクタ
00063     public HRangeDialog(Shell shell) {
00064         super(shell);
00065         shell_ = shell;
00066     }
00067     
00068     protected void configureShell(Shell newShell) {   
00069         super.configureShell(newShell);
00070         newShell.setText(MessageBundle.get("dialog.graph.hrange.title")); //$NON-NLS-1$
00071     }
00072         
00073     protected Control createDialogArea(Composite parent) {
00074         Composite composite = (Composite)super.createDialogArea(parent);
00075         composite.setLayout(new RowLayout(SWT.VERTICAL));
00076         Composite comp0 = new Composite(composite, SWT.NONE);
00077         comp0.setLayout(new RowLayout());
00078         
00079         Label label1 = new Label(comp0, SWT.NONE);
00080         label1.setText(MessageBundle.get("dialog.graph.hrange.hrange")); //$NON-NLS-1$
00081         
00082         hRangeField_ = new Text(comp0, SWT.BORDER);
00083         hRangeField_.setText(String.format("%10.3f", hRange_)); //$NON-NLS-1$
00084         first_ = true;
00085         hRangeField_.addKeyListener(new KeyListener(){
00086                         public void keyPressed(KeyEvent e) {
00087                                 if(first_){
00088                                         hRangeField_.setText(""); //$NON-NLS-1$
00089                                         first_ = false;
00090                                 }
00091                         }
00092                         public void keyReleased(KeyEvent e) {
00093                         }
00094         });
00095         hRangeField_.setFocus();
00096         
00097         Label label2 = new Label(comp0, SWT.NONE);
00098         label2.setText(MessageBundle.get("dialog.graph.hrange.unit")); //$NON-NLS-1$
00099         
00100         Composite comp1 = new Composite(composite, SWT.NONE);
00101         comp1.setLayout(new RowLayout());
00102         
00103         Label label3 = new Label(comp1, SWT.NONE);
00104         label3.setText(MessageBundle.get("dialog.graph.hrange.markerpos")); //$NON-NLS-1$
00105         
00106         markerSlider_ = new Scale(comp1, SWT.HORIZONTAL);
00107         markerSlider_.setMinimum(0);
00108         markerSlider_.setMaximum(MARKER_POS_STEPS);
00109         markerSlider_.setIncrement(10);
00110         markerSlider_.setSelection((int)(markerPos_ * MARKER_POS_STEPS));
00111         
00112         updateFlag_ = 0;
00113         return composite;
00114     }
00115         
00116     protected void buttonPressed(int buttonId) {
00117         if (buttonId == IDialogConstants.OK_ID) {
00118                  double range;
00119              try {
00120                  range = Double.parseDouble(hRangeField_.getText());
00121              } catch (NumberFormatException ex) {
00122                  // エラー表示
00123                  MessageDialog.openError(shell_, 
00124                                  MessageBundle.get("dialog.graph.hrange.invalidinput.title"), //$NON-NLS-1$
00125                          MessageBundle.get("dialog.graph.hrange.invalidinput.message")); //$NON-NLS-1$
00126                 
00127                  hRangeField_.setFocus();    // フォーカス設定
00128                  return;
00129              }
00130              // 入力値チェック
00131              if (range < minHRange_ || range > maxHRange_) {
00132                  // エラー表示
00133                  MessageDialog.openError(shell_, 
00134                      MessageBundle.get("dialog.graph.hrange.invalidrange.title"), //$NON-NLS-1$
00135                      MessageBundle.get("dialog.graph.hrange.invalidrange.message") //$NON-NLS-1$
00136                          + "\n(" + minHRange_ + "  -  " + maxHRange_ + ")"    ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
00137                  hRangeField_.setFocus();    // フォーカス設定
00138                  return;
00139              }
00140              double pos = markerSlider_.getSelection() / (double)MARKER_POS_STEPS;
00141              // 更新チェック
00142              updateFlag_ = 0;
00143              if (range != hRange_) { // レンジ更新?
00144                  hRange_ = range;
00145                  updateFlag_ += RANGE_UPDATED;
00146              }
00147              if (pos != markerPos_) {    // マーカ更新?
00148                  markerPos_ = pos;
00149                  updateFlag_ += POS_UPDATED;
00150              }
00151         }
00152         setReturnCode(buttonId);
00153         close();
00154         super.buttonPressed(buttonId);
00155     }
00156      
00157     // -----------------------------------------------------------------
00158     // メソッド
00159    
00165     public void setHRange(
00166         double hRange
00167     ) {
00168         hRange_ = hRange;
00169     }
00170 
00176     public void setMaxHRange(
00177         double maxHRange
00178     ) {
00179         maxHRange_ = maxHRange;
00180     }
00181 
00187     public void setMinHRange(
00188         double minHRange
00189     ) {
00190         minHRange_ = minHRange;
00191     }
00192 
00198     public void setMarkerPos(
00199         double markerPos
00200     ) {
00201         markerPos_ = markerPos;
00202     }
00203 
00209     public double getHRange() {
00210         return hRange_;
00211     }
00212 
00218     public double getMarkerPos() {
00219         return markerPos_;
00220     }
00221 
00227     public int getUpdateFlag() {
00228         return updateFlag_;
00229     }
00230 
00231 }


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:16