org-netbeans-api-progress

16:39:27.667 INFO  jd.cli.Main - Decompiling org-netbeans-api-progress.jar
package org.netbeans.api.progress;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JLabel;
import org.netbeans.modules.progress.spi.InternalHandle;

public final class ProgressHandle
{
  private static final Logger LOG = Logger.getLogger(ProgressHandle.class.getName());
  private InternalHandle internal;
  
  ProgressHandle(InternalHandle paramInternalHandle)
  {
    LOG.fine(paramInternalHandle.getDisplayName());
    internal = paramInternalHandle;
  }
  
  public void start()
  {
    start(0, -1L);
  }
  
  public void start(int paramInt)
  {
    start(paramInt, -1L);
  }
  
  public void start(int paramInt, long paramLong)
  {
    internal.start("", paramInt, paramLong);
  }
  
  public void switchToIndeterminate()
  {
    internal.toIndeterminate();
  }
  
  public void suspend(String paramString)
  {
    LOG.log(Level.FINE, "{0}: {1}", new Object[] { internal.getDisplayName(), paramString });
    internal.toSilent(paramString);
  }
  
  public void switchToDeterminate(int paramInt)
  {
    internal.toDeterminate(paramInt, -1L);
  }
  
  public void switchToDeterminate(int paramInt, long paramLong)
  {
    internal.toDeterminate(paramInt, paramLong);
  }
  
  public void finish()
  {
    internal.finish();
  }
  
  public void progress(int paramInt)
  {
    progress(null, paramInt);
  }
  
  public void progress(String paramString)
  {
    progress(paramString, -2);
  }
  
  public void progress(String paramString, int paramInt)
  {
    LOG.log(Level.FINE, "{0}: {1}", new Object[] { internal.getDisplayName(), paramString });
    internal.progress(paramString, paramInt);
  }
  
  public void setInitialDelay(int paramInt)
  {
    internal.setInitialDelay(paramInt);
  }
  
  public void setDisplayName(String paramString)
  {
    LOG.fine(paramString);
    internal.requestDisplayNameChange(paramString);
  }
  
  JComponent extractComponent()
  {
    return internal.extractComponent();
  }
  
  InternalHandle getInternalHandle()
  {
    return internal;
  }
  
  JLabel extractDetailLabel()
  {
    return internal.extractDetailLabel();
  }
  
  JLabel extractMainLabel()
  {
    return internal.extractMainLabel();
  }
  
  /* Error */
  String getDisplayName()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 5	org/netbeans/api/progress/ProgressHandle:internal	Lorg/netbeans/modules/progress/spi/InternalHandle;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 5	org/netbeans/api/progress/ProgressHandle:internal	Lorg/netbeans/modules/progress/spi/InternalHandle;
    //   11: invokevirtual 3	org/netbeans/modules/progress/spi/InternalHandle:getDisplayName	()Ljava/lang/String;
    //   14: aload_1
    //   15: monitorexit
    //   16: areturn
    //   17: astore_2
    //   18: aload_1
    //   19: monitorexit
    //   20: aload_2
    //   21: athrow
    // Line number table:
    //   Java source line #228	-> byte code offset #0
    //   Java source line #229	-> byte code offset #7
    //   Java source line #230	-> byte code offset #17
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	22	0	this	ProgressHandle
    //   5	14	1	Ljava/lang/Object;	Object
    //   17	4	2	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   7	16	17	finally
    //   17	20	17	finally
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.ProgressHandle
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress;

import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JLabel;
import org.netbeans.modules.progress.spi.InternalHandle;
import org.openide.util.Cancellable;

public final class ProgressHandleFactory
{
  public static ProgressHandle createHandle(String paramString)
  {
    return createHandle(paramString, null, null);
  }
  
  public static ProgressHandle createHandle(String paramString, Cancellable paramCancellable)
  {
    return createHandle(paramString, paramCancellable, null);
  }
  
  public static ProgressHandle createHandle(String paramString, Action paramAction)
  {
    return createHandle(paramString, null, paramAction);
  }
  
  public static ProgressHandle createHandle(String paramString, Cancellable paramCancellable, Action paramAction)
  {
    return new ProgressHandle(new InternalHandle(paramString, paramCancellable, true, paramAction));
  }
  
  public static JComponent createProgressComponent(ProgressHandle paramProgressHandle)
  {
    return paramProgressHandle.extractComponent();
  }
  
  public static JLabel createMainLabelComponent(ProgressHandle paramProgressHandle)
  {
    return paramProgressHandle.extractMainLabel();
  }
  
  public static JLabel createDetailLabelComponent(ProgressHandle paramProgressHandle)
  {
    return paramProgressHandle.extractDetailLabel();
  }
  
  public static ProgressHandle createSystemHandle(String paramString)
  {
    return createSystemHandle(paramString, null);
  }
  
  public static ProgressHandle createSystemHandle(String paramString, Cancellable paramCancellable)
  {
    return new ProgressHandle(new InternalHandle(paramString, paramCancellable, false, null));
  }
  
  public static ProgressHandle createSystemHandle(String paramString, Cancellable paramCancellable, Action paramAction)
  {
    return new ProgressHandle(new InternalHandle(paramString, paramCancellable, false, paramAction));
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.ProgressHandleFactory
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress;

public abstract interface ProgressRunnable<T>
{
  public abstract T run(ProgressHandle paramProgressHandle);
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.ProgressRunnable
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress;

import java.util.concurrent.atomic.AtomicReference;

final class ProgressUtils$1
  implements Runnable
{
  ProgressUtils$1(String paramString, AtomicReference paramAtomicReference, ProgressRunnable paramProgressRunnable) {}
  
  public void run()
  {
    ProgressHandle localProgressHandle = ProgressHandleFactory.createHandle(val$displayName);
    localProgressHandle.start();
    localProgressHandle.switchToIndeterminate();
    try
    {
      val$ref.set(val$operation.run(localProgressHandle));
    }
    finally
    {
      localProgressHandle.finish();
    }
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.ProgressUtils.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress;

import java.util.concurrent.Callable;

final class ProgressUtils$2
  implements Callable<T>
{
  ProgressUtils$2(ProgressRunnable paramProgressRunnable, ProgressHandle paramProgressHandle) {}
  
  public T call()
    throws Exception
  {
    return (T)val$operation.run(val$handle);
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.ProgressUtils.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress;

final class ProgressUtils$RunnableWrapper
  implements ProgressRunnable<Void>
{
  private final Runnable toRun;
  
  ProgressUtils$RunnableWrapper(Runnable paramRunnable)
  {
    toRun = paramRunnable;
  }
  
  public Void run(ProgressHandle paramProgressHandle)
  {
    toRun.run();
    return null;
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.ProgressUtils.RunnableWrapper
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress;

import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.SwingUtilities;
import org.netbeans.modules.progress.spi.RunOffEDTProvider;
import org.openide.util.RequestProcessor;
import org.openide.util.RequestProcessor.Task;

class ProgressUtils$Trivial
  implements RunOffEDTProvider
{
  private static final RequestProcessor WORKER = new RequestProcessor(ProgressUtils.class.getName());
  
  public void runOffEventDispatchThread(Runnable paramRunnable, String paramString, AtomicBoolean paramAtomicBoolean, boolean paramBoolean, int paramInt1, int paramInt2)
  {
    if (SwingUtilities.isEventDispatchThread())
    {
      RequestProcessor.Task localTask = WORKER.post(paramRunnable);
      localTask.waitFinished();
    }
    else
    {
      paramRunnable.run();
    }
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.ProgressUtils.Trivial
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.swing.SwingUtilities;
import org.netbeans.modules.progress.spi.RunOffEDTProvider;
import org.netbeans.modules.progress.spi.RunOffEDTProvider.Progress;
import org.openide.util.Lookup;
import org.openide.util.RequestProcessor;
import org.openide.util.RequestProcessor.Task;

public final class ProgressUtils
{
  private static final RunOffEDTProvider PROVIDER = ;
  private static final int DISPLAY_DIALOG_MS = 9450;
  private static final int DISPLAY_WAIT_CURSOR_MS = 50;
  
  private static RunOffEDTProvider getProvider()
  {
    RunOffEDTProvider localRunOffEDTProvider = (RunOffEDTProvider)Lookup.getDefault().lookup(RunOffEDTProvider.class);
    return localRunOffEDTProvider != null ? localRunOffEDTProvider : new Trivial(null);
  }
  
  public static void runOffEventDispatchThread(Runnable paramRunnable, String paramString, AtomicBoolean paramAtomicBoolean, boolean paramBoolean)
  {
    PROVIDER.runOffEventDispatchThread(paramRunnable, paramString, paramAtomicBoolean, paramBoolean, 50, 9450);
  }
  
  public static void runOffEventDispatchThread(Runnable paramRunnable, String paramString, AtomicBoolean paramAtomicBoolean, boolean paramBoolean, int paramInt1, int paramInt2)
  {
    PROVIDER.runOffEventDispatchThread(paramRunnable, paramString, paramAtomicBoolean, paramBoolean, paramInt1, paramInt2);
  }
  
  public static void showProgressDialogAndRun(Runnable paramRunnable, ProgressHandle paramProgressHandle, boolean paramBoolean)
  {
    if ((PROVIDER instanceof RunOffEDTProvider.Progress))
    {
      RunOffEDTProvider.Progress localProgress = (RunOffEDTProvider.Progress)PROVIDER;
      localProgress.showProgressDialogAndRun(paramRunnable, paramProgressHandle, paramBoolean);
    }
    else
    {
      PROVIDER.runOffEventDispatchThread(paramRunnable, paramProgressHandle.getDisplayName(), new AtomicBoolean(false), false, 0, 0);
    }
  }
  
  public static <T> T showProgressDialogAndRun(final ProgressRunnable<T> paramProgressRunnable, String paramString, boolean paramBoolean)
  {
    if ((PROVIDER instanceof RunOffEDTProvider.Progress))
    {
      localObject = (RunOffEDTProvider.Progress)PROVIDER;
      return (T)((RunOffEDTProvider.Progress)localObject).showProgressDialogAndRun(paramProgressRunnable, paramString, paramBoolean);
    }
    final Object localObject = new AtomicReference();
    PROVIDER.runOffEventDispatchThread(new Runnable()
    {
      public void run()
      {
        ProgressHandle localProgressHandle = ProgressHandleFactory.createHandle(val$displayName);
        localProgressHandle.start();
        localProgressHandle.switchToIndeterminate();
        try
        {
          localObject.set(paramProgressRunnable.run(localProgressHandle));
        }
        finally
        {
          localProgressHandle.finish();
        }
      }
    }, paramString, new AtomicBoolean(false), true, 0, 0);
    
    return (T)((AtomicReference)localObject).get();
  }
  
  public static void showProgressDialogAndRun(Runnable paramRunnable, String paramString)
  {
    showProgressDialogAndRun(new RunnableWrapper(paramRunnable), paramString, false);
  }
  
  public static <T> Future<T> showProgressDialogAndRunLater(ProgressRunnable<T> paramProgressRunnable, final ProgressHandle paramProgressHandle, boolean paramBoolean)
  {
    if ((PROVIDER instanceof RunOffEDTProvider.Progress))
    {
      localObject = (RunOffEDTProvider.Progress)PROVIDER;
      return ((RunOffEDTProvider.Progress)localObject).showProgressDialogAndRunLater(paramProgressRunnable, paramProgressHandle, paramBoolean);
    }
    Object localObject = new FutureTask(new Callable()
    {
      public T call()
        throws Exception
      {
        return (T)val$operation.run(paramProgressHandle);
      }
    });
    PROVIDER.runOffEventDispatchThread((Runnable)localObject, paramProgressHandle.getDisplayName(), new AtomicBoolean(false), true, 0, 0);
    return (Future<T>)localObject;
  }
  
  private static final class RunnableWrapper
    implements ProgressRunnable<Void>
  {
    private final Runnable toRun;
    
    RunnableWrapper(Runnable paramRunnable)
    {
      toRun = paramRunnable;
    }
    
    public Void run(ProgressHandle paramProgressHandle)
    {
      toRun.run();
      return null;
    }
  }
  
  private static class Trivial
    implements RunOffEDTProvider
  {
    private static final RequestProcessor WORKER = new RequestProcessor(ProgressUtils.class.getName());
    
    public void runOffEventDispatchThread(Runnable paramRunnable, String paramString, AtomicBoolean paramAtomicBoolean, boolean paramBoolean, int paramInt1, int paramInt2)
    {
      if (SwingUtilities.isEventDispatchThread())
      {
        RequestProcessor.Task localTask = WORKER.post(paramRunnable);
        localTask.waitFinished();
      }
      else
      {
        paramRunnable.run();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.ProgressUtils
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress.aggregate;

import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JLabel;
import org.openide.util.Cancellable;

public final class AggregateProgressFactory
{
  public static AggregateProgressHandle createHandle(String paramString, ProgressContributor[] paramArrayOfProgressContributor, Cancellable paramCancellable, Action paramAction)
  {
    return new AggregateProgressHandle(paramString, paramArrayOfProgressContributor, paramCancellable, paramAction, false);
  }
  
  public static ProgressContributor createProgressContributor(String paramString)
  {
    return new ProgressContributor(paramString);
  }
  
  public static AggregateProgressHandle createSystemHandle(String paramString, ProgressContributor[] paramArrayOfProgressContributor, Cancellable paramCancellable, Action paramAction)
  {
    return new AggregateProgressHandle(paramString, paramArrayOfProgressContributor, paramCancellable, paramAction, true);
  }
  
  public static JComponent createProgressComponent(AggregateProgressHandle paramAggregateProgressHandle)
  {
    return paramAggregateProgressHandle.extractComponent();
  }
  
  public static JLabel createMainLabelComponent(AggregateProgressHandle paramAggregateProgressHandle)
  {
    return paramAggregateProgressHandle.extractMainLabel();
  }
  
  public static JLabel createDetailLabelComponent(AggregateProgressHandle paramAggregateProgressHandle)
  {
    return paramAggregateProgressHandle.extractDetailLabel();
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.aggregate.AggregateProgressFactory
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress.aggregate;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JLabel;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.util.Cancellable;

public final class AggregateProgressHandle
{
  private static final Logger LOG = Logger.getLogger(AggregateProgressHandle.class.getName());
  private ProgressMonitor monitor;
  private ProgressHandle handle;
  static final int WORKUNITS = 10000;
  private boolean finished;
  private Collection<ProgressContributor> contributors;
  private int current;
  private String displayName;
  
  AggregateProgressHandle(String paramString, ProgressContributor[] paramArrayOfProgressContributor, Cancellable paramCancellable, Action paramAction, boolean paramBoolean)
  {
    handle = ProgressHandleFactory.createHandle(paramString, paramCancellable, paramAction);
    finished = false;
    contributors = new ArrayList();
    if (paramArrayOfProgressContributor != null) {
      for (int i = 0; i < paramArrayOfProgressContributor.length; i++) {
        addContributor(paramArrayOfProgressContributor[i]);
      }
    }
    displayName = paramString;
  }
  
  public void start()
  {
    start(-1L);
  }
  
  public synchronized void start(long paramLong)
  {
    handle.start(10000, paramLong);
    current = 0;
  }
  
  public synchronized void finish()
  {
    if (finished) {
      return;
    }
    finished = true;
    handle.finish();
  }
  
  public void suspend(String paramString)
  {
    LOG.log(Level.FINE, "{0}: {1}", new Object[] { displayName, paramString });
    handle.suspend(paramString);
  }
  
  public void setInitialDelay(int paramInt)
  {
    handle.setInitialDelay(paramInt);
  }
  
  public synchronized void addContributor(ProgressContributor paramProgressContributor)
  {
    if (finished) {
      return;
    }
    int i = contributors.size();
    int j = 0;
    double d = 0.0D;
    if (i > 0)
    {
      localIterator = contributors.iterator();
      while (localIterator.hasNext())
      {
        ProgressContributor localProgressContributor1 = (ProgressContributor)localIterator.next();
        j += localProgressContributor1.getRemainingParentWorkUnits();
        d += 1.0D - localProgressContributor1.getCompletedRatio();
      }
    }
    j = 10000;
    d = 0.0D;
    
    int k = (int)(j / (d + 1.0D));
    
    Iterator localIterator = contributors.iterator();
    while (localIterator.hasNext())
    {
      ProgressContributor localProgressContributor2 = (ProgressContributor)localIterator.next();
      int m = (int)((1.0D - localProgressContributor2.getCompletedRatio()) * k);
      
      j -= m;
      localProgressContributor2.setAvailableParentWorkUnits(m);
    }
    paramProgressContributor.setAvailableParentWorkUnits(j);
    contributors.add(paramProgressContributor);
    paramProgressContributor.setParent(this);
  }
  
  /**
   * @deprecated
   */
  int getCurrentProgress()
  {
    return current;
  }
  
  void processContributorStep(ProgressContributor paramProgressContributor, String paramString, int paramInt)
  {
    synchronized (this)
    {
      if (finished) {
        return;
      }
      current += paramInt;
      handle.progress(paramString, current);
    }
    if (monitor != null) {
      monitor.progressed(paramProgressContributor);
    }
  }
  
  void processContributorStart(ProgressContributor paramProgressContributor, String paramString)
  {
    synchronized (this)
    {
      if (finished) {
        return;
      }
      if (paramString != null) {
        handle.progress(paramString);
      }
    }
    if (monitor != null) {
      monitor.started(paramProgressContributor);
    }
  }
  
  void processContributorFinish(ProgressContributor paramProgressContributor)
  {
    synchronized (this)
    {
      if (finished) {
        return;
      }
      contributors.remove(paramProgressContributor);
      if (contributors.size() == 0) {
        finish();
      }
    }
    if (monitor != null) {
      monitor.finished(paramProgressContributor);
    }
  }
  
  public void setMonitor(ProgressMonitor paramProgressMonitor)
  {
    monitor = paramProgressMonitor;
  }
  
  public void setDisplayName(String paramString)
  {
    handle.setDisplayName(paramString);
  }
  
  JComponent extractComponent()
  {
    return ProgressHandleFactory.createProgressComponent(handle);
  }
  
  JLabel extractDetailLabel()
  {
    return ProgressHandleFactory.createDetailLabelComponent(handle);
  }
  
  JLabel extractMainLabel()
  {
    return ProgressHandleFactory.createMainLabelComponent(handle);
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.aggregate.AggregateProgressHandle
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress.aggregate;

public final class ProgressContributor
{
  private String id;
  private int workunits;
  private int current;
  private int parentUnits;
  private int lastParentedUnit;
  private AggregateProgressHandle parent;
  
  ProgressContributor(String paramString)
  {
    id = paramString;
    workunits = 0;
    current = 0;
    lastParentedUnit = 0;
  }
  
  public String getTrackingId()
  {
    return id;
  }
  
  void setParent(AggregateProgressHandle paramAggregateProgressHandle)
  {
    parent = paramAggregateProgressHandle;
  }
  
  int getWorkUnits()
  {
    return workunits;
  }
  
  int getRemainingParentWorkUnits()
  {
    return parentUnits;
  }
  
  void setAvailableParentWorkUnits(int paramInt)
  {
    parentUnits = paramInt;
  }
  
  double getCompletedRatio()
  {
    return workunits == 0 ? 0.0D : current / workunits;
  }
  
  public void start(int paramInt)
  {
    if (parent == null) {
      return;
    }
    workunits = paramInt;
    parent.processContributorStart(this, null);
  }
  
  public void finish()
  {
    if (parent == null) {
      return;
    }
    if (current < workunits) {
      progress(null, workunits);
    }
    parent.processContributorFinish(this);
  }
  
  public void progress(int paramInt)
  {
    progress(null, paramInt);
  }
  
  public void progress(String paramString)
  {
    progress(paramString, current);
  }
  
  public void progress(String paramString, int paramInt)
  {
    if (parent == null) {
      return;
    }
    assert ((paramInt >= current) && (paramInt <= workunits));
    if ((paramString != null) && (paramInt == current))
    {
      parent.processContributorStep(this, paramString, 0);
      return;
    }
    current = paramInt;
    int i = current - lastParentedUnit;
    double d = 1.0D / (parentUnits / (workunits - lastParentedUnit));
    if (i >= d)
    {
      int j = (int)(i / d);
      lastParentedUnit += (int)(j * d);
      parentUnits -= j;
      
      parent.processContributorStep(this, paramString, j);
    }
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.aggregate.ProgressContributor
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.progress.aggregate;

public abstract interface ProgressMonitor
{
  public abstract void started(ProgressContributor paramProgressContributor);
  
  public abstract void finished(ProgressContributor paramProgressContributor);
  
  public abstract void progressed(ProgressContributor paramProgressContributor);
}

/* Location:
 * Qualified Name:     org.netbeans.api.progress.aggregate.ProgressMonitor
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.progress.spi;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class Controller$1
  implements ActionListener
{
  Controller$1(Controller paramController) {}
  
  public void actionPerformed(ActionEvent paramActionEvent)
  {
    this$0.runNow();
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.progress.spi.Controller.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.progress.spi;

class Controller$2
  implements Runnable
{
  Controller$2(Controller paramController) {}
  
  public void run()
  {
    this$0.runNow();
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.progress.spi.Controller.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.progress.spi;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import org.netbeans.progress.module.TrivialProgressUIWorkerProvider;
import org.openide.util.Lookup;

public class Controller
{
  public static Controller defaultInstance;
  private ProgressUIWorker component;
  private TaskModel model;
  private List<ProgressEvent> eventQueue;
  private boolean dispatchRunning;
  protected Timer timer;
  private long timerStart = 0L;
  private static final int TIMER_QUANTUM = 400;
  public static final int INITIAL_DELAY = 500;
  
  public Controller(ProgressUIWorker paramProgressUIWorker)
  {
    component = paramProgressUIWorker;
    model = new TaskModel();
    eventQueue = new ArrayList();
    dispatchRunning = false;
    timer = new Timer(400, new ActionListener()
    {
      public void actionPerformed(ActionEvent paramAnonymousActionEvent)
      {
        runNow();
      }
    });
    timer.setRepeats(false);
  }
  
  public static synchronized Controller getDefault()
  {
    if (defaultInstance == null) {
      defaultInstance = new Controller(null);
    }
    return defaultInstance;
  }
  
  public Component getVisualComponent()
  {
    if (component == null) {
      getProgressUIWorker();
    }
    if ((component instanceof Component)) {
      return (Component)component;
    }
    return null;
  }
  
  ProgressUIWorker getProgressUIWorker()
  {
    if (component == null)
    {
      Object localObject = (ProgressUIWorkerProvider)Lookup.getDefault().lookup(ProgressUIWorkerProvider.class);
      if (localObject == null)
      {
        Logger.getLogger(Controller.class.getName()).log(Level.CONFIG, "Using fallback trivial progress implementation");
        localObject = new TrivialProgressUIWorkerProvider();
      }
      ProgressUIWorkerWithModel localProgressUIWorkerWithModel = ((ProgressUIWorkerProvider)localObject).getDefaultWorker();
      localProgressUIWorkerWithModel.setModel(defaultInstance.getModel());
      component = localProgressUIWorkerWithModel;
    }
    return component;
  }
  
  public TaskModel getModel()
  {
    return model;
  }
  
  void start(InternalHandle paramInternalHandle)
  {
    ProgressEvent localProgressEvent = new ProgressEvent(paramInternalHandle, 0, isWatched(paramInternalHandle));
    if ((this == getDefault()) && (paramInternalHandle.getInitialDelay() > 100)) {
      postEvent(localProgressEvent, true);
    } else {
      runImmediately(Collections.singleton(localProgressEvent));
    }
  }
  
  void finish(InternalHandle paramInternalHandle)
  {
    ProgressEvent localProgressEvent = new ProgressEvent(paramInternalHandle, 4, isWatched(paramInternalHandle));
    postEvent(localProgressEvent);
  }
  
  void toIndeterminate(InternalHandle paramInternalHandle)
  {
    ProgressEvent localProgressEvent = new ProgressEvent(paramInternalHandle, 5, isWatched(paramInternalHandle));
    model.updateSelection();
    postEvent(localProgressEvent);
  }
  
  void toSilent(InternalHandle paramInternalHandle, String paramString)
  {
    ProgressEvent localProgressEvent = new ProgressEvent(paramInternalHandle, 6, isWatched(paramInternalHandle), paramString);
    model.updateSelection();
    postEvent(localProgressEvent);
  }
  
  void toDeterminate(InternalHandle paramInternalHandle)
  {
    ProgressEvent localProgressEvent = new ProgressEvent(paramInternalHandle, 5, isWatched(paramInternalHandle));
    model.updateSelection();
    postEvent(localProgressEvent);
  }
  
  void progress(InternalHandle paramInternalHandle, String paramString, int paramInt, double paramDouble, long paramLong)
  {
    ProgressEvent localProgressEvent = new ProgressEvent(paramInternalHandle, paramString, paramInt, paramDouble, paramLong, isWatched(paramInternalHandle));
    postEvent(localProgressEvent);
  }
  
  ProgressEvent snapshot(InternalHandle paramInternalHandle, String paramString, int paramInt, double paramDouble, long paramLong)
  {
    if (paramInternalHandle.isInSleepMode()) {
      return new ProgressEvent(paramInternalHandle, 6, isWatched(paramInternalHandle), paramString);
    }
    return new ProgressEvent(paramInternalHandle, paramString, paramInt, paramDouble, paramLong, isWatched(paramInternalHandle));
  }
  
  void explicitSelection(InternalHandle paramInternalHandle)
  {
    InternalHandle localInternalHandle = model.getExplicitSelection();
    model.explicitlySelect(paramInternalHandle);
    ArrayList localArrayList = new ArrayList();
    localArrayList.add(paramInternalHandle.requestStateSnapshot());
    if ((localInternalHandle != null) && (localInternalHandle != paramInternalHandle)) {
      localArrayList.add(localInternalHandle.requestStateSnapshot());
    }
    runImmediately(localArrayList);
  }
  
  void displayNameChange(InternalHandle paramInternalHandle, int paramInt, double paramDouble, long paramLong, String paramString)
  {
    ArrayList localArrayList = new ArrayList();
    localArrayList.add(new ProgressEvent(paramInternalHandle, null, paramInt, paramDouble, paramLong, isWatched(paramInternalHandle), paramString));
    runImmediately(localArrayList);
  }
  
  private boolean isWatched(InternalHandle paramInternalHandle)
  {
    return model.getExplicitSelection() == paramInternalHandle;
  }
  
  void runImmediately(Collection<ProgressEvent> paramCollection)
  {
    synchronized (this)
    {
      eventQueue.addAll(paramCollection);
      dispatchRunning = true;
    }
    if (SwingUtilities.isEventDispatchThread()) {
      runNow();
    } else {
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          runNow();
        }
      });
    }
  }
  
  void postEvent(ProgressEvent paramProgressEvent)
  {
    postEvent(paramProgressEvent, false);
  }
  
  void postEvent(ProgressEvent paramProgressEvent, boolean paramBoolean)
  {
    synchronized (this)
    {
      eventQueue.add(paramProgressEvent);
      if (!dispatchRunning)
      {
        timerStart = System.currentTimeMillis();
        int i = timer.getInitialDelay();
        if ((paramBoolean) && (timer.getInitialDelay() > paramProgressEvent.getSource().getInitialDelay())) {
          i = paramProgressEvent.getSource().getInitialDelay();
        }
        dispatchRunning = true;
        resetTimer(i, true);
      }
      else if (paramBoolean)
      {
        if (System.currentTimeMillis() - timerStart > paramProgressEvent.getSource().getInitialDelay()) {
          resetTimer(paramProgressEvent.getSource().getInitialDelay(), true);
        }
      }
    }
  }
  
  protected void resetTimer(int paramInt, boolean paramBoolean)
  {
    timer.setInitialDelay(paramInt);
    if (paramBoolean) {
      timer.restart();
    }
  }
  
  public void runNow()
  {
    HashMap localHashMap = new HashMap();
    int i = 0;
    long l1 = 400L;
    
    InternalHandle localInternalHandle1 = model.getSelectedHandle();
    long l2 = System.currentTimeMillis();
    Object localObject1;
    synchronized (this)
    {
      localIterator = eventQueue.iterator();
      localObject1 = new ArrayList();
      while (localIterator.hasNext())
      {
        localObject2 = (ProgressEvent)localIterator.next();
        int j = l2 - ((ProgressEvent)localObject2).getSource().getTimeStampStarted() < ((ProgressEvent)localObject2).getSource().getInitialDelay() ? 1 : 0;
        if (((ProgressEvent)localObject2).getType() == 0)
        {
          if ((((ProgressEvent)localObject2).getSource().isCustomPlaced()) || (j == 0)) {
            model.addHandle(((ProgressEvent)localObject2).getSource());
          } else {
            ((Collection)localObject1).add(((ProgressEvent)localObject2).getSource());
          }
        }
        else if ((((ProgressEvent)localObject2).getType() == 4) && (!((Collection)localObject1).contains(((ProgressEvent)localObject2).getSource()))) {
          model.removeHandle(((ProgressEvent)localObject2).getSource());
        }
        ProgressEvent localProgressEvent1 = (ProgressEvent)localHashMap.get(((ProgressEvent)localObject2).getSource());
        if ((localProgressEvent1 != null) && (((ProgressEvent)localObject2).getType() == 4) && (((Collection)localObject1).contains(((ProgressEvent)localObject2).getSource())) && (j != 0))
        {
          localHashMap.remove(((ProgressEvent)localObject2).getSource());
          ((Collection)localObject1).remove(((ProgressEvent)localObject2).getSource());
        }
        else
        {
          if (localProgressEvent1 != null)
          {
            ((ProgressEvent)localObject2).copyMessageFromEarlier(localProgressEvent1);
            if (localProgressEvent1.isSwitched()) {
              ((ProgressEvent)localObject2).markAsSwitched();
            }
          }
          localHashMap.put(((ProgressEvent)localObject2).getSource(), localObject2);
        }
        localIterator.remove();
      }
      Object localObject2 = ((Collection)localObject1).iterator();
      while (((Iterator)localObject2).hasNext())
      {
        InternalHandle localInternalHandle2 = (InternalHandle)((Iterator)localObject2).next();
        long l3 = l2 - localInternalHandle2.getTimeStampStarted();
        if (l3 >= localInternalHandle2.getInitialDelay())
        {
          model.addHandle(localInternalHandle2);
        }
        else
        {
          eventQueue.add(new ProgressEvent(localInternalHandle2, 0, isWatched(localInternalHandle2)));
          ProgressEvent localProgressEvent2 = (ProgressEvent)localHashMap.remove(localInternalHandle2);
          if (localProgressEvent2.getType() != 0) {
            eventQueue.add(localProgressEvent2);
          }
          i = 1;
          l1 = Math.min(l1, localInternalHandle2.getInitialDelay() - l3);
        }
      }
    }
    ??? = model.getSelectedHandle();
    ??? = ??? == null ? localInternalHandle1 : ???;
    Iterator localIterator = localHashMap.values().iterator();
    if (component == null) {
      getProgressUIWorker();
    }
    while (localIterator.hasNext())
    {
      localObject1 = (ProgressEvent)localIterator.next();
      if (??? == ((ProgressEvent)localObject1).getSource()) {
        component.processSelectedProgressEvent((ProgressEvent)localObject1);
      }
      component.processProgressEvent((ProgressEvent)localObject1);
    }
    synchronized (this)
    {
      timer.stop();
      if (i != 0)
      {
        timerStart = System.currentTimeMillis();
        resetTimer((int)Math.max(100L, l1), true);
      }
      else
      {
        dispatchRunning = false;
        resetTimer(400, false);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.progress.spi.Controller
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.progress.spi;

import javax.swing.JComponent;
import javax.swing.JLabel;

public abstract interface ExtractedProgressUIWorker
  extends ProgressUIWorker
{
  public abstract JComponent getProgressComponent();
  
  public abstract JLabel getMainLabelComponent();
  
  public abstract JLabel getDetailLabelComponent();
}

/* Location:
 * Qualified Name:     org.netbeans.modules.progress.spi.ExtractedProgressUIWorker
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.progress.spi;

import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JLabel;
import org.netbeans.progress.module.TrivialProgressUIWorkerProvider;
import org.openide.util.Cancellable;
import org.openide.util.Lookup;

public final class InternalHandle
{
  private static final Logger LOG = Logger.getLogger(InternalHandle.class.getName());
  private String displayName;
  private boolean customPlaced1 = false;
  private boolean customPlaced2 = false;
  private boolean customPlaced3 = false;
  private int state;
  private int totalUnits;
  private int currentUnit;
  private long initialEstimate;
  private long timeStarted;
  private long timeLastProgress;
  private long timeSleepy = 0L;
  private String lastMessage;
  private final Cancellable cancelable;
  private final Action viewAction;
  private final boolean userInitiated;
  private int initialDelay = 500;
  private Controller controller;
  private ExtractedProgressUIWorker component;
  public static final int STATE_INITIALIZED = 0;
  public static final int STATE_RUNNING = 1;
  public static final int STATE_FINISHED = 2;
  public static final int STATE_REQUEST_STOP = 3;
  public static final int NO_INCREASE = -2;
  
  public InternalHandle(String paramString, Cancellable paramCancellable, boolean paramBoolean, Action paramAction)
  {
    displayName = paramString;
    userInitiated = paramBoolean;
    state = 0;
    totalUnits = 0;
    lastMessage = null;
    cancelable = paramCancellable;
    viewAction = paramAction;
  }
  
  public String getDisplayName()
  {
    return displayName;
  }
  
  public synchronized int getState()
  {
    return state;
  }
  
  public boolean isAllowCancel()
  {
    return (cancelable != null) && (!isCustomPlaced());
  }
  
  public boolean isAllowView()
  {
    return (viewAction != null) && (!isCustomPlaced());
  }
  
  public boolean isCustomPlaced()
  {
    return component != null;
  }
  
  public boolean isUserInitialized()
  {
    return userInitiated;
  }
  
  private int getCurrentUnit()
  {
    return currentUnit;
  }
  
  public int getTotalUnits()
  {
    return totalUnits;
  }
  
  public void setInitialDelay(int paramInt)
  {
    if (state != 0)
    {
      LOG.warning("Setting ProgressHandle.setInitialDelay() after the task is started has no effect");
      return;
    }
    initialDelay = paramInt;
  }
  
  public int getInitialDelay()
  {
    return initialDelay;
  }
  
  public synchronized void toSilent(String paramString)
  {
    if ((state != 1) && (state != 3) && 
      (!$assertionsDisabled)) {
      throw new AssertionError("cannot switch to silent mode when not running");
    }
    timeLastProgress = System.currentTimeMillis();
    timeSleepy = timeLastProgress;
    if (paramString != null) {
      lastMessage = paramString;
    }
    controller.toSilent(this, paramString);
  }
  
  public boolean isInSleepMode()
  {
    return timeSleepy == timeLastProgress;
  }
  
  public synchronized void toIndeterminate()
  {
    if ((state != 1) && (state != 3) && 
      (!$assertionsDisabled)) {
      throw new AssertionError("cannot switch to indeterminate mode when not running: " + state);
    }
    totalUnits = 0;
    currentUnit = 0;
    initialEstimate = -1L;
    timeLastProgress = System.currentTimeMillis();
    controller.toIndeterminate(this);
  }
  
  public synchronized void toDeterminate(int paramInt, long paramLong)
  {
    if ((state != 1) && (state != 3) && 
      (!$assertionsDisabled)) {
      throw new AssertionError("cannot switch to determinate mode when not running");
    }
    if (paramInt < 0) {
      throw new IllegalArgumentException("number of workunits cannot be negative");
    }
    totalUnits = paramInt;
    currentUnit = 0;
    initialEstimate = paramLong;
    timeLastProgress = System.currentTimeMillis();
    controller.toDeterminate(this);
  }
  
  public synchronized void start(String paramString, int paramInt, long paramLong)
  {
    if (state != 0) {
      throw new IllegalStateException("Cannot call start twice on a handle");
    }
    if (paramInt < 0) {
      throw new IllegalArgumentException("number of workunits cannot be negative");
    }
    totalUnits = paramInt;
    currentUnit = 0;
    
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd