📄 operator.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Author$
* $Date$
* $Revision$
*/
package eti.bi.alphaminer.operation.operator;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusListener;
import java.awt.event.InputMethodListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import java.util.jar.JarFile;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTextPane;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import com.prudsys.pdm.Core.MiningAlgorithmParameter;
import com.prudsys.pdm.Core.MiningAlgorithmSpecification;
import com.prudsys.pdm.Core.MiningException;
import eti.bi.alphaminer.core.observer.HelpObserveSubject;
import eti.bi.alphaminer.core.observer.HelpObserver;
import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.core.help.AlphaminerHelpHandler;
import eti.bi.alphaminer.ui.ICaseDiagram;
import eti.bi.alphaminer.ui.IMessageDialog;
import eti.bi.alphaminer.ui.ISystemMessageHandler;
import eti.bi.alphaminer.vo.BIObject;
import eti.bi.alphaminer.vo.IBIData;
import eti.bi.alphaminer.vo.IBIModel;
import eti.bi.alphaminer.vo.IBIObject;
import eti.bi.alphaminer.vo.IOperatorNode;
import eti.bi.exception.AppException;
import eti.bi.exception.BaseException;
import eti.bi.exception.SysException;
import eti.bi.util.ResourceLoader;
import eti.bi.common.Locale.Resource;
/**
*
* Operator is a JPanel which contains an operator image and an operator description.
*/
public abstract class Operator extends JPanel implements
MouseListener,
KeyListener,
DropTargetListener,
HelpObserver {
public static int OPERATOR_WIDTH = 70;
public static int OPERATOR_HEIGHT = 64;
public final static int MAX_PARENT = 10;
public final static int MODE_CLEAR = 0;
public final static int MODE_SELECTED = 1;
public final static int MODE_RUNNING = 2;
public final static int MODE_ERROR = 3;
public final static int MODE_SUCCEED = 4;
public final static int ICON_WIDTH= 44;
public final static int ICON_HEIGHT= 44;
public final static int TEXTAREA_WIDTH_MIN = ICON_WIDTH;
public final static int TEXTAREA_WIDTH_MAX = 120;
public final static int TEXTAREA_LINE_HEIGHT = 16;
public final static int ICON_TEXT_SPACE_OFFSET = 5;
public final static int FONT_SIZE = 12;
public final static String FONT_FAMILY = Resource.srcStr("font");
public final static int IMAGE_WIDTH= 30;
public final static int IMAGE_HEIGHT= 30;
public final static int INTERVAL_IMAGE_MODE = 5;
public final static int modeColorWidth = 2;
public final static int modeEmptyWidth = 5;
public static int m_TextAreaWidth = TEXTAREA_WIDTH_MAX;
public static int m_TextAreaHeight = TEXTAREA_LINE_HEIGHT * 4; // 4 Lines
public static int m_Icon_Offset_X = INTERVAL_IMAGE_MODE+(m_TextAreaWidth - ICON_WIDTH)/2;
public static int m_ExecutionMode = MODE_CLEAR;
// << 21/07/2005 Kenneth Lai: Add for JHelp
private JButton m_TransparentHelpButton;
// 21/07/2005 Kenneth Lai: Add for JHelp>>
private JPanel m_ModePanel;
private JLabel m_OperatorImage;
/*
* m_DropEventPanel is used to receive the DropTargetDragEvent.
* It is needed because the Operator label with JTextPane Object would block
* the drop event, it used to catch the event and pass it to the CaseDiagramPanel to handle.
*/
private JPanel m_DropEventPanel;
/**
* operator's processing model
* */
private OperatorProgressModel processModel;
private JTextPane m_OperatorLabel;
protected String m_Description;
protected String m_CaseID;
protected String m_NodeID;
protected int m_NodeType;
// <<22/07/2005 Kenneth Lai: Add for JHelp
protected boolean m_HelpState;
// 22/07/2005 Kenneth Lai: Add for JHelp>>
protected IBIObject[] m_InputBIObject = new BIObject[MAX_PARENT];
protected IBIObject m_OutputBIObject;
/* CaseWindow to which the current Operator is to be added onto it. */
// protected CaseWindow m_CaseWindow;
protected String m_DMEnginePrefix = "ETI"; //<<Frank Xu, 09/12/2004, string to differentiate DM Engines. 09/12/2004, Frank Xu>>
protected String m_DefaultDataSourceName = "Unknown Data Source";
protected String m_OperatorDefinitionID = "";
protected static ICaseHandler m_CaseHandler;
protected INodeInfo m_NodeInfo;
protected ISystemMessageHandler m_SystemMessageHandler;
protected IMessageDialog m_MessageDialog;
/**
* for writing temp file
* */
private boolean haschanged;
/**
* Creates an Operator.
* @param a_CaseID ID of the Case containing the node represented
* by this Operator.
* @param a_CaseWindow CaseWindow in which this Operator to be added.
*/
public Operator(String a_CaseID, INodeInfo a_OperatorInfo, ICaseHandler aCaseHandler)
{
m_CaseID = a_CaseID;
m_NodeInfo = a_OperatorInfo;
m_CaseHandler = aCaseHandler;
m_SystemMessageHandler = m_CaseHandler.getSystemMessageHandler(m_CaseID);
setOperatorDefinitionID(a_OperatorInfo.getDefinitionID());
m_MessageDialog = m_CaseHandler.getMessageDialog();
createOperator();
setOperatorImage(m_NodeInfo.getFlowImageFileName(),m_NodeInfo.getJafFile());
setDescription(m_NodeInfo.getDisplayName());
// <<22/07/2005 Kenneth Lai: Add for JHelp
HelpObserveSubject.registerInterest(this);
setHelpMode(false);
// 22/07/2005 Kenneth Lai: Add for JHelp>>
m_OutputBIObject = new BIObject();
}
/**
* Gets the Case ID.
* @return ID of the Case containing this operator.
*/
public String getCaseID() {
return m_CaseID;
}
/**
* Sets the Case ID. It should only be invoked by case diagrampanel or case handler
* @param a_CaseID
*/
public void setCaseID(String a_CaseID)
{
m_CaseID = a_CaseID;
}
/**
* Sets the Node ID.
* @param a_NodeID ID to be set.
*/
public void setNodeID(String a_NodeID) {
m_NodeID = a_NodeID;
}
/**
* Gets the Node ID.
* @return ID of the Node represented by this operator.
*/
public String getNodeID() {
return m_NodeID;
}
/**
* Sets the Node type of this operator.
* @param a_Type type of the node.
*/
public void setNodeType(int a_Type) {
m_NodeType = a_Type;
}
/**
* Gets the operator image of this operator.
* @return the JLable containing the operator image.
*/
public JLabel getOperatorImage() {
return m_OperatorImage;
}
/**
* Gets the operator image dimension of this operator.
* @return the Dimension of the operator image.
*/
public Dimension getImageDimension() {
return new Dimension(ICON_WIDTH, ICON_HEIGHT);
}
/**
* Gets the description textarea of this operator.
* @return the description JTextArea of this operator.
*/
/*public JTextArea getTextArea() {
return m_Label;
}*/
/*
* Set the default data source name. All data input operators
* should call this method to set the correct default data source name.
*
*/
public void setDefaultDataSourceName(String a_Name)
{
m_DefaultDataSourceName = a_Name;
}
/* Get the Bounds of the Image Icon relative to the Case Diagram*/
public Rectangle getIconBounds()
{
//Operator Bounds relative to the Case Diagram
Rectangle thisBound = this.getBounds();
// Image Icon bouds relative to this operator
Rectangle relativeIconBound = m_OperatorImage.getBounds();
// Image Icon bounds relative to the Case Diagram
Rectangle absoluteIconBound = new Rectangle(thisBound.x+relativeIconBound.x,
thisBound.y+relativeIconBound.y,
relativeIconBound.width,
relativeIconBound.height);
return absoluteIconBound;
}
/*
* Get the default data source name. It would invoke the first parent node's
* getDefaultDataSoutceName.
*/
public String getDefaultDataSourceName() throws SysException
{
Vector parents = m_CaseHandler.getParentOperators(m_CaseID, m_NodeID);
if (parents==null || parents.size()==0)
{
// return the default data source name if there is no parent node
return m_DefaultDataSourceName;
}
// Recursively invoke parent node's get DefaultDataSourceName til the head(no parent node)
return ((Operator)parents.elementAt(0)).getDefaultDataSourceName();
}
/**
* Return if the description textarea is currently editable.
* @return true if it is editable; false otherwise.
*/
public boolean isEditing() {
// return m_Label.isEditable();
return false;
}
/**
* Sets description textarea to editable/non-editable.
* @param a_Status status to be set. It is true to set the textarea
* editable; false to set it non-editable.
*/
public void setEditable(boolean a_Status) {
//m_Label.setEditable(a_Status);
//m_Label.getCaret().setVisible(false);
}
/**
* Gets the Mode Panel.
* @return the Mode Panel
*/
public JPanel getModePanel() {
return m_ModePanel;
}
/* Set the current execution mode of this operator */
public void setExecutionMode(int a_Mode)
{
m_ExecutionMode = a_Mode;
}
/* Return the current execution mode of this operator */
public int getExecutionMode()
{
return m_ExecutionMode;
}
/**
* Clear mode of the Mode Panel.
*/
public void clearMode()
{
setExecutionMode(MODE_CLEAR);
m_ModePanel.setBorder(null);
}
/**
* Sets operator to its selected mode.
*/
public void setSelectMode()
{
if (m_ExecutionMode != MODE_RUNNING && m_ExecutionMode != MODE_ERROR &&
m_ExecutionMode != MODE_SUCCEED )
{
setExecutionMode(MODE_SELECTED);
m_ModePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(modeEmptyWidth, modeEmptyWidth,modeEmptyWidth, modeEmptyWidth), BorderFactory.createLineBorder(Color.BLACK)));
}
}
/*
* Sets operator to its clear mode if it is in selected mode.
*/
public void setUnSelectMode()
{
if (m_ExecutionMode == MODE_SELECTED)
{
clearMode();
}
}
/**
* Sets operator to its running mode.
*/
public void setRunningMode()
{
setExecutionMode(MODE_RUNNING);
m_ModePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(modeEmptyWidth, modeEmptyWidth,modeEmptyWidth, modeEmptyWidth), BorderFactory.createLineBorder(Color.YELLOW, modeColorWidth)));
}
/**
* Sets operator to its running error mode.
*/
public void setRunningErrorMode()
{
setExecutionMode(MODE_ERROR);
m_ModePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(modeEmptyWidth, modeEmptyWidth,modeEmptyWidth, modeEmptyWidth), BorderFactory.createLineBorder(Color.RED, modeColorWidth)));
}
/**
* Set operator to its finish running mode.
*/
public void setFinishRunningMode() {
setExecutionMode(MODE_CLEAR);
m_ModePanel.setBorder(null);
}
public void setSucceedMode()
{
setExecutionMode(MODE_SUCCEED);
haschanged = true;
m_ModePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(modeEmptyWidth, modeEmptyWidth,modeEmptyWidth, modeEmptyWidth), BorderFactory.createLineBorder(Color.GREEN, modeColorWidth)));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -