GrxORBMonitor.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00010 /*
00011  *  GrxORBMonitor.java
00012  *
00013  *  Copyright (C) 2007 GeneralRobotix, Inc.
00014  *  All Rights Reserved
00015  *
00016  *  @author Yuichiro Kawasumi (General Robotix, Inc.)
00017  *  2004/03/16
00018  */
00019 package com.generalrobotix.ui.util;
00020 
00021 import org.eclipse.swt.SWT;
00022 import org.eclipse.swt.events.SelectionEvent;
00023 import org.eclipse.swt.events.SelectionListener;
00024 import org.eclipse.swt.layout.GridData;
00025 import org.eclipse.swt.layout.GridLayout;
00026 import org.eclipse.swt.widgets.Button;
00027 import org.eclipse.swt.widgets.Composite;
00028 import org.eclipse.swt.widgets.Label;
00029 import org.eclipse.swt.widgets.MessageBox;
00030 import org.eclipse.swt.widgets.Text;
00031 
00032 @SuppressWarnings("serial") //$NON-NLS-1$
00033 public class GrxORBMonitor extends Composite {
00034     private MessageBox dialog_     = null;
00035 
00036     private Label      labelNs     = null;
00037     private Text       multiText   = null;
00038     private Text       textNsHost_ = null;
00039     private Text       textNsPort_ = null;
00040 
00041     public GrxORBMonitor(Composite parent, int style) {
00042         super(parent, style);
00043         this.setLayout(new GridLayout(1, false));
00044 
00045         Composite northPane = new Composite(this, SWT.NONE);
00046         northPane.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
00047         GridLayout gridLayout = new GridLayout(5, false);
00048         gridLayout.marginWidth = 5;
00049         gridLayout.horizontalSpacing = 5;
00050         northPane.setLayout(gridLayout);
00051 
00052         Button button = new Button(northPane, SWT.PUSH);
00053         button.setText(MessageBundle.get("GrxORBMonitor.button.update")); //$NON-NLS-1$
00054         GridData btnGridData = new GridData();
00055         btnGridData.widthHint = 80;
00056         btnGridData.heightHint = 26;
00057         button.setLayoutData(btnGridData);
00058         button.addSelectionListener(new SelectionListener() {
00059             public void widgetDefaultSelected(SelectionEvent e) {}
00060             public void widgetSelected(SelectionEvent e) {
00061                 update();
00062             }
00063         });
00064 
00065         new Label(northPane, SWT.NONE).setText(MessageBundle.get("GrxORBMonitor.label.host")); //$NON-NLS-1$
00066 
00067         textNsHost_ = new Text(northPane, SWT.SINGLE | SWT.BORDER);
00068         textNsHost_.setText(GrxCorbaUtil.nsHost());
00069         GridData textGridData = new GridData();
00070         textGridData.widthHint = 100;
00071         textNsHost_.setLayoutData(textGridData);
00072 
00073         new Label(northPane, SWT.NONE).setText(MessageBundle.get("GrxORBMonitor.label.port")); //$NON-NLS-1$
00074 
00075         textNsPort_ = new Text(northPane, SWT.SINGLE | SWT.BORDER);
00076         Integer nsPort = new Integer(GrxCorbaUtil.nsPort());
00077         textNsPort_.setText(nsPort.toString());
00078         textNsPort_.setLayoutData(textGridData);
00079 
00080         multiText = new Text(this, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
00081         multiText.setEditable(false);
00082         multiText.setLayoutData(new GridData(GridData.FILL_BOTH));
00083 
00084         labelNs = new Label(this, SWT.SHADOW_NONE);
00085         labelNs.setText(MessageBundle.get("GrxORBMonitor.label.NSURL0")); //$NON-NLS-1$
00086         labelNs.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
00087 
00088         setSize(412, 280);
00089     }
00090 
00091     // public methods --------------------------------------------------------
00092     //    public static GrxORBMonitor getInstance() {
00093     //        if (this_ == null){
00094     //            this_ =  new GrxORBMonitor();
00095     //        }
00096     //        return this_;
00097     //    }
00098 
00099     public void showDialog() {//JFrame frame){
00100         if (dialog_ == null) {
00101             dialog_ = new MessageBox(null, SWT.OK);
00102             //dialog_ = new JDialog(frame,"ORB Monitor",false);
00103             dialog_.setMessage(MessageBundle.get("GrxORBMonitor.dialog.message.ORB")); //$NON-NLS-1$
00104             //dialog_.pack();
00105             //dialog_.setContentPane(this);
00106             //            dialog_.addWindowListener(new java.awt.event.WindowAdapter() { 
00107             //                public void windowClosing(java.awt.event.WindowEvent e) {    
00108             //                    dialog_.setVisible(false);
00109             //                }
00110             //            });
00111         }
00112         multiText.setText(""); //$NON-NLS-1$
00113         dialog_.open();
00114     }
00115 
00116     public void update() {
00117         String nsHost = textNsHost_.getText();
00118         String nsPort = textNsPort_.getText();
00119         if (nsHost == null || nsPort == null) {
00120             return;
00121         }
00122         int nsPortInt = Integer.parseInt(nsPort);
00123         labelNs.setText(MessageBundle.get("GrxORBMonitor.label.NSURL1") + nsHost + ":" + nsPort + "/NameService"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
00124 
00125         String s[] = GrxCorbaUtil.getObjectNameList(nsHost, nsPortInt);
00126         multiText.setText(""); //$NON-NLS-1$
00127         if (s == null) {
00128             return;
00129         }
00130         for (int i = 0; i < s.length; i++) {
00131             String str = null;
00132             if (GrxCorbaUtil.isConnected(s[i], nsHost, nsPortInt)) {
00133                 str = MessageBundle.get("GrxORBMonitor.text.active") + s[i] + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
00134             } else {
00135                 GrxDebugUtil.println("[GrxORBMonitor] " + s[i] + " is not in " + nsHost + ":" + nsPortInt + " active"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
00136                 str = MessageBundle.get("GrxORBMonitor.text.notActive") + s[i] + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
00137             }
00138             multiText.append(str);
00139         }
00140 
00141         GrxDebugUtil.println("ObjectNum:" + s.length); //$NON-NLS-1$
00142     }
00143 
00144     public String getNSHost() {
00145         return textNsHost_.getText();
00146     }
00147 
00148     public String getNSPort() {
00149         return textNsPort_.getText();
00150     }
00151 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16