📄 operation.java
字号:
/*====================================================================*\Operation.javaOperation class.------------------------------------------------------------------------This file is part of FuncPlotter, a combined Java application and appletfor plotting explicit functions in one variable.Copyright 2005-2007 Andy Morgan-Richards.FuncPlotter is free software: you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation, either version 3 of the License, or (at youroption) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith this program. If not, see <http://www.gnu.org/licenses/>.\*====================================================================*/// PACKAGEpackage util;//----------------------------------------------------------------------// IMPORTSimport exception.AppException;import exception.TerminatedException;import gui.ProgressView;import java.util.ArrayList;import java.util.List;//----------------------------------------------------------------------// OPERATION CLASSpublic abstract class Operation implements Runnable{////////////////////////////////////////////////////////////////////////// Constructors//////////////////////////////////////////////////////////////////////// protected Operation( ) { } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Static initialiser//////////////////////////////////////////////////////////////////////// static { threads = new ArrayList<Thread>( ); }////////////////////////////////////////////////////////////////////////// Class methods//////////////////////////////////////////////////////////////////////// public static synchronized boolean isException( ) { return ( exception != null ); } //------------------------------------------------------------------ public static synchronized AppException getException( ) { return exception; } //------------------------------------------------------------------ public static synchronized boolean isTerminated( ) { return terminated; } //------------------------------------------------------------------ public static synchronized boolean isExceptionOrTerminated( ) { return ( (exception != null) || terminated ); } //------------------------------------------------------------------ public static synchronized ProgressView getProgressView( ) { return progressView; } //------------------------------------------------------------------ public static synchronized void setException( AppException exception, boolean override ) { if ( override || (Operation.exception == null) ) Operation.exception = exception; } //------------------------------------------------------------------ public static synchronized void setTerminated( boolean terminate ) { terminated = terminate; } //------------------------------------------------------------------ public static synchronized void setProgressView( ProgressView progressView ) { Operation.progressView = progressView; } //------------------------------------------------------------------ public static synchronized int getNumThreads( ) { return threads.size( ); } //------------------------------------------------------------------ public static synchronized int addThread( Thread thread ) { threads.add( thread ); return threads.size( ); } //------------------------------------------------------------------ public static synchronized void removeThread( ) { threads.remove( Thread.currentThread( ) ); if ( threads.isEmpty( ) ) { if ( progressView != null ) { progressView.close( ); progressView = null; } } } //------------------------------------------------------------------ public static synchronized void throwOnException( ) throws AppException { if ( exception != null ) throw exception; } //------------------------------------------------------------------ public static synchronized void throwOnTerminated( ) throws TerminatedException { if ( terminated ) throw new TerminatedException( ); } //------------------------------------------------------------------ public static synchronized void throwOnExceptionOrTerminated( ) throws AppException { throwOnException( ); throwOnTerminated( ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods//////////////////////////////////////////////////////////////////////// public boolean start( ) { if ( terminated ) return false; Thread thread = new Thread( this, "app-" + getClass( ).getName( ) + "-" + threadId++ ); thread.setDaemon( true ); if ( addThread( thread ) == 1 ) primary = true; thread.start( ); return true; } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Class variables//////////////////////////////////////////////////////////////////////// private static AppException exception; private static boolean terminated; private static ProgressView progressView; private static int threadId; private static List<Thread> threads;////////////////////////////////////////////////////////////////////////// Instance variables//////////////////////////////////////////////////////////////////////// private boolean primary;}//----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -