SEDoubleTextWithSpin.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  */
00017 package com.generalrobotix.ui.view.graph;
00018 
00019 import java.awt.BorderLayout;
00020 import java.awt.Component;
00021 import java.awt.event.ActionEvent;
00022 import java.awt.event.ActionListener;
00023 import java.awt.event.FocusEvent;
00024 import java.awt.event.FocusListener;
00025 
00026 import javax.swing.JPanel;
00027 import javax.swing.JTextField;
00028 
00029 public class SEDoubleTextWithSpin extends JPanel implements SpinListener {
00030     SEDouble value_;
00031     double max_;
00032     double min_;
00033     double step_;
00034     JTextField text_;
00035     
00036     public SEDoubleTextWithSpin(double min,double max,double step) {
00037         value_ = new SEDouble(0);
00038         
00039         max_ = max;
00040         min_ = min;
00041         step_ = step;
00042         SpinControl spin = new SpinControl(this);
00043         text_ = new JTextField();
00044         text_.addActionListener(
00045             new ActionListener() {
00046                public void actionPerformed(ActionEvent e) {
00047                    setValue(text_.getText());
00048                }
00049             }
00050         );
00051         text_.addFocusListener(
00052             new FocusListener() {
00053                 public void focusGained(FocusEvent e) {
00054                 }
00055                 public void focusLost(FocusEvent e) {
00056                    setValue(text_.getText());
00057                 }
00058             }
00059         );
00060         
00061         setLayout(new BorderLayout());
00062         add(BorderLayout.CENTER,text_);
00063         add(BorderLayout.EAST,spin);
00064         
00065         setValue((max+min)/2);
00066     }
00067     
00068     public void up() {
00069         setValue(text_.getText());
00070         double v = value_.doubleValue() + step_;
00071         setValue(v);
00072     }
00073 
00074     public void down() {
00075         setValue(text_.getText());
00076         double v = value_.doubleValue() - step_;
00077         setValue(v);
00078     }
00079     
00080     public SEDouble getValue() {
00081         setValue(text_.getText());
00082         return value_;
00083     }
00084     
00085     public void setValue(String s) {
00086         double v = new SEDouble(s).doubleValue();
00087         setValue(v);
00088     }
00089     
00090     public void setValue(double v) {
00091         if (isOk(v)) {
00092             value_.setValue(new Double(v));
00093         }
00094 
00095         text_.setText(value_.toString());
00096     }
00097 
00098     public boolean isOk(double v) {
00099         return (min_ <= v && v<=max_);
00100     }
00101 
00102     public void setEnabled(boolean flag) {
00103         super.setEnabled(flag);
00104         Component[] cmps = getComponents();
00105         for (int i = 0; i < cmps.length; i++) {
00106             cmps[i].setEnabled(flag);
00107         }
00108     }
00109 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:57