16 package com.generalrobotix.ui.view.simulation;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.events.SelectionListener;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Combo;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Label;
34 @SuppressWarnings(
"serial")
37 public static final String[] METHOD_NAMES = {
"RUNGE_KUTTA",
"EULER" };
40 private static final int COMBO_WIDTH = 100;
41 private static final double MIN_TIME_STEP = 0.000001;
48 Button chkViewSimulate_;
54 setLayout(
new GridLayout(2,
true));
56 Label label =
new Label(
this,SWT.SHADOW_NONE);
60 label =
new Label(
this,SWT.SHADOW_NONE);
62 label =
new Label(
this,SWT.SHADOW_NONE);
64 GridData gridData =
new GridData();
65 gridData.horizontalAlignment = SWT.END;
66 label.setLayoutData(gridData);
70 spinTotalTime_.
setKey(
"totalTime");
73 label =
new Label(
this,SWT.SHADOW_NONE);
75 gridData =
new GridData();
76 gridData.horizontalAlignment = SWT.END;
77 label.setLayoutData(gridData);
81 spinStepTime_.
setKey(
"timeStep");
84 label =
new Label(
this,SWT.SHADOW_NONE);
86 gridData =
new GridData();
87 gridData.horizontalAlignment = SWT.END;
88 label.setLayoutData(gridData);
92 spinLogStepTime_.
setKey(
"logTimeStep");
95 label =
new Label(
this,SWT.SHADOW_NONE);
97 gridData =
new GridData();
98 gridData.horizontalAlignment = SWT.END;
99 label.setLayoutData(gridData);
102 cmbMethod_ =
new Combo(
this,SWT.DROP_DOWN | SWT.READ_ONLY);
103 cmbMethod_.setItems(METHOD_NAMES);
104 gridData =
new GridData();
105 gridData.widthHint = COMBO_WIDTH;
106 cmbMethod_.setLayoutData(gridData);
107 cmbMethod_.select(0);
109 cmbMethod_.addSelectionListener(
new SelectionListener(){
111 public void widgetDefaultSelected(SelectionEvent e) {
114 public void widgetSelected(SelectionEvent e) {
115 if (currentItem_ !=
null)
116 currentItem_.
setProperty(
"method", cmbMethod_.getText());
128 label =
new Label(
this,SWT.SHADOW_NONE);
130 gridData =
new GridData();
131 gridData.horizontalAlignment = SWT.END;
132 label.setLayoutData(gridData);
136 spinGravity_.
setKey(
"gravity");
137 spinGravity_.setBounds(12 + 130 + 6, 12 + 36 + 36 + 36 + 36 + 36, 100, 24);
139 chkIntegrate_ =
new Button(
this,SWT.CHECK);
140 chkIntegrate_.setText(
MessageBundle.
get(
"panel.simulation.start.integrate"));
142 chkIntegrate_.addSelectionListener(
new SelectionListener() {
144 public void widgetDefaultSelected(SelectionEvent e) {
147 public void widgetSelected(SelectionEvent e) {
148 if (currentItem_ !=
null)
149 currentItem_.
setProperty(
"integrate", String.valueOf(chkIntegrate_.getSelection()));
153 label =
new Label(
this,SWT.SHADOW_NONE);
155 chkRealTime_ =
new Button(
this,SWT.CHECK);
157 chkRealTime_.addSelectionListener(
new SelectionListener() {
159 public void widgetDefaultSelected(SelectionEvent e) {
162 public void widgetSelected(SelectionEvent e) {
163 if (currentItem_ !=
null)
164 currentItem_.
setProperty(
"realTime", String.valueOf(chkRealTime_.getSelection()));
168 label =
new Label(
this,SWT.SHADOW_NONE);
170 chkViewSimulate_ =
new Button(
this,SWT.CHECK);
171 chkViewSimulate_.setText(
MessageBundle.
get(
"panel.simulation.start.viewsimulate"));
172 chkViewSimulate_.addSelectionListener(
new SelectionListener() {
173 public void widgetDefaultSelected(SelectionEvent e) {
176 public void widgetSelected(SelectionEvent e) {
177 if (currentItem_ !=
null)
178 currentItem_.
setProperty(
"viewsimulate", String.valueOf(chkViewSimulate_.getSelection()));
184 label =
new Label(
this,SWT.SHADOW_NONE);
186 gridData =
new GridData();
187 gridData.horizontalAlignment = SWT.END;
189 this.setSize(260,330);
194 super.setEnabled(flag);
195 Control[] cmps = this.getChildren();
196 for (
int i = 0;
i < cmps.length;
i++) {
197 cmps[
i].setEnabled(flag);
220 chkIntegrate_.setSelection(f);
224 chkRealTime_.setSelection(f);
228 chkViewSimulate_.setSelection(f);
248 return chkIntegrate_.getSelection();
252 return chkViewSimulate_.getSelection();
260 return new SEEnumeration(METHOD_NAMES,cmbMethod_.getSelectionIndex());
265 setEnabled(item !=
null);
272 setTotalTime(item.
getDbl(
"totalTime", 20.0));
273 setStepTime(item.
getDbl(
"timeStep", 0.001));
274 setGravity(item.
getDbl(
"gravity", 9.8));
275 setMethod(item.getProperty(
"method",METHOD_NAMES[0]));
276 setIntegrate(item.
isTrue(
"integrate",
true));
277 setRealTime(item.
isTrue(
"realTime",
false));
278 setViewSimulate(item.
isTrue(
"viewsimulate",
false));
284 setEnabled(item !=
null);
285 spinLogStepTime_.
setItem(item);
287 setLogStepTime(item.
getDbl(
"logTimeStep", 0.001));
void setMethod(String method)
static final String get(String key)
void updateLogTime(GrxBaseItem item)
void setTotalTime(double time)
final boolean isTrue(String key)
check whether value associated to key includes a word "true"
#define null
our own NULL pointer
void setViewSimulate(boolean f)
void setStepTime(double time)
void setItem(GrxBaseItem item)
SimulationParameterPanel(Composite parent, int style)
SEEnumeration getMethod()
void setGravity(double g)
boolean isSimulatingView()
Object setProperty(String key, String value)
set property value associated with a keyword
final Double getDbl(String key, Double defaultVal)
get double value associated to key
void setRealTime(boolean f)
void setEnabled(boolean flag)
void updateItem(GrxBaseItem item)
Object fromString(String str)
png_infop png_uint_32 flag
void setIntegrate(boolean f)
void setLogStepTime(double time)