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 scaleShow(final View view, final Runnable rWhenEnd) { if (view.getVisibility() == View.VISIBLE) { view.setVisibility(View.VISIBLE); if (rWhenEnd != null) { rWhenEnd.run(); }/*from w ww. ja v a 2 s .co m*/ return; } if (view.getWindowToken() == null) { view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { @Override public void onViewAttachedToWindow(View v) { scaleShow(view); } @Override public void onViewDetachedFromWindow(View v) { } }); } ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0f, 1f); ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0f, 1f); AnimatorSet set = new AnimatorSet(); set.playTogether(scaleX, scaleY); set.setDuration(DURATION_SHORT); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.VISIBLE); if (rWhenEnd != null) { rWhenEnd.run(); } } @Override public void onAnimationCancel(Animator animation) { view.setVisibility(View.VISIBLE); if (rWhenEnd != null) { rWhenEnd.run(); } } @Override public void onAnimationRepeat(Animator animation) { } }); set.start(); }
From source file:Main.java
public static void postOnPreDraw(final View view, final Runnable runnable) { view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override/*from ww w . j a va2 s. co m*/ public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); runnable.run(); return true; } }); }
From source file:Main.java
public static void runInThread(final Runnable runnable) throws Throwable { final AtomicReference<Throwable> exception = new AtomicReference<Throwable>(); Runnable exceptionGuard = new Runnable() { public void run() { try { runnable.run(); } catch (Throwable throwable) { exception.set(throwable); }//from w w w. j av a 2 s . c om } }; Thread thread = new Thread(exceptionGuard); thread.setDaemon(true); thread.start(); thread.join(); if (exception.get() != null) { throw exception.get(); } }
From source file:com.connectsdk.core.Util.java
public static void runInBackground(Runnable runnable, boolean forceNewThread) { if (forceNewThread || isMain()) { executor.execute(runnable);/*from www . j a va 2 s .c o m*/ } else { runnable.run(); } }
From source file:eu.esdihumboldt.util.http.ProxyUtil.java
/** * Add a proxy initializer. It will be called before the first proxy usage * //from ww w . ja v a2s . com * @param initializer the initializer */ public static void addInitializer(Runnable initializer) { synchronized (initializers) { if (initialized) { try { initializer.run(); } catch (Exception e) { _log.error("Error executing proxy initializer", e); //$NON-NLS-1$ } } else { initializers.add(initializer); } } }
From source file:de.blizzy.backup.Utils.java
static void runAsync(Display display, Runnable runnable) { if (Display.findDisplay(Thread.currentThread()) != null) { runnable.run(); } else if (!display.isDisposed()) { display.asyncExec(runnable);/*w w w. j av a 2 s . co m*/ } }
From source file:GUIUtils.java
public static void processOnSwingEventThread(Runnable todo, boolean wait) { if (todo == null) { throw new IllegalArgumentException("Runnable == null"); }//from w w w .j a v a2 s.c o m if (wait) { if (SwingUtilities.isEventDispatchThread()) { todo.run(); } else { try { SwingUtilities.invokeAndWait(todo); } catch (Exception ex) { throw new RuntimeException(ex); } } } else { if (SwingUtilities.isEventDispatchThread()) { todo.run(); } else { SwingUtilities.invokeLater(todo); } } }
From source file:com.anrisoftware.globalpom.threads.listenablefuture.DefaultListenableFuture.java
private static Runnable createExceptionRunnable(final Runnable runnable) { return new Runnable() { @Override/*from w w w . java2 s. co m*/ public void run() { try { runnable.run(); } catch (Exception e) { logger.error("", e); } } }; }
From source file:Main.java
/** * Thread-friendly wrapper method for <code>Component.setEnabled</code>. * @param enable//w w w .j a va2s . c o m * @param components * @deprecated */ @Deprecated public static void setEnabled(final boolean enable, final Component... components) { Runnable r = new Runnable() { public void run() { for (Component comp : components) { comp.setEnabled(enable); } } }; if (EventQueue.isDispatchThread()) { r.run(); return; } runTask(r, true); }
From source file:Main.StaticTools.java
/** Generates a windows beep */ public static void beep() { final Runnable runnable = (Runnable) Toolkit.getDefaultToolkit() .getDesktopProperty("win.sound.exclamation"); if (runnable != null) runnable.run(); }