mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
support EventHandler
This commit is contained in:
parent
02a7246732
commit
383bd3534d
83
CS2JLibrary/NetFramework/System/EventHandler.xml
Normal file
83
CS2JLibrary/NetFramework/System/EventHandler.xml
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
-->
|
||||
<Delegate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports>
|
||||
<Import>CS2JNet.System.EventHandler</Import>
|
||||
</Imports>
|
||||
<Java>EventHandler*[${TEventArgs}]*</Java>
|
||||
<Name>System.EventHandler</Name>
|
||||
<TypeParams>
|
||||
<Name>TEventArgs</Name>
|
||||
</TypeParams>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
<Type>System.Object</Type>
|
||||
</Inherits>
|
||||
<Methods>
|
||||
<Method static="true">
|
||||
<Imports>
|
||||
<Import>CS2JNet.System.__MultiEventHandler</Import>
|
||||
</Imports>
|
||||
<Java>__MultiEventHandler.Combine(${a},${b})</Java>
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.EventHandler*[TEventArgs]*</Type>
|
||||
<Name>a</Name>
|
||||
</Param>
|
||||
<Param>
|
||||
<Type>System.EventHandler*[TEventArgs]*</Type>
|
||||
<Name>b</Name>
|
||||
</Param>
|
||||
</Params>
|
||||
<Name>Combine</Name>
|
||||
<TypeParams>
|
||||
<Name>T</Name>
|
||||
</TypeParams>
|
||||
<Return>System.EventHandler*[TEventArgs]*</Return>
|
||||
</Method>
|
||||
<Method static="true">
|
||||
<Imports>
|
||||
<Import>CS2JNet.System.__MultiEventHandler</Import>
|
||||
</Imports>
|
||||
<Java>__MultiEventHandler.Remove(${a},${b})</Java>
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.EventHandler*[TEventArgs]*</Type>
|
||||
<Name>a</Name>
|
||||
</Param>
|
||||
<Param>
|
||||
<Type>System.EventHandler*[TEventArgs]*</Type>
|
||||
<Name>b</Name>
|
||||
</Param>
|
||||
</Params>
|
||||
<Name>Remove</Name>
|
||||
<TypeParams>
|
||||
<Name>T</Name>
|
||||
</TypeParams>
|
||||
<Return>System.EventHandler*[TEventArgs]*</Return>
|
||||
</Method>
|
||||
</Methods>
|
||||
<Invoke>
|
||||
<Java>${this:16}.Invoke(${sender}, ${e})</Java>
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.Object</Type>
|
||||
<Name>sender</Name>
|
||||
</Param>
|
||||
<Param>
|
||||
<Type>TEventArgs</Type>
|
||||
<Name>e</Name>
|
||||
</Param>
|
||||
</Params>
|
||||
<Name>Invoke</Name>
|
||||
<TypeParams />
|
||||
<Return>void</Return>
|
||||
</Invoke>
|
||||
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>10gQjwZURfUiWRQQZHHLhjzvyao=</DigestValue></Reference></SignedInfo><SignatureValue>LqaNkGhL5G8I7kNkIqKGWaU1y3aQS1NNeLnUK0bAhiQDk2aatsldV3RvSyA+sUyHJ/La+jYz5chPUmZusenax1EoM9CvvOoP9Uzpz4V4VtpWWBJr65Hc9rLhyfkgxoGgSnuvFOxxLVd/t1LqzE+SHlfgaxYTttwwIoSqHksEsAc=</SignatureValue></Signature>
|
||||
</Delegate>
|
30
CS2JLibrary/src/CS2JNet/System/EventHandler.java
Normal file
30
CS2JLibrary/src/CS2JNet/System/EventHandler.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2007,2008,2009,2010 Rustici Software, LLC
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
package CS2JNet.System;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EventHandler<TEventArgs> {
|
||||
void Invoke(Object sender, TEventArgs value) throws Exception ;
|
||||
|
||||
List<EventHandler<TEventArgs>> GetInvocationList() throws Exception ;
|
||||
|
||||
}
|
78
CS2JLibrary/src/CS2JNet/System/__MultiEventHandler.java
Normal file
78
CS2JLibrary/src/CS2JNet/System/__MultiEventHandler.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
|
||||
package CS2JNet.System;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import CS2JNet.JavaSupport.util.ListSupport;
|
||||
|
||||
/**
|
||||
* @author keving
|
||||
*
|
||||
*/
|
||||
public class __MultiEventHandler<TEventArgs> implements EventHandler<TEventArgs> {
|
||||
|
||||
public void Invoke(Object other, TEventArgs e) throws Exception {
|
||||
for (EventHandler<TEventArgs> d : this.GetInvocationList())
|
||||
{
|
||||
d.Invoke(other, e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<EventHandler<TEventArgs>> _invocationList = new ArrayList<EventHandler<TEventArgs>>();
|
||||
public static <TEventArgs>EventHandler<TEventArgs> Combine(EventHandler<TEventArgs> a, EventHandler<TEventArgs> b) throws Exception {
|
||||
if (a == null)
|
||||
return b;
|
||||
|
||||
if (b == null)
|
||||
return a;
|
||||
|
||||
__MultiEventHandler<TEventArgs> ret = new __MultiEventHandler<TEventArgs>();
|
||||
ret._invocationList = a.GetInvocationList();
|
||||
ret._invocationList.addAll(b.GetInvocationList());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static <TEventArgs>EventHandler<TEventArgs> Remove(EventHandler<TEventArgs> a, EventHandler<TEventArgs> b) throws Exception {
|
||||
if (a == null || b == null)
|
||||
return a;
|
||||
|
||||
List<EventHandler<TEventArgs>> aInvList = a.GetInvocationList();
|
||||
List<EventHandler<TEventArgs>> newInvList = ListSupport.removeFinalStretch(aInvList, b.GetInvocationList());
|
||||
if (aInvList == newInvList)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
__MultiEventHandler<TEventArgs> ret = new __MultiEventHandler<TEventArgs>();
|
||||
ret._invocationList = newInvList;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public List<EventHandler<TEventArgs>> GetInvocationList() throws Exception {
|
||||
return _invocationList;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user