📄 functionmanagerform.java
字号:
/**
*
*/
package flow.graph.gui.graph.lua.gui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.beans.XMLDecoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import flow.graph.app.FlowManager;
import flow.graph.gui.graph.FlowGraphConstants;
import flow.graph.gui.graph.cell.bpel.FunctionTips;
import flow.graph.gui.graph.cell.bpel.Functions;
import flow.graph.gui.graph.cell.ui.table.FunctionTipsTable;
import flow.graph.gui.graph.cell.ui.table.FunctionTipsTableModel;
import flow.graph.gui.graph.encoder.XMLEncoder;
import flow.graph.gui.graph.lua.code.LuaFunctionParse;
import flow.graph.gui.graph.template.TemplateFactory;
/**
* @author Administrator
*
*/
public class FunctionManagerForm {
private JDialog dialog;
private JTextField functionTipsName;
private JTextField functionTipsParameter;
private JTextField functionTipsDiscription;
//数据类型增加按钮
private JButton functionTipsAddButton;
//数据类型表格
private FunctionTipsTable functionTipsTable;
//数据类型删除按钮
private JButton functionTipsDeleteButton;
//数据类型修改按钮
private JButton functionTipsModifyButton;
private int functionTipsRowID = -1;
private JButton closeButton;
private Functions ownfunctions;
public FunctionManagerForm(){
dialog = new JDialog(FlowManager.getInstance(), "系统函数声明", true);
functionTipsName = new JTextField(20);
functionTipsParameter = new JTextField(20);
functionTipsDiscription = new JTextField(100);
functionTipsAddButton = new JButton("增加");
functionTipsAddButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(functionTipsName.getText().length() <= 0){
//提示不能为空
JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"函数名称不能为空!",
"工作流操作提示",
JOptionPane.CLOSED_OPTION);
functionTipsName.setFocusable(true);
return;
}
for(int i=0;i<((FunctionTipsTableModel)functionTipsTable.getModel()).getRowCount();i++){
if(((FunctionTipsTableModel)functionTipsTable.getModel()).getValueAt(i, 0).toString().equalsIgnoreCase(functionTipsName.getText())){
JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"函数 "+functionTipsName.getText()+" 已经存在!",
"工作流操作提示",
JOptionPane.CLOSED_OPTION);
return;
}
}
((FunctionTipsTableModel)functionTipsTable.getModel()).addRow(functionTipsName.getText(), functionTipsParameter.getText(), functionTipsDiscription.getText());
FunctionTips functionTips = new FunctionTips(functionTipsName.getText(), functionTipsParameter.getText(), functionTipsDiscription.getText());
ownfunctions.addFunctionTips(functionTips);
functionTipsName.setText("");
functionTipsParameter.setText("");
functionTipsDiscription.setText("");
}
});
functionTipsModifyButton = new JButton("修改");
functionTipsModifyButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(functionTipsRowID != -1){
if(functionTipsName.getText().length() <= 0){
//提示不能为空
JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"函数名称不能为空!",
"工作流操作提示",
JOptionPane.CLOSED_OPTION);
functionTipsName.setFocusable(true);
return;
}
for(int i=0;i<((FunctionTipsTableModel)functionTipsTable.getModel()).getRowCount();i++){
if(i == functionTipsRowID)
continue;
if(((FunctionTipsTableModel)functionTipsTable.getModel()).getValueAt(i, 0).toString().equalsIgnoreCase(functionTipsName.getText())){
JOptionPane.showConfirmDialog(FlowManager.getInstance(),
"函数 "+functionTipsName.getText()+" 已经存在!",
"工作流操作提示",
JOptionPane.CLOSED_OPTION);
return;
}
}
if(ownfunctions != null){
for(int i=0;i<ownfunctions.getFunctionTips().size();i++){
FunctionTips functionTips = ((FunctionTips)ownfunctions.getFunctionTips().get(i));
if(functionTips.getName().equals(((FunctionTipsTableModel)functionTipsTable.getModel()).getValueAt(functionTipsRowID, 0))){
((FunctionTips)ownfunctions.getFunctionTips().get(i)).setName(functionTipsName.getText());
((FunctionTips)ownfunctions.getFunctionTips().get(i)).setParameter(functionTipsParameter.getText());
((FunctionTips)ownfunctions.getFunctionTips().get(i)).setDiscription(functionTipsDiscription.getText());
}
}
}
((FunctionTipsTableModel)functionTipsTable.getModel()).setValueAt(functionTipsName.getText(), functionTipsRowID, 0);
((FunctionTipsTableModel)functionTipsTable.getModel()).setValueAt(functionTipsParameter.getText(), functionTipsRowID, 1);
((FunctionTipsTableModel)functionTipsTable.getModel()).setValueAt(functionTipsDiscription.getText(), functionTipsRowID, 2);
functionTipsName.setText("");
functionTipsParameter.setText("");
functionTipsDiscription.setText("") ;
}
functionTipsRowID = -1;
}
});
File file = new File(System.getProperty("user.dir")+"/"+TemplateFactory.CACHE_PATH+"/"+TemplateFactory.FUNCTION_FILES);
if(file.exists()){
ownfunctions = (Functions)readGraphFile(System.getProperty("user.dir")+"/"+TemplateFactory.CACHE_PATH+"/"+TemplateFactory.FUNCTION_FILES);
} else
try {
file.createNewFile();
if(ownfunctions == null) ownfunctions = new Functions();
writeGraphFile(System.getProperty("user.dir")+"/"+TemplateFactory.CACHE_PATH+"/"+TemplateFactory.FUNCTION_FILES, ownfunctions);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
functionTipsTable = new FunctionTipsTable(ownfunctions);
functionTipsTable.setDragEnabled(false);
functionTipsTable.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
int rowID = functionTipsTable.rowAtPoint(e.getPoint());
functionTipsRowID = rowID;
//System.out.println("rowID="+rowID);
int columnID = functionTipsTable.columnAtPoint(e.getPoint());
functionTipsName.setText(((FunctionTipsTableModel)functionTipsTable.getModel()).getValueAt(rowID, 0).toString());
functionTipsParameter.setText(((FunctionTipsTableModel)functionTipsTable.getModel()).getValueAt(rowID, 1).toString());
functionTipsDiscription.setText(((FunctionTipsTableModel)functionTipsTable.getModel()).getValueAt(rowID, 2).toString());
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
});
functionTipsDeleteButton = new JButton("删 除");
functionTipsDeleteButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(functionTipsRowID != -1){
if(ownfunctions != null){
for(int i=0;i<ownfunctions.getFunctionTips().size();i++){
FunctionTips functionTips = ((FunctionTips)ownfunctions.getFunctionTips().get(i));
if(functionTips.getName().equals(((FunctionTipsTableModel)functionTipsTable.getModel()).getValueAt(functionTipsRowID, 0))){
ownfunctions.getFunctionTips().remove(i);
}
}
}
((FunctionTipsTableModel)functionTipsTable.getModel()).removeRow(functionTipsRowID);
functionTipsName.setText("");
functionTipsParameter.setText("");
functionTipsDiscription.setText("");
}
functionTipsRowID = -1;
}
});
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
closeButton = new JButton("关 闭");
closeButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//System.out.println(((Functions)FlowGraphConstants.getBpelFunctions(cell.getAttributes())).toString());
saveData();
}
});
JPanel functionTipsTitlePanel = new JPanel(new BorderLayout());
functionTipsTitlePanel.setBorder(new TitledBorder("定义函数说明库"));
Box funcationTipsLayoutBox = Box.createVerticalBox();
Box funcationTipsAddBox1 = Box.createHorizontalBox();
funcationTipsAddBox1.add(new JLabel("函数名称:"));
funcationTipsAddBox1.add(functionTipsName);
funcationTipsAddBox1.add(Box.createHorizontalStrut(5));
funcationTipsAddBox1.add(new JLabel("参数列表:"));
funcationTipsAddBox1.add(functionTipsParameter);
funcationTipsAddBox1.add(Box.createHorizontalStrut(5));
funcationTipsAddBox1.add(functionTipsAddButton);
funcationTipsAddBox1.add(Box.createHorizontalStrut(5));
funcationTipsAddBox1.add(functionTipsModifyButton);
Box funcationTipsAddBox2 = Box.createHorizontalBox();
funcationTipsAddBox2.add(new JLabel("函数说明:"));
funcationTipsAddBox2.add(functionTipsDiscription);
funcationTipsLayoutBox.add(funcationTipsAddBox1);
funcationTipsLayoutBox.add(Box.createVerticalStrut(2));
funcationTipsLayoutBox.add(funcationTipsAddBox2);
funcationTipsLayoutBox.add(Box.createVerticalStrut(2));
JPanel controlTipsPanel = new JPanel(new FlowLayout());
controlTipsPanel.add(functionTipsDeleteButton);
funcationTipsLayoutBox.add(new JScrollPane(functionTipsTable));
funcationTipsLayoutBox.add(Box.createVerticalStrut(2));
funcationTipsLayoutBox.add(controlTipsPanel);
functionTipsTitlePanel.add(funcationTipsLayoutBox, BorderLayout.CENTER);
/////////////////////////////////////////////////
dialog.getContentPane().setLayout(new BorderLayout());
Box rootLayout = Box.createVerticalBox();
//rootLayout.add(functionTitlePanel);
//rootLayout.add(Box.createVerticalStrut(5));
rootLayout.add(functionTipsTitlePanel);
JPanel exitPanel = new JPanel(new FlowLayout());
exitPanel.add(closeButton);
rootLayout.add(exitPanel);
//rootLayout.add(assignTitlePanel);
dialog.setSize(600, 550);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
dialog.setLocation((screenSize.width-600)/2, (screenSize.height-550)/2);
dialog.setResizable(true);
dialog.add(rootLayout, BorderLayout.CENTER);
dialog.addWindowListener(new WindowListener(){
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
saveData();
}
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
});
dialog.show();
}
public Object readGraphFile(String s){
try {
XMLDecoder dec = new XMLDecoder(new BufferedInputStream(new FileInputStream(s)));
Object obj = dec.readObject();
dec.close();
return obj;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public void writeGraphFile(String s, Functions fun){
try {
XMLEncoder dec = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(s)));
dec.writeObject(fun);
dec.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void saveData(){
writeGraphFile(System.getProperty("user.dir")+"/"+TemplateFactory.CACHE_PATH+"/"+TemplateFactory.FUNCTION_FILES, ownfunctions);
dialog.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -