Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.progress.ui;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.netbeans.api.progress.ProgressRunnable;
import org.netbeans.api.progress.ProgressUtils;
import org.netbeans.modules.progress.spi.RunOffEDTProvider;
import org.netbeans.modules.progress.spi.RunOffEDTProvider.Progress;
import org.netbeans.modules.progress.spi.RunOffEDTProvider.Progress2;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.*;
import org.openide.util.RequestProcessor.Task;
import org.openide.util.lookup.ServiceProvider;
import org.openide.windows.WindowManager;
/**
* Default RunOffEDTProvider implementation for ProgressUtils.runOffEventDispatchThread() methods
* @author Jan Lahoda, Tomas Holy
*/
@ServiceProvider(service=RunOffEDTProvider.class, position = 100)
public class RunOffEDTImpl implements RunOffEDTProvider, Progress, Progress2 {
private static final RequestProcessor TI_WORKER = new RequestProcessor("TI_" + ProgressUtils.class.getName(), 1, true);
private static final Map CUMULATIVE_SPENT_TIME = new HashMap();
private static final Map MAXIMAL_SPENT_TIME = new HashMap();
private static final Map INVOCATION_COUNT = new HashMap();
private static final int CANCEL_TIME = 1000;
private static final int WARNING_TIME = Integer.getInteger("org.netbeans.modules.progress.ui.WARNING_TIME", 10000);
private static final Logger LOG = Logger.getLogger(RunOffEDTImpl.class.getName());
//@GuardedBy("rqByClz")
private final Map,Pair> rqByClz = new HashMap, Pair>();
private final boolean assertionsOn;
@Override
public void runOffEventDispatchThread(final Runnable operation, final String operationDescr,
final AtomicBoolean cancelOperation, boolean waitForCanceled, int waitCursorTime, int dlgTime) {
Parameters.notNull("operation", operation); //NOI18N
Parameters.notNull("cancelOperation", cancelOperation); //NOI18N
if (!SwingUtilities.isEventDispatchThread()) {
operation.run();
return;
}
long startTime = System.currentTimeMillis();
runOffEventDispatchThreadImpl(operation, operationDescr, cancelOperation, waitForCanceled, waitCursorTime, dlgTime);
long elapsed = System.currentTimeMillis() - startTime;
if (assertionsOn) {
String clazz = operation.getClass().getName();
Long cumulative = CUMULATIVE_SPENT_TIME.get(clazz);
if (cumulative == null) {
cumulative = 0L;
}
cumulative += elapsed;
CUMULATIVE_SPENT_TIME.put(clazz, cumulative);
Long maximal = MAXIMAL_SPENT_TIME.get(clazz);
if (maximal == null) {
maximal = 0L;
}
if (elapsed > maximal) {
maximal = elapsed;
MAXIMAL_SPENT_TIME.put(clazz, maximal);
}
Integer count = INVOCATION_COUNT.get(clazz);
if (count == null) {
count = 0;
}
count++;
INVOCATION_COUNT.put(clazz, count);
if (elapsed > WARNING_TIME) {
LOG.log(Level.WARNING, "Lengthy operation: {0}:{1}:{2}:{3}:{4}", new Object[] {
clazz, cumulative, count, maximal, String.format("%3.2f", ((double) cumulative) / count)});
}
}
}
private void runOffEventDispatchThreadImpl(final Runnable operation, final String operationDescr,
final AtomicBoolean cancelOperation, boolean waitForCanceled, int waitCursorTime, int dlgTime) {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference