1 package com.generalrobotix.ui.view.graph;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.events.FocusEvent;
5 import org.eclipse.swt.events.FocusListener;
6 import org.eclipse.swt.events.VerifyEvent;
7 import org.eclipse.swt.events.VerifyListener;
8 import org.eclipse.swt.events.MouseEvent;
9 import org.eclipse.swt.events.MouseListener;
10 import org.eclipse.swt.events.MouseTrackListener;
11 import org.eclipse.swt.events.MouseMoveListener;
12 import org.eclipse.swt.events.ControlEvent;
13 import org.eclipse.swt.events.ControlListener;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Button;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Text;
21 import org.eclipse.swt.widgets.Display;
52 GridLayout gl =
new GridLayout(2,
false);
53 gl.horizontalSpacing = 0;
54 gl.verticalSpacing = 0;
57 text_ =
new Text(
this,SWT.SINGLE | SWT.BORDER);
58 text_.addFocusListener(
new FocusListener(){
59 public void focusLost(FocusEvent e){
63 public void focusGained(FocusEvent e){
66 text_.addVerifyListener(
new VerifyListener(){
67 public void verifyText(VerifyEvent e){
69 if(max_ == Double.POSITIVE_INFINITY)
75 for(
int i = 0;
i < e.text.length();
i++){
76 char c = e.text.charAt(
i);
77 if(!((
'0' <= c && c <=
'9') ||
80 c ==
'e' || c ==
'E'))
88 GridData gridData =
new GridData();
89 gridData.widthHint = 80;
90 text_.setLayoutData(gridData);
92 Composite inner =
new Composite(
this, SWT.NULL);
93 GridLayout rlInner =
new GridLayout(1,
false);
94 rlInner.marginHeight = 0;
95 rlInner.marginWidth = 0;
96 rlInner.horizontalSpacing = 0;
97 rlInner.verticalSpacing = 0;
98 inner.setLayout(rlInner);
99 GridData innerGrid =
new GridData();
100 innerGrid.verticalAlignment = SWT.FILL;
101 inner.setLayoutData(innerGrid);
103 buttonUP_ =
new Button(inner,SWT.ARROW | SWT.UP);
104 buttonUP_.addMouseTrackListener(
new MouseTrackListener(){
105 public void mouseEnter(MouseEvent e){
106 isMouseOverBtnUp_ =
true;
108 public void mouseExit(MouseEvent e){
109 isMouseOverBtnUp_ =
false;
111 public void mouseHover(MouseEvent e){
115 buttonUP_.addMouseMoveListener(
new MouseMoveListener(){
116 public void mouseMove(MouseEvent e){
117 isMouseOverBtnUp_ = (0 <= e.x && e.x < buttonUP_.getSize().x && 0 <= e.y && e.y < buttonUP_.getSize().y);
120 buttonUP_.addMouseListener(
new MouseListener(){
121 public void mouseDoubleClick(MouseEvent e){
123 public void mouseDown(MouseEvent e) {
129 public void mouseUp(MouseEvent e) {
136 buttonDOWN_ =
new Button(inner,SWT.ARROW | SWT.DOWN);
137 buttonDOWN_.addMouseTrackListener(
new MouseTrackListener(){
138 public void mouseEnter(MouseEvent e){
139 isMouseOverBtnDown_ =
true;
141 public void mouseExit(MouseEvent e){
142 isMouseOverBtnDown_ =
false;
144 public void mouseHover(MouseEvent e){
148 buttonDOWN_.addMouseMoveListener(
new MouseMoveListener(){
149 public void mouseMove(MouseEvent e){
150 isMouseOverBtnDown_ = (0 <= e.x && e.x < buttonDOWN_.getSize().x && 0 <= e.y && e.y < buttonDOWN_.getSize().y);
153 buttonDOWN_.addMouseListener(
new MouseListener(){
154 public void mouseDoubleClick(MouseEvent e){
156 public void mouseDown(MouseEvent e) {
162 public void mouseUp(MouseEvent e) {
169 text_.addControlListener(
new ControlListener(){
170 public void controlMoved(ControlEvent e) {
172 public void controlResized(ControlEvent e) {
173 GridData buttonUpGrid =
new GridData();
174 buttonUpGrid.heightHint= text_.getSize().y/2;
175 buttonUP_.setLayoutData(buttonUpGrid);
176 GridData buttonDownGrid =
new GridData();
177 buttonDownGrid.heightHint= text_.getSize().y/2;
178 buttonDOWN_.setLayoutData(buttonDownGrid);
184 incrementRun_ =
new Runnable() {
186 Display display = text_.getDisplay();
187 if (!display.isDisposed())
189 if(isMouseOverBtnUp_)
191 mouseBtnActionNum += 1;
194 display.timerExec((mouseBtnActionNum < mouseBtnAccelNeed_ ? mouseBtnRepeat_ : mouseBtnAccelRepeat_),
this);
198 decrementRun_ =
new Runnable() {
200 Display display = text_.getDisplay();
201 if (!display.isDisposed())
203 if(isMouseOverBtnDown_)
205 mouseBtnActionNum += 1;
208 display.timerExec((mouseBtnActionNum < mouseBtnAccelNeed_ ? mouseBtnRepeat_ : mouseBtnAccelRepeat_),
this);
218 String s = text_.getText();
222 }
catch (Exception e) {
248 public boolean isOk(
double v) {
249 return (min_ <= v && v<=max_);
253 super.setEnabled(flag);
254 Control[] cmps = getChildren();
255 for (
int i = 0;
i < cmps.length;
i++) {
256 cmps[
i].setEnabled(flag);
271 mouseBtnActionNum = 0;
273 Display display = text_.getDisplay();
274 if (!display.isDisposed())
276 display.timerExec(mouseBtnRepeat_, incrementRun_);
280 mouseBtnActionNum = 0;
282 Display display = text_.getDisplay();
283 if (!display.isDisposed())
285 display.timerExec(-1, incrementRun_);
289 mouseBtnActionNum = 0;
291 Display display = text_.getDisplay();
292 if (!display.isDisposed())
294 display.timerExec(mouseBtnRepeat_, decrementRun_);
298 mouseBtnActionNum = 0;
300 Display display = text_.getDisplay();
301 if (!display.isDisposed())
303 display.timerExec(-1, decrementRun_);
void setEnabled(boolean flag)
void stopDecrementTimer()
static int min(int a, int b)
void setValue(Object value)
boolean isMouseOverBtnUp_
void stopIncrementTimer()
void startDecrementTimer()
boolean isMouseOverBtnDown_
void startIncrementTimer()
png_infop png_uint_32 flag
static int max(int a, int b)
SEDoubleTextWithSpinForSWT(Composite parent, int style, double min, double max, double step)