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

📄 testframe.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				
			}});
		inputModifyButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(inputRowID != -1){
					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;
					}
					
					//////////////////////////
					//判断变量名是否已经存在
					for(int i=0;i<((ParameterTableModel)inputTable.getModel()).getRowCount();i++){
						if(i == inputRowID)
							continue;
						if(((ParameterTableModel)inputTable.getModel()).getValueAt(i, 0).toString().equalsIgnoreCase(inputName.getText())){
							JOptionPane.showConfirmDialog(FlowManager.getInstance(),
									"变量"+inputName.getText()+" 已经存在!",
									"工作流操作提示",
									JOptionPane.CLOSED_OPTION);
							return;
						}
					}
					int index = ((Parameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getExistsParameter(inputName.getText());
					if(index >= 0){
						((Parameter)((Parameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setName(inputName.getText());
						((Parameter)((Parameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setType(inputType.getSelectedItem().toString());
						((Parameter)((Parameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setName(inputValue.getText());
						((Parameter)((Parameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().get(index)).setName(inputDiscription.getText());
					}
					
					((ParameterTableModel)inputTable.getModel()).setValueAt(inputName.getText(), inputRowID, 0);
					((ParameterTableModel)inputTable.getModel()).setValueAt(inputType.getSelectedItem().toString(), inputRowID, 1);
					((ParameterTableModel)inputTable.getModel()).setValueAt(inputValue.getText(), inputRowID, 2);
					((ParameterTableModel)inputTable.getModel()).setValueAt(inputDiscription.getText(), inputRowID, 3);
					inputName.setText("");
					inputType.setSelectedIndex(0);
					inputValue.setText("");
					inputDiscription.setText("");					
				}
				inputRowID = -1;
			}});
		inputDeleteButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(inputRowID != -1){
					((ParameterTableModel)inputTable.getModel()).removeRow(inputRowID);
					int index = ((Parameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getExistsParameter(inputName.getText());
					if(index >= 0){
						((Parameters)FlowGraphConstants.getInputTemplate(cell.getAttributes())).getParameters().remove(index);
					}
					inputName.setText("");
					inputType.setSelectedIndex(0);
					inputValue.setText("");
					inputDiscription.setText("");					
				}
				inputRowID = -1;
			}});

		///////////////////////////////////////////////////////////
		outputAddButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(outputName.getText().length() <= 0){
					JOptionPane.showConfirmDialog(FlowManager.getInstance(),
							"变量名称不能为空!",
							"工作流操作提示",
							JOptionPane.CLOSED_OPTION);
					outputName.requestFocus();
					return;
				}
				if(outputType.getSelectedIndex() == 0){
					JOptionPane.showConfirmDialog(FlowManager.getInstance(),
							"请选择数据类型!",
							"工作流操作提示",
							JOptionPane.CLOSED_OPTION);
					outputType.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<((ParameterTableModel)outputTable.getModel()).getRowCount();i++){
					if(((ParameterTableModel)outputTable.getModel()).getValueAt(i, 0).toString().equalsIgnoreCase(outputName.getText())){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"变量"+outputName.getText()+" 已经存在!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						return;
					}
				}
				
				((ParameterTableModel)outputTable.getModel()).addRow(outputName.getText(), outputType.getSelectedItem().toString(), outputValue.getText(), outputDiscription.getText());
				Parameter p = new Parameter(outputName.getText(), outputType.getSelectedItem().toString(), outputValue.getText(), outputDiscription.getText());
				((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).addParameter(p);
				outputName.setText("");
				outputType.setSelectedIndex(0);
				outputValue.setText("");
				outputDiscription.setText("");
			}});
		
		outputTable.addMouseListener(new MouseListener(){

			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				outputRowID = outputTable.rowAtPoint(e.getPoint());
				int columnID = outputTable.columnAtPoint(e.getPoint());
				outputName.setText(((ParameterTableModel)outputTable.getModel()).getValueAt(outputRowID, 0).toString());
				outputType.setSelectedItem(((ParameterTableModel)outputTable.getModel()).getValueAt(outputRowID, 1).toString());
				outputValue.setText(((ParameterTableModel)outputTable.getModel()).getValueAt(outputRowID, 2).toString());
				outputDiscription.setText(((ParameterTableModel)outputTable.getModel()).getValueAt(outputRowID, 3).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
				
			}});
		outputModifyButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(outputRowID != -1){
					if(outputName.getText().length() <= 0){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"变量名称不能为空!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						outputName.requestFocus();
						return;
					}
					if(outputType.getSelectedIndex() == 0){
						JOptionPane.showConfirmDialog(FlowManager.getInstance(),
								"请选择数据类型!",
								"工作流操作提示",
								JOptionPane.CLOSED_OPTION);
						outputType.requestFocus();
						return;
					}
					
					//////////////////////////
					//判断变量名是否已经存在
					for(int i=0;i<((ParameterTableModel)outputTable.getModel()).getRowCount();i++){
						if(i == outputRowID)
							continue;
						if(((ParameterTableModel)outputTable.getModel()).getValueAt(i, 0).toString().equalsIgnoreCase(outputName.getText())){
							JOptionPane.showConfirmDialog(FlowManager.getInstance(),
									"变量"+outputName.getText()+" 已经存在!",
									"工作流操作提示",
									JOptionPane.CLOSED_OPTION);
							return;
						}
					}
					int index = ((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getExistsParameter(outputName.getText());
					if(index >= 0){
						((Parameter)((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().get(index)).setName(outputName.getText());
						((Parameter)((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().get(index)).setType(outputType.getSelectedItem().toString());
						((Parameter)((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().get(index)).setName(outputValue.getText());
						((Parameter)((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().get(index)).setName(outputDiscription.getText());
					}
					
					((ParameterTableModel)outputTable.getModel()).setValueAt(outputName.getText(), outputRowID, 0);
					((ParameterTableModel)outputTable.getModel()).setValueAt(outputType.getSelectedItem().toString(), outputRowID, 1);
					((ParameterTableModel)outputTable.getModel()).setValueAt(outputValue.getText(), outputRowID, 2);
					((ParameterTableModel)outputTable.getModel()).setValueAt(outputDiscription.getText(), outputRowID, 3);
					outputName.setText("");
					outputType.setSelectedIndex(0);
					outputValue.setText("");
					outputDiscription.setText("");					
				}
				outputRowID = -1;
			}});
		outputDeleteButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(outputRowID != -1){
					((ParameterTableModel)outputTable.getModel()).removeRow(outputRowID);
					int index = ((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getExistsParameter(outputName.getText());
					if(index >= 0){
						((Parameters)FlowGraphConstants.getOutputTemplate(cell.getAttributes())).getParameters().remove(index);
					}
					outputName.setText("");
					outputType.setSelectedIndex(0);
					outputValue.setText("");
					outputDiscription.setText("");					
				}
				outputRowID = -1;
			}});
		///////////////////////////////////////////////////////////
		dialog.getContentPane().setLayout(new BorderLayout());
		Box layoutBox = Box.createVerticalBox();
		layoutBox.add(inputTitledPanel);
		//layoutBox.add(Box.createVerticalStrut(1));
		layoutBox.add(outputTitledPanel);
		//layoutBox.add(Box.createVerticalStrut(3));
		//layoutBox.add(actionPanel);
		Box layoutBox1 = Box.createVerticalBox();
		layoutBox1.add(layoutBox);
		//layoutBox1.add(Box.createVerticalStrut(1));
		layoutBox1.add(actionPanel);
		
		dialog.getContentPane().add(layoutBox1, BorderLayout.CENTER);
		dialog.getContentPane().add(exitPanel, BorderLayout.SOUTH);
		dialog.setSize(500, 650);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		dialog.setLocation((screenSize.width-500)/2, (screenSize.height-650)/2);
		dialog.setResizable(true);
		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();		
	}
	
	private void saveData(){
		if(FlowGraphConstants.getActionTemplate(cell.getAttributes()) != null){
			((ActionTemplate)FlowGraphConstants.getActionTemplate(cell.getAttributes())).setAction(actionArea.getText());
		}
		dialog.dispose();
	}

	public static void main(String[] args){
		try {
			com.nilo.plaf.nimrod.NimRODTheme nt = new com.nilo.plaf.nimrod.NimRODTheme();
			nt.setOpacity(100);
			com.nilo.plaf.nimrod.NimRODLookAndFeel NimRODLF = new com.nilo.plaf.nimrod.NimRODLookAndFeel();
			NimRODLF.setCurrentTheme( nt);
			UIManager.setLookAndFeel( NimRODLF);
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		new TestFrame(new DefaultGraphCell(), new JGraph());
	}
}

⌨️ 快捷键说明

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