package com.vci.client.workflow.editor.ui; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JComponent; import javax.swing.JEditorPane; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; import javax.swing.SingleSelectionModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.view.mxGraph; import com.vci.client.workflow.editor.BasicGraphEditor; import com.vci.client.workflow.editor.EditorCreateXmlToJbpm; import com.vci.client.workflow.editor.ProcessComponentFactory; import com.vci.corba.common.VCIError; public class FlowEditor extends JSplitPane { private static final long serialVersionUID = 7562492732674456910L; private mxGraph graph = null; private BasicGraphEditor basicGraphEditor = null; private JEditorPane xmlPane; public mxGraph getGraph() { return graph; } public FlowEditor(BasicGraphEditor basicGraphEditor) { this.basicGraphEditor = basicGraphEditor; mxGraphComponent graphComponent = basicGraphEditor.getGraphComponent(); this.graph = graphComponent.getGraph(); JTabbedPane editor = new JTabbedPane(JTabbedPane.BOTTOM); editor.add("Design", graphComponent); xmlPane = new JEditorPane(); editor.add("Source", new JScrollPane(xmlPane)); editor.getModel().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { SingleSelectionModel source = (SingleSelectionModel)e.getSource(); int selectedIndex = source.getSelectedIndex(); freshGraphEditor(selectedIndex); } }); this.setOrientation(JSplitPane.VERTICAL_SPLIT); this.setTopComponent(editor); mxCell cell = (mxCell)getGraph().getModel().getRoot(); this.setBottomComponent((JComponent)cell.getValue()); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setDividerLocation(screenSize.height - 280); this.setDividerSize(7); this.setOneTouchExpandable(true); } private void freshGraphEditor(int selectedIndex) { if(selectedIndex == 1){//1是source属性页的index EditorCreateXmlToJbpm getXml= new EditorCreateXmlToJbpm(basicGraphEditor); xmlPane.setText(getXml.getsXml()); xmlPane.setCaretPosition(0); } } public void updatePanel(Object cell) throws VCIError { Object value = ((mxCell)cell).getValue(); if(value instanceof JComponent) { this.setBottomComponent((JComponent)value); } else if(value instanceof String) { JComponent component = ProcessComponentFactory.getComponent(graph, ((mxCell)cell)); ((mxCell)cell).setValue(component); this.setBottomComponent(component); } int location = this.getDividerLocation(); this.setDividerLocation(location); } public String getXml(){ return xmlPane.getText(); } }