Horus Doc || Java GUI Reference || Doxygen's quick Index  

TestApp Class Reference

A simple application using CORBA to call C++ functions. More...

Inheritance diagram for TestApp::

CorbaSampleApp StubRepositoryGuard SampleApp List of all members.

Public Methods

void handleOpenImageJava ()
 This function is called by _bmenu if the associated menu item is selected. More...

void handleExit ()
 This function is called by _bmenu if the associated menu item is selected. More...

void handleServerImage ()
void handleWebImage ()
void handleRegisterApp ()
void handleStubBrowser ()
void handleAppBrowser ()
void handleIDLScript ()
void handleViewImageStub (String id, String imgName)
void handleResult (String type, String value)
void setLeftDisplayMode (String m)
void setRightDisplayMode (String m)
void addStub (String intfId, String name, Object stub)
void removeStub (String intfId, String name)
void dragGestureRecognized (DragGestureEvent event)
void dragDropEnd (DragSourceDropEvent event)
void dragEnter (DragSourceDragEvent event)
void dragOver (DragSourceDragEvent event)
void dragExit (DragSourceEvent event)
void dropActionChanged (DragSourceDragEvent event)
void dragOver (DropTargetDragEvent event)
void drop (final DropTargetDropEvent event)
void dragEnter (DropTargetDragEvent event)
void dragExit (DropTargetEvent event)
void dropActionChanged (DropTargetDragEvent event)

Static Public Methods

void main (String[] args)
 main is called when this is used as an application. More...


Protected Methods

boolean buildSample (JFrame parent, JApplet applet, String[] args)

Detailed Description

A simple application using CORBA to call C++ functions.


Member Function Documentation

void TestApp::main String    args[] [inline, static]
 

main is called when this is used as an application.

This function has to be overloaded in the "leaf node" application itself.

Reimplemented from SampleApp.

00042 {
00043     TestApp app = new TestApp();
00044     app.doMain(args);
00045 
00046     // doMain will call buildSample
00047 }

void TestApp::handleOpenImageJava   [inline]
 

This function is called by _bmenu if the associated menu item is selected.

00054 {
00055     ImageManager imageMgr = ImageManager.defaultImageMgr();
00056     if(imageMgr == null) return;
00057 
00058     File file = askFilename(JAVA_FILTER, true);
00059     if(file == null) return;
00060 
00061     String name = nameFromFile(file);
00062 
00063     try {
00064         HxCorba.ImageRep img = imageMgr.loadLocalImage(file);
00065         StubRepository.instance().addStub(IMAGE_ID, name, img);
00066         showLeftImage(img, name);
00067     }
00068     catch(org.omg.CORBA.OBJECT_NOT_EXIST ex) {
00069         ErrorStreamArea.println("Cannot open image "+file.getPath());
00070     }
00071 }

void TestApp::handleExit   [inline]
 

This function is called by _bmenu if the associated menu item is selected.

00078 {
00079     unregisterApp();
00080     quitSample();
00081 }

void TestApp::handleServerImage   [inline]
 

00084 {
00085     ImageManager imageMgr = ImageManager.defaultImageMgr();
00086     if(imageMgr == null) return;
00087 
00088     File file = askFilename(HORUS_FILTER, CorbaMediator.instance().hasLocalServer());
00089     if(file == null) return;
00090 
00091     String name = nameFromFile(file); // not the full path...
00092 
00093     try {
00094         HxCorba.ImageRep img = imageMgr.loadServerImage(file.getPath());
00095         StubRepository.instance().addStub(IMAGE_ID, name, img);
00096         showLeftImage(img, name);
00097     }
00098     catch(org.omg.CORBA.SystemException ex){
00099         ErrorStreamArea.println(""+ex);
00100     }
00101 }

void TestApp::handleWebImage   [inline]
 

00104 {
00105     try {
00106         String urlStr = JOptionPane.showInputDialog("URL:");
00107         if(urlStr == null) return;
00108 
00109         URL url = new URL(urlStr);
00110         String name = nameFromFile(new File(url.getFile()));
00111 
00112         ImageManager imageMgr = ImageManager.defaultImageMgr();
00113         if(imageMgr == null) return;
00114 
00115         HxCorba.ImageRep img = imageMgr.loadWebImage(url);
00116         StubRepository.instance().addStub(IMAGE_ID, name, img);
00117         showLeftImage(img, name);
00118     }
00119     catch(org.omg.CORBA.SystemException ex){
00120         ErrorStreamArea.println(""+ex);
00121     }
00122     catch(MalformedURLException ex){
00123         ErrorStreamArea.println(""+ex);
00124     }
00125 }

void TestApp::handleRegisterApp   [inline]
 

00128 {
00129     registerApp(new TestServant());
00130 }

void TestApp::handleStubBrowser   [inline]
 

00133 {
00134     StubBrowser st = new StubBrowser();
00135     st.addStubAction(IMAGE_ID, "View", this, "handleViewImageStub");
00136 
00137     JDialog dlg = new JDialog(getParentFrame(), "Stub Browser", true);
00138     dlg.getContentPane().add(st);
00139     dlg.pack();
00140     dlg.setVisible(true);
00141 }

void TestApp::handleAppBrowser   [inline]
 

00144 {
00145     AppBrowser app = new AppBrowser(/*CorbaMediator.appMgr()*/);
00146     JDialog dlg = new JDialog(getParentFrame(), "App Browser", false);
00147     dlg.getContentPane().add(app);
00148     dlg.pack();
00149     dlg.setVisible(true);
00150 }

void TestApp::handleIDLScript   [inline]
 

00153 {
00154     if(_idlScriptDialog == null) {
00155         IDLScriptShell sh = new IDLScriptShell();
00156         _idlScriptDialog = new JDialog(getParentFrame(), "IDL Script", false);
00157         _idlScriptDialog.getContentPane().add(sh);
00158         _idlScriptDialog.pack();
00159         _idlScriptDialog.setLocation(576, 428);
00160         _idlScriptDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
00161 
00162         sh.setGuard(this);
00163         StubRepository.instance().addStubListener(sh);
00164     }
00165 
00166     _idlScriptDialog.setVisible(true);
00167 }

void TestApp::handleViewImageStub String    id,
String    imgName
[inline]
 

00170 {
00171     Object obj = StubRepository.instance().getStub(IMAGE_ID, imgName);
00172     HxCorba.ImageRep image = HxCorba.ImageRepHelper.narrow((org.omg.CORBA.Object)obj);
00173 
00174     showLeftImage(image, imgName);
00175 }

void TestApp::handleResult String    type,
String    value
[inline]
 

00178 {
00179     if(type.equals("interface ImageRep")) {
00180         Object obj = StubRepository.instance().getStub(IMAGE_ID, value);
00181         HxCorba.ImageRep image = HxCorba.ImageRepHelper.narrow((org.omg.CORBA.Object)obj);
00182 
00183         showRightImage(image, value);
00184     }
00185     else if(type.equals("void"))
00186         OutputStreamArea.println("void");
00187     else if(type.equals("error"))
00188         ErrorStreamArea.println(value);
00189     else
00190         OutputStreamArea.println("Result: "+value+", type: "+type);
00191 }

void TestApp::setLeftDisplayMode String    m [inline]
 

00194 {
00195     _leftDisplayMode = m;
00196     _leftCanvas.setDisplayMode(m);
00197     _leftViewer.doRefresh();
00198 }

void TestApp::setRightDisplayMode String    m [inline]
 

00202 {
00203     _rightDisplayMode = m;
00204     _rightCanvas.setDisplayMode(m);
00205     _rightViewer.doRefresh();
00206 }

void TestApp::addStub String    intfId,
String    name,
Object    stub
[inline]
 

Reimplemented from StubRepositoryGuard.

00211 {
00212     StubRepository.instance().addStub(intfId, name, stub);
00213 
00214     if(intfId.equals(IMAGE_ID)) {
00215         org.omg.CORBA.Object obj = (org.omg.CORBA.Object)stub;
00216         HxCorba.ImageRep img = HxCorba.ImageRepHelper.narrow(obj);
00217         showRightImage(img, name);
00218     }
00219 }

void TestApp::removeStub String    intfId,
String    name
[inline]
 

Reimplemented from StubRepositoryGuard.

00222 {}

void TestApp::dragGestureRecognized DragGestureEvent    event [inline]
 

00226 {
00227     // a drag gesture has been initiated
00228     HxCorba.ImageRep image = null;
00229     String name = null;
00230     String type = IMAGE_ID;
00231     String ior = null;
00232 
00233     if(event.getDragSource() == _rightDragSource) {
00234         name = _rightName;
00235         image = _rightImage;
00236     }
00237     else { //event.getDragSource() == _leftDragSource
00238         name = _leftName;
00239         image = _leftImage;
00240     }
00241 
00242     if(image != null) {
00243         ior = CorbaMediator.instance().object_to_string(image);
00244         Transferable data = new ObjectTransfer(type, name, ior);
00245         event.getDragSource().startDrag(event, DragSource.DefaultMoveNoDrop, data, this);
00246     }
00247 }

void TestApp::dragDropEnd DragSourceDropEvent    event [inline]
 

00251 {}

void TestApp::dragEnter DragSourceDragEvent    event [inline]
 

00252 {}

void TestApp::dragOver DragSourceDragEvent    event [inline]
 

00253 { }

void TestApp::dragExit DragSourceEvent    event [inline]
 

00254 {}

void TestApp::dropActionChanged DragSourceDragEvent    event [inline]
 

00255 { }

void TestApp::dragOver DropTargetDragEvent    event [inline]
 

00259 {
00260     if(event.isDataFlavorSupported(HxCorbaDataFlavor.objectFlavor) ||
00261             event.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
00262         event.acceptDrag(event.getDropAction());
00263     else
00264         event.rejectDrag();
00265 }

void TestApp::drop final DropTargetDropEvent    event [inline]
 

00269 {
00270     if(!event.isDataFlavorSupported(HxCorbaDataFlavor.objectFlavor) &&
00271             !event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
00272         event.rejectDrop();
00273         return;
00274     }
00275 
00276     try {
00277         event.acceptDrop(event.getDropAction());
00278         Transferable transferable = event.getTransferable();
00279         final DropTargetContext ctx = event.getDropTargetContext();
00280         final Object data;
00281 
00282         DataFlavor fl = HxCorbaDataFlavor.objectFlavor;
00283         if(transferable.isDataFlavorSupported(fl)) {
00284             data = transferable.getTransferData(fl);
00285             Thread t = new Thread() {
00286                 public void run() {
00287                     doDrop((ObjectTransfer)data, ctx.getDropTarget());
00288                 }
00289             };
00290             t.start();
00291             ctx.dropComplete(true);
00292             return;
00293         }
00294 
00295         fl = DataFlavor.javaFileListFlavor;
00296         if(transferable.isDataFlavorSupported(fl)) {
00297             data = transferable.getTransferData(fl);
00298             Thread t = new Thread() {
00299                 public void run() {
00300                     doDrop((java.util.List)data, ctx.getDropTarget());
00301                 }
00302             };
00303             t.start();
00304             ctx.dropComplete(true);
00305             return;
00306         }
00307 
00308     }
00309     catch (java.io.IOException exception) {
00310         exception.printStackTrace();
00311         event.rejectDrop();
00312     }catch (UnsupportedFlavorException ufException ) {
00313         ufException.printStackTrace();
00314         event.rejectDrop();
00315     }
00316 }

void TestApp::dragEnter DropTargetDragEvent    event [inline]
 

00319 {}

void TestApp::dragExit DropTargetEvent    event [inline]
 

00320 {}

void TestApp::dropActionChanged DropTargetDragEvent    event [inline]
 

00321 {}

boolean TestApp::buildSample JFrame    parent,
JApplet    applet,
String    args[]
[inline, protected, virtual]
 

Reimplemented from SampleApp.

00332 {
00333     OutputStreamArea.println("Initializing CorbaMediator...");
00334     initCorbaMediator(args);
00335     setAdvancedLookupManager(parent);
00336 
00337     addInitialService(HxCorba.ConstructorHelper.id(), "Constructor", "CTOR");
00338     addInitialService(HxCorba.GlobalOpsHelper.id(), "GlobalOps", "OPS");
00339 
00340     OutputStreamArea.println("Building "+getSampleName()+" GUI...");
00341     if(isStandalone());
00342         parent.setTitle(getSampleName()+" (unregistered)");
00343 
00344     // set layout manager
00345 
00346     JPanel gui = new JPanel(new GridBagLayout());
00347 
00348 
00349     // Add splitpane with two viewers
00350 
00351     _leftViewer = ViewerFactory.makeBasicViewer();
00352     _rightViewer = ViewerFactory.makeBasicViewer();
00353 
00354     _leftDropTarget = new DropTarget(((BasicViewer)_leftViewer).ed, this);
00355     _rightDropTarget = new DropTarget(((BasicViewer)_rightViewer).ed, this);
00356     _leftDragSource = new DragSource();
00357     _leftDragSource.createDefaultDragGestureRecognizer(((BasicViewer)_leftViewer).ed,
00358         DnDConstants.ACTION_COPY_OR_MOVE, this);
00359     _rightDragSource = new DragSource();
00360     _rightDragSource.createDefaultDragGestureRecognizer(((BasicViewer)_rightViewer).ed,
00361         DnDConstants.ACTION_COPY_OR_MOVE, this);
00362 
00363     //_leftViewer.addMouseMotionListener(this);
00364     //_rightViewer.addMouseMotionListener(this);
00365     //((BasicViewer)_leftViewer).ed.addMouseMotionListener(this);
00366     //((BasicViewer)_rightViewer).vi.addMouseMotionListener(this);
00367     //_frame.addMouseMotionListener(this);
00368 
00369     JSplitPane viewSP = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
00370                                        _leftViewer, _rightViewer);
00371     viewSP.setOneTouchExpandable(true);
00372     viewSP.setDividerLocation(570);
00373     HX.addGridComp(gui, viewSP, 0, 0, 1, 1,
00374                    GridBagConstraints.BOTH, 1.0, 1.0, 1, 1);
00375 
00376     // Create CorbaExtMenuBar:
00377 
00378     OutputStreamArea.println("Querying InterfaceRepository...");
00379 
00380     //_bmenu = (isStandalone())?
00381     //    new CorbaExtMenuBar(parent, this) : new ExtMenuBar(this);
00382     _bmenu = new CorbaExtMenuBar(parent, this);
00383 
00384     _bmenu.addMenu("File");
00385     if(isStandalone())
00386         _bmenu.addMenuItem("File", "Open Local Image", "handleOpenImageJava");
00387     _bmenu.addMenuItem("File", "Open Server Image", "handleServerImage");
00388     if(isStandalone())
00389         _bmenu.addMenuItem("File", "Open Web Image", "handleWebImage");
00390     _bmenu.addSeparator("File");
00391     _bmenu.addMenuItem("File", "Exit", "handleExit");
00392 
00393     _bmenu.addMenu("Viewer");
00394     _bmenu.addSubMenu("Viewer", "Left display mode");
00395     _bmenu.addSubMenu("Viewer", "Right display mode");
00396     String[] modes = getRGBModes();
00397     _bmenu.addGroupMenu("Left display mode", modes, "setLeftDisplayMode", _leftDisplayMode);
00398     _bmenu.addGroupMenu("Right display mode", modes, "setRightDisplayMode", _rightDisplayMode);
00399 
00400     _bmenu.addCorbaObjectMenu("ImageRep");
00401     _bmenu.addCorbaObjectMenu("GlobalOps");
00402     _bmenu.addCorbaObjectsMenu();
00403 
00404 
00405     _bmenu.addMenu("Tools");
00406     _bmenu.addMenuItem("Tools", "Stub Browser", "handleStubBrowser");
00407     if(isStandalone()) {
00408         _bmenu.addMenuItem("Tools", "App Browser", "handleAppBrowser");
00409         _bmenu.addMenuItem("Tools", "IDL Script", "handleIDLScript");
00410         _bmenu.addSeparator("Tools");
00411         _bmenu.addMenuItem("Tools", "Register App", "handleRegisterApp");
00412     }
00413 
00414     parent.setJMenuBar(_bmenu);
00415     parent.getContentPane().add(gui, BorderLayout.CENTER);
00416 
00417     parent.setSize(1150, 450);
00418     parent.setLocation(0, 0);
00419 
00420     OutputStreamArea.println("Done");
00421 
00422     OutDialog out = new OutDialog(parent, 12, 4, 50);
00423     out.setLocation(0, 428);
00424     out.show();
00425 
00426     return true;
00427 }


The documentation for this class was generated from the following file:
Generated on Mon Jan 27 15:11:27 2003 for JavaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001