List of usage examples for java.lang Runnable run
public abstract void run();
Runnable
is used to create a thread, starting the thread causes the object's run
method to be called in that separately executing thread. From source file:Main.java
public static void runFlipHorizonAnimation(@NonNull View view, long duration, final Runnable rWhenEnd) { view.setAlpha(0);/*from w w w . ja v a 2 s.c om*/ AnimatorSet set = new AnimatorSet(); ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(view, "rotationY", -180f, 0f); ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f); set.setDuration(duration); set.playTogether(objectAnimator1, objectAnimator2); if (rWhenEnd != null) set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { rWhenEnd.run(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); set.start(); }
From source file:com.haulmont.cuba.web.gui.components.WebComponentsHelper.java
/** * Add actions to vaadin action container. * * @param container any {@link Action.Container} * @param actions map of actions/*from ww w .j a va 2 s . c o m*/ */ public static void setActions(Action.Container container, Map<Action, Runnable> actions) { container.addActionHandler(new Action.Handler() { @Override public Action[] getActions(Object target, Object sender) { Set<Action> shortcuts = actions.keySet(); return shortcuts.toArray(new Action[shortcuts.size()]); } @Override public void handleAction(Action action, Object sender, Object target) { Runnable runnable = actions.get(action); if (runnable != null) { runnable.run(); } } }); }
From source file:Main.java
public static void SlideInRight(View v, final Runnable onComplete) { v.clearAnimation();/*from w ww . jav a 2 s . c o m*/ TranslateAnimation aout = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f); aout.setDuration(300); v.startAnimation(aout); if (onComplete != null) aout.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { } @Override public void onAnimationRepeat(Animation arg0) { } @Override public void onAnimationEnd(Animation arg0) { onComplete.run(); } }); }
From source file:net.vleu.par.android.rpc.Transceiver.java
/** * Ensures that application has a fresh permission from the user to use all * of his Google accounts/*from w w w . ja va2 s . co m*/ * * @param activity * The Activity context to use for launching a new sub-Activity * to prompt the user for a password if necessary; used only to * call startActivity(); must not be null. * @param onUserResponse * If not null, will be called in the main thread after the user * answered for all accounts */ public static void askUserForPermissionsIfNecessary(final Activity activity, final Runnable onUserResponse) { final Account[] allAcounts = listGoogleAccounts(activity); final Runnable callback = new Runnable() { int count = 0; @Override public void run() { this.count++; if (this.count == allAcounts.length && onUserResponse != null) onUserResponse.run(); } }; for (final Account account : allAcounts) askUserForSinglePermissionIfNecessary(activity, callback, account); }
From source file:io.fabric8.jube.local.NodeHelper.java
/** * Performs a block of code and updates the pod model if its updated *//*from w w w . j a v a2 s .c o m*/ public static void podTransaction(KubernetesModel model, Pod pod, Runnable task) { String oldJson = getPodJson(pod); task.run(); String newJson = getPodJson(pod); // lets only update the model if we've really changed the pod if (!java.util.Objects.equals(oldJson, newJson)) { model.updatePod(getName(pod), pod); } }
From source file:Main.java
public static void executeWithProgressDialogInBackground(final Runnable runnable, final StackPane target, final String text) { Thread th = new Thread() { @Override/*from w w w.j ava 2 s .c o m*/ public void run() { final Node progressIndicator = createProgressIndicator(); final Label label = new Label(text); try { Platform.runLater(new Runnable() { @Override public void run() { target.getChildren().add(progressIndicator); label.setWrapText(true); target.getChildren().add(label); } }); runnable.run(); } finally { Platform.runLater(new Runnable() { @Override public void run() { target.getChildren().remove(progressIndicator); target.getChildren().remove(label); } }); } } }; th.setDaemon(true); th.start(); }
From source file:io.hummer.util.ws.AbstractNode.java
@SuppressWarnings("all") public static void deploy(final Object service, String url, Handler<?>... handler) throws AbstractNodeException { long t1 = System.currentTimeMillis(); try {//from w w w . ja v a 2 s. c o m URL u = new URL(url); if (strUtil.isEmpty(System.getProperty(SYSPROP_HTTP_SERVER_PROVIDER_CLASS))) { System.setProperty(SYSPROP_HTTP_SERVER_PROVIDER_CLASS, JettyHttpServerProvider.class.getName()); } ContextHandlerCollection chc = new ContextHandlerCollection(); // disable log output from Metro and Jetty java.util.logging.Logger.getAnonymousLogger().getParent().setLevel(Level.WARNING); Class<?> cls3 = org.eclipse.jetty.server.Server.class; Class<?> cls4 = org.eclipse.jetty.server.AbstractConnector.class; org.apache.log4j.Level lev3 = Logger.getLogger(cls3).getLevel(); org.apache.log4j.Level lev4 = Logger.getLogger(cls4).getLevel(); Logger.getLogger(cls3).setLevel(org.apache.log4j.Level.WARN); Logger.getLogger(cls4).setLevel(org.apache.log4j.Level.WARN); JettyHttpServer httpServer = httpServers.get(u.getPort()); Server server = servers.get(u.getPort()); if (httpServer == null) { org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog()); server = new Server(u.getPort()); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(u.getPort()); connector.setAcceptQueueSize(1000); connector.setThreadPool(new ExecutorThreadPool(GlobalThreadPool.getExecutorService())); server.setConnectors(new Connector[] { connector }); server.setHandler(chc); httpServer = new JettyHttpServer(server, true); httpServers.put(u.getPort(), httpServer); servers.put(u.getPort(), server); if (!server.isStarted()) server.start(); } JettyHttpContext wsContext1 = (JettyHttpContext) httpServer.createContext(u.getPath()); Endpoint endpoint = Endpoint.create(service); if (service instanceof AbstractNode) { if (((AbstractNode) service).endpoint != null) logger.warn("AbstractNode " + service + " has apparently been double-deployed, " + "because there already exists an endpoint for this instance."); ((AbstractNode) service).endpoint = endpoint; } // add JAX-WS handlers (e.g., needed for TeCoS invocation intercepting...) List<Handler> handlers = endpoint.getBinding().getHandlerChain(); handlers.addAll(Arrays.asList(handler)); endpoint.getBinding().setHandlerChain(handlers); if (service instanceof AbstractNode) { AbstractNode a = (AbstractNode) service; for (Handler h : handlers) if (!a.activeHandlers.contains(h)) a.activeHandlers.add(h); } Class<?> cls1 = org.eclipse.jetty.util.component.AbstractLifeCycle.class; Class<?> cls2 = org.eclipse.jetty.server.handler.ContextHandler.class; org.apache.log4j.Level lev1 = Logger.getLogger(cls1).getLevel(); org.apache.log4j.Level lev2 = Logger.getLogger(cls2).getLevel(); try { String bindUrl = u.getProtocol() + "://0.0.0.0:" + u.getPort() + u.getPath(); if (u.getQuery() != null) { bindUrl += "?" + u.getQuery(); } Logger.getLogger(cls1).setLevel(org.apache.log4j.Level.OFF); Logger.getLogger(cls2).setLevel(org.apache.log4j.Level.WARN); logger.info("Binding service to " + bindUrl); endpoint.publish(bindUrl); } catch (Exception e) { if (e instanceof BindException || (e.getCause() != null && e.getCause() instanceof BindException) || (e.getCause() != null && e.getCause().getCause() != null && e.getCause().getCause() instanceof BindException)) { /** we expect a BindException here, just swallow */ } else { logger.warn("Unexpected error.", e); } } finally { Logger.getLogger(cls1).setLevel(lev1); Logger.getLogger(cls2).setLevel(lev2); Logger.getLogger(cls3).setLevel(lev3); Logger.getLogger(cls4).setLevel(lev4); } Field f = endpoint.getClass().getDeclaredField("actualEndpoint"); f.setAccessible(true); // DO NOT do this (the two lines below), because HttpEndpoint creates some nasty // compile-time dependencies with respect to JAXWS-RT. At runtime, we can (hopefully) // assume that this class is present, in all newer Sun JVM implementations.. //HttpEndpoint httpEndpoint = (HttpEndpoint)f.get(e1); //httpEndpoint.publish(wsContext1); Object httpEndpoint = f.get(endpoint); httpEndpoint.getClass().getMethod("publish", Object.class).invoke(httpEndpoint, wsContext1); Endpoint e2 = Endpoint.create(new CrossdomainXML()); JettyHttpContext wsContext2 = (JettyHttpContext) httpServer.createContext("/crossdomain.xml"); e2.publish(wsContext2); // Also deploy as RESTful service.. if (service instanceof AbstractNode) { AbstractNode node = (AbstractNode) service; if (node.isRESTfulService()) { String path = u.getPath(); if (!path.contains("/")) path = "/"; path = "/rest"; String wadlURL = netUtil.getUrlBeforePath(u) + path + "/application.wadl"; if (logger.isDebugEnabled()) logger.debug("Deploying node as RESTful service: " + wadlURL); JettyHttpContext wsContext3 = (JettyHttpContext) httpServer.createContext(path); ResourceConfig rc = new PackagesResourceConfig(service.getClass().getPackage().getName(), AbstractNode.class.getPackage().getName()); HttpHandler h = RuntimeDelegate.getInstance().createEndpoint(rc, HttpHandler.class); wsContext3.setHandler(h); node.setWadlURL(wadlURL); } deployedNodes.put(url, node); } final HttpHandler h = wsContext1.getHandler(); wsContext1.setHandler(new HttpHandler() { public void handle(com.sun.net.httpserver.HttpExchange ex) throws IOException { if (!ex.getRequestMethod().equals("OPTIONS")) { addCORSHeaders(ex); h.handle(ex); //System.out.println(ex.getRequestMethod() + ": " + ex.getResponseHeaders() + " - " + new HashMap<>(ex.getResponseHeaders())); return; } if (ex.getRequestMethod().equals("OPTIONS")) { addCORSHeaders(ex); ex.sendResponseHeaders(200, -1); ex.getResponseBody().close(); return; } //System.out.println(new HashMap<>(ex.getResponseHeaders())); } }); // add shutdown task for this node if (service instanceof AbstractNode) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { Runnable r = ((AbstractNode) service).getTerminateTask(null); if (r != null) r.run(); } catch (Exception e) { } } }); } } catch (Exception e) { throw new AbstractNodeException(e); } long diff = System.currentTimeMillis() - t1; logger.info("Deployment took " + diff + "ms"); }
From source file:Main.java
public static void SlideOutLeft(View v, final Runnable onComplete) { v.clearAnimation();/*from w w w . j a v a 2s . c o m*/ TranslateAnimation aout = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, -1f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f); aout.setDuration(300); aout.setFillAfter(true); v.startAnimation(aout); if (onComplete != null) aout.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { } @Override public void onAnimationRepeat(Animation arg0) { } @Override public void onAnimationEnd(Animation arg0) { onComplete.run(); } }); }
From source file:io.fabric8.jube.local.NodeHelper.java
/** * Performs a block of code and updates the pod model if its updated *//*from w w w . j a v a2s . co m*/ public static void excludeFromProcessMonitor(ProcessMonitor monitor, Pod pod, Runnable task) { String id = getName(pod); monitor.addExcludedPodId(id); try { task.run(); } finally { monitor.removeExcludedPodId(id); } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java
@Deprecated public static void addEnterShortcut(com.haulmont.cuba.gui.components.TextField textField, final Runnable runnable) { JTextField impl = (JTextField) DesktopComponentsHelper.unwrap(textField); impl.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enter"); impl.getActionMap().put("enter", new ValidationAwareAction() { @Override//from ww w .j a va 2s .c o m public void actionPerformedAfterValidation(ActionEvent e) { runnable.run(); } }); }