ItemPropertyDoubleSpin.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.util;
18 
19 import java.awt.BorderLayout;
20 import java.awt.Component;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 
24 import javax.swing.JPanel;
25 import javax.swing.JTextField;
26 
31 
32 @SuppressWarnings("serial")
33 public class ItemPropertyDoubleSpin extends JPanel implements SpinListener {
34  private SEDouble value_;
35  private double max_;
36  private double min_;
37  private double step_;
38  private JTextField text_;
39 
40  private GrxBaseItem item_;
41  private String key_;
42 
43  public ItemPropertyDoubleSpin(double min,double max,double step) {
44  value_ = new SEDouble(0);
45 
46  max_ = max;
47  min_ = min;
48  step_ = step;
49  SpinControl spin = new SpinControl(this);
50  text_ = new JTextField();
51  text_.addActionListener(
52  new ActionListener() {
53  public void actionPerformed(ActionEvent e) {
54  setValue(text_.getText());
55  }
56  }
57  );
58 
59  setLayout(new BorderLayout());
60  add(BorderLayout.CENTER,text_);
61  add(BorderLayout.EAST,spin);
62 
63  setValue((max+min)/2);
64  }
65 
66  public void up() {
67  setValue(text_.getText());
68  double v = value_.doubleValue() + step_;
69  setValue(v);
70  }
71 
72  public void down() {
73  setValue(text_.getText());
74  double v = value_.doubleValue() - step_;
75  setValue(v);
76  }
77 
78  public double getValue() {
79  setValue(text_.getText());
80  return value_.doubleValue();
81  }
82 
83  public void setValue(String s) {
84  double v = 0;
85  try {
86  v = new SEDouble(s).doubleValue();
87  } catch (Exception e) {
88  v = value_.doubleValue();
89  }
90 
91  setValue(v);
92  }
93 
94  public void setValue(double v) {
95  if (isOk(v)) {
96  value_.setValue(new Double(v));
97  }
98 
99  text_.setText(value_.toString());
100 
101  if (item_ != null && key_ != null)
102  item_.setDbl(key_, v);
103  }
104 
105  public boolean isOk(double v) {
106  return (min_ <= v && v<=max_);
107  }
108 
109  public void setEnabled(boolean flag) {
110  super.setEnabled(flag);
111  Component[] cmps = getComponents();
112  for (int i = 0; i < cmps.length; i++) {
113  cmps[i].setEnabled(flag);
114  }
115  }
116 
117  public void setItem(GrxBaseItem item, String key) {
118  if (item_ != null && key_ != null)
119  item_.setProperty(key_, value_.toString());
120  item_ = item;
121  key_ = key;
122  }
123 }
#define null
our own NULL pointer
Definition: IceTypes.h:57
static int min(int a, int b)
png_uint_32 i
Definition: png.h:2735
final void setDbl(String key, double value)
associate double value to key
Object setProperty(String key, String value)
set property value associated with a keyword
ItemPropertyDoubleSpin(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 Apr 13 2019 02:14:23