Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/com/google/gwt/gen2/event/shared/JavaHandlerRegistry.java

Diff revisions: vs.
  @@ -1,71 +1,71 @@
1 - /*
2 - * Copyright 2008 Google Inc.
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 - * use this file except in compliance with the License. You may obtain a copy of
6 - * the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 - * License for the specific language governing permissions and limitations under
14 - * the License.
15 - */
16 -
17 - package com.google.gwt.gen2.event.shared;
18 -
19 - import com.google.gwt.gen2.event.shared.AbstractEvent.*;
20 -
21 - import java.util.*;
22 -
23 - /**
24 - * The default Handler manager's handler registry.
25 - */
26 - class JavaHandlerRegistry extends HashMap<AbstractEvent.Type, ArrayList<EventHandler>> {
27 -
28 - public void addHandler( AbstractEvent.Type eventKey, EventHandler handler ) {
29 - ArrayList<EventHandler> l = super.get( eventKey );
30 - if ( l == null ) {
31 - l = new ArrayList<EventHandler>();
32 - super.put( eventKey, l );
33 - }
34 - l.add( handler );
35 - }
36 -
37 - public void clearHandlers( Type<?, ?> type ) {
38 - super.remove( type );
39 - }
40 -
41 - public void fireEvent( AbstractEvent event ) {
42 - Type type = event.getType();
43 - int count = getHandlerCount( type );
44 - for ( int i = 0; i < count; i++ ) {
45 - EventHandler handler = getHandler( type, i );
46 - type.fire( handler, event );
47 - }
48 - }
49 -
50 - public EventHandler getHandler( AbstractEvent.Type eventKey, int index ) {
51 - assert (index < getHandlerCount( eventKey ));
52 - ArrayList<EventHandler> l = super.get( eventKey );
53 - return l.get( index );
54 - }
55 -
56 - public int getHandlerCount( AbstractEvent.Type eventKey ) {
57 - ArrayList<EventHandler> l = super.get( eventKey );
58 - if ( l == null ) {
59 - return 0;
60 - } else {
61 - return l.size();
62 - }
63 - }
64 -
65 - public void removeHandler( AbstractEvent.Type eventKey, EventHandler handler ) {
66 - ArrayList<EventHandler> l = super.get( eventKey );
67 - if ( l != null ) {
68 - l.remove( handler );
69 - }
70 - }
71 - }
1 + /*
2 + * Copyright 2008 Google Inc.
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 + * use this file except in compliance with the License. You may obtain a copy of
6 + * the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 + * License for the specific language governing permissions and limitations under
14 + * the License.
15 + */
16 +
17 + package com.google.gwt.gen2.event.shared;
18 +
19 + import com.google.gwt.gen2.event.shared.AbstractEvent.*;
20 +
21 + import java.util.*;
22 +
23 + /**
24 + * The default Handler manager's handler registry.
25 + */
26 + class JavaHandlerRegistry extends HashMap<AbstractEvent.Type, ArrayList<EventHandler>> {
27 +
28 + public void addHandler( AbstractEvent.Type eventKey, EventHandler handler ) {
29 + ArrayList<EventHandler> l = super.get( eventKey );
30 + if ( l == null ) {
31 + l = new ArrayList<EventHandler>();
32 + super.put( eventKey, l );
33 + }
34 + l.add( handler );
35 + }
36 +
37 + public void clearHandlers( Type<?, ?> type ) {
38 + super.remove( type );
39 + }
40 +
41 + public void fireEvent( AbstractEvent event ) {
42 + Type type = event.getType();
43 + int count = getHandlerCount( type );
44 + for ( int i = 0; i < count; i++ ) {
45 + EventHandler handler = getHandler( type, i );
46 + type.fire( handler, event );
47 + }
48 + }
49 +
50 + public EventHandler getHandler( AbstractEvent.Type eventKey, int index ) {
51 + assert (index < getHandlerCount( eventKey ));
52 + ArrayList<EventHandler> l = super.get( eventKey );
53 + return l.get( index );
54 + }
55 +
56 + public int getHandlerCount( AbstractEvent.Type eventKey ) {
57 + ArrayList<EventHandler> l = super.get( eventKey );
58 + if ( l == null ) {
59 + return 0;
60 + } else {
61 + return l.size();
62 + }
63 + }
64 +
65 + public void removeHandler( AbstractEvent.Type eventKey, EventHandler handler ) {
66 + ArrayList<EventHandler> l = super.get( eventKey );
67 + if ( l != null ) {
68 + l.remove( handler );
69 + }
70 + }
71 + }