summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/graph/view/EditorPanel.java
blob: 78fb5c99c40e12691b3e2dcb42bf8f8d936ae49e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.c2kernel.graph.view;
import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.c2kernel.graph.controller.AutoScrollController;
import com.c2kernel.graph.controller.EdgeConstructionController;
import com.c2kernel.graph.controller.MultiSelectionDragController;
import com.c2kernel.graph.controller.VertexConstructionController;
import com.c2kernel.graph.model.*;
public class EditorPanel extends JPanel
{
	// Graph Model
	public final GraphModelManager mGraphModelManager = new GraphModelManager();
	// Graph View
	public GraphPanel mGraphPanel = null;
    protected JScrollPane mGraphScrollPane = null;
	// Graph Controllers
	protected MultiSelectionDragController mMultiSelectionDragController = new MultiSelectionDragController();
    protected VertexConstructionController mVertexConstructionController = new VertexConstructionController();
    protected EdgeConstructionController mEdgeConstructionController = new EdgeConstructionController();
    protected AutoScrollController mAutoScrollController = new AutoScrollController();
	// Tool bar
    protected EditorToolBar mEditorToolBar = null;
	protected EditorPanel()
    {
    }
    public EditorPanel(EdgeFactory eFactory, VertexFactory vFactory, VertexOutlineCreator vOutlineCreator, boolean edgeCreationMode,	// True
																																		// if
																																		// edges
																																		// can
																																		// be
																																		// created
	JButton[] otherButtons, GraphPanel graphPanel)
	{
		// Create the graph panel and editor tool bar
        setDoubleBuffered(true);
		mGraphPanel = graphPanel;
		mGraphPanel.setGraphModelManager(mGraphModelManager);
		mGraphScrollPane = new JScrollPane(mGraphPanel);
		mGraphModelManager.setExternalEdgeFactory(eFactory);
		mGraphModelManager.setExternalVertexFactory(vFactory);
		mGraphModelManager.setVertexOutlineCreator(vOutlineCreator);
		mEditorToolBar = new EditorToolBar(edgeCreationMode, otherButtons, graphPanel);
		mEditorToolBar.setGraphModelManager(mGraphModelManager);
		mEditorToolBar.setGraphPanel(mGraphPanel);
		createLayout();
		// The graph panel observes the graph model
		mGraphModelManager.addObserver(mGraphPanel);
		// The multi selection drag controller modifies the graph model
		// and listens to the graph panel and editor tool bar
		mMultiSelectionDragController.setGraphModelManager(mGraphModelManager);
		mGraphPanel.addMouseListener(mMultiSelectionDragController);
		mGraphPanel.addMouseMotionListener(mMultiSelectionDragController);
		mGraphPanel.addKeyListener(mMultiSelectionDragController);
		mEditorToolBar.addEditorModeListener(mMultiSelectionDragController);
		// The edge construction controller modifies the graph model
		// and listens to the graph panel and editor tool bar
		mEdgeConstructionController.setGraphModelManager(mGraphModelManager);
		mGraphPanel.addMouseListener(mEdgeConstructionController);
		mGraphPanel.addMouseMotionListener(mEdgeConstructionController);
		mEdgeConstructionController.setEditorToolBar(mEditorToolBar);
		// The vertex construction controller modifies the graph model
		// and listens to the graph panel and editor tool bar
		mVertexConstructionController.setGraphModelManager(mGraphModelManager);
		mGraphPanel.addMouseListener(mVertexConstructionController);
		mVertexConstructionController.setEditorToolBar(mEditorToolBar);
		// The auto scroll controller listens to and modifies the
		// graph panel
		mAutoScrollController.setGraphPanel(mGraphPanel);
	}

    protected void createLayout()
	{
		setLayout(new BorderLayout());
		add(mEditorToolBar, BorderLayout.NORTH);
		mGraphPanel.setPreferredSize(new Dimension(mGraphModelManager.getModel().getWidth(), mGraphModelManager.getModel().getHeight()));
		add(mGraphScrollPane, BorderLayout.CENTER);
	}
	public void enterSelectMode()
	{
		mEditorToolBar.enterSelectMode();
	}
	public void updateEdgeTypes(TypeNameAndConstructionInfo[] typeNameAndConstructionInfo)
	{
		mEditorToolBar.updateEdgeTypes(typeNameAndConstructionInfo);
	}
	public void updateVertexTypes(TypeNameAndConstructionInfo[] typeNameAndConstructionInfo)
	{
		mEditorToolBar.updateVertexTypes(typeNameAndConstructionInfo);
	}
	public void setEditable(boolean editable)
	{
		mGraphModelManager.setEditable(editable);
		mEditorToolBar.setGraphEditable(editable);
	}
}