Demo: Embedding Windows Presentation Foundation elements inside a Java GUI application. Version 7.3



Similar documents
Demo: Controlling.NET Windows Forms from a Java Application. Version 7.3

Understanding class paths in Java EE projects with Rational Application Developer Version 8.0

JAMF Software Server Installation Guide for Linux. Version 8.6

TIBCO ActiveMatrix BusinessWorks Plug-in for TIBCO Managed File Transfer Software Installation

Programmabilty. Programmability in Microsoft Dynamics AX Microsoft Dynamics AX White Paper

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB)

Creating.NET-based Mappers and Reducers for Hadoop with JNBridgePro

Getting Started with ANT PC Development

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

Eclipse with Mac OSX Getting Started Selecting Your Workspace. Creating a Project.

Image Acquisition Toolbox Adaptor Kit User's Guide

Last edited on 7/30/07. Copyright Syncfusion., Inc

Developing, Deploying, and Debugging Applications on Windows Embedded Standard 7

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Fundamentals of Java Programming

AT&T Conferencing Add-in for Outlook Implementation Guide v9.5

Quartz.Net Scheduler in Depth

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

SDK Code Examples Version 2.4.2


JAMF Software Server Installation Guide for Windows. Version 8.6

TIBCO FTL Installation

APPLICATION NOTE 1740 White Paper 6: 1-Wire Drivers Installation Guide for Windows

Aras Innovator.NET Client Security Policy Configuration

GUI and Web Programming

IBM Rational Web Developer for WebSphere Software Version 6.0

Lab: Application Lifecycle Management (ALM) Across Heterogeneous Platforms (Java/.NET)

Configuring and Integrating JMX

TIBCO Spotfire Statistics Services Installation and Administration

Security Classification: EIDA ID Card Toolkit v2.7. Developer s Guide

GridWorld Installation Guide

EMC Documentum Composer

Functional UI testing of Adobe Flex RIA. Viktor Gamov August,

Using Microsoft Windows Authentication for Microsoft SQL Server Connections in Data Archive

unipaas V1.9g Release Notes

TIBCO Hawk SNMP Adapter Installation

TIBCO Runtime Agent Authentication API User s Guide. Software Release November 2012

CrossPlatform ASP.NET with Mono. Daniel López Ridruejo

InRule. The Premier BRMS for the Microsoft Platform. Benefits THE POWER OF INRULE. Key Capabilities

Installation guidance ProjectWise Explorer

Developing Algo Trading Applications with SmartQuant Framework The Getting Started Guide SmartQuant Ltd Dr. Anton B.

Internet Information Services Integration Kit. Version 2.4. User Guide

Getting Microsoft Outlook and Salesforce in Sync

TIBCO Spotfire Statistics Services Installation and Administration Guide

BEAJRockit Mission Control. Using JRockit Mission Control in the Eclipse IDE

Download and Installation Instructions. Visual C# 2010 Help Library

Implementing multi-user multi-touch scenarios using WPF in Windows* 8 Desktop Apps

For Active Directory Installation Guide

unipaas V1.9c Release Notes

Export Server Object Extension and Export Task Install guide. (V1.1) Author: Domenico Ciavarella ( )

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

TIBCO ActiveMatrix BusinessWorks Process Monitor Server. Installation

How to extend WindowBuilder to support new components. 1. Add component to palette Palette contribution in project

1 Documentation Accessibility

Reporting Services. White Paper. Published: August 2007 Updated: July 2008

Java (12 Weeks) Introduction to Java Programming Language

Talend Open Studio for ESB. Release Notes 5.2.1

Script Manager for Nexio G-Scribe

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Advertiser Campaign SDK Your How-to Guide

FAQ CE 5.0 and WM 5.0 Application Development

netduino Getting Started

BusinessObjects Enterprise XI Release 2 Administrator s Guide

Protect, License and Sell Xojo Apps

Tutorial Reference Manual. Java WireFusion 4.1

Synchronizing databases

How To Connect A Java To A Microsoft Database To An Ibm.Com Database On A Microsq Server On A Blackberry (Windows) Computer (Windows 2000) On A Powerpoint (Windows 5) On An Ubio.Com

Adobe Certified Expert Program

Tutorial: BlackBerry Object API Application Development. Sybase Unwired Platform 2.2 SP04

EJB 3.0 and IIOP.NET. Table of contents. Stefan Jäger / stefanjaeger@bluewin.ch

Oracle Solaris Studio Code Analyzer

Introduction to the BackgroundWorker Component in WPF

Patterns in. Lecture 2 GoF Design Patterns Creational. Sharif University of Technology. Department of Computer Engineering

McAfee epolicy Orchestrator Software

Computing Concepts with Java Essentials

ASP.NET: THE NEW PARADIGM FOR WEB APPLICATION DEVELOPMENT

How to Install Eclipse. Windows

Custom Tasks for SAS. Enterprise Guide Using Microsoft.NET. Chris Hemedinger SAS. Press

BPM Scheduling with Job Scheduler

Practical Android Projects Lucas Jordan Pieter Greyling

Catálogo de cursos plataforma elearning Microsoft Imagine Academy: Microsoft SQL Server y Visual Studio

CS506 Web Design and Development Solved Online Quiz No. 01

Security Vulnerability Notice

Eclipse installation, configuration and operation

1) SETUP ANDROID STUDIO

Android Application Development Course Program

Bypassing Browser Memory Protections in Windows Vista

A CROSS-PLATFORM.NET CUSTOM CONTROL ARCHITECTURE FOR HUMAN MACHINE INTERFACE RUNTIME APPLICATION

TIBCO Spotfire Statistics Services Installation and Administration. Release 5.5 May 2013

Visual Basic. murach's TRAINING & REFERENCE

InfoSphere Master Data Management operational server v11.x OSGi best practices and troubleshooting guide

Transcription:

Demo: Embedding Windows Presentation Foundation elements inside a Java GUI application Version 7.3

JNBridge, LLC www.jnbridge.com COPYRIGHT 2002 2015 JNBridge, LLC. All rights reserved. JNBridge is a registered trademark and JNBridgePro and the JNBridge logo are trademarks of JNBridge, LLC. Java is a registered trademark of Oracle and/or its affiliates. Microsoft, Visual Studio, and IntelliSense are trademarks or registered trademarks of Microsoft Corporation in the United States and other countries. Apache is a trademark of The Apache Software Foundation. All other marks are the property of their respective owners. July 22, 2015

Introduction This document shows how a.net Windows Presentation Foundation (WPF) control can be embedded inside a Java GUI application (either an AWT, Swing, or SWT application). If you are unfamiliar with JNBridgePro, we recommend that you work through one of the other demos first. We recommend working through the Java-to-.NET demo, which will work through the entire process of generating proxies and setting up, configuring, and running an interop project. This current document assumes such knowledge, and is mainly a guided tour of the code and configuration information necessary to embed.net GUI elements inside GUI-based Java applications. The.NET GUI component In this example, we have provided a Windows Presentation Foundation control, WPFControlDemo.UserControl1. This control is adapted from the example in the first chapter of the book Essential Windows Presentation Foundation, by Chris Anderson (Addison-Wesley). Any WPF component to be embedded inside a Java GUI application must be derived from System.Windows.Controls.Control. The UserControl1 class above is derived from System.Windows.Controls.UserControl, which is a subclass of System.Windows.Controls.Control. UserControl1 contains a TextBox, a Button, and an Image, and also include an animated cube painted with copies of the TextBox, Button, and Image. UserControl1 also contains a public method makes it possible to register an event handler for the button. UserControl1 should look like this: 3

Generating the proxies We have provided a proxy jar file proxies.jar, which contains the proxies for WPFControlDemo.UserControl1, plus all supporting classes. However, it is straightforward to generate the proxies oneself. If you generate the proxy jar file, you should make sure that WPFControlDemo.dll (the dll with the WPF control), and System.Windows.Forms and PresentationCore (from the GAC) are in the proxy generator s assembly list. Make sure you have the correct version of System.Windows.Forms. Also, you must explicitly add System.Windows.Forms.Application and System.Windows.Media.Composition.DUCE (and supporting classes) to the proxy generation project and proxy them. You will be directly calling the proxy of System.Windows.Forms.Application (which resides in the assembly System.Windows.Forms), and other proxies reference System.Windows.Media.Composition.DUCE (which resides in PresentationCore) and some development environments may report an error if it isn t present. Embedding the Java component inside the Windows Form We have prepared a Java AWT application to contain the embedded.net component. Inside the application s main method, we have added the following lines // create the WPF control UserControl1 c = new UserControl1(); // wrap it so it can be embedded DotNetControl dnc = new DotNetControl(c); // size it dnc.setsize(300, 390); // embed it f.add(dnc, dncconstraints); The code first instantiates the proxy for the.net component (UserControl1), then embeds it inside a special wrapper, com.jnbridge.embedding.dotnetcontrol, which inherits from java.awt.canvas, and which allows the.net component to be used wherever a Java component is expected. The DotNetControl is then resized to be the same size as the embedded.net control, and the control is added to the application s Frame object, along with previously defined layout constraints. We have also created a callback class that implements WPFControlDemo.clickDelegate, the interface representing the button s event handler, and which will be executed whenever the WPF component s button is clicked: static TextField echo; public static class ClickEventHandler implements clickdelegate { public void Invoke(String message) { echo.settext(message); 4

The callback code takes the text from the WPF TextBox (passed as a parameter), and writes it to the Java TextField echo. The callback is instantiated and registered with the WPF component as an clickdelegate by the following line in the main method: c.registerclickdelegate(new ClickEventHandler()); Before any proxy call, JNBridgePro is started and configured through a call to com.jnbridge.jnbcore.dotnetside.init(): DotNetSide.init(props); where props is a Java Properties object containing the configuration information. The next section explains the configuration. It is also possible to put this information into a.properties file and supply the path to the.properties file as an argument to DotNetSide.init(). Finally, we must drive the.net-side event loop. We do so by calling System.Windows.Forms.Application.DoEvents() inside a loop: while(!muststop) { Application.DoEvents(); We terminate the loop by setting the muststop flag inside a windowclosing() event handler that we install in the application s Frame: f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent evt) { Window w = evt.getwindow(); w.setvisible(false); w.dispose(); muststop = true; ); Note that the muststop flag must be set as the last action in windowclosing(). If it is set before w.dispose(), the application s process may not terminate. Configuring and running the application The project is constructed in the same way as other.net-to-java interop projects. The communications mechanism must be shared memory: Properties props = new Properties(); props.put("dotnetside.servertype", "sharedmem"); props.put("dotnetside.assemblylist.1", "../DotNet/bin/Debug/WPFControlDemo.dll"); props.put("dotnetside.javaentry", "C:/Program Files (x86)/jnbridge/jnbridgepro v7.3/2.0- targeted/jnbjavaentry_x86.dll"); props.put("dotnetside.appbase", "C:/Program Files (x86)/jnbridge/jnbridgepro v7.3/2.0-targeted"); props.put("dotnetside.apartmentthreadingmodel", "STA"); Use JNBJavaEntry_x86.dll or JNBJavaEntry_x64.dll, depending on whether you re running the application as a 32-bit or a 64-bit process. 5

The properties above specify that shared memory is to be used. They also specify the location of the DLL containing the WPF control. (Since WPFControlDemo.dll references System.Windows.Forms.dll, it will be loaded automatically, although there is no harm in also adding it to the assembly list in another property. Following that, we specify the location of JNBJavaEntry.dll, and the folder in which jnbshare.dll, jnbsharedmem_x86.dll (or jnbsharedmem_x64.dll), jnbjavaentry2_x86.dll (or jnbjavaentry2_x64.dll), jnbwpfembedding.dll, and jnbauth_x86.dll (or jnbauth_x64.dll) reside. Finally, we must specify that the.net side will use the single-threaded apartment model. (If we leave this out, an exception will be thrown.) It is also possible to leave out the dotnetside.appbase property, if you must make sure that jnbshare.dll, jnbsharedmem.dll, and jnbjavaentry2.dll are all installed in the Global Assembly Cache (GAC), but we recommend using the dotnetside.appbase property. We supply a.bat file runjava.bat to encapsulate the commands needed to start the application When the Java application is run, the.wpf component appears embedded in the Java application, and when text is entered in the WPF component s text field and the Send button is clicked, the text will appear in the Java application s text box, illustrating how the WPF and Java GUI elements communicate. 6

Embedding.NET controls in SWT applications It is also possible to embed a.net control in an SWT application. The process is identical to that of embedding in AWT/Swing applications, as described above, except for the following differences: Instead of wrapping the embedded.net control inside com.jnbridge.embedding.dotnetcontrol, you must embed it inside com.jnbridge.embedding.dotnetswtcontrol, which inherits from org.eclipse.swt.widgets.composite. The constructor for DotNetSWTControl takes as arguments both the embedded.net control and the parent SWT composite object that will contain it: DotNetSWTControl mycontrol = new DotNetSWTControl(dotNetControl, parent); mycontrol.setbounds(0, 50, 655, 303); // and set its size and location Note that the DotNetSWTControl should be positioned and sized after being created. The Win32 version of swt.jar must be in the run-time classpath. The path of the folder containing the Win32 version of the SWT dlls (typically the plugins\org.eclipse.swt.win32_3.1.0\os\win32\x86 folder in the Eclipse installation folder) must be in the Java library path. For example, for Eclipse 3.1, add -Djava.library.path="C:\Program Files\Eclipse 3.1\eclipse\plugins\org.eclipse.swt.win32_3.1.0\os\win32\x86" to the command-line immediately after the java command. This path will differ depending on your installation and the version of Eclipse you are using. Summary The above example shows how simple it is to embed a Windows Presentation Foundation (WPF) component inside a Java GUI application. This embedding can be accomplished in three steps: Proxy the WPF component and the supporting classes Write code to wrap the Java component s proxy in the special DotNetControl wrapper class, size it, and add that DotNetControl object to the containing Java Frame. Create Java classes to implement any event handlers, and register them with the.net control s proxy, We also describe how to embed.net controls inside SWT applications. The main difference between embedding in SWT applications and embedding in AWT/SWT applications is that you must use the DotNetSWTControl wrapper class when embedding in SWT applications. 7