Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * Demetrix process modelling system | |
3 | * | |
4 | * Copyright (c) 2003, 2004 Dimitri A. Pissarenko | |
5 | * | |
6 | * This file is part of Demetrix. | |
7 | * | |
8 | * Demetrix is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2.1 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * Demetrix is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with Demetrix; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | * For further information you may | |
23 | * | |
24 | * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net | |
25 | * - look at http://sourceforge.net/projects/demetrix/ | |
26 | * - look at http://demetrix.sourceforge.net/ | |
27 | * - look at http://members.inode.at/d.pissarenko/ | |
28 | * | |
29 | *****************************************************************************/ | |
30 | package net.sourceforge.demetrix.ui; | |
31 | import java.awt.HeadlessException; | |
32 | import java.awt.event.ActionEvent; | |
33 | import java.awt.event.MouseListener; | |
34 | import java.util.Iterator; | |
35 | import javax.swing.AbstractAction; | |
36 | import javax.swing.Action; | |
37 | import javax.swing.JFrame; | |
38 | import javax.swing.JMenuItem; | |
39 | import javax.swing.JScrollPane; | |
40 | import javax.swing.JSplitPane; | |
41 | import net.sourceforge.demetrix.Demetrix; | |
42 | import net.sourceforge.demetrix.graph.ProcessChainGraph; | |
43 | import net.sourceforge.demetrix.model.Link; | |
44 | import net.sourceforge.demetrix.model.ProcessChain; | |
45 | import net.sourceforge.demetrix.model.Resource; | |
46 | import net.sourceforge.demetrix.model.Task; | |
47 | import org._3pq.jgrapht.ext.JGraphModelAdapter; | |
48 | import org._3pq.jgrapht.graph.ListenableDirectedGraph; | |
49 | import org.apache.log4j.Logger; | |
50 | import org.jgraph.JGraph; | |
51 | import org.jgraph.event.GraphSelectionEvent; | |
52 | import org.jgraph.event.GraphSelectionListener; | |
53 | import org.jgraph.graph.DefaultGraphCell; | |
54 | import org.jgraph.graph.DefaultGraphModel; | |
55 | import org.jgraph.graph.GraphLayoutCache; | |
56 | import org.jgraph.layout.AnnealingLayoutController; | |
57 | import org.jgraph.layout.LayoutController; | |
58 | import org.swixml.SwingEngine; | |
59 | /** | |
60 | * @author Dimitri Pissarenko | |
61 | * | |
62 | */ | |
63 | 20 | public class ProcessChainEditor |
64 | implements CurrentlySelectedNodeObserver, CurrentProcessChainObserver { | |
65 | private static ProcessChainEditor instance; | |
66 | private LayoutController layoutController; | |
67 | public static ProcessChainEditor getInstance() { | |
68 | 85 | if (instance == null) { |
69 | 3 | instance = new ProcessChainEditor(); |
70 | } | |
71 | 85 | return instance; |
72 | } | |
73 | public JMenuItem about; | |
74 | 3 | public Action aboutAction = new AbstractAction() { |
75 | public void actionPerformed(ActionEvent event) { | |
76 | actionsExecutor.aboutAction(); | |
77 | } | |
78 | }; | |
79 | private ProcessChainEditorActions actionsExecutor; | |
80 | public JMenuItem balanceSheet; | |
81 | 3 | public Action balanceSheetAction = new AbstractAction() { |
82 | public void actionPerformed(ActionEvent event) { | |
83 | actionsExecutor.balanceSheetAction(); | |
84 | } | |
85 | }; | |
86 | public JMenuItem createTaskSubGraph; | |
87 | 3 | public Action createTaskSubGraphAction = new AbstractAction() { |
88 | public void actionPerformed(ActionEvent event) { | |
89 | actionsExecutor.createTaskSubGraphAction(grapht, jgraph); | |
90 | } | |
91 | }; | |
92 | public JMenuItem delete; | |
93 | 3 | public Action deleteAction = new AbstractAction() { |
94 | public void actionPerformed(ActionEvent event) { | |
95 | actionsExecutor.deleteAction(jgraph); | |
96 | } | |
97 | }; | |
98 | ||
99 | public JMenuItem descendIntoSubGraph; | |
100 | 3 | public Action descendIntoSubGraphAction = new AbstractAction() { |
101 | public void actionPerformed(ActionEvent event) { | |
102 | actionsExecutor.descendIntoSubGraphAction(); | |
103 | } | |
104 | }; | |
105 | public JMenuItem exit; | |
106 | 3 | public Action exitAction = new AbstractAction() { |
107 | public void actionPerformed(ActionEvent event) { | |
108 | exitAction(); | |
109 | } | |
110 | }; | |
111 | public JMenuItem exportToPNG; | |
112 | 3 | public Action exportToPNGAction = new AbstractAction() { |
113 | public void actionPerformed(ActionEvent event) { | |
114 | actionsExecutor.exportToPNGAction(jgraph); | |
115 | } | |
116 | }; | |
117 | private JFrame frame; | |
118 | public JScrollPane graphScrollPane; | |
119 | private ListenableDirectedGraph grapht; | |
120 | private JGraph jgraph; | |
121 | private JGraphModelAdapter jgraphModelAdapter; | |
122 | public JMenuItem loadProcessChain; | |
123 | 3 | public Action loadProcessChainAction = new AbstractAction() { |
124 | public void actionPerformed(ActionEvent event) { | |
125 | actionsExecutor.loadProcessChainActionAction(); | |
126 | } | |
127 | }; | |
128 | private Logger logger = Logger.getLogger(getClass()); | |
129 | public JMenuItem newLink; | |
130 | 3 | public Action newLinkAction = new AbstractAction() { |
131 | public void actionPerformed(ActionEvent event) { | |
132 | actionsExecutor.newLinkAction(jgraph, grapht); | |
133 | } | |
134 | }; | |
135 | public JMenuItem newProcessChain; | |
136 | 3 | public Action newProcessChainAction = new AbstractAction() { |
137 | public void actionPerformed(ActionEvent event) { | |
138 | actionsExecutor.newProcessChainAction(); | |
139 | } | |
140 | }; | |
141 | public JMenuItem newResource; | |
142 | 3 | public Action newResourceAction = new AbstractAction() { |
143 | public void actionPerformed(ActionEvent event) { | |
144 | actionsExecutor.newResourceAction(grapht); | |
145 | } | |
146 | }; | |
147 | public JMenuItem newTask; | |
148 | 3 | public Action newTaskAction = new AbstractAction() { |
149 | public void actionPerformed(ActionEvent event) { | |
150 | actionsExecutor.newTaskAction(grapht); | |
151 | } | |
152 | }; | |
153 | private MouseListener popupListener; | |
154 | public JMenuItem saveProcessChain; | |
155 | 3 | public Action saveProcessChainAction = new AbstractAction() { |
156 | public void actionPerformed(ActionEvent event) { | |
157 | actionsExecutor.saveProcessChainAction(); | |
158 | } | |
159 | }; | |
160 | public JScrollPane sideBarScrollPane; | |
161 | public JSplitPane splitPane; | |
162 | public JMenuItem systemBalanceSheet; | |
163 | 3 | public Action systemBalanceSheetAction = new AbstractAction() { |
164 | public void actionPerformed(ActionEvent event) { | |
165 | actionsExecutor.systemBalanceSheetAction(); | |
166 | } | |
167 | }; | |
168 | public final static String UI_DEF_FILE_NAME = | |
169 | "net/sourceforge/demetrix/ui/ProcessChainEditor.xml"; | |
170 | protected ProcessChainEditor() throws HeadlessException { | |
171 | 3 | super(); |
172 | 3 | DefaultGraphModel model = null; |
173 | 3 | GraphLayoutCache cellMapper = null; |
174 | 3 | PopupMenu popupMenu = null; |
175 | ||
176 | 3 | CurrentProcessChainSingleton.getInstance().attach(this); |
177 | ||
178 | 3 | this.actionsExecutor = new ProcessChainEditorActions(); |
179 | try { | |
180 | ||
181 | 3 | this.frame = |
182 | (JFrame) (new SwingEngine(this)).render( | |
183 | ClassLoader.getSystemClassLoader().getResource( | |
184 | UI_DEF_FILE_NAME)); | |
185 | ||
186 | 0 | } catch (Exception exception) { |
187 | this.logger.error("", exception); | |
188 | 3 | } |
189 | 3 | CursorManagementSingleton.getInstance().setFrame(this.frame); |
190 | 3 | CurrentlySelectedNodeSingleton.getInstance().attach(this); |
191 | 3 | this.frame.addWindowListener(new java.awt.event.WindowAdapter() { |
192 | public void windowClosing(java.awt.event.WindowEvent evt) { | |
193 | System.exit(0); | |
194 | } | |
195 | }); | |
196 | 3 | this.popupListener = new PopupListener(new PopupMenu()); |
197 | 3 | this.sideBarScrollPane.setViewportView((SideBar.getInstance()).getSplitPane()); |
198 | 3 | this.enableMenuItemsWhenNoProcessChainIsThere(); |
199 | 3 | this.setLayoutController(new AnnealingLayoutController()); |
200 | 3 | } |
201 | public void createGraphNodes( | |
202 | ListenableDirectedGraph graph, | |
203 | ProcessChain processChain) { | |
204 | 0 | Iterator iterator = null; |
205 | 0 | Resource resource = null; |
206 | 0 | Task task = null; |
207 | 0 | Link link = null; |
208 | ||
209 | 0 | iterator = processChain.getResources().iterator(); |
210 | 0 | while (iterator.hasNext()) { |
211 | 0 | resource = (Resource) iterator.next(); |
212 | 0 | graph.addVertex(resource); |
213 | } | |
214 | 0 | iterator = processChain.getTasks().iterator(); |
215 | 0 | while (iterator.hasNext()) { |
216 | 0 | task = (Task) iterator.next(); |
217 | 0 | graph.addVertex(task); |
218 | } | |
219 | 0 | iterator = processChain.getLinks().iterator(); |
220 | 0 | while (iterator.hasNext()) { |
221 | 0 | link = (Link) iterator.next(); |
222 | 0 | graph.addEdge(link); |
223 | } | |
224 | ||
225 | 0 | this.getLayoutController().getLayoutAlgorithm().perform( |
226 | this.jgraph, | |
227 | true, | |
228 | this.getLayoutController().getConfiguration()); | |
229 | 0 | } |
230 | /* (non-Javadoc) | |
231 | * @see net.sourceforge.demetrix.ui.CurrentlySelectedNodeObserver#currentlySelectedNodeChanged() | |
232 | */ | |
233 | public void currentlySelectedNodeChanged() { | |
234 | 24 | DefaultGraphCell currentlySelectedNode = null; |
235 | 24 | currentlySelectedNode = |
236 | CurrentlySelectedNodeSingleton | |
237 | .getInstance() | |
238 | .getCurrentlySelectedNode(); | |
239 | 24 | if (currentlySelectedNode != null) { |
240 | 15 | if (currentlySelectedNode.getUserObject() instanceof Task) { |
241 | 9 | this.balanceSheet.setEnabled(true); |
242 | } else { | |
243 | 6 | this.balanceSheet.setEnabled(false); |
244 | } | |
245 | } | |
246 | 24 | if (CurrentlySelectedNodeSingleton |
247 | .getInstance() | |
248 | .getCurrentlySelectedCells() | |
249 | != null) { | |
250 | 12 | if (CurrentlySelectedNodeSingleton |
251 | .getInstance() | |
252 | .getCurrentlySelectedCells() | |
253 | .length | |
254 | > 1) { | |
255 | 9 | this.createTaskSubGraph.setEnabled(true); |
256 | ||
257 | } else { | |
258 | 3 | this.createTaskSubGraph.setEnabled(false); |
259 | } | |
260 | } else { | |
261 | 12 | this.createTaskSubGraph.setEnabled(false); |
262 | } | |
263 | 24 | if (CurrentlySelectedNodeSingleton |
264 | .getInstance() | |
265 | .getCurrentlySelectedNode() | |
266 | == null) { | |
267 | 9 | this.createTaskSubGraph.setEnabled(false); |
268 | } | |
269 | ||
270 | 24 | this.delete.setEnabled(this.getStateOfDeleteMenuItem()); |
271 | 24 | } |
272 | public boolean getStateOfDeleteMenuItem() { | |
273 | 92 | if (CurrentlySelectedNodeSingleton |
274 | .getInstance() | |
275 | .getCurrentlySelectedNode() | |
276 | != null) { | |
277 | 59 | return true; |
278 | 33 | } else if ( |
279 | (CurrentlySelectedNodeSingleton | |
280 | .getInstance() | |
281 | .getCurrentlySelectedCells() | |
282 | != null) | |
283 | && (CurrentlySelectedNodeSingleton | |
284 | .getInstance() | |
285 | .getCurrentlySelectedCells() | |
286 | .length | |
287 | > 0)) { | |
288 | 19 | return true; |
289 | } else { | |
290 | 14 | return false; |
291 | } | |
292 | } | |
293 | public void enableMenuItemsWhenNoProcessChainIsThere() { | |
294 | 3 | about.setEnabled(true); |
295 | 3 | balanceSheet.setEnabled(false); |
296 | 3 | exit.setEnabled(true); |
297 | 3 | exportToPNG.setEnabled(false); |
298 | 3 | newLink.setEnabled(false); |
299 | 3 | newProcessChain.setEnabled(true); |
300 | 3 | newResource.setEnabled(false); |
301 | 3 | newTask.setEnabled(false); |
302 | 3 | saveProcessChain.setEnabled(false); |
303 | 3 | systemBalanceSheet.setEnabled(false); |
304 | 3 | delete.setEnabled(false); |
305 | 3 | } |
306 | public void enableMenuItemsWhenProcessChainIsThere() { | |
307 | 7 | about.setEnabled(true); |
308 | 7 | balanceSheet.setEnabled(false); |
309 | 7 | exit.setEnabled(true); |
310 | 7 | exportToPNG.setEnabled(true); |
311 | 7 | newLink.setEnabled(true); |
312 | 7 | newProcessChain.setEnabled(true); |
313 | 7 | newResource.setEnabled(true); |
314 | 7 | newTask.setEnabled(true); |
315 | 7 | saveProcessChain.setEnabled(true); |
316 | 7 | systemBalanceSheet.setEnabled(true); |
317 | 7 | delete.setEnabled(false); |
318 | 7 | } |
319 | private void exitAction() { | |
320 | 0 | DemetrixConfigurationSingleton.getInstance().writeData(); |
321 | logger.info("Thank you for using " + Demetrix.PRODUCT_NAME + "!"); | |
322 | 0 | System.exit(0); |
323 | 0 | } |
324 | public JFrame getFrame() { | |
325 | 1 | return frame; |
326 | } | |
327 | private void layoutGraph() { | |
328 | 7 | LayoutController controller = null; |
329 | 7 | controller = new AnnealingLayoutController(); |
330 | 7 | controller.getLayoutAlgorithm().perform( |
331 | this.jgraph, | |
332 | true, | |
333 | controller.getConfiguration()); | |
334 | 7 | } |
335 | public void newResourcePopupAction(int x, int y) { | |
336 | 0 | this.actionsExecutor.newResourcePopupAction( |
337 | this.grapht, | |
338 | x, | |
339 | y, | |
340 | this.jgraphModelAdapter); | |
341 | 0 | } |
342 | public void newTaskPopupAction(int x, int y) { | |
343 | 0 | this.actionsExecutor.newTaskPopupAction( |
344 | this.grapht, | |
345 | x, | |
346 | y, | |
347 | this.jgraphModelAdapter); | |
348 | 0 | } |
349 | public void recreateGraphs() { | |
350 | 7 | this.grapht = |
351 | (ListenableDirectedGraph) CurrentProcessChainSingleton | |
352 | .getInstance() | |
353 | .getCurrentGraphParent() | |
354 | .getSubGraph(); | |
355 | 7 | this.jgraphModelAdapter = new JGraphModelAdapter(grapht); |
356 | 7 | this.jgraph = |
357 | new ProcessChainGraph( | |
358 | this.jgraphModelAdapter, | |
359 | new DemetrixMarqueeHandler()); | |
360 | 7 | this.jgraph.addMouseListener(this.popupListener); |
361 | 7 | this.layoutGraph(); |
362 | 7 | this.graphScrollPane.setViewportView(this.jgraph); |
363 | 7 | this.jgraph.addGraphSelectionListener(new GraphSelectionListener() { |
364 | public void valueChanged(GraphSelectionEvent event) { | |
365 | Object cell = null; | |
366 | cell = jgraph.getSelectionCell(); | |
367 | if (cell instanceof DefaultGraphCell) { | |
368 | CurrentlySelectedNodeSingleton | |
369 | .getInstance() | |
370 | .setCurrentlySelectedNode( | |
371 | (DefaultGraphCell) cell); | |
372 | } else { | |
373 | CurrentlySelectedNodeSingleton | |
374 | .getInstance() | |
375 | .setCurrentlySelectedNode( | |
376 | null); | |
377 | } | |
378 | CurrentlySelectedNodeSingleton | |
379 | .getInstance() | |
380 | .setCurrentlySelectedCells( | |
381 | jgraph.getSelectionCells()); | |
382 | CurrentlySelectedNodeSingleton | |
383 | .getInstance() | |
384 | .informCurrentlySelectedNodeChanged(); | |
385 | } | |
386 | }); | |
387 | 7 | } |
388 | /** | |
389 | * this method is used to tell the class that grapht has changed and | |
390 | * the graph needs to be repainted | |
391 | **/ | |
392 | public void redrawGraph() { | |
393 | 0 | this.jgraph.repaint(); |
394 | 0 | } |
395 | public void show() { | |
396 | 0 | this.frame.show(); |
397 | 0 | } |
398 | /* (non-Javadoc) | |
399 | * @see net.sourceforge.demetrix.ui.CurrentProcessChainObserver#currentGraphParentChanged() | |
400 | */ | |
401 | public void currentGraphParentChanged() { | |
402 | this.logger.debug("currentGraphParentChanged"); | |
403 | 7 | this.recreateGraphs(); |
404 | 7 | this.enableMenuItemsWhenProcessChainIsThere(); |
405 | 7 | CursorManagementSingleton.getInstance().setDefaultCursor(); |
406 | 7 | } |
407 | /** | |
408 | * @return | |
409 | */ | |
410 | public LayoutController getLayoutController() { | |
411 | 2 | return layoutController; |
412 | } | |
413 | ||
414 | /** | |
415 | * @param controller | |
416 | */ | |
417 | public void setLayoutController(LayoutController controller) { | |
418 | 3 | layoutController = controller; |
419 | 3 | } |
420 | ||
421 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |