jaroslav@435: /** jaroslav@435: * Back 2 Browser Bytecode Translator jaroslav@1787: * Copyright (C) 2012-2015 Jaroslav Tulach jaroslav@435: * jaroslav@435: * This program is free software: you can redistribute it and/or modify jaroslav@435: * it under the terms of the GNU General Public License as published by jaroslav@435: * the Free Software Foundation, version 2 of the License. jaroslav@435: * jaroslav@435: * This program is distributed in the hope that it will be useful, jaroslav@435: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@435: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@435: * GNU General Public License for more details. jaroslav@435: * jaroslav@435: * You should have received a copy of the GNU General Public License jaroslav@435: * along with this program. Look for COPYING file in the top folder. jaroslav@435: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@435: */ jaroslav@435: package org.apidesign.bck2brwsr.htmlpage.api; jaroslav@435: jaroslav@435: /** Controller created via {@link OnEvent#of(org.apidesign.bck2brwsr.htmlpage.api.Element[])}. jaroslav@435: * jaroslav@435: * @author Jaroslav Tulach jaroslav@435: */ jaroslav@435: public final class OnController { jaroslav@435: private final Element[] arr; jaroslav@435: private final OnEvent event; jaroslav@435: jaroslav@435: OnController(OnEvent event, Element[] arr) { jaroslav@435: this.event = event; jaroslav@435: this.arr = arr; jaroslav@435: } jaroslav@435: jaroslav@813: /** Registers an event handler on associated {@link OnEvent} jaroslav@813: * and {@link Element} jaroslav@813: * jaroslav@813: * @param handler the handler to be called when the event occurs jaroslav@813: */ jaroslav@813: public void perform(final OnHandler handler) { jaroslav@813: for (Element e : arr) { jaroslav@813: e.on(event, handler); jaroslav@813: } jaroslav@813: } jaroslav@813: jaroslav@435: /** Registers a runnable to be performed on associated {@link OnEvent} jaroslav@435: * and {@link Element}. jaroslav@435: * jaroslav@435: * @see OnEvent#of jaroslav@435: */ jaroslav@813: public void perform(final Runnable r) { jaroslav@813: class W implements OnHandler { jaroslav@813: @Override jaroslav@813: public void onEvent(Object event) throws Exception { jaroslav@813: r.run(); jaroslav@813: } jaroslav@813: } jaroslav@813: perform(new W()); jaroslav@813: OnHandler w = new W(); jaroslav@435: for (Element e : arr) { jaroslav@813: e.on(event, w); jaroslav@435: } jaroslav@435: } jaroslav@435: }