001/*
002 * $Id: GuiExecutor.java,v 1.4 2011/03/24 16:06:35 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2011
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 * 
012 * All Rights Reserved
013 * 
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.  
016 * 
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 * 
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025 * GNU Lesser Public License for more details.
026 * 
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program.  If not, see http://www.gnu.org/licenses.
029 */
030package edu.wisc.ssec.mcidasv.util;
031
032import java.util.List;
033import java.util.concurrent.AbstractExecutorService;
034import java.util.concurrent.TimeUnit;
035
036import javax.swing.SwingUtilities;
037
038
039/**
040 * Executor built atop SwingUtilities. Courtesy of <i>Java Concurrency in 
041 * Practice</i>, written by Brian Goetz and Tim Peierls.
042 */
043// TODO: couldn't find a license for this code? is it public domain?
044public class GuiExecutor extends AbstractExecutorService {
045    // Singletons have a private constructor and a public factory
046    private static final GuiExecutor instance = new GuiExecutor();
047
048    private GuiExecutor() {
049    }
050
051    public static GuiExecutor instance() {
052        return instance;
053    }
054
055    public void execute(Runnable r) {
056        if (SwingUtilities.isEventDispatchThread())
057            r.run();
058        else
059            SwingUtilities.invokeLater(r);
060    }
061
062    public void shutdown() {
063        throw new UnsupportedOperationException();
064    }
065
066    public List<Runnable> shutdownNow() {
067        throw new UnsupportedOperationException();
068    }
069
070    public boolean awaitTermination(long timeout, TimeUnit unit)
071            throws InterruptedException {
072        throw new UnsupportedOperationException();
073    }
074
075    public boolean isShutdown() {
076        return false;
077    }
078
079    public boolean isTerminated() {
080        return false;
081    }
082}