Coverage details for net.sourceforge.demetrix.ui.ProcessChainEditor

LineHitsSource
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  */
6320public class ProcessChainEditor
64     implements CurrentlySelectedNodeObserver, CurrentProcessChainObserver {
65     private static ProcessChainEditor instance;
66     private LayoutController layoutController;
67     public static ProcessChainEditor getInstance() {
6885        if (instance == null) {
693            instance = new ProcessChainEditor();
70         }
7185        return instance;
72     }
73     public JMenuItem about;
743    public Action aboutAction = new AbstractAction() {
75         public void actionPerformed(ActionEvent event) {
76             actionsExecutor.aboutAction();
77         }
78     };
79     private ProcessChainEditorActions actionsExecutor;
80     public JMenuItem balanceSheet;
813    public Action balanceSheetAction = new AbstractAction() {
82         public void actionPerformed(ActionEvent event) {
83             actionsExecutor.balanceSheetAction();
84         }
85     };
86     public JMenuItem createTaskSubGraph;
873    public Action createTaskSubGraphAction = new AbstractAction() {
88         public void actionPerformed(ActionEvent event) {
89             actionsExecutor.createTaskSubGraphAction(grapht, jgraph);
90         }
91     };
92     public JMenuItem delete;
933    public Action deleteAction = new AbstractAction() {
94         public void actionPerformed(ActionEvent event) {
95             actionsExecutor.deleteAction(jgraph);
96         }
97     };
98  
99     public JMenuItem descendIntoSubGraph;
1003    public Action descendIntoSubGraphAction = new AbstractAction() {
101         public void actionPerformed(ActionEvent event) {
102             actionsExecutor.descendIntoSubGraphAction();
103         }
104     };
105     public JMenuItem exit;
1063    public Action exitAction = new AbstractAction() {
107         public void actionPerformed(ActionEvent event) {
108             exitAction();
109         }
110     };
111     public JMenuItem exportToPNG;
1123    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;
1233    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;
1303    public Action newLinkAction = new AbstractAction() {
131         public void actionPerformed(ActionEvent event) {
132             actionsExecutor.newLinkAction(jgraph, grapht);
133         }
134     };
135     public JMenuItem newProcessChain;
1363    public Action newProcessChainAction = new AbstractAction() {
137         public void actionPerformed(ActionEvent event) {
138             actionsExecutor.newProcessChainAction();
139         }
140     };
141     public JMenuItem newResource;
1423    public Action newResourceAction = new AbstractAction() {
143         public void actionPerformed(ActionEvent event) {
144             actionsExecutor.newResourceAction(grapht);
145         }
146     };
147     public JMenuItem newTask;
1483    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;
1553    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;
1633    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 {
1713        super();
1723        DefaultGraphModel model = null;
1733        GraphLayoutCache cellMapper = null;
1743        PopupMenu popupMenu = null;
175  
1763        CurrentProcessChainSingleton.getInstance().attach(this);
177  
1783        this.actionsExecutor = new ProcessChainEditorActions();
179         try {
180  
1813            this.frame =
182                 (JFrame) (new SwingEngine(this)).render(
183                     ClassLoader.getSystemClassLoader().getResource(
184                         UI_DEF_FILE_NAME));
185  
1860        } catch (Exception exception) {
187             this.logger.error("", exception);
1883        }
1893        CursorManagementSingleton.getInstance().setFrame(this.frame);
1903        CurrentlySelectedNodeSingleton.getInstance().attach(this);
1913        this.frame.addWindowListener(new java.awt.event.WindowAdapter() {
192             public void windowClosing(java.awt.event.WindowEvent evt) {
193                 System.exit(0);
194             }
195         });
1963        this.popupListener = new PopupListener(new PopupMenu());
1973        this.sideBarScrollPane.setViewportView((SideBar.getInstance()).getSplitPane());
1983        this.enableMenuItemsWhenNoProcessChainIsThere();
1993        this.setLayoutController(new AnnealingLayoutController());
2003    }
201     public void createGraphNodes(
202         ListenableDirectedGraph graph,
203         ProcessChain processChain) {
2040        Iterator iterator = null;
2050        Resource resource = null;
2060        Task task = null;
2070        Link link = null;
208  
2090        iterator = processChain.getResources().iterator();
2100        while (iterator.hasNext()) {
2110            resource = (Resource) iterator.next();
2120            graph.addVertex(resource);
213         }
2140        iterator = processChain.getTasks().iterator();
2150        while (iterator.hasNext()) {
2160            task = (Task) iterator.next();
2170            graph.addVertex(task);
218         }
2190        iterator = processChain.getLinks().iterator();
2200        while (iterator.hasNext()) {
2210            link = (Link) iterator.next();
2220            graph.addEdge(link);
223         }
224         
2250        this.getLayoutController().getLayoutAlgorithm().perform(
226             this.jgraph,
227             true,
228             this.getLayoutController().getConfiguration());
2290    }
230     /* (non-Javadoc)
231      * @see net.sourceforge.demetrix.ui.CurrentlySelectedNodeObserver#currentlySelectedNodeChanged()
232      */
233     public void currentlySelectedNodeChanged() {
23424        DefaultGraphCell currentlySelectedNode = null;
23524        currentlySelectedNode =
236             CurrentlySelectedNodeSingleton
237                 .getInstance()
238                 .getCurrentlySelectedNode();
23924        if (currentlySelectedNode != null) {
24015            if (currentlySelectedNode.getUserObject() instanceof Task) {
2419                this.balanceSheet.setEnabled(true);
242             } else {
2436                this.balanceSheet.setEnabled(false);
244             }
245         }
24624        if (CurrentlySelectedNodeSingleton
247             .getInstance()
248             .getCurrentlySelectedCells()
249             != null) {
25012            if (CurrentlySelectedNodeSingleton
251                 .getInstance()
252                 .getCurrentlySelectedCells()
253                 .length
254                 > 1) {
2559                this.createTaskSubGraph.setEnabled(true);
256  
257             } else {
2583                this.createTaskSubGraph.setEnabled(false);
259             }
260         } else {
26112            this.createTaskSubGraph.setEnabled(false);
262         }
26324        if (CurrentlySelectedNodeSingleton
264             .getInstance()
265             .getCurrentlySelectedNode()
266             == null) {
2679            this.createTaskSubGraph.setEnabled(false);
268         }
269  
27024        this.delete.setEnabled(this.getStateOfDeleteMenuItem());
27124    }
272     public boolean getStateOfDeleteMenuItem() {
27392        if (CurrentlySelectedNodeSingleton
274             .getInstance()
275             .getCurrentlySelectedNode()
276             != null) {
27759            return true;
27833        } else if (
279             (CurrentlySelectedNodeSingleton
280                 .getInstance()
281                 .getCurrentlySelectedCells()
282                 != null)
283                 && (CurrentlySelectedNodeSingleton
284                     .getInstance()
285                     .getCurrentlySelectedCells()
286                     .length
287                     > 0)) {
28819            return true;
289         } else {
29014            return false;
291         }
292     }
293     public void enableMenuItemsWhenNoProcessChainIsThere() {
2943        about.setEnabled(true);
2953        balanceSheet.setEnabled(false);
2963        exit.setEnabled(true);
2973        exportToPNG.setEnabled(false);
2983        newLink.setEnabled(false);
2993        newProcessChain.setEnabled(true);
3003        newResource.setEnabled(false);
3013        newTask.setEnabled(false);
3023        saveProcessChain.setEnabled(false);
3033        systemBalanceSheet.setEnabled(false);
3043        delete.setEnabled(false);
3053    }
306     public void enableMenuItemsWhenProcessChainIsThere() {
3077        about.setEnabled(true);
3087        balanceSheet.setEnabled(false);
3097        exit.setEnabled(true);
3107        exportToPNG.setEnabled(true);
3117        newLink.setEnabled(true);
3127        newProcessChain.setEnabled(true);
3137        newResource.setEnabled(true);
3147        newTask.setEnabled(true);
3157        saveProcessChain.setEnabled(true);
3167        systemBalanceSheet.setEnabled(true);
3177        delete.setEnabled(false);
3187    }
319     private void exitAction() {
3200        DemetrixConfigurationSingleton.getInstance().writeData();
321         logger.info("Thank you for using " + Demetrix.PRODUCT_NAME + "!");
3220        System.exit(0);
3230    }
324     public JFrame getFrame() {
3251        return frame;
326     }
327     private void layoutGraph() {
3287        LayoutController controller = null;
3297        controller = new AnnealingLayoutController();
3307        controller.getLayoutAlgorithm().perform(
331             this.jgraph,
332             true,
333             controller.getConfiguration());
3347    }
335     public void newResourcePopupAction(int x, int y) {
3360        this.actionsExecutor.newResourcePopupAction(
337             this.grapht,
338             x,
339             y,
340             this.jgraphModelAdapter);
3410    }
342     public void newTaskPopupAction(int x, int y) {
3430        this.actionsExecutor.newTaskPopupAction(
344             this.grapht,
345             x,
346             y,
347             this.jgraphModelAdapter);
3480    }
349     public void recreateGraphs() {
3507        this.grapht =
351             (ListenableDirectedGraph) CurrentProcessChainSingleton
352                 .getInstance()
353                 .getCurrentGraphParent()
354                 .getSubGraph();
3557        this.jgraphModelAdapter = new JGraphModelAdapter(grapht);
3567        this.jgraph =
357             new ProcessChainGraph(
358                 this.jgraphModelAdapter,
359                 new DemetrixMarqueeHandler());
3607        this.jgraph.addMouseListener(this.popupListener);
3617        this.layoutGraph();
3627        this.graphScrollPane.setViewportView(this.jgraph);
3637        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         });
3877    }
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() {
3930        this.jgraph.repaint();
3940    }
395     public void show() {
3960        this.frame.show();
3970    }
398     /* (non-Javadoc)
399      * @see net.sourceforge.demetrix.ui.CurrentProcessChainObserver#currentGraphParentChanged()
400      */
401     public void currentGraphParentChanged() {
402         this.logger.debug("currentGraphParentChanged");
4037        this.recreateGraphs();
4047        this.enableMenuItemsWhenProcessChainIsThere();
4057        CursorManagementSingleton.getInstance().setDefaultCursor();
4067    }
407     /**
408      * @return
409      */
410     public LayoutController getLayoutController() {
4112        return layoutController;
412     }
413  
414     /**
415      * @param controller
416      */
417     public void setLayoutController(LayoutController controller) {
4183        layoutController = controller;
4193    }
420  
421 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.