com.javonet.api

Class NControlContainer

  • java.lang.Object
    • java.awt.Component
      • java.awt.Container
        • java.awt.Panel
          • com.javonet.api.NControlContainer
  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

    public class NControlContainer
    extends java.awt.Panel
    A class that is used to embed .NET UI components in AWT, Swing or JavaFX window or UI elements.

    Use this class to wrap the NObject instance holding the reference to .NET WinForms or WPF user control.

    You can add any .NET WPF or WinForms user control to JAVA user interface. NControlContainer class
    will take care of embedding and integrating .NET UI components with JAVA and bind the window events
    like resizing, minimizing, maximizing, moving or closing. .NET UI components transparently for end-user
    lives within JAVA user interface added to grid, panel or window with size being adjusted either automatically
    by layout or set to fixed values on NControlContainer class.

    NControlContainer class derives from Panel and offers the same functionality as JAVA panel control.

    Usage

    To embed .NET WinForms or WPF user control in JAVA user interface you must add reference to .NET DLL file which contains
    the implementation of .NET UI component, initialize the instance of .NET user control and store it in NObject variable.
    Finally initialize the NControlContainer class passing .NET user control stored in NObject as argument to
    NControlContainer constructor.

    Control wrapped in NControlContainer class can be added to JAVA AWT, Swing or JavaFX interface like in the code
    sample below:

     
     Javonet.addReference("Javonet.WinFormsUserControlSample.dll");
     NObject userControl = Javonet.New("Javonet.WinFormsUserControlSample.UserControl1");
     NControlContainer wuc = new NControlContainer(userControl);
     
     Frame guiFrame = new Frame();
     guiFrame.add(wuc, BorderLayout.CENTER);
     

    Interaction with user control and events handling

    You can easily interact with .NET user control stored in NControlContainer class. Because .NET user control is wrapped
    by the container class, to interact with its content you should use either the instance of NObject passed to NControlContainer constructor
    or get the wrapped class using getUserControl() method.

    With user control you can interact in the same way as with any .NET class stored in NObject. Therefore you can bind events, invoke methods
    get / set fields and properties and modify the user control appearance.

    Sample below show how to bind to Click event:

      
     (...)
     NControlContainer wuc = new NControlContainer(userControl);
     
     wuc.addEventListener("ButtonClicked", new NEventListener() {
     	public void eventOccurred(Object[] arguments) {
     		//custom event handling code that will be called when button on .NET user 
    		//control is clicked
    
     		//ButtonClicked event subscribed has been exposed in the user control class 
     		//implementation on .NET side (in this particular example)
    			
     		//arguments[0] of button click events send from .NET usually contains value of 
     		//"object sender" argument therefore it gives access to the instance of event source control
     	}
     });
     
     
    Since:
    1.4hf14
    Version:
    1.4hf14
    See Also:
    Serialized Form


    • Nested Class Summary



      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.BaselineResizeBehavior



    • Field Summary



      • Fields inherited from class java.awt.Component

        BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT



      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH



    • Constructor Summary

      Constructors 
      Constructor and Description
      NControlContainer(NObject userControlArg)

      Constructor that initializes new instance of NControlContainer object.
      NControlContainer(java.lang.String typeName)

      Constructor that initializes new instance of NControlContainer object using type name.



    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void finalize() 
      NObject getUserControl()

      Returns the NObject instance of .NET user control being wrapped by this
      NControlContainer.
      <T> T invoke(java.lang.String methodName)

      Invokes any parameter-less method on associated .NET user control object and returns result.
      <T> T invoke(java.lang.String methodName,
      java.lang.Object... parameters)

      Invokes any method with parameters on associated .NET user control object and returns result.
      void RegisterMnemonics(java.lang.String[] javaMnemonicKeys,
      java.lang.String[] dotnetMnemonicKeys)

      Registers mnemonic keys that will be routed between .NET and Java.
      void requestFocus() 
      NObject set(java.lang.String fieldName,
      java.lang.Object fieldValue)

      Sets value for any static or instance field and property on associated .NET user control object.


      • Methods inherited from class java.awt.Panel

        addNotify, getAccessibleContext



      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, isValidateRoot, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate



      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle



      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait



    • Constructor Detail



      • NControlContainer

        public NControlContainer(NObject userControlArg)
                          throws JavonetException
        Constructor that initializes new instance of NControlContainer object.
        This constructor takes as an argument the instance of NObject class that
        holds the reference to .NET WinForms or WPF user control.

        Control passed as argument will be wrapped by NControlContainer and when
        NControlContainer instance will be added to AWT, Swing or JavaFX window
        the wrapped .NET user control will be hosted in that window.

        Parameters:
        userControl – userControl that will be wrapped by NControlContainer for further placement in AWT, Swing or JavaFX window.
        Throws:
        JavonetException – If .NET exception occurs during during initialization



      • NControlContainer

        public NControlContainer(java.lang.String typeName)
                          throws JavonetException
        Constructor that initializes new instance of NControlContainer object using type name.
        This constructor takes as an argument the name of .NET WinForms or WPF user control class.

        Control passed as argument will be initialized and wrapped by NControlContainer and when
        NControlContainer instance will be added to AWT, Swing or JavaFX window
        the wrapped .NET user control will be hosted in that window.

        Parameters:
        typeName – name with or without namespace of user control class that will be wrapped by NControlContainer for further placement in AWT, Swing or JavaFX window.
        Throws:
        JavonetException – If .NET exception occurs during during initialization



    • Method Detail



      • finalize

        public void finalize()
                      throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable



      • getUserControl

        public NObject getUserControl()
        Returns the NObject instance of .NET user control being wrapped by this
        NControlContainer. You can use this method to access the underlying control
        to bind events, get/set fields, invoke methods or modify the appearance of
        the user control.
        Returns:
        NObject of userControl being wrapped by this instance of NControlContainer



      • invoke

        public <T> T invoke(java.lang.String methodName)
                     throws JavonetException
        Invokes any parameter-less method on associated .NET user control object and returns result.

        For primitive-type results appropriate Java primitive type will be returned (string, integer, float…)

        If reference-type results instance of another NObject will be returned associated to returned .NET object.

        For void results NULL will be returned.

        Type Parameters:
        T – Java type to which the result returned by invoked method will be casted. Provide either Java value type like: integer, string, boolean or for reference type results please use NObject
        Parameters:
        methodName – Name of the method to be invoked
        Returns:
        Result of method invocation. It can be JAVA primitive type (string, integer, float) or instance of another NObject
        Throws:
        JavonetException – If .NET exception occurs during method invocation
        See Also:
        NObject.invoke(String, Object...)



      • invoke

        public <T> T invoke(java.lang.String methodName,
                            java.lang.Object... parameters)
                     throws JavonetException
        Invokes any method with parameters on associated .NET user control object and returns result.

        Parameters can be specified as any Java primitive type or instance of another NObject to pass reference to another .NET object.

        For primitive-type results appropriate Java primitive type will be returned (String, Integer, Float…)

        If reference-type results instance of another NObject will be returned associated to returned .NET object.

        For void results NULL will be returned.

        Type Parameters:
        T – Java type to which the result returned by invoked method will be casted. Provide either Java value type like: integer, string, boolean or for reference type results please use NObject
        Parameters:
        methodName – Name of the method to be invoked
        parameters – Input parameters for method to be invoked. It can be JAVA primitive types or NObject to pass .NET reference
        Returns:
        Result of method invocation. It can be Java primitive type (string, integer, float) or instance of another NObject
        Throws:
        JavonetException – If .NET exception occurs during method invocation



      • RegisterMnemonics

        public void RegisterMnemonics(java.lang.String[] javaMnemonicKeys,
                                      java.lang.String[] dotnetMnemonicKeys)
                               throws JavonetException
        Registers mnemonic keys that will be routed between .NET and Java.

        As arguments pass the collections of the keys X that will be used
        in combination ALT+X.

        Keys registered as Java mnemonics will be routed when users presses
        the key combination while keeping the focus in .NET control.

        Keys registered as .NET mnemonics will be routed when users presses
        the key combination while keeping the focus in Java control.

        Registered keys will be consumed and prevented from further processing
        on .NET or Java side. Non-registered keys will not be forwarded.

        If more than one .NET user control container on the Java form will have
        registered the same .NET mnemonic key only the first one in Java window hierarchy
        will consume the shortcut and process.

        Parameters:
        javaMnemonicKeys – Keys that can be used in ALT+X combination to access Java controls
        dotnetMnemonicKeys – keys that can be used in ALT+X combination to access .NET controls
        Throws:
        JavonetException – exception raised of .NET and Java mnemonic keys collections contains common elements



      • requestFocus

        public void requestFocus()
        Overrides:
        requestFocus in class java.awt.Component



      • set

        public NObject set(java.lang.String fieldName,
                           java.lang.Object fieldValue)
                    throws JavonetException
        Sets value for any static or instance field and property on associated .NET user control object.

        Value can be specified as any Java primitive type (integer, string, float etc…)
        or as NObject instance to pass reference to another instance of initialized .NET object.

        Parameters:
        fieldName – Name of the instance or static field or property
        fieldValue – Value to be set on selected field or property. Value can be any JAVA primitive type or instance of NObject to pass reference-type
        Returns:
        Instance of NObject upon which method is invoked. This allows method invocations to be chained on that object; for example

         b.set("Field1",0).set("Field2",10).set("Field3","String Value"); 
        Throws:
        JavonetException – If .NET exception occurs within corresponding setter on .NET side