KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > JaWEGraphSelectionModel


1 /* PEGraphSelectionModel.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11 package org.enhydra.jawe;
12
13 import org.jgraph.graph.*;
14 import org.jgraph.JGraph;
15
16 import java.util.*;
17 import org.enhydra.jawe.PackageEditor;
18
19 /**
20 * JaWE implementation of selection model.
21 */

22 public class JaWEGraphSelectionModel extends DefaultGraphSelectionModel {
23
24     /** Constructs a DefaultGraphSelectionModel for the specified graph. */
25     public JaWEGraphSelectionModel(JGraph graph) {
26         super(graph);
27     }
28
29     /**
30     * Modifies original method to avoid selection of in/out of subflow.
31     */

32     public void setSelectionCells(Object JavaDoc[] cells) {
33         super.setSelectionCells(removeForbiddenCells(cells));
34     }
35
36     /**
37     * Modifies original method to avoid selection of in/out of subflow.
38     */

39     public void addSelectionCells(Object JavaDoc[] cells) {
40         super.addSelectionCells(removeForbiddenCells(cells));
41     }
42
43     /**
44     * Modifies original method to avoid deselection of in/out of subflow.
45     */

46     public void removeSelectionCells(Object JavaDoc[] cells) {
47         super.removeSelectionCells(removeForbiddenCells(cells));
48     }
49
50     /**
51     * Removes forbiden objects from selection.
52     */

53     private Object JavaDoc[] removeForbiddenCells (Object JavaDoc[] cells) {
54         /*
55         if (cells != null && cells.length>0) {
56             Set cellsToSelect=new HashSet();
57             for (int i=0; i<cells.length; i++) {
58                 if (!(cells[i] instanceof SubflowPort)) {
59                     cellsToSelect.add(cells[i]);
60                 }
61             }
62             if (cellsToSelect.size()>0) {
63                 cells=cellsToSelect.toArray();
64             }
65             else {
66                 cells=null;
67             }
68         }
69         */

70         return cells;
71     }
72
73     // NOTE: FOLLOWING METHOD IS NEVER CALLED BECAUSE PEJGRAPH IMPLEMENTS
74
// IT'S OWN METHOD TO DO THIS. IT COULD BE CHANGED.
75
/**
76     * Returns the cells that are currently selectable.
77     */

78     public Object JavaDoc[] getSelectables() {
79       Object JavaDoc[] selectables=super.getSelectables();
80
81       if (selectables!=null && selectables.length>0) {
82         Set removedForbiddenElements=new HashSet();
83         for (int i=0; i<selectables.length; i++) {
84             //if (!(selectables[i] instanceof SubflowPort)) {
85
removedForbiddenElements.add(selectables[i]);
86             //}
87
}
88         selectables=removedForbiddenElements.toArray();
89       }
90         return selectables;
91    }
92
93 }
94
95 /* End of PEGraphSelectionModel.java */
96
Popular Tags