All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.kwhat.jnativehook.dispatcher.SwingDispatchService Maven / Gradle / Ivy

There is a newer version: 2.2.2
Show newest version
/* JNativeHook: Global keyboard and mouse listeners for Java.
 * Copyright (C) 2006-2021 Alexander Barker.  All Rights Reserved.
 * https://github.com/kwhat/jnativehook/
 *
 * JNativeHook is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JNativeHook is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see .
 */
package com.github.kwhat.jnativehook.dispatcher;

import com.github.kwhat.jnativehook.GlobalScreen;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.TimeUnit;
import javax.swing.SwingUtilities;

/**
 * Swing compatible implementation of the ExecutorService used to dispatch native
 * events.  This wraps event dispatching with {@link java.awt.EventQueue#invokeLater}.
 *
 * @author Alexander Barker ([email protected])
 * @version 2.0
 * @since 2.0
 * @see java.util.concurrent.ExecutorService
 * @see GlobalScreen#setEventDispatcher
 */
public class SwingDispatchService extends AbstractExecutorService {
    private boolean running;

    public SwingDispatchService() {
        running = true;
    }

    public void shutdown() {
        running = false;
    }

    public List shutdownNow() {
        running = false;
        return new ArrayList<>(0);
    }

    public boolean isShutdown() {
        return !running;
    }

    public boolean isTerminated() {
        return !running;
    }

    public boolean awaitTermination(long timeout, TimeUnit unit) {
        return true;
    }

    public void execute(Runnable r) {
        SwingUtilities.invokeLater(r);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy