communicationtask.java
来自「主要是对串口驱动的的一些控制源码!!! 在下载javacomm20-win32」· Java 代码 · 共 195 行
JAVA
195 行
package de.fhm.jkf.gui;
/*
* <br><br><center><table border="1" width="80%"><hr>
* <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
* <p>
* Copyright (C) 2002 by Marten Wulff
* <p>
* This library 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 2.1 of the License, or (at your option) any later version.
* <p>
* This library 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
* Lesser General Public License for more details.
* <p>
* You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
* GNU Lesser General Public License</a> along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
* <hr></table></center>
*
* $Log: CommunicationTask.java,v $
* Revision 1.7 2003/03/12 14:44:25 willaxt
* adjusted to new error handling code
*
* Revision 1.6 2003/02/06 11:51:55 willaxt
* added javadoc comments
*
* Revision 1.5 2003/02/04 21:47:43 willaxt
* only code formatting, nothing changed in code
*
* Revision 1.4 2003/02/01 00:28:16 mwulff
* calls setBusy on the JKFSubApplicationPanel, for setting the different cursors
*
* Revision 1.3 2003/01/30 09:45:12 mwulff
* no message
*
* Revision 1.2 2003/01/16 15:47:47 mwulff
* know calls the JKFEventQueue to lock and unlock it's JKFView
*
* Revision 1.1 2003/01/16 13:10:54 mwulff
* initial version
*
* Revision 1.2 2003/01/05 16:28:37 willaxt
* added javadoc comments
*
* Revision 1.1 2002/12/31 12:18:41 mwulff
* no message
*
*/
import java.awt.Container;
import de.fhm.jkf.thread.cl.InterruptableTask;
/**
* Special abstract class for communication tasks which are
* processed by the <code>CommunicationThreadPool</code>.
*
* @author marten wulff
* @version 1.0
*
* @see de.fhm.jkf.gui.CommunicationThreadPool
*/
public abstract class CommunicationTask implements InterruptableTask {
/**
* Saves the exception which occured during server communication.
* If no <code>Exception</code> occured this member is <code>null</code>.
*/
private Exception communicationError = null;
/**
* The panel this task works with.
*/
private JKFView panel = null;
/**
* Disable constructing <code>CommunicationTask</code>s without
* view we can reference to.
*/
private CommunicationTask() {
}
/**
* Creates a new <code>CommunicationTask</code> with a
* panel this task works an. The panel is needed to disable
* user input during communication with the server.
*
* @param panel the panel this task works with.
*/
public CommunicationTask(JKFView panel) {
this.panel = panel;
}
/**
* Called when the task starts. Sets the sub application to bussy and
* locks the event queue.
*/
public final void start() {
getSubApplicationPanel(panel).setBussy(true);
JKFEventQueue.lock(getSubApplicationPanel(panel));
}
/**
* Called when the task stops. Sets the sub application to be not bussy
* any more and unlocks the event queue.
*/
public final void stop() {
JKFEventQueue.unlock(getSubApplicationPanel(panel));
getSubApplicationPanel(panel).setBussy(false);
}
/**
* Helper method which walks up the component hierarchie to
* find the <code>JKFSubApplicationPanel</code> where the
* given panel lives in.
*
* @param c the <code>Container</code> from which the component
* hierarchie is walked up.
* @return the sub application panel the panel of this task lives in.
*/
private JKFSubApplicationPanel getSubApplicationPanel(Container c) {
while (!(c instanceof JKFSubApplicationPanel)) {
c = c.getParent();
if (c == null) {
break;
}
}
return (JKFSubApplicationPanel) c;
}
/**
* Method for presenting the result of a query. Always check
* if an error occured during communication with the server.
* This is done via the <code>getError()</code> method in
* this class.
*
* @see de.fhm.jkf.gui.CommunicationTask#getError()
*/
public abstract void doPresentation();
/**
* Returns the exception that occured during communication.
* If no exception occured, <code>null</code> is returned.
*
* @return the <code>Exception</code> which occured,
* <code>null</code> otherwise.
*/
public Exception getError() {
return this.communicationError;
}
/**
* The query that should be performed by the framework should
* be implemented in this method.
*/
public abstract void doQuery();
/**
* Called if the thread is interrupted. Will be called
* from the thread pool.
*/
public abstract void interrupt();
/**
* Executed by the thread pool. Calls the
* <code>doQuery()</code> method in a new
* thread.
*/
public final void run() {
doQuery();
}
/**
* Returns the panel this task works with.
*/
public JKFView getPanel() {
return panel;
}
/**
* Called from the <code>CommuncationThreadPool</code> if something
* went wrong during the communication. Stores the exception
* in the member <code>communicationError</code>.
*
* @see de.fhm.jkf.thread.cl.InterruptableTask#getError()
*/
public final void handleException(Exception ex) {
communicationError = ex;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?