1 package com.generalrobotix.ui.view.simulation;
3 import java.io.BufferedReader;
4 import java.io.BufferedWriter;
6 import java.io.FileNotFoundException;
7 import java.io.FileReader;
8 import java.io.FileWriter;
9 import java.io.IOException;
10 import java.util.HashMap;
11 import java.util.Iterator;
12 import java.util.Vector;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.jface.viewers.ArrayContentProvider;
18 import org.eclipse.jface.viewers.CellEditor;
19 import org.eclipse.jface.viewers.ComboBoxCellEditor;
20 import org.eclipse.jface.viewers.DialogCellEditor;
21 import org.eclipse.jface.viewers.ICellModifier;
22 import org.eclipse.jface.viewers.ILabelProviderListener;
23 import org.eclipse.jface.viewers.ITableLabelProvider;
24 import org.eclipse.jface.viewers.TableViewer;
25 import org.eclipse.jface.viewers.TextCellEditor;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.custom.PopupList;
28 import org.eclipse.swt.custom.StyledText;
29 import org.eclipse.swt.dnd.DND;
30 import org.eclipse.swt.dnd.DragSource;
31 import org.eclipse.swt.dnd.DragSourceEvent;
32 import org.eclipse.swt.dnd.DragSourceListener;
33 import org.eclipse.swt.dnd.DropTarget;
34 import org.eclipse.swt.dnd.DropTargetEvent;
35 import org.eclipse.swt.dnd.DropTargetListener;
36 import org.eclipse.swt.dnd.TextTransfer;
37 import org.eclipse.swt.dnd.Transfer;
38 import org.eclipse.swt.events.ModifyEvent;
39 import org.eclipse.swt.events.ModifyListener;
40 import org.eclipse.swt.events.MouseEvent;
41 import org.eclipse.swt.events.MouseListener;
42 import org.eclipse.swt.events.SelectionEvent;
43 import org.eclipse.swt.events.SelectionListener;
44 import org.eclipse.swt.graphics.Color;
45 import org.eclipse.swt.graphics.Image;
46 import org.eclipse.swt.graphics.Rectangle;
47 import org.eclipse.swt.layout.FillLayout;
48 import org.eclipse.swt.layout.GridData;
49 import org.eclipse.swt.layout.GridLayout;
50 import org.eclipse.swt.layout.RowLayout;
51 import org.eclipse.swt.widgets.Button;
52 import org.eclipse.swt.widgets.Composite;
53 import org.eclipse.swt.widgets.Control;
54 import org.eclipse.swt.widgets.FileDialog;
55 import org.eclipse.swt.widgets.Item;
56 import org.eclipse.swt.widgets.Label;
57 import org.eclipse.swt.widgets.Shell;
58 import org.eclipse.swt.widgets.Table;
59 import org.eclipse.swt.widgets.TableColumn;
60 import org.eclipse.swt.widgets.Text;
79 private Vector<Inport>
inport_ =
new Vector<Inport>();
80 private Vector<Outport>
outport_ =
new Vector<Outport>();
81 private HashMap<String, String>
connection_ =
new HashMap<String, String>();
91 public static enum NUMID_CODE {INVALID_TYPE, NOT_USED,
USED, ONLY_ONE, NUMBER};
93 String[] s =
new String[values().length];
114 if(ordinal <= 3 || (8<=ordinal && ordinal <=11) )
116 if(4<=ordinal && ordinal<=7)
120 if(13<=ordinal && ordinal<=15)
155 if(System.getProperty(
"os.name").equals(
"Linux") || System.getProperty(
"os.name").equals(
"Mac OS X")){
168 super.configureShell(newShell);
173 Composite composite = (Composite)super.createDialogArea(parent);
174 composite.setLayout(
new GridLayout(1,
true));
176 Composite panel0 =
new Composite(composite,SWT.NONE);
177 panel0.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
178 panel0.setLayout(
new GridLayout(3,
false));
179 Label label =
new Label(panel0, SWT.LEFT );
181 final Text text =
new Text(panel0, SWT.BORDER);
183 text.addModifyListener(
new ModifyListener(){
184 public void modifyText(ModifyEvent e) {
185 String newName = text.getText();
196 GridData gridData =
new GridData(GridData.FILL_HORIZONTAL);
197 gridData.horizontalSpan = 2;
198 text.setLayoutData(gridData);
199 Label label0 =
new Label(panel0, SWT.LEFT );
201 Label label1 =
new Label(panel0, SWT.LEFT);
203 label1.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
204 rrnText_ =
new Text(panel0, SWT.BORDER);
205 GridData gridData0 =
new GridData();
206 gridData0.horizontalAlignment = GridData.FILL;
207 gridData0.grabExcessHorizontalSpace =
true;
210 rrnText_.addModifyListener(
new ModifyListener(){
211 public void modifyText(ModifyEvent e) {
219 tableviewer_ =
new TableViewer(composite, SWT.FULL_SELECTION | SWT.BORDER);
222 table.setLinesVisible(
true);
223 table.setHeaderVisible(
true);
224 TableColumn column =
new TableColumn(table,SWT.NONE);
225 column.setText(
"Type");
226 column.setWidth(100);
227 column =
new TableColumn(table,SWT.NONE);
228 column.setText(
"name");
229 column.setWidth(100);
230 column =
new TableColumn(table,SWT.NONE);
231 column.setText(
"property");
232 column.setWidth(100);
233 column =
new TableColumn(table,SWT.NONE);
234 column.setText(
"id");
235 column.setWidth(100);
236 column =
new TableColumn(table,SWT.NONE);
237 column.setText(
"output Time");
238 column.setWidth(100);
239 column =
new TableColumn(table,SWT.NONE);
240 column.setText(
"Controller : Port name");
241 column.setWidth(200);
242 GridData gridData1 =
new GridData(GridData.FILL_VERTICAL);
243 gridData1.minimumHeight = 200;
245 tableviewer_.setContentProvider(
new ArrayContentProvider());
248 tableviewer_.setColumnProperties(
new String[] {
"type",
"name",
"property",
"id",
"time",
"portName"});
249 DialogCellEditor idCellEditor =
new DialogCellEditor(
tableviewer_.getTable()){
250 protected Object openDialogBox(Control cellEditorWindow) {
252 dialog.
setId((String)getValue());
253 if(dialog.open() == IDialogConstants.OK_ID)
254 setValue(dialog.
getId());
258 CellEditor[] editors =
new CellEditor[] {
259 new ComboBoxCellEditor(
tableviewer_.getTable(),
new String[]{
"IN",
"OUT" }),
267 tableviewer_.getControl().addMouseListener(
new MouseListener(){
268 public void mouseDoubleClick(MouseEvent e) {
270 public void mouseDown(MouseEvent e) {
272 PopupList list =
new PopupList(getShell());
275 Rectangle rectangle = getShell().getBounds();
276 String s = list.open(
new Rectangle(rectangle.x+e.x, rectangle.y+e.y, 100, 100));
282 _port.
id_ =
"All joints";
296 public void mouseUp(MouseEvent e) {
301 Composite panel1 =
new Composite(composite,SWT.NONE);
302 panel1.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
303 panel1.setLayout(
new GridLayout(3,
false));
304 Label label2 =
new Label(panel1, SWT.LEFT );
306 Label label3 =
new Label(panel1, SWT.LEFT );
308 nshText_ =
new Text(panel1, SWT.BORDER);
309 Label dumy =
new Label(panel1, SWT.LEFT );
310 Label label4 =
new Label(panel1, SWT.LEFT );
312 nspText_ =
new Text(panel1, SWT.BORDER);
317 ModifyListener nsModifyListener =
new ModifyListener(){
318 public void modifyText(ModifyEvent e) {
324 nshText_.addModifyListener(nsModifyListener);
325 nspText_.addModifyListener(nsModifyListener);
327 Composite panel5 =
new Composite(composite,SWT.NONE);
328 panel5.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
329 panel5.setLayout(
new GridLayout(4,
false));
330 Label label8 =
new Label(panel5, SWT.LEFT );
332 final Text text4 =
new Text(panel5, SWT.BORDER);
333 text4.setLayoutData(gridData0);
335 text4.addModifyListener(
new ModifyListener(){
336 public void modifyText(ModifyEvent e) {
341 Label label9 =
new Label(panel5, SWT.LEFT );
343 final Text text5 =
new Text(panel5, SWT.BORDER);
344 text5.setLayoutData(gridData0);
346 text5.addModifyListener(
new ModifyListener(){
347 public void modifyText(ModifyEvent e) {
353 Composite panel6 =
new Composite(composite,SWT.NONE);
354 panel6.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
355 panel6.setLayout(
new GridLayout(2,
false));
356 final Button configFileButton =
new Button(panel6, SWT.CHECK);
358 configFileButton.addSelectionListener(
new SelectionListener(){
359 public void widgetDefaultSelected(SelectionEvent e) {
361 public void widgetSelected(SelectionEvent e) {
367 configFileButton.setSelection(
true);
368 final Text text6 =
new Text(panel6, SWT.BORDER);
369 text6.setLayoutData(gridData0);
371 text6.addModifyListener(
new ModifyListener(){
372 public void modifyText(ModifyEvent e) {
379 Composite panel4 =
new Composite(composite,SWT.NONE);
380 panel4.setLayout(
new GridLayout(1,
false));
381 Button button =
new Button(panel4, SWT.PUSH);
383 button.addSelectionListener(
new SelectionListener(){
384 public void widgetDefaultSelected(SelectionEvent e) {
386 public void widgetSelected(SelectionEvent e) {
401 cbtext_ =
new StyledText(panel4, SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL);
402 GridData gridData2 =
new GridData();
403 gridData2.horizontalAlignment = GridData.FILL;
404 gridData2.grabExcessHorizontalSpace =
true;
405 gridData2.verticalAlignment = GridData.FILL;
406 gridData2.grabExcessVerticalSpace =
true;
407 gridData2.minimumHeight = 100;
408 gridData2.widthHint = 700;
409 cbtext_.setLayoutData(gridData2);
415 bctext_ =
new StyledText(panel4, SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL);
416 GridData gridData5 =
new GridData();
417 gridData5.horizontalAlignment = GridData.FILL;
418 gridData5.grabExcessHorizontalSpace =
true;
419 gridData5.verticalAlignment = GridData.FILL;
420 gridData5.grabExcessVerticalSpace =
true;
421 gridData5.minimumHeight = 100;
422 gridData5.widthHint = 700;
423 bctext_.setLayoutData(gridData5);
428 Composite panel3 =
new Composite(composite,SWT.NONE);
429 panel3.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
430 panel3.setLayout(
new GridLayout(1,
false));
436 rctext_ =
new StyledText(panel3, SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL );
437 GridData gridData4 =
new GridData();
438 gridData4.horizontalAlignment = GridData.FILL;
439 gridData4.grabExcessHorizontalSpace =
true;
440 gridData4.verticalAlignment = GridData.FILL;
441 gridData4.grabExcessVerticalSpace =
true;
442 gridData4.widthHint = 700;
443 gridData4.minimumHeight = 50;
444 rctext_.setLayoutData(gridData4);
449 emText_ =
new StyledText(panel3, SWT.NONE );
450 GridData gridData3 =
new GridData();
451 gridData3.horizontalAlignment = GridData.FILL;
452 gridData3.grabExcessHorizontalSpace =
true;
453 gridData3.verticalAlignment = GridData.FILL;
454 gridData3.grabExcessVerticalSpace =
true;
455 gridData3.minimumHeight = 50;
456 emText_.setLayoutData(gridData3);
457 emText_.setBackground(panel3.getBackground());
465 private final int SAVE_ID = IDialogConstants.CLIENT_ID;
471 createButton(parent, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL,
false);
480 }
else if(buttonId == IDialogConstants.CLOSE_ID){
520 public boolean canModify(Object element, String property) {
524 public Object
getValue(Object element, String property) {
526 if(property.equals(
"type"))
527 return port.
type_.equals(
"IN") ? 0 : 1 ;
528 else if(property.equals(
"name"))
530 else if(property.equals(
"property")){
532 }
else if(property.equals(
"id"))
534 else if(property.equals(
"time"))
536 else if(property.equals(
"portName"))
541 public void modify(Object element, String property, Object
value) {
542 if (element instanceof Item) {
543 element = ((Item) element).getData();
546 if(property.equals(
"type"))
547 port.
type_ = (Integer)
value==0 ?
"IN" :
"OUT";
548 else if(property.equals(
"name"))
550 else if(property.equals(
"property")){
552 }
else if(property.equals(
"id"))
554 else if(property.equals(
"time"))
556 else if(property.equals(
"portName"))
563 public boolean load(String fileName){
564 File file =
new File(fileName);
565 if (file ==
null || !file.isFile())
570 BufferedReader reader =
new BufferedReader(
new FileReader(file));
572 boolean comline =
false;
574 while (reader.ready()) {
575 String
string = reader.readLine();
579 int index =
string.indexOf(
"openhrp-controller-bridge");
582 string =
string.substring(index+25).trim();
586 string =
string.trim();
599 String[] options =
option.split(
"--");
600 rtcConfFileName_ = file.getCanonicalFile().getParent()+File.separator+
"rtc.conf";
610 }
catch (FileNotFoundException e) {
613 }
catch (IOException e) {
621 File file =
new File(fileName);
622 if (file ==
null || !file.isFile())
625 BufferedReader reader =
new BufferedReader(
new FileReader(file));
626 while (reader.ready()) {
627 String
string = reader.readLine();
628 if(
string.startsWith(
"#"))
631 String string0 =
string.trim();
632 if(string0.startsWith(
"corba.nameservers:")){
633 String[] s=string0.substring(18).trim().split(
":");
638 }
else if(
string.trim().startsWith(
"manager.modules.preload:"))
640 else if(
string.trim().startsWith(
"manager.components.precreate:"))
645 }
catch (FileNotFoundException e) {
648 }
catch (IOException e) {
688 rtcConfFile_.add(
"exec_cxt.periodic.type: SynchExtTriggerEC");
691 rtcConfFile_.add(
"manager.modules.abs_path_allowed: yes");
723 private void parse(String[] options){
724 for(
int i=0;
i<options.length;
i++){
725 options[
i] = options[
i].trim();
726 int endIndex = options[
i].indexOf(
" ");
729 String
option = options[
i].substring(0,endIndex);
730 String parameter = options[
i].substring(endIndex).trim();
731 if(
option.equals(
"server-name")){
733 }
else if(
option.equals(
"in-port")){
735 String[] s = parameter.split(
":");
737 _inport.
name_ = s[0].trim();
740 }
else if(s.length==3){
741 _inport.
name_ = s[0].trim();
743 _inport.
id_ = s[1].split(
",");
744 for(
int j=0; j<_inport.
id_.length; j++)
745 _inport.
id_[j] = _inport.
id_[j].trim();
750 }
else if(
option.equals(
"out-port")){
752 String[] s = parameter.split(
":");
753 _outport.
name_ = s[0].trim();
763 }
catch(IllegalArgumentException e){
767 String[] _id = s[j].split(
",");
768 _outport.
idName_ =
new String[_id.length];
769 for(
int k=0; k<_id.length; k++){
771 _outport.
idNo_ = Integer.parseInt(_id[k]);
773 }
catch(NumberFormatException ex){
774 _outport.
idName_[k] = _id[k].trim();
786 }
else if(
option.equals(
"connection")){
787 String[] s = parameter.split(
":");
788 String controllerPortName=
"";
791 }
else if(s.length ==3){
792 controllerPortName = s[1].trim()+
":"+s[2].trim();
795 }
else if(
option.equals(
"robot-name")){
797 }
else if(
option.equals(
"name-server")){
798 String[] s = parameter.split(
":");
801 }
else if(
option.equals(
"config-file")){
812 fileName = file.getCanonicalFile().getParent()+File.separator+fileName;
813 }
catch (IOException e) {
816 file =
new File(fileName);
817 if (file ==
null || !file.isFile())
820 BufferedReader reader =
new BufferedReader(
new FileReader(file));
821 Vector<String> options =
new Vector<String>();
822 while (reader.ready()) {
823 String
string = reader.readLine();
824 if(
string.startsWith(
"#"))
827 String[] s =
string.split(
"=");
829 options.add(s[0]+
" "+s[1]);
831 parse(options.toArray(
new String[0]));
833 }
catch (FileNotFoundException e) {
836 }
catch (IOException e) {
844 Iterator<Inport> it =
inport_.iterator();
846 Inport inport = it.next();
851 if(inport.
id_ ==
null)
852 _port.
id_ =
"All joints";
855 for(
int i=0;
i<inport.
id_.length-1;
i++)
856 _port.
id_ += inport.
id_[
i] +
",";
857 _port.
id_ += inport.
id_[inport.
id_.length-1];
861 if(controllerPort==
null)
866 Iterator<Outport> it0 =
outport_.iterator();
867 while(it0.hasNext()){
874 _port.
id_ =
"All joints";
875 else if(outport.
idNo_ != -1){
876 _port.
id_ = String.valueOf(outport.
idNo_);
888 if(controllerPort==
null)
959 rtcConfFileName_ = file.getCanonicalFile().getParent()+File.separator+
"rtc.conf";
960 }
catch (IOException e) {
964 String bridgeConfFileName=
null;
967 bridgeConfFileName = file.getCanonicalFile().getParent()+File.separator+
configFileName_;
968 }
catch (IOException e) {
973 BufferedWriter writer =
new BufferedWriter(
new FileWriter(
fileName_));
976 writer.write(it.next());
985 writer.write(it.next());
992 writer =
new BufferedWriter(
new FileWriter(bridgeConfFileName));
997 }
catch (IOException e) {
1007 String fileName = fdlg.open();
1008 if( fileName !=
null ) {
1012 rtcConfFileName_ = file.getCanonicalFile().getParent()+File.separator+
"rtc.conf";
1022 }
catch (IOException e) {
1023 e.printStackTrace();
1032 int index = commandLine.indexOf(
"openhrp-controller-bridge");
1034 commandLine = commandLine.substring(0,index+25)+
" ";
1052 while(it.hasNext()){
1054 Port port = it.next();
1055 if(port.
type_.equals(
"IN")){
1056 string +=
"--in-port "+port.
name_;
1057 if(!port.
id_.equals(
"All joints") && !port.
id_.equals(
""))
1058 string +=
":"+port.
id_;
1061 string +=
"--out-port "+port.
name_;
1062 if(!port.
id_.equals(
"All joints") && !port.
id_.equals(
""))
1063 string +=
":"+port.
id_;
1074 controllerPortName = s[1];
1075 string =
"--connection "+port.
name_+
":"+controllerPortName+
" "+
endChar_;
1090 string =
string.substring(0,
string.
length()-1);
1096 String lineSeparator = System.getProperty(
"line.separator");
1101 while(it.hasNext()){
1103 Port port = it.next();
1104 if(port.
type_.equals(
"IN")){
1105 string +=
"in-port = "+port.
name_;
1106 if(!port.
id_.equals(
"All joints") && !port.
id_.equals(
""))
1107 string +=
":"+port.
id_;
1110 string +=
"out-port = "+port.
name_;
1111 if(!port.
id_.equals(
"All joints") && !port.
id_.equals(
""))
1112 string +=
":"+port.
id_;
1122 controllerPortName = s[1];
1123 string =
"connection = "+port.
name_+
":"+controllerPortName+lineSeparator;
1128 String
string =
"robot-name = "+
robotRtcName_ +lineSeparator;
1140 if(
string.startsWith(
"corba.nameservers:")){
1143 }
else if(
string.startsWith(
"manager.modules.preload:")){
1146 }
else if(
string.startsWith(
"manager.components.precreate:")){
1157 s += it.next() +
"\n";
1166 s += it.next() +
"\n";
1187 while(it.hasNext()){
1188 Port port = it.next();
1189 if(port.
name_.equals(
""))
1195 String[] s = port.
id_.split(
",");
1201 Integer.valueOf(port.
id_);
1202 }
catch(NumberFormatException e){
1206 if(port.
type_.equals(
"IN")){
1220 }
catch(NumberFormatException e){
1237 @SuppressWarnings(
"unchecked")
1250 return name_.equals(((
IdData)
object).name_);
1252 return name_.equals(((
IdData)
object).name_) || id_ == ((
IdData)
object).id_ ;
1257 super(
name, jointId);
1267 private Vector<Link> links_ =
new Vector<Link>();
1270 private Vector<Button> linkButtons_ =
new Vector<Button>();
1277 for(
int i=0;
i<joints.length;
i++)
1278 links_.add(
new Link(joints[
i],
i));
1280 while(it.hasNext()){
1286 sensors_[
i] =
new Vector<IdData>();
1289 for(
int j=0; j<names.length; j++)
1290 sensors_[
i].add(
new IdData(names[j], j));
1292 sensorButtons_[
i] =
new Vector<Button>();
1297 Composite composite = (Composite)super.createDialogArea(parent);
1298 composite.setLayout(
new GridLayout(2,
true));
1300 Composite panel0 =
new Composite(composite,SWT.NONE);
1301 panel0.setLayoutData(
new GridData(GridData.FILL_VERTICAL));
1302 panel0.setLayout(
new FillLayout(SWT.VERTICAL));
1303 Label label0 =
new Label(panel0, SWT.NONE);
1304 label0.setText(
"Link");
1306 allJointButton_ =
new Button(panel0, SWT.TOGGLE|SWT.CENTER);
1307 allJointButton_.setText(
"All joints");
1308 allJointButton_.addSelectionListener(
new SelectionListener(){
1309 public void widgetDefaultSelected(SelectionEvent e) {
1311 public void widgetSelected(SelectionEvent e) {
1312 if(allJointButton_.getSelection()){
1313 for(
int i=0;
i<links_.size();
i++){
1314 if(links_.get(
i).isJoint())
1315 linkButtons_.get(
i).setSelection(
true);
1318 for(
int i=0;
i<links_.size();
i++){
1319 if(links_.get(
i).isJoint())
1320 linkButtons_.get(
i).setSelection(
false);
1325 for(
int i=0;
i<links_.size();
i++){
1326 linkButtons_.add(
new Button(panel0, SWT.CHECK|SWT.LEFT));
1327 linkButtons_.get(
i).addSelectionListener(
new SelectionListener(){
1328 public void widgetDefaultSelected(SelectionEvent e) {
1330 public void widgetSelected(SelectionEvent e) {
1331 updateAllJointButton();
1335 updateButton(
true, 0);
1337 Composite panel1 =
new Composite(composite,SWT.NONE);
1338 panel1.setLayoutData(
new GridData(GridData.FILL_VERTICAL));
1339 panel1.setLayout(
new RowLayout(SWT.VERTICAL));
1341 Label label =
new Label(panel1, SWT.NONE);
1344 for(
int j=0; j<sensors_[
i].size(); j++){
1345 sensorButtons_[
i].add(
new Button(panel1, SWT.CHECK|SWT.LEFT));
1347 Label dumy =
new Label(panel1, SWT.NONE);
1349 updateButton(
false, -1);
1351 Transfer [] transfers =
new Transfer[]{ TextTransfer.getInstance() };
1352 DragSourceListener dragSourceListener =
new DragSourceListener() {
1353 public void dragFinished(DragSourceEvent event) {
1355 public void dragSetData(DragSourceEvent event) {
1356 Button sourceButton = (Button)((DragSource)
event.getSource()).getControl();
1357 int index = linkButtons_.indexOf(sourceButton);
1359 event.data =
"link "+String.valueOf(index);
1361 for(
int i=0;
i<sensorButtons_.length;
i++){
1362 index = sensorButtons_[
i].indexOf(sourceButton);
1364 event.data =
"sensor "+String.valueOf(
i)+
" "+String.valueOf(index);
1369 public void dragStart(DragSourceEvent event) {
1372 DropTargetListener dropTargetListener =
new DropTargetListener(){
1373 public void drop(DropTargetEvent event){
1375 Button targetButton = (Button)((DropTarget)
event.getSource()).getControl();
1376 String
string = (String)event.data;
1377 String[] source =
string.split(
" ");
1378 if(source[0].equals(
"link")){
1379 for(
int i=0;
i<links_.size();
i++)
1380 links_.get(
i).selection_ = linkButtons_.get(
i).getSelection();
1381 int sourceIndex = Integer.parseInt(source[1]);
1382 int targetIndex = linkButtons_.indexOf(targetButton);
1383 if(targetIndex >=0){
1384 Link sourceLink = links_.get(sourceIndex);
1385 Link targetLink = links_.get(targetIndex);
1386 links_.remove(sourceLink);
1387 links_.insertElementAt(sourceLink, links_.indexOf(targetLink));
1388 updateButton(
true, 0);
1391 int type = Integer.parseInt(source[1]);
1392 for(
int i=0;
i<sensors_[
type].size();
i++)
1393 sensors_[
type].
get(
i).selection_ = sensorButtons_[
type].get(
i).getSelection();
1394 int sourceIndex = Integer.parseInt(source[2]);
1395 int targetIndex = sensorButtons_[
type].indexOf(targetButton);
1396 if(targetIndex >=0){
1397 IdData sourceData = sensors_[
type].get(sourceIndex);
1398 IdData targetData = sensors_[
type].get(targetIndex);
1399 sensors_[
type].remove(sourceData);
1400 sensors_[
type].insertElementAt(sourceData, sensors_[
type].indexOf(targetData));
1401 updateButton(
false,
type);
1406 private Color buttonColor_;
1407 public void dragEnter(DropTargetEvent event) {
1408 Button targetButton = (Button)((DropTarget)
event.getSource()).getControl();
1409 buttonColor_ = targetButton.getBackground();
1412 public void dragLeave(DropTargetEvent event) {
1413 Button targetButton = (Button)((DropTarget)
event.getSource()).getControl();
1414 targetButton.setBackground(buttonColor_);
1416 public void dragOperationChanged(DropTargetEvent event) {
1418 public void dragOver(DropTargetEvent event) {
1420 public void dropAccept(DropTargetEvent event) {
1423 for(
int i=0;
i<links_.size();
i++){
1424 DragSource source =
new DragSource(linkButtons_.get(
i), DND.DROP_MOVE );
1425 source.setTransfer(transfers);
1426 source.addDragListener(dragSourceListener);
1427 DropTarget target =
new DropTarget(linkButtons_.get(
i), DND.DROP_MOVE);
1428 target.setTransfer(transfers);
1429 target.addDropListener(dropTargetListener);
1432 for(
int i=0;
i<sensors_.length;
i++){
1433 for(
int j=0; j<sensors_[
i].size(); j++){
1434 DragSource source =
new DragSource(sensorButtons_[
i].
get(j), DND.DROP_MOVE );
1435 source.setTransfer(transfers);
1436 source.addDragListener(dragSourceListener);
1437 DropTarget target =
new DropTarget(sensorButtons_[
i].
get(j), DND.DROP_MOVE);
1438 target.setTransfer(transfers);
1439 target.addDropListener(dropTargetListener);
1447 if (buttonId == IDialogConstants.OK_ID) {
1449 for(
int i=0;
i<links_.size();
i++){
1450 if(links_.get(
i).isJoint()){
1452 if(!linkButtons_.get(
i).getSelection()){
1462 for(
int i=0;
i<linkButtons_.size();
i++)
1463 if(linkButtons_.get(
i).getSelection())
1464 id_ += links_.get(
i).name_ +
",";
1465 for(
int i=1;
i<sensorButtons_.length;
i++)
1466 for(
int j=0; j<sensorButtons_[
i].size(); j++)
1467 if(sensorButtons_[
i].
get(j).getSelection())
1468 id_ += sensors_[
i].get(j).name_ +
",";
1470 id_ = id_.substring(0, id_.length()-1);
1472 for(
int i=0;
i<sensorButtons_[0].size();
i++)
1473 if(sensorButtons_[0].
get(
i).getSelection())
1474 id_ = String.valueOf(sensors_[0].
get(
i).id_);
1478 super.buttonPressed(buttonId);
1487 if(id_.equals(
"All joints")){
1488 for(
int i=0;
i<links_.size();
i++){
1489 if(links_.get(
i).isJoint())
1490 links_.get(
i).selection_ =
true;
1493 String[] names = id_.split(
",");
1494 for(
int i=names.length;
i>0; ){
1495 String
name = names[--
i].trim();
1496 int index = links_.indexOf(
new Link(
name, -1));
1498 Link link = links_.get(index);
1500 links_.remove(link);
1501 links_.insertElementAt(link, 0);
1505 index = sensors_[j].indexOf(
new IdData(
name, -1));
1507 IdData idData = sensors_[j].get(index);
1509 sensors_[j].remove(idData);
1510 sensors_[j].insertElementAt(idData, 0);
1515 int id = Integer.valueOf(
name);
1516 index = sensors_[0].indexOf(
new IdData(
"",
id));
1518 IdData idData = sensors_[0].get(index);
1520 sensors_[0].remove(idData);
1521 sensors_[0].insertElementAt(idData, 0);
1523 }
catch(NumberFormatException e){
1532 for(
int i=0;
i<links_.size();
i++){
1533 String
string = links_.get(
i).name_;
1534 if(links_.get(
i).isJoint())
1535 string +=
" (id= "+links_.get(
i).id_+
")";
1536 linkButtons_.get(
i).setText(
string);
1537 linkButtons_.get(
i).setSelection(links_.get(
i).selection_);
1539 updateAllJointButton();
1543 for(
int j=0; j<sensors_[
i].size(); j++){
1544 sensorButtons_[
i].get(j).setText(sensors_[
i].
get(j).name_+
" (id= "+sensors_[
i].
get(j).id_+
")");
1545 sensorButtons_[
i].get(j).setSelection(sensors_[
i].
get(j).selection_);
1549 for(
int j=0; j<sensors_[
type].size(); j++){
1550 sensorButtons_[
type].get(j).setText(sensors_[
type].
get(j).name_+
" (id= "+sensors_[
type].
get(j).id_+
")");
1551 sensorButtons_[
type].get(j).setSelection(sensors_[
type].
get(j).selection_);
1559 for(
int i=0;
i<links_.size();
i++)
1560 if(links_.get(
i).isJoint())
1561 b =
b && linkButtons_.get(
i).getSelection();
1563 allJointButton_.setSelection(
true);
1565 allJointButton_.setSelection(
false);