Mercurial > hg > ccmieditor
comparison java/src/uk/ac/qmul/eecs/ccmi/gui/DiagramPanel.java @ 0:9418ab7b7f3f
Initial import
author | Fiore Martin <fiore@eecs.qmul.ac.uk> |
---|---|
date | Fri, 16 Dec 2011 17:35:51 +0000 |
parents | |
children | 9e67171477bc |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9418ab7b7f3f |
---|---|
1 /* | |
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool | |
3 | |
4 Copyright (C) 2002 Cay S. Horstmann (http://horstmann.com) | |
5 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) | |
6 | |
7 This program is free software: you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation, either version 3 of the License, or | |
10 (at your option) any later version. | |
11 | |
12 This program is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 */ | |
20 | |
21 package uk.ac.qmul.eecs.ccmi.gui; | |
22 | |
23 import java.awt.BorderLayout; | |
24 | |
25 import javax.swing.JPanel; | |
26 import javax.swing.JScrollPane; | |
27 import javax.swing.JSplitPane; | |
28 import javax.swing.event.ChangeEvent; | |
29 import javax.swing.event.ChangeListener; | |
30 | |
31 /** | |
32 * It's the panel which displays a diagram. It contains a {@link GraphPanel}, a {@link DiagramTree} | |
33 * and a {@link GraphToolbar} | |
34 * | |
35 */ | |
36 @SuppressWarnings("serial") | |
37 public class DiagramPanel extends JPanel{ | |
38 | |
39 public DiagramPanel(Diagram diagram, EditorTabbedPane tabbedPane){ | |
40 this.diagram = diagram; | |
41 this.tabbedPane = tabbedPane; | |
42 setName(diagram.getLabel()); | |
43 setLayout(new BorderLayout()); | |
44 | |
45 modelChangeListener = new ChangeListener(){ | |
46 @Override | |
47 public void stateChanged(ChangeEvent e) { | |
48 setModified(true); | |
49 } | |
50 }; | |
51 | |
52 toolbar = new GraphToolbar(diagram); | |
53 graphPanel = new GraphPanel(diagram, toolbar); | |
54 /* the focus must be hold by the tree and the tab panel only */ | |
55 toolbar.setFocusable(false); | |
56 graphPanel.setFocusable(false); | |
57 | |
58 tree = new DiagramTree(diagram); | |
59 | |
60 /* the panel containing the graph and the toolbar */ | |
61 JPanel graphAndToolbarPanel = new JPanel(new BorderLayout()); | |
62 graphAndToolbarPanel.add(toolbar, BorderLayout.NORTH); | |
63 graphAndToolbarPanel.add(new JScrollPane(graphPanel),BorderLayout.CENTER); | |
64 | |
65 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, | |
66 new JScrollPane(tree), | |
67 graphAndToolbarPanel); | |
68 splitPane.setDividerLocation((int)tree.getPreferredSize().width*2); | |
69 add(splitPane, BorderLayout.CENTER); | |
70 | |
71 diagram.getCollectionModel().addChangeListener(modelChangeListener); | |
72 } | |
73 | |
74 public String getFilePath(){ | |
75 return filePath; | |
76 } | |
77 | |
78 public void setFilePath(String newValue){ | |
79 filePath = newValue; | |
80 } | |
81 | |
82 public Diagram getDiagram(){ | |
83 return diagram; | |
84 } | |
85 | |
86 public void setDiagram(Diagram diagram){ | |
87 /* remove the listener from the old model */ | |
88 this.diagram.getCollectionModel().removeChangeListener(modelChangeListener); | |
89 diagram.getCollectionModel().addChangeListener(modelChangeListener); | |
90 | |
91 this.diagram = diagram; | |
92 tree.setDiagram(diagram); | |
93 graphPanel.setModelUpdater(diagram.getModelUpdater()); | |
94 setName(diagram.getLabel()); | |
95 /* set the * according to the new diagram's model modification status */ | |
96 setModified(isModified()); | |
97 } | |
98 | |
99 public GraphPanel getGraphPanel(){ | |
100 return graphPanel; | |
101 } | |
102 | |
103 public DiagramTree getTree(){ | |
104 return tree; | |
105 } | |
106 | |
107 /** This method is for changing the 'modified' status of the diagram. * | |
108 * When called passing false as argument listeners are notified that the * | |
109 * diagram has been saved. */ | |
110 public void setModified(boolean modified){ | |
111 if(!modified) | |
112 diagram.getCollectionModel().setUnmodified(); | |
113 /* add an asterisk to notify that the diagram has changed */ | |
114 if(modified) | |
115 setName(getName()+"*"); | |
116 else | |
117 setName(diagram.getLabel()); | |
118 tabbedPane.refreshComponentTabTitle(this); | |
119 } | |
120 | |
121 public boolean isModified(){ | |
122 return diagram.getCollectionModel().isModified(); | |
123 } | |
124 | |
125 private Diagram diagram; | |
126 private GraphPanel graphPanel; | |
127 private DiagramTree tree; | |
128 private GraphToolbar toolbar; | |
129 private String filePath; | |
130 private ChangeListener modelChangeListener; | |
131 private EditorTabbedPane tabbedPane; | |
132 } |