-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhances JNetReflector to manage classes that needs to create Callbacks in .NET #512
Comments
More or less the same behavior shall be applied to the classes ending with public abstract class WindowAdapter
implements WindowListener, WindowStateListener, WindowFocusListener
{
/**
* Constructs a {@code WindowAdapter}.
*/
protected WindowAdapter() {}
/// other methods
/**
* Invoked when a window is activated.
*/
public void windowActivated(WindowEvent e) {}
/// other methods
} the class is managed in JNet with the following JVM WindowAdapter snippet: public final class WindowAdapter extends org.mases.jcobridge.JCListener implements java.awt.event.WindowListener, java.awt.event.WindowStateListener, java.awt.event.WindowFocusListener {
public WindowAdapter(String key) throws org.mases.jcobridge.JCNativeException {
super(key);
}
//@Override
public void windowActivated(java.awt.event.WindowEvent arg0) {
raiseEvent("windowActivated", arg0);
}
/// other methods
} and the following .NET WindowAdapter class: public partial class WindowAdapter : MASES.JCOBridge.C2JBridge.JVMBridgeListener
{
/// <summary>
/// Default constructor: even if the corresponding Java class does not have one, it is mandatory for JCOBridge
/// </summary>
public WindowAdapter() { InitializeHandlers(); }
const string _bridgeClassName = "org.mases.jnet.generated.java.awt.event.WindowAdapter";
private static readonly IJavaType _LocalBridgeClazz = ClazzOf(_bridgeClassName);
private static IJavaType LocalBridgeClazz => _LocalBridgeClazz ?? throw new InvalidOperationException($"Class {_bridgeClassName} was not found.");
/// <summary>
/// <see href="https://www.jcobridge.com/api-clr/html/P_MASES_JCOBridge_C2JBridge_JVMBridgeListener_BridgeClassName.htm"/>
/// </summary>
public override string BridgeClassName => _bridgeClassName;
#region Instance methods
/// <summary>
/// Handlers initializer for <see cref="WindowAdapter"/>
/// </summary>
protected virtual void InitializeHandlers()
{
AddEventHandler("windowActivated", new global::System.EventHandler<CLRListenerEventArgs<CLREventData<Java.Awt.EventNs.WindowEvent>>>(WindowActivatedEventHandler));
/// other invocations
}
/// <summary>
/// Handler for <see href="https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/event/WindowAdapter.html#windowActivated(java.awt.event.WindowEvent)"/>
/// </summary>
/// <remarks>If <see cref="OnWindowActivated"/> has a value it takes precedence over corresponding class method</remarks>
public global::System.Action<Java.Awt.EventNs.WindowEvent> OnWindowActivated { get; set; } = null;
void WindowActivatedEventHandler(object sender, CLRListenerEventArgs<CLREventData<Java.Awt.EventNs.WindowEvent>> data)
{
var methodToExecute = (OnWindowActivated != null) ? OnWindowActivated : WindowActivated;
methodToExecute.Invoke(data.EventData.TypedEventData);
}
/// <summary>
/// <see href="https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/event/WindowAdapter.html#windowActivated(java.awt.event.WindowEvent)"/>
/// </summary>
/// <param name="arg0"><see cref="Java.Awt.EventNs.WindowEvent"/></param>
public virtual void WindowActivated(Java.Awt.EventNs.WindowEvent arg0)
{
}
/// other methods
#endregion
} In case of public final class WindowAdapter extends java.awt.event.WindowAdapter implements org.mases.jcobridge.IJCListener {
org.mases.jcobridge.JCListener _jumper;
public WindowAdapter(String key) throws org.mases.jcobridge.JCNativeException {
super();
_jumper = new org.mases.jcobridge.JCListener(key);
}
protected void finalize() throws Throwable {
super.finalize();
_jumper.finalize();
}
/**
* Invoked when the CLR counterpart request to release the instance.
*/
public synchronized void release() {
_jumper.release();
}
/// all other methods of org.mases.jcobridge.IJCListener
//@Override
public void windowActivated(java.awt.event.WindowEvent arg0) {
org.mases.jnet.EventResult executionResult = new org.mases.jnet.EventResult();
_jumper.raiseEvent("windowActivated", executionResult, arg0);
if (!executionResult.hasImplementation()) {
super.windowActivated(arg0);
}
}
/// other methods
} from the snippet above a new class EventResult {
boolean _hasImplementation = false;
Object _returnData;
public boolean getHasImplementation() {
return _hasImplementation;
}
public boolean setHasImplementation(boolean hasImplementation) {
_hasImplementation = hasImplementation;
}
public Object getReturnData() {
return _returnData;
}
public void setReturnData(Object retData) {
_returnData = retData;
}
} To obtain the previous extended behavior maybe a new class shall be created which extends |
Maybe the changes requested from #512 (comment) shall be managed differentiating the repository between:
Point 1 can be associated to #513 since many classes are used from Netdroid or other projects based on JNetReflector |
Reopen since #525 partially covers the needs of this issue |
Latest step to cover the request of masesgroup/netdroid#75 is to add a sort of method filter using a new configuration property:
If a class does not belong to the new property, the tool will use a the default pattern |
…hCallbacks to manage classes which defines methods and optionally declares some methods to be managed as callbacks
… to manage classes which defines methods and optionally declares some methods to be managed as callbacks (#528)
Looking at the code in masesgroup/netdroid#101 generated using latest JNetReflector a missing functionality is not available. When a method is overridden the base method sometime shall be invoked like in the example reported in masesgroup/netdroid#75 (comment). public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState, PersistableBundle pers) {
super.onCreate(savedInstanceState, pers);
setContentView(R.layout.activity_main);
}
} needs to invoke //@Override
public void onCreate(android.os.Bundle arg0, android.os.PersistableBundle arg1) {
org.mases.jnet.developed.JNetEventResult eventDataExchange = new org.mases.jnet.developed.JNetEventResult();
raiseEvent("onCreate", eventDataExchange, arg0, arg1); if (!eventDataExchange.getHasOverride()) super.onCreate(arg0, arg1);
} |
* Update on #552 * #512 (comment): Added invocation of base methods
Originally posted by @masesdevelopers in masesgroup/netdroid#75 (comment)
The text was updated successfully, but these errors were encountered: