/** * Notifies this actor's listeners of the event. The event is not propagated to any parents. * Before notifying the listeners, this actor is set as the {@link Event#getListenerActor() * listener actor}. The event {@link Event#setTarget(Actor) target} must be set before calling * this method. If this actor is not in the stage, the stage must be set before calling this * method. * * @param capture If true, the capture listeners will be notified instead of the regular * listeners. * @return true of the event was {@link Event#cancel() cancelled}. */ public boolean notify(Event event, boolean capture) { if (event.getTarget() == null) throw new IllegalArgumentException("The event target cannot be null."); DelayedRemovalArray<EventListener> listeners = capture ? captureListeners : this.listeners; if (listeners.size == 0) return event.isCancelled(); event.setListenerActor(this); event.setCapture(capture); if (event.getStage() == null) event.setStage(stage); listeners.begin(); for (int i = 0, n = listeners.size; i < n; i++) { EventListener listener = listeners.get(i); if (listener.handle(event)) { event.handle(); if (event instanceof InputEvent) { InputEvent inputEvent = (InputEvent) event; if (inputEvent.getType() == Type.touchDown) { event .getStage() .addTouchFocus( listener, this, inputEvent.getTarget(), inputEvent.getPointer(), inputEvent.getButton()); } } } } listeners.end(); return event.isCancelled(); }
private void fireEvent(HideEvent event) { if (listeners != null) { for (Iterator<EventListener> it = listeners.iterator(); it.hasNext(); ) { EventListener l = it.next(); l.notificationHidden(event); } } }
/** * Fires an event to all observers. * * @param type Kind of event * @throws NullPointerException if type is null */ protected final void fireEvent(/*@Nonnull*/ final EventType type) { Check.notNull(type, "Event type cannot be null"); for (final EventListener listener : listeners) { assert listener != null : "addListener rejects null"; listener.onGlyphRendererEvent(type); } }
protected void notifyEvent(Event e) { myListenersLock.lock(); try { for (EventListener listener : myListeners) { listener.onEvent(e); } } finally { myListenersLock.unlock(); } }
/** * Return the condition to use. * * <p>Matches the {@code condition} attribute of the {@link EventListener} annotation or any * matching attribute on a composed annotation that is meta-annotated with {@code @EventListener}. */ protected String getCondition() { if (this.condition == null) { EventListener eventListener = AnnotatedElementUtils.findMergedAnnotation(this.method, EventListener.class); if (eventListener != null) { this.condition = eventListener.condition(); } } return this.condition; }
/** * Sets an event listener to be called when events occur, so they can be reported by the app as, * for example, Google Analytics events. If not set or set to null, no events will be reported. * * @param eventListener The event listener. * @throws IllegalArgumentException if the eventListener is an inner or anonymous class */ public static void setEventListener(EventListener eventListener) { if (eventListener != null && eventListener.getClass().getEnclosingClass() != null && !Modifier.isStatic(eventListener.getClass().getModifiers())) { throw new IllegalArgumentException( "The event listener cannot be an inner or anonymous class, because it will need to be serialized. Change it to a class of its own, or make it a static inner class."); } else { CustomActivityOnCrash.eventListener = eventListener; } }
public void setListener(EventListener eventListener) { switch (state) { case START: eventListener.onStart(type); break; case ERROR: eventListener.onError(type, message); break; case FINISH: eventListener.onFinish(type); break; } }
public void testDoc(String fileName) throws Exception { XComponent xDoc = null; EventListener xListener = new EventListener(); try { m_xGEB.addDocumentEventListener(xListener); System.out.println("Loading document: " + fileName + " ..."); PropertyValue[] loadProps = new PropertyValue[1]; loadProps[0] = new PropertyValue(); loadProps[0].Name = "ReadOnly"; loadProps[0].Value = new Boolean(true); String sourceFile = m_fileURL + m_SourceDir + fileName; xDoc = util.DesktopTools.loadDoc(m_xMSF, sourceFile, loadProps); System.out.println("... done"); { // apparently OnLayoutFinished is not sent for every doc??? // 10 seconds is evidently not enough for large documents int time = 0; while (!xListener.IsLayoutFinished() && (time < 30000)) { Thread.sleep(100); time += 100; } if (time >= 30000) { System.out.println("timeout: no OnLayoutFinished received"); } } System.out.println("Storing document: " + fileName + " ..."); XStorable xStor = UnoRuntime.queryInterface(XStorable.class, xDoc); String targetFile = m_fileURL + m_TargetDir + fileName; xStor.storeToURL(targetFile, new PropertyValue[0]); System.out.println("... done"); } finally { if (xDoc != null) { util.DesktopTools.closeDoc(xDoc); } if (xListener != null) { m_xGEB.removeDocumentEventListener(xListener); } } }
@Test public void testSetEditGeom() throws Exception { EditBlackboard bb = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); EventListener l = new EventListener(); bb.getListeners().add(l); bb.getGeoms().get(0).setChanged(true); assertEquals(1, bb.getGeoms().size()); EditGeom geom = bb.newGeom(null, ShapeType.LINE); assertEquals(2, bb.getGeoms().size()); assertTrue(bb.getGeoms().contains(geom)); assertEquals(EventType.ADD_GEOMS, l.event.getType()); assertEquals(geom, ((List) l.getEditBlackboardEvent().getNewValue()).get(0)); }
private synchronized void signalEventListeners(int event, int arg1, int arg2, String mrl) { for (EventListener listener : mEventListenerList) { switch (event) { case EVENT_ADDED: listener.onItemAdded(arg1, mrl); break; case EVENT_REMOVED: listener.onItemRemoved(arg1, mrl); break; case EVENT_MOVED: listener.onItemMoved(arg1, arg2, mrl); break; } } }
/** * Closes the app. If an event listener is provided, the close app event is invoked. Must only be * used from your error activity. * * @param activity The current error activity. Must not be null. * @param eventListener The event listener as obtained by calling getEventListenerFromIntent. */ public static void closeApplication(Activity activity, EventListener eventListener) { if (eventListener != null) { eventListener.onCloseAppFromErrorActivity(); } activity.finish(); killCurrentProcess(); }
public synchronized void registerListener(EventListener listener) { Class<? extends EventListener> listenerClass = listener.getClass(); for (Method method : listenerClass.getMethods()) { if (!method.isAnnotationPresent(EventHandler.class)) continue; if (method.getParameterTypes().length != 1) throw new IllegalArgumentException( "Method " + method.toString() + " in class " + method.getDeclaringClass().getName() + " has incorrect amount of parameters"); Class<? extends Event> eventClass = method.getParameterTypes()[0].asSubclass(Event.class); boolean senderExists = false; for (EventSender sender : eventSenders) { if (eventClass.isAssignableFrom(sender.getListenerEventClass())) sender.addHandler(listener, method); if (eventClass == sender.getListenerEventClass()) senderExists = true; } if (!senderExists) { EventSender sender = new EventSender(eventClass); eventSenders.add(sender); sender.addHandler(listener, method); } } }
/** TransactionService interface implementation. */ @Override public void start() throws CantStartServiceException { /** I will initialize the handling of com.bitdubai.platform events. */ EventListener eventListener; EventHandler eventHandler; eventListener = eventManager.getNewListener( EventType.INCOMING_CRYPTO_TRANSACTIONS_WAITING_TRANSFERENCE_EXTRA_USER); eventHandler = new IncomingCryptoTransactionsWaitingTransferenceExtraUserEventHandler(this); eventListener.setEventHandler(eventHandler); eventManager.addListener(eventListener); listenersAdded.add(eventListener); this.serviceStatus = ServiceStatus.STARTED; }
@Override public void clear() { final Collection<E> copy = Lists.newArrayList(delegate()); super.clear(); for (E element : copy) { listener.removed(element); } }
@Override public boolean add(E element) { final boolean added = super.add(element); if (added) { listener.added(element); } return added; }
/* * Test method for 'org.locationtech.udig.tools.edit.support.PixelCoordMap.deleteCoords(int, int)' */ @Test public void testDeleteCoords() { GeometryFactory factory = new GeometryFactory(); LinearRing ring1 = createShellRing(factory, 10); LinearRing ring2 = createShellRing(factory, 10); LinearRing ring3 = createShellRing(factory, 10); EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); EventListener l = new EventListener(); map.getListeners().add(l); Map<Geometry, EditGeom> mapping = map.setGeometries(ring1, null); mapping.putAll(map.addGeometry(ring2, null)); mapping.putAll(map.addGeometry(ring3, null)); assertPixMapState(map, 3, 5, 0, 0); List<Coordinate> modified = map.removeCoordsAtPoint(20, 10); assertEquals(6, modified.size()); assertEquals(3, mapping.get(ring1).getShell().getNumPoints()); assertEquals(3, mapping.get(ring1).getShell().getNumCoords()); EditBlackboardEvent editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(EventType.REMOVE_POINT, l.event.getType()); assertEquals(Point.valueOf(20, 10), editBlackboardEvent.getOldValue()); assertEquals(null, editBlackboardEvent.getNewValue()); assertEquals(3, mapping.get(ring2).getShell().getNumPoints()); assertEquals(3, mapping.get(ring2).getShell().getNumCoords()); assertEquals(3, mapping.get(ring3).getShell().getNumPoints()); assertEquals(3, mapping.get(ring3).getShell().getNumCoords()); assertEquals(0, map.getGeoms(20, 10).size()); // delete nothing modified = map.removeCoordsAtPoint(0, 0); assertEquals(0, modified.size()); // make sure this works on holes Polygon poly = createPolygon(factory, 10); mapping = map.setGeometries(poly, null); modified = map.removeCoordsAtPoint(25, 12); assertEquals(2, modified.size()); assertEquals(3, mapping.get(poly).getHoles().get(0).getNumCoords()); assertEquals(new Coordinate(15, 7), modified.get(0)); assertEquals(new Coordinate(15, 7), modified.get(1)); }
@Override public boolean remove(Object object) { final boolean removed = super.remove(object); if (removed) { @SuppressWarnings("unchecked") final E element = (E) object; listener.removed(element); } return removed; }
private void notifyListener(EventListener listener) { String currentProcess; if (dataImporter.getStatus() == DataImporter.Status.RUNNING_DELTA_DUMP) { currentProcess = Context.DELTA_DUMP; } else { currentProcess = Context.FULL_DUMP; } listener.onEvent( new ContextImpl(null, getVariableResolver(), null, currentProcess, session, null, this)); }
/** * Given an Intent, restarts the app and launches a startActivity to that intent. The flags * NEW_TASK and CLEAR_TASK are set if the Intent does not have them, to ensure the app stack is * fully cleared. If an event listener is provided, the restart app event is invoked. Must only be * used from your error activity. * * @param activity The current error activity. Must not be null. * @param intent The Intent. Must not be null. * @param eventListener The event listener as obtained by calling getEventListenerFromIntent. */ public static void restartApplicationWithIntent( Activity activity, Intent intent, EventListener eventListener) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); if (eventListener != null) { eventListener.onRestartAppFromErrorActivity(); } activity.finish(); activity.startActivity(intent); killCurrentProcess(); }
@Override public boolean retainAll(Collection<?> elements) { final Collection<E> copy = Lists.newArrayList(delegate()); // this leaves all elements in copy which will be deleted in our collection copy.removeAll(elements); final boolean retained = super.retainAll(elements); for (E element : copy) { listener.removed(element); } return retained; }
@Test public void testReceiveEvent() throws Exception { EventBus eventBus = new EventBus("test"); EventListener listener = new EventListener(); eventBus.register(listener); eventBus.post(new TestEvent(200)); eventBus.post(new TestEvent(300)); eventBus.post(new TestEvent(400)); System.out.println("最后message的值是:" + listener.getLastMessage()); eventBus.unregister(listener); eventBus.post(new TestEvent(500)); System.out.println("没有监控的情况下,最后message的值是:" + listener.getLastMessage()); }
private static void dispatchEventImpl(Event evt, Element elem, EventListener listener) { // If this element has capture... if (elem == sCaptureElem) { // ... and it's losing capture, clear sCaptureElem. if (eventGetType(evt) == Event.ONLOSECAPTURE) { sCaptureElem = null; } } // Pass the event to the listener. listener.onBrowserEvent(evt); }
private List<ResolvableType> resolveDeclaredEventTypes() { int count = this.method.getParameterCount(); if (count > 1) { throw new IllegalStateException( "Maximum one parameter is allowed for event listener method: " + this.method); } EventListener ann = getEventListener(); if (ann != null && ann.classes().length > 0) { List<ResolvableType> types = new ArrayList<>(); for (Class<?> eventType : ann.classes()) { types.add(ResolvableType.forClass(eventType)); } return types; } else { if (count == 0) { throw new IllegalStateException( "Event parameter is mandatory for event listener method: " + this.method); } return Collections.singletonList(ResolvableType.forMethodParameter(this.method, 0)); } }
@Test public void testRemoveGeoms() throws Exception { EventListener l = new EventListener(); EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, new AffineTransform(), layerToWorld); map.getListeners().add(l); GeometryFactory factory = new GeometryFactory(); map.getListeners().add(l); map.setGeometries(factory.createPoint(new Coordinate(10, 10)), null); map.addGeometry(factory.createPoint(new Coordinate(20, 10)), null); Coordinate coordinate = new Coordinate(30, 10); map.addGeometry(factory.createPoint(coordinate), null); Coordinate coordinate2 = new Coordinate(40, 10); map.addGeometry(factory.createPoint(coordinate2), null); List<EditGeom> toRemove = new ArrayList<EditGeom>(map.getGeoms()); toRemove.remove(0); toRemove.remove(0); assertTrue(map.getCoords(30, 10).contains(coordinate)); assertTrue(map.getCoords(40, 10).contains(coordinate2)); assertEquals(1, map.getGeoms(30, 10).size()); assertEquals(1, map.getGeoms(40, 10).size()); List<EditGeom> removed = map.removeGeometries(toRemove); assertTrue(toRemove.containsAll(removed)); // this is specific to this case. I know that all geometries in toRemove were in the blackboard // this test is not true for the more general case assertTrue(removed.containsAll(toRemove)); assertTrue(((List) l.getEditBlackboardEvent().getOldValue()).contains(toRemove.get(0))); assertTrue(((List) l.getEditBlackboardEvent().getOldValue()).contains(toRemove.get(1))); assertEquals(2, ((List) l.getEditBlackboardEvent().getOldValue()).size()); assertFalse(map.getCoords(30, 10).contains(coordinate)); assertFalse(map.getCoords(40, 10).contains(coordinate2)); assertEquals(0, map.getGeoms(30, 10).size()); assertEquals(0, map.getGeoms(40, 10).size()); }
private synchronized Cluster clusterFor(EventListener eventListener) { Cluster cluster = clusterSelector.selectCluster(eventListener); if (cluster == null) { Class listenerType = eventListener.getClass(); if (eventListener instanceof EventListenerProxy) { listenerType = ((EventListenerProxy) eventListener).getTargetType(); } throw new EventListenerSubscriptionFailedException( format( "Unable to subscribe [%s] to the Event Bus. There is no suitable cluster for it. " + "Make sure the ClusterSelector is configured properly", listenerType.getName())); } if (clusters.add(cluster)) { terminal.onClusterCreated(cluster); } return cluster; }
protected void fireEventForUnrestrictedListeners(Event event) { for (EventListener listener : unrestrictedListeners) { listener.onEvent(event); } }
@Override public void handleEvent(E e) { for (EventListener<E> listener : listeners) { listener.handleEvent(e); } }
public ServerEventListener<B> priority(Priority priority) { super.priority(priority); return this; }
public ServerEventListener<B> post() { super.post(); return this; }
protected final void fireEvent(final AntEventSummary event) { for (Iterator itr = listeners.iterator(); itr.hasNext(); ) { final EventListener lstr = (EventListener) itr.next(); lstr.eventReceived(event); } }