⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extendsform.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * 
 */
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.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
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 org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphCell;

import flow.graph.app.FlowManager;
import flow.graph.gui.graph.FlowGraphConstants;
import flow.graph.gui.graph.lua.GraphTemplateCell;
import flow.graph.gui.graph.lua.code.LuaExtendsParse;
import flow.graph.gui.graph.lua.code.LuaInvokeParse;
import flow.graph.gui.graph.lua.gui.function.FunctionTree;
import flow.graph.gui.graph.lua.gui.table.InputParameterTable;
import flow.graph.gui.graph.lua.gui.table.InputParameterTableModel;
import flow.graph.gui.graph.lua.xml.ActionTemplate;
import flow.graph.gui.graph.lua.xml.InputParameter;
import flow.graph.gui.graph.lua.xml.InputParameters;
import flow.graph.gui.graph.lua.xml.Parameter;
import flow.graph.gui.syntax.JHightLightLineTextPane;

/**
 * @author Administrator
 *
 */
public class ExtendsForm {
	private DefaultGraphCell cell;
	private JGraph graph;
	private JDialog dialog;

	private JTextField inputName;
	private JComboBox inputType;
	private JCheckBox inputFlag;
	private JComboBox inputSource;
	private JTextField inputValue;
	private JTextField inputDiscription;
	private JButton inputAddButton, inputModifyButton, inputDeleteButton;
	private InputParameterTable inputTable;
	private int inputRowID = -1;

	private JHightLightLineTextPane actionArea;

	public ExtendsForm(final DefaultGraphCell cell, JGraph graph){
		this.cell = cell;
		this.graph = graph;
		
		if(FlowGraphConstants.getInputTemplate(cell.getAttributes()) == null){
			FlowGraphConstants.setInputTemplate(cell.getAttributes(), new InputParameters());
		}
		if(FlowGraphConstants.getActionTemplate(cell.getAttributes()) == null){
			FlowGraphConstants.setActionTemplate(cell.getAttributes(), new ActionTemplate());
		}		

		///////////////////////////////////
		inputName = new JTextField(20);
		inputName.setBounds(0,0,30,10);
		//inputName.setPreferredSize(new Dimension(20, 20));
		inputType = new JComboBox(Parameter.ParameterType);
		inputType.setBounds(50,0,40,10);
		//inputType.setPreferredSize(new Dimension(100, 20));
		inputFlag = new JCheckBox();
		Vector v = new Vector();
		v.add("");
		Hashtable owner = new Hashtable();
		if(FlowGraphConstants.getInputTemplate(cell.getAttributes()) != null){
			if(FlowGraphConstants.getCellID(cell.getAttributes()) != null){
				String cellid = FlowGraphConstants.getCellID(cell.getAttributes()).toString();
				InputParameters input = (InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes());
				if(input.getParameters()!= null){
					for(int i=0;i<input.getParameters().size();i++){
						InputParameter p = (InputParameter)input.getParameters().get(i);
						owner.put(cellid+"_"+p.getName(), cellid+"_"+p.getName());
					}
				}
			}
		}
		Hashtable ht = new Hashtable();
		Vector tv = GraphTemplateCell.getSourceParameter(cell);
		if(tv != null){
			for(int i=0;i<tv.size();i++){
				String tx = tv.get(i).toString();
				if(owner.get(tx) == null)
					ht.put(tx,tx);
			}
		}
		if(ht.size()>0){
			Set set = ht.keySet();
			Iterator iter = set.iterator();
			while(iter.hasNext()){
				v.add(iter.next().toString());
			}
		}

		inputSource = new JComboBox(v.toArray());
		//inputSource.setPreferredSize(new Dimension(100, 20));
		inputSource.setEditable(true);
		
		inputValue = new JTextField(20);
		inputDiscription = new JTextField(30);
		inputAddButton = new JButton("增  加");
		inputModifyButton = new JButton("修  改");
		inputDeleteButton = new JButton("删  除");
		inputTable = new InputParameterTable(cell);

		JPanel inputTitledPanel = new JPanel(new BorderLayout());
		inputTitledPanel.setBorder(new TitledBorder("输入参数"));
		inputTitledPanel.setPreferredSize(new Dimension(600, 80));
		Box inputAddBox1 = Box.createHorizontalBox();
		inputAddBox1.add(new JLabel("名称:"));
		inputAddBox1.add(inputName);
		inputAddBox1.add(Box.createHorizontalStrut(5));
		inputAddBox1.add(new JLabel("类型:"));
		inputAddBox1.add(inputType);
		inputAddBox1.add(Box.createHorizontalStrut(5));
		inputAddBox1.add(new JLabel("标识:"));
		inputAddBox1.add(inputFlag);
		inputAddBox1.add(Box.createHorizontalStrut(5));
		inputAddBox1.add(new JLabel("来源:"));
		inputAddBox1.add(inputSource);

		Box inputAddBox2 = Box.createHorizontalBox();
		inputAddBox2.add(new JLabel("    值:"));
		inputAddBox2.add(inputValue);
		
		Box inputAddBox3 = Box.createHorizontalBox();
		inputAddBox3.add(new JLabel("说明:"));
		inputAddBox3.add(inputDiscription);
		inputAddBox3.add(Box.createHorizontalStrut(5));
		inputAddBox3.add(inputAddButton);
		inputAddBox3.add(Box.createHorizontalStrut(5));
		inputAddBox3.add(inputModifyButton);
		inputAddBox3.add(Box.createHorizontalStrut(5));
		inputAddBox3.add(inputDeleteButton);

		Box inputLayoutBox = Box.createVerticalBox();
		inputLayoutBox.add(inputAddBox1);
		//inputLayoutBox.add(Box.createVerticalStrut(1));
		inputLayoutBox.add(inputAddBox2);
		inputLayoutBox.add(inputAddBox3);
		//inputLayoutBox.add(Box.createVerticalStrut(1));
		inputLayoutBox.add(new JScrollPane(inputTable));
		//inputLayoutBox.add(Box.createVerticalStrut(1));
		//inputLayoutBox.add(inputDeletePanel);
		inputTitledPanel.add(inputLayoutBox, BorderLayout.CENTER);

		///////////////////////////////////
		////////////////////////////////////////////////////////////
		inputAddButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(inputName.getText().length() <= 0){
					JOptionPane.showConfirmDialog(FlowManager.getInstance(),
							"变量名称不能为空!",
							"工作流操作提示",
							JOptionPane.CLOSED_OPTION);
					inputName.requestFocus();
					return;
				}
				if(inputType.getSelectedIndex() == 0){
					JOptionPane.showConfirmDialog(FlowManager.getInstance(),
							"请选择数据类型!",
							"工作流操作提示",
							JOptionPane.CLOSED_OPTION);
					inputType.requestFocus();
					return;
				}
				if(inputFlag.isSelected() == true){
					if(inputSource.getSelectedIndex() <= 0){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"请选择数据来源!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						inputSource.requestFocus();
						return;
					}
				}
				
				//////////////////////////
				//判断变量名是否已经存在
				/*
				if(FlowGraphConstants.getInputTemplate(cell.getAttributes()) != null){
					if(((Parameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).exitsParameter(inputName.getText())){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"变量"+inputName.getText()+"已经存在!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						inputName.requestFocus();
						return;
					}
				}*/
				for(int i=0;i<((InputParameterTableModel)inputTable.getModel()).getRowCount();i++){
					if(((InputParameterTableModel)inputTable.getModel()).getValueAt(i, 0).toString().equalsIgnoreCase(inputName.getText())){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"变量"+inputName.getText()+" 已经存在!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						inputName.requestFocus();
						return;
					}
				}
				
				((InputParameterTableModel)inputTable.getModel()).addRow(inputName.getText(), inputType.getSelectedItem().toString(), inputFlag.isSelected(), inputSource.getSelectedItem()==null?"":inputSource.getSelectedItem().toString(), inputValue.getText(), inputDiscription.getText());
				InputParameter p = new InputParameter(inputName.getText(), inputType.getSelectedItem().toString(), inputFlag.isSelected(), inputSource.getSelectedItem()==null?"":inputSource.getSelectedItem().toString(), inputValue.getText(), inputDiscription.getText());
				((InputParameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).addParameter(p);
				inputName.setText("");
				inputType.setSelectedIndex(0);
				inputFlag.setSelected(false);
				inputSource.setSelectedIndex(0);
				inputValue.setText("");
				inputDiscription.setText("");
			}});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -