SEDoubleTextWithSpin.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  */
17 package com.generalrobotix.ui.view.graph;
18 
19 import java.awt.BorderLayout;
20 import java.awt.Component;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.awt.event.FocusEvent;
24 import java.awt.event.FocusListener;
25 
26 import javax.swing.JPanel;
27 import javax.swing.JTextField;
28 
29 public class SEDoubleTextWithSpin extends JPanel implements SpinListener {
30  SEDouble value_;
31  double max_;
32  double min_;
33  double step_;
34  JTextField text_;
35 
36  public SEDoubleTextWithSpin(double min,double max,double step) {
37  value_ = new SEDouble(0);
38 
39  max_ = max;
40  min_ = min;
41  step_ = step;
42  SpinControl spin = new SpinControl(this);
43  text_ = new JTextField();
44  text_.addActionListener(
45  new ActionListener() {
46  public void actionPerformed(ActionEvent e) {
47  setValue(text_.getText());
48  }
49  }
50  );
51  text_.addFocusListener(
52  new FocusListener() {
53  public void focusGained(FocusEvent e) {
54  }
55  public void focusLost(FocusEvent e) {
56  setValue(text_.getText());
57  }
58  }
59  );
60 
61  setLayout(new BorderLayout());
62  add(BorderLayout.CENTER,text_);
63  add(BorderLayout.EAST,spin);
64 
65  setValue((max+min)/2);
66  }
67 
68  public void up() {
69  setValue(text_.getText());
70  double v = value_.doubleValue() + step_;
71  setValue(v);
72  }
73 
74  public void down() {
75  setValue(text_.getText());
76  double v = value_.doubleValue() - step_;
77  setValue(v);
78  }
79 
80  public SEDouble getValue() {
81  setValue(text_.getText());
82  return value_;
83  }
84 
85  public void setValue(String s) {
86  double v = new SEDouble(s).doubleValue();
87  setValue(v);
88  }
89 
90  public void setValue(double v) {
91  if (isOk(v)) {
92  value_.setValue(new Double(v));
93  }
94 
95  text_.setText(value_.toString());
96  }
97 
98  public boolean isOk(double v) {
99  return (min_ <= v && v<=max_);
100  }
101 
102  public void setEnabled(boolean flag) {
103  super.setEnabled(flag);
104  Component[] cmps = getComponents();
105  for (int i = 0; i < cmps.length; i++) {
106  cmps[i].setEnabled(flag);
107  }
108  }
109 }
static int min(int a, int b)
png_uint_32 i
Definition: png.h:2735
SEDoubleTextWithSpin(double min, double max, double step)
png_infop png_uint_32 flag
Definition: png.h:2159
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 May 8 2021 02:42:41