KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* PEMarqueeHandler.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  * Harald Meister harald.meister@abacus.ch
9  *
10  */

11
12 package org.enhydra.jawe;
13
14 import org.enhydra.jawe.actions.*;
15 import org.enhydra.jawe.graph.*;
16
17 import org.jgraph.JGraph;
18 import org.jgraph.graph.*;
19
20 import java.awt.*;
21 import java.awt.geom.Point2D JavaDoc;
22 import java.awt.geom.Rectangle2D JavaDoc;
23 import java.awt.event.*;
24 import java.util.*;
25 import javax.swing.*;
26 import javax.swing.event.*;
27 import javax.swing.border.*;
28 import org.enhydra.jawe.PackageEditor;
29 import org.enhydra.jawe.xml.elements.WorkflowProcess;
30
31 //import java.io.*;
32

33 /**
34  * Implementation of a marquee handler for Process Editor. This is also a place
35  * where (after mouse click or release) participants, activities (normal, subflows,
36  * block activities) and transitions are inserted, where persistent mode is achived and
37  * where mouse cursors are changing, and where popup menu is implemented. When
38  * inserting cells it calls WorkflowManager.
39  */

40 public class JaWEMarqueeHandler extends BasicMarqueeHandler { //implements Serializable {
41

42    /** JGraph reference */
43    private transient AbstractGraph graph=null;
44    /** Editor reference */
45    private transient AbstractEditor ED=null;
46    /** WorkflowManager reference */
47    private transient WorkflowManager workflowManager=null;
48
49    /** Signifies the persistent mode. */
50    private boolean persistent=false;
51
52    /** Button for selecting. */
53    private transient JToggleButton selectButton = new JToggleButton();
54    /** Button for inserting process activity. */
55    private transient JToggleButton processButton = new JToggleButton();
56    /** Button for inserting participant. */
57    private transient JToggleButton participantButton = new JToggleButton();
58    /** Button for inserting subflow activity. */
59    private transient JToggleButton subflowActivityButton = new JToggleButton();
60    /** Button for inserting block activity. */
61    private transient JToggleButton blockActivityButton = new JToggleButton();
62    /** Button for inserting start. */
63    private transient JToggleButton startButton = new JToggleButton();
64    /** Button for inserting end. */
65    private transient JToggleButton endButton = new JToggleButton();
66    /** Button for automatically inserting starts and ends. */
67    private transient JToggleButton automaticStartEndButton = new JToggleButton();
68    /** Button for inserting generic activity. */
69    private transient JToggleButton genericActivityButton = new JToggleButton();
70    /** Button for inserting route activity. */
71    private transient JToggleButton routeActivityButton = new JToggleButton();
72    /** Button for inserting transition. */
73    private transient JToggleButton transitionButton = new JToggleButton();
74    /** Button for inserting transition. */
75    private transient JToggleButton selfRoutedTransitionButton = new JToggleButton();
76    /** Button for inserting transition. */
77    private transient JToggleButton circularTransitionButton = new JToggleButton();
78
79    // cursors
80
/** Mouse cursor for participant */
81    private transient Cursor participantCursor;
82    /** Mouse cursor for process activity */
83    private transient Cursor processCursor;
84    /** Mouse cursor for subflow activity */
85    private transient Cursor subflowActivityCursor;
86    /** Mouse cursor for block activity */
87    private transient Cursor blockActivityCursor;
88    /** Mouse cursor for start. */
89    private transient Cursor startCursor;
90    /** Mouse cursor for end. */
91    private transient Cursor endCursor;
92    /** Mouse cursor for generic activity */
93    private transient Cursor genericActivityCursor;
94    /** Mouse cursor for route activity */
95    private transient Cursor routeActivityCursor;
96    /** Mouse cursor for transition */
97    private transient Cursor transitionCursor;
98    /** Mouse cursor for transition */
99    private transient Cursor selfRoutedTransitionCursor;
100    /** Mouse cursor for transition */
101    private transient Cursor circularTransitionCursor;
102
103    /** Mouse listener (implements persistent mode). */
104    private transient ML ml=new ML();
105    /** Mouse listener (implements automatical inserting of start/end bubbles). */
106    private transient ASEML aseml=new ASEML();
107    /** Activity listener (implements mouse cursor change). */
108    private transient AL al=new AL();
109
110    /** Starting point (where mouse was pressed). */
111    protected Point start;
112    /** Current point (where mouse was dragged). */
113    protected Point current;
114    /** Current port (when mouse was pressed). */
115    protected PortView port;
116    /** First port (when mouse was pressed). */
117    protected PortView firstPort;
118    /** Last port (when mouse was draged). */
119    protected PortView lastPort;
120    /** A point where popup window has been created last time. */
121    protected Point popupPoint;
122
123
124    /** mouse listener to achieve persistent mode if button is doubleclicked. */
125    class ML extends MouseAdapter { //implements Serializable {
126
public void mousePressed(MouseEvent ev) {
127          if (ev.getClickCount()==2) persistent=true;
128          else persistent=false;
129       }
130    }
131
132    /** mouse listener for automatical inserting of start/end bubbles. */
133    class ASEML extends MouseAdapter { //implements Serializable {
134
public void mousePressed(MouseEvent ev) {
135          if (ED instanceof PackageEditor) {
136             Set activities=JaWEGraphModel.getAllActivitiesInModel(graph.getModel());
137             if (activities!=null) {
138                Iterator it=activities.iterator();
139                while(it.hasNext()) {
140                   Activity act=(Activity)it.next();
141                   ProcessEditor pe=act.getImplementationEditor();
142                   if (pe!=null) {
143                      ProcessGraph pg=(ProcessGraph)pe.getGraph();
144                      pg.getWorkflowManager().createGraphStarts((WorkflowProcess)pg.getPropertyObject(),true,true);
145                      pg.getWorkflowManager().createGraphEnds((WorkflowProcess)pg.getPropertyObject(),true,true);
146
147                      // find all block activities
148
Set blockActs=pg.getWorkflowManager().getBlockActivities(true);
149                      Iterator itBas=blockActs.iterator();
150                      while (itBas.hasNext()) {
151                         BlockActivity ba=(BlockActivity)itBas.next();
152                         ProcessEditor bwe=ba.getImplementationEditor();
153                         if (bwe!=null) {
154                            ProcessGraph bag=(ProcessGraph)bwe.getGraph();
155                            bag.getWorkflowManager().createGraphStarts((WorkflowProcess)pg.getPropertyObject(),true,true);
156                            bag.getWorkflowManager().createGraphEnds((WorkflowProcess)pg.getPropertyObject(),true,true);
157                         }
158                      }
159                   }
160                }
161             }
162
163          } else {
164             workflowManager.createGraphStarts((WorkflowProcess)graph.getPropertyObject(),true,true);
165             workflowManager.createGraphEnds((WorkflowProcess)graph.getPropertyObject(),true,true);
166          }
167          ED.getStatusBar().updateMessage();
168       }
169    }
170
171    /** Action listener for changing cursors. */
172    class AL implements ActionListener { //, Serializable {
173
public void actionPerformed (ActionEvent ev) {
174          JToggleButton source=(JToggleButton)ev.getSource();
175          setProperCursor(source);
176       }
177    }
178
179
180    /**
181     * Creates custom marquee handler.
182     */

183    public JaWEMarqueeHandler (AbstractGraph graph) {
184       // setting PEGraph reference
185
this.graph=graph;
186       // getting editor reference
187
ED=graph.getEditor();
188       // setting workflowManager reference
189
workflowManager=graph.getWorkflowManager();
190
191       // cursors icon
192
ImageIcon curIc;
193       // cursors hot spot
194
Point hotSpot;
195       // cursors image
196
Image curIm;
197
198       // get icons, crete images and create cursors
199
try {
200          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.PARTICIPANT_TOOL+JaWEConstants.IMAGE_SUFFIX));
201          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
202          curIm = curIc.getImage();
203          participantCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,
204                                                                  "participant20x20");
205       } catch (Exception JavaDoc e) {
206          System.err.println("Missing participant cursor in property file !");
207       }
208
209       try {
210          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.PROCESS_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX));
211          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
212          curIm = curIc.getImage();
213          processCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,
214                                                              "process20x20");
215       } catch (Exception JavaDoc e) {
216          System.err.println("Missing process cursor in property file !");
217       }
218
219       try {
220          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.SUBFLOW_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX));
221          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
222          curIm = curIc.getImage();
223          subflowActivityCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,
224                                                                      "subflowActivity20x20");
225       } catch (Exception JavaDoc e) {
226          System.err.println("Missing subflow activity cursor in property file !");
227       }
228
229       try {
230          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.BLOCK_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX));
231          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
232          curIm = curIc.getImage();
233          blockActivityCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,
234                                                                    "blockActivity20x20");
235       } catch (Exception JavaDoc e) {
236          System.err.println("Missing block activity cursor in property file !");
237       }
238
239       try {
240          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.START_TOOL+JaWEConstants.IMAGE_SUFFIX));
241          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
242          curIm = curIc.getImage();
243          startCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,
244                                                            "start20x20");
245       } catch (Exception JavaDoc e) {
246          System.err.println("Missing start cursor in property file !");
247       }
248
249       try {
250          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.END_TOOL+JaWEConstants.IMAGE_SUFFIX));
251          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
252          curIm = curIc.getImage();
253          endCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"end20x20");
254       } catch (Exception JavaDoc e) {
255          System.err.println("Missing end cursor in property file !");
256       }
257
258       try {
259          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.GENERIC_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX));
260          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
261          curIm = curIc.getImage();
262          genericActivityCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,
263                                                                      "genericActivity20x20");
264       } catch (Exception JavaDoc e) {
265          System.err.println("Missing generic activity cursor in property file !");
266       }
267
268       try {
269          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.ROUTE_ACTIVITY_TOOL+JaWEConstants.IMAGE_SUFFIX));
270          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
271          curIm = curIc.getImage();
272          routeActivityCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"routeActivity20x20");
273       } catch (Exception JavaDoc e) {
274          System.err.println("Missing route activity cursor in property file !");
275       }
276
277       try {
278          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.TRANSITION_TOOL+JaWEConstants.IMAGE_SUFFIX));
279          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
280          curIm = curIc.getImage();
281          transitionCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"transition20x20");
282       } catch (Exception JavaDoc e) {
283          System.err.println("Missing transition cursor in property file !");
284       }
285
286       try {
287          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.SELF_ROUTED_TRANSITION_TOOL+JaWEConstants.IMAGE_SUFFIX));
288          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
289          curIm = curIc.getImage();
290          selfRoutedTransitionCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"selfRoutedTransition20x20");
291       } catch (Exception JavaDoc e) {
292          System.err.println("Missing self routed transition cursor in property file !");
293       }
294
295       try {
296          curIc=new ImageIcon(ResourceManager.getResource(JaWEConstants.CIRCULAR_TRANSITION_TOOL+JaWEConstants.IMAGE_SUFFIX));
297          hotSpot=new Point(curIc.getIconWidth()/2,curIc.getIconHeight()/2);
298          curIm = curIc.getImage();
299          circularTransitionCursor=graph.getToolkit().createCustomCursor(curIm,hotSpot,"circularTransition20x20");
300       } catch (Exception JavaDoc e) {
301          System.err.println("Missing circular transition cursor in property file !");
302       }
303
304       // add mouse listener to buttons (used to determine persistent mode)
305
selectButton.addMouseListener(ml);
306       participantButton.addMouseListener(ml);
307       processButton.addMouseListener(ml);
308       subflowActivityButton.addMouseListener(ml);
309       blockActivityButton.addMouseListener(ml);
310       startButton.addMouseListener(ml);
311       endButton.addMouseListener(ml);
312       automaticStartEndButton.addMouseListener(aseml);
313       genericActivityButton.addMouseListener(ml);
314       routeActivityButton.addMouseListener(ml);
315       transitionButton.addMouseListener(ml);
316       selfRoutedTransitionButton.addMouseListener(ml);
317       circularTransitionButton.addMouseListener(ml);
318
319       // add action listeners to buttons (used to set appropriate mouse cursor)
320
selectButton.addActionListener(al);
321       participantButton.addActionListener(al);
322       processButton.addActionListener(al);
323       subflowActivityButton.addActionListener(al);
324       blockActivityButton.addActionListener(al);
325       startButton.addActionListener(al);
326       endButton.addActionListener(al);
327       automaticStartEndButton.addActionListener(al);
328       genericActivityButton.addActionListener(al);
329       routeActivityButton.addActionListener(al);
330       transitionButton.addActionListener(al);
331       selfRoutedTransitionButton.addActionListener(al);
332       circularTransitionButton.addActionListener(al);
333
334       ButtonGroup group = new ButtonGroup();
335       if (ED instanceof ProcessEditor) {
336          group.add(selectButton);
337          group.add(participantButton);
338          group.add(subflowActivityButton);
339          group.add(blockActivityButton);
340          group.add(startButton);
341          group.add(endButton);
342          group.add(automaticStartEndButton);
343          group.add(genericActivityButton);
344          group.add(routeActivityButton);
345          group.add(transitionButton);
346          group.add(selfRoutedTransitionButton);
347          group.add(circularTransitionButton);
348       } else {
349          group.add(selectButton);
350          group.add(processButton);
351          group.add(automaticStartEndButton);
352       }
353       if (!JaWEConfig.getInstance().getUseBubblesStatus()) {
354          enableBubblesButtons(false);
355       }
356
357    }
358
359    /** Return true if this handler should be preferred over other handlers. */
360    public boolean isForceMarqueeEvent(MouseEvent e) {
361       return ((selectButton.isSelected() && SwingUtilities.isRightMouseButton(e)) ||
362                  !selectButton.isSelected() ||
363                  super.isForceMarqueeEvent(e));
364    }
365
366    public void mousePressed(MouseEvent ev) {
367       // If Right Mouse Button
368
if (SwingUtilities.isRightMouseButton(ev)) {
369          // Find Cell in Model Coordinates
370
Object JavaDoc cell = graph.getFirstCellForLocation(ev.getX(),ev.getY());
371          // Create PopupMenu for the Cell (Scale From Screen to Model)
372
popupPoint = (Point)graph.fromScreen(new Point(ev.getPoint()));//HM, JGraph3.4.1
373
JPopupMenu menu = createPopupMenu(cell);
374          // Display PopupMenu
375
menu.show(graph,ev.getX(),ev.getY());
376       } else if (!ev.isConsumed() && !selectButton.isSelected()) {
377
378          start = (Point)graph.snap(ev.getPoint());//HM, JGraph3.4.1
379
firstPort = port;
380
381          // if transition is selected
382
if ((transitionButton.isSelected() || selfRoutedTransitionButton.isSelected()) && firstPort!=null) {
383             double scale=graph.getScale();
384             start=firstPort.getBounds().getBounds().getLocation();//HM, JGraph3.4.1
385
start.x+=JaWEPortView.getPortSize()/2;start.y+=JaWEPortView.getPortSize()/2;
386             start=new Point((int)(start.getX() * scale),
387                                (int)(start.getY() * scale));
388             // start the transition only if start is valid
389
if (acceptsSourceOrTarget(firstPort,true,null,false)) {
390                ev.consume();
391             } else {
392                firstPort=null;
393                port = null;
394                start = null;
395                current = null;
396             }
397             return;
398          }
399
400          // check if this is an circular transition
401
if (circularTransitionButton.isSelected() && firstPort!=null) {
402             boolean as=acceptsSourceOrTarget(firstPort,true,null,true);
403             boolean at=acceptsSourceOrTarget(firstPort,false,firstPort,true);
404             if (as && at) {
405                // finish a transition and create it if end is valid
406
// and it is not the same as begining one
407
workflowManager.insertTransition(start,start,firstPort,firstPort,
408                                                 false,true);
409             }
410
411          }
412
413          // if participant is selected
414
if (participantButton.isSelected()) {
415             workflowManager.insertParticipantAndArrangeParticipants(start,null);
416          }
417
418          // if process is selected
419
if (processButton.isSelected()) {
420             org.enhydra.jawe.graph.Process pr=workflowManager.insertProcess (((PackageGraph)graph).getNextInsertionPoint(),true);
421             ((PackageEditor)ED).putProcessObjectMapping((WorkflowProcess)pr.getUserObject(),pr);
422          }
423
424          // if subflow is selected
425
if (subflowActivityButton.isSelected()) {
426             workflowManager.insertSubflowAndArrangeParticipants(start);
427          }
428
429          // if block activity is selected
430
if (blockActivityButton.isSelected()) {
431             workflowManager.insertBlockActivityAndArrangeParticipants(start);
432          }
433
434          // if start is selected
435
if (startButton.isSelected()) {
436             workflowManager.insertStartAndArrangeParticipants(start);
437          }
438
439          // if end is selected
440
if (endButton.isSelected()) {
441             workflowManager.insertEndAndArrangeParticipants(start);
442          }
443
444          // if activity is selected
445
if (genericActivityButton.isSelected()) {
446             workflowManager.insertActivityAndArrangeParticipants(start);
447          }
448
449          // if route activity is selected
450
if (routeActivityButton.isSelected()) {
451             workflowManager.insertRouteAndArrangeParticipants(start);
452          }
453
454          ev.consume();
455          if (!persistent) selectButton.doClick();
456          firstPort=null;
457          port = null;
458          start = null;
459          current = null;
460
461       }
462
463       if(!SwingUtilities.isRightMouseButton(ev)) {
464          super.mousePressed(ev);
465       }
466
467       setProperCursor();
468    }
469
470    public void mouseDragged(MouseEvent ev) {
471       if (!ev.isConsumed() && (transitionButton.isSelected() || selfRoutedTransitionButton.isSelected()) && (firstPort != null) &&
472           !SwingUtilities.isRightMouseButton(ev)) {
473          Graphics g = graph.getGraphics();
474          Color bg = graph.getBackground();
475          Color fg = Utils.getColor(JaWEConfig.getInstance().getTransitionColor());
476          g.setColor(fg);
477          g.setXORMode(bg);
478          overlay(g);
479          current = (Point)graph.snap(ev.getPoint());//HM, JGraph3.4.1
480
/*port = graph.getPortViewAt(ev.getX(), ev.getY());
481           if (port!=null) {
482           current=port.getLocation(null);
483           }*/

484          double scale=graph.getScale();
485          port=graph.getPortViewAt((int)(ev.getX() / scale),
486                                      (int)(ev.getY() / scale));
487          if (port!=null) {
488             current = port.getBounds().getBounds().getLocation();//HM, JGraph3.4.1
489
//current=lastPort.getLocation(null);
490
current=new Point((int)(current.x * scale),
491                                  (int)(current.y * scale));
492             current.x+=JaWEPortView.getPortSize()/2;current.y+=JaWEPortView.getPortSize()/2;
493
494          }
495          g.setColor(bg);
496          g.setXORMode(fg);
497          overlay(g);
498          ev.consume();
499       }
500       // if(!SwingUtilities.isRightMouseButton(ev)) {
501
super.mouseDragged(ev);
502       // }
503

504    }
505
506    public void mouseReleased(MouseEvent ev) {
507       if (ev != null && !ev.isConsumed() && (transitionButton.isSelected() || selfRoutedTransitionButton.isSelected())
508           && !SwingUtilities.isRightMouseButton(ev)) {
509          // finish a transition and create it if end is valid
510
// and it is not the same as begining one
511
if (acceptsSourceOrTarget(port,false,firstPort,false) && port!=firstPort) {
512             workflowManager.insertTransition(start,current,firstPort,port,
513                                              selfRoutedTransitionButton.isSelected(),true);
514          }
515          else {
516             Graphics g = graph.getGraphics();
517             Color bg = graph.getBackground();
518             Color fg = Utils.getColor(JaWEConfig.getInstance().getTransitionColor());
519             g.setColor(fg);
520             g.setXORMode(bg);
521             port = firstPort;
522             overlay(g);
523          }
524          ev.consume();
525       }
526       if (!persistent) selectButton.doClick();
527       firstPort = null;
528       port = null;
529       start = null;
530       current = null;
531       // modified original method
532
try {
533          if (ev != null && !ev.isConsumed() && marqueeBounds != null
534              && !SwingUtilities.isRightMouseButton(ev)) {
535             Rectangle2D JavaDoc bounds = graph.fromScreen(marqueeBounds);//HM, JGraph3.4.1
536
CellView[] rootViews = graph.getGraphLayoutCache().getRoots(bounds);
537
538             // added - getting all views in model (except forbidden objects)
539
CellView[] views = AbstractCellView.getDescendantViews(rootViews);
540             ArrayList wholeList = new ArrayList();
541             ArrayList participantList = new ArrayList();
542             ArrayList otherList = new ArrayList();
543             for (int i = 0; i < views.length; i++) {
544                if (bounds.contains(views[i].getBounds())) {
545                   if (!(views[i] instanceof ParticipantView)) {
546                      otherList.add(views[i].getCell());
547                   }
548                   else {
549                      participantList.add(views[i].getCell());
550                   }
551                   //if (!(views[i].getCell() instanceof SubflowPort)) {
552
wholeList.add(views[i].getCell());
553                   //}
554
}
555             }
556
557             /*
558              if (participantList.size()>0)
559              cells = participantList.toArray();
560              else
561              cells = otherList.toArray();
562              */

563             Object JavaDoc[] cells = wholeList.toArray();
564
565             graph.getUI().selectCellsForEvent(graph, cells, ev);
566             //graph.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
567
//graph.setCursor(previousCursor);
568
Rectangle dirty = marqueeBounds.getBounds();//HM, JGraph3.4.1
569
dirty.width++; dirty.height++;//HM, JGraph3.4.1
570
graph.repaint(dirty);
571             ev.consume();
572          }
573       } finally {
574          currentPoint = null;
575          startPoint = null;
576          marqueeBounds = null;
577       }
578       setProperCursor();
579    }
580
581    public void mouseMoved(MouseEvent ev) {
582       if (!ev.isConsumed() && !selectButton.isSelected()) {
583          ev.consume();
584          if (transitionButton.isSelected() || selfRoutedTransitionButton.isSelected() ||
585              circularTransitionButton.isSelected()) {
586             PortView oldPort = port;
587             double scale=graph.getScale();
588             PortView newPort=graph.getPortViewAt((int)(ev.getX() / scale),
589                                                     (int)(ev.getY() / scale));
590             //PortView newPort = graph.getPortViewAt(ev.getX(), ev.getY());
591
if (oldPort != newPort) {
592                Graphics g = graph.getGraphics();
593                Color bg = graph.getBackground();
594                Color fg = graph.getMarqueeColor();
595                g.setColor(fg);
596                g.setXORMode(bg);
597                overlay(g);
598                port = newPort;
599                g.setColor(bg);
600                g.setXORMode(fg);
601                overlay(g);
602             }
603          }
604       }
605       super.mouseMoved(ev);
606    }
607
608    public void overlay(Graphics g) {
609       super.overlay(g);
610       paintPort(graph.getGraphics());
611       if (start != null) {
612          if ((transitionButton.isSelected() || selfRoutedTransitionButton.isSelected()) && current != null) {
613             g.drawLine(start.x, start.y, current.x, current.y);
614          }
615       }
616    }
617
618    protected void paintPort(Graphics g) {
619       if (port != null) {
620          boolean offset = (GraphConstants.getOffset(port.getAttributes()) != null);
621          Rectangle r = (offset) ? port.getBounds().getBounds()//HM, JGraph3.4.1
622
: port.getParentView().getBounds().getBounds();//HM, JGraph3.4.1
623
r = (Rectangle)graph.toScreen(new Rectangle(r));//HM, JGraph3.4.1
624
int s = 3;
625          r.translate(-s, -s);
626          r.setSize(r.width+2*s, r.height+2*s);
627          JaWEGraphUI ui = (JaWEGraphUI)graph.getUI();
628          ui.paintCell(g, port, r, true);
629       }
630    }
631
632    //
633
// PopupMenu
634
//
635
/**
636     * Creates popup menu and adds a various actions (depending of where
637     * mouse was pressed - which cell(s) is/are selected).
638     */

639    protected JPopupMenu createPopupMenu(final Object JavaDoc cell) {
640       JPopupMenu menu = new JPopupMenu();
641       BarFactory jbf=new BarFactory(ED);
642
643       JMenuItem mi;
644
645       if (((cell==null) || (
646               !(cell instanceof Participant) &&
647                  !(cell instanceof org.enhydra.jawe.graph.Process) &&
648                  !(cell instanceof BlockActivity) &&
649                  !(cell instanceof Transition) &&
650                  !(cell instanceof Start) &&
651                  !(cell instanceof End))) && (graph instanceof ProcessGraph)) {
652          // adding cut action
653
menu.add(jbf.createMenuItem(
654                      Utils.getUnqualifiedClassName(Cut.class),false));
655          // adding copy action
656
menu.add(jbf.createMenuItem(
657                      Utils.getUnqualifiedClassName(Copy.class),false));
658
659          // adding pasteAt action
660
menu.add(jbf.createMenuItem(
661                      Utils.getUnqualifiedClassName(PasteAt.class),false));
662          if (!graph.isSelectionEmpty() && cell != null) {
663             menu.addSeparator();
664          }
665       }
666       // adding delete action
667
if (!graph.isSelectionEmpty() && cell!=null) {
668
669          menu.add(jbf.createMenuItem(
670                      Utils.getUnqualifiedClassName(Delete.class),false));
671          menu.addSeparator();
672       }
673       // adding properties action
674
if ((cell != null) &&
675           !(cell instanceof Start) &&
676           !(cell instanceof End)) {
677
678          if (cell instanceof Transition && graph instanceof ProcessGraph) {
679             Transition t=(Transition)cell;
680             boolean isCircular=Utils.isCircularTransition(t.getAttributes());
681             if (!isCircular) {
682                boolean isRouting=Utils.isRoutingTransition(t.getAttributes());
683
684                if (t.getSourceActivity() instanceof Start ||
685                    t.getTargetActivity() instanceof End) {
686                   if (!isRouting) {
687                      menu.add(jbf.createMenuItem(
688                                  Utils.getUnqualifiedClassName(SetSelfRouting.class),false));
689                   } else {
690                      menu.add(jbf.createMenuItem(
691                                  Utils.getUnqualifiedClassName(SetNoRouting.class),false));
692                   }
693                } else {
694                   menu.add(jbf.createMenuItem(
695                               Utils.getUnqualifiedClassName(EditProperties.class),false));
696                   if (!isRouting) {
697                      menu.add(jbf.createMenuItem(
698                                  Utils.getUnqualifiedClassName(AddPoint.class),false));
699                      menu.add(jbf.createMenuItem(
700                                  Utils.getUnqualifiedClassName(RemovePoint.class),false));
701                      menu.add(jbf.createMenuItem(
702                                  Utils.getUnqualifiedClassName(SetSelfRouting.class),false));
703                   } else {
704                      menu.add(jbf.createMenuItem(
705                                  Utils.getUnqualifiedClassName(SetNoRouting.class),false));
706                   }
707                }
708             } else {
709                menu.add(jbf.createMenuItem(
710                            Utils.getUnqualifiedClassName(EditProperties.class),false));
711             }
712          } else {
713             menu.add(jbf.createMenuItem(
714                         Utils.getUnqualifiedClassName(EditProperties.class),false));
715          }
716
717          // adding edit action for processes, subflows, block activities
718
if (cell instanceof org.enhydra.jawe.graph.Process ||
719              cell instanceof Subflow ||
720              cell instanceof BlockActivity) {
721             boolean toAdd=true;
722             if (cell instanceof Subflow) {
723                Subflow sbflw=(Subflow)cell;
724                WorkflowProcess wp=sbflw.getReferencedWorkflowProcess(graph.getXMLPackage());
725                if (wp==null) {
726                   toAdd=false;
727                }
728             }
729             if (toAdd) {
730                menu.add(jbf.createMenuItem(
731                            Utils.getUnqualifiedClassName(EditCell.class),false));
732             }
733          }
734
735          if (cell instanceof org.enhydra.jawe.graph.Process) {
736             menu.add(jbf.createMenuItem(
737                         Utils.getUnqualifiedClassName(MakeCopyOfProcess.class),false));
738          }
739
740       }
741
742       if (cell instanceof Activity && !(cell instanceof org.enhydra.jawe.graph.Process) &&
743           !(cell instanceof Start) && !(cell instanceof End)) {
744          menu.add(jbf.createMenuItem(JaWEConstants.REFERRED_DOCUMENT,false));
745       }
746
747       // Harald Meister: added possibility to move participant position
748
if (cell instanceof Participant) {
749          menu.addSeparator();
750          menu.add(jbf.createMenuItem(
751                      Utils.getUnqualifiedClassName(MoveUpParticipant.class),false));
752          menu.add(jbf.createMenuItem(
753                      Utils.getUnqualifiedClassName(MoveDownParticipant.class),false));
754       }
755       // Harald Meister
756

757       return menu;
758    }
759
760    /**
761     * Gets the point of last popup menu creation.
762     */

763    public Point getPopupPoint () {
764       return popupPoint;
765    }
766
767    /**
768     * Returns <code>true</code> if parent cell of given port accepts
769     * source or target, depending on <code>source</code> parameter.
770     */

771    public boolean acceptsSourceOrTarget (PortView port,
772                                          boolean source,
773                                          PortView firstPort,
774                                          boolean circularTransition) {
775       // if port is a valid
776
if (port!=null && port.getCell()!=null
777           // and it is a port
778
&& (port.getCell() instanceof DefaultPort)) {
779          // and it's parent is instance of Linkable
780
// return if it accepts to be a source or a target
781
Object JavaDoc p=((DefaultPort)port.getCell()).getParent();
782          if ((p instanceof Linkable)) {
783             boolean usingBubbles=JaWEConfig.getInstance().getUseBubblesStatus();
784             if (source) {
785                if (!((Linkable)p).acceptsSource()) return false;
786                // if bubbles are used, do not allow last activity to have an
787
// outgoing transitions, except exceptional or circular ones
788
if (usingBubbles) {
789                   if (p instanceof Activity) {
790                      Activity act=(Activity)p;
791                      if (Utils.hasConnectedEndBubble(act) && !circularTransition) {
792                         JOptionPane.showMessageDialog(ED.getWindow(),
793                                                       ResourceManager.getLanguageDependentString(
794                                                          "ErrorLastActivityCannotHaveOutgoingTransitions"),
795                                                       JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE);
796                         return false;
797
798                      }
799                   }
800                }
801                return true;
802             } else {
803                if (!((Linkable)p).acceptsTarget()) return false;
804                Object JavaDoc srcCell=((DefaultPort)firstPort.getCell()).getParent();
805                // if bubbles are used, do not allow start-end connection
806
if (usingBubbles && (p instanceof End) && (srcCell instanceof Start)) {
807                   JOptionPane.showMessageDialog(ED.getWindow(),
808                                                 ResourceManager.getLanguageDependentString("ErrorCannotConnectStartAndEnd"),
809                                                 JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE);
810                   return false;
811                }
812                if (p instanceof Activity) {
813                   Activity act=(Activity)p;
814                   Set trns=act.getIncomingTransitions();
815                   // if bubbles are used, do not allow that first activity has incoming transitions,
816
// or that last activity has outgoing transitions except circular one
817
if (usingBubbles) {
818                      if (trns.size()==1 || trns.size()==2) {
819                         Object JavaDoc[] trnsArr=trns.toArray();
820                         if((((Transition)trnsArr[0]).getSourceActivity() instanceof Start) ||
821                               (trns.size()==2 && ((Transition)trnsArr[1]).getSourceActivity() instanceof Start)) {
822                            if (!circularTransition) {
823                               JOptionPane.showMessageDialog(ED.getWindow(),
824                                                             ResourceManager.getLanguageDependentString(
825                                                                "ErrorFirstActivityCannotHaveIncomingTransitions"),
826                                                             JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE);
827                               return false;
828                            }
829                         }
830                      }
831                      if ((trns.size()>0) && (srcCell instanceof Start)) {
832                         if (trns.size()>1 || (trns.size()==1 && !Utils.hasCircularTransitions(trns))) {
833                            JOptionPane.showMessageDialog(ED.getWindow(),
834                                                          ResourceManager.getLanguageDependentString(
835                                                             "ErrorFirstActivityCannotHaveIncomingTransitions"),
836                                                          JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE);
837                            return false;
838                         }
839                      }
840                      if (act instanceof End) {
841                         Set saNETrns=((Activity)srcCell).getNonExceptionalOutgoingTransitions();
842                         if (saNETrns.size()>1 || (saNETrns.size()==1 && !Utils.hasCircularTransitions(saNETrns))) {
843                            JOptionPane.showMessageDialog(ED.getWindow(),
844                                                          ResourceManager.getLanguageDependentString(
845                                                             "ErrorLastActivityCannotHaveOutgoingTransitions"),
846                                                          JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE);
847                            return false;
848                         }
849                      }
850                   }
851                   // Do not allow activity to have more than one transition
852
// from the same activity
853
if (trns.size()>0) {
854                      Iterator it=trns.iterator();
855                      while (it.hasNext()) {
856                         Object JavaDoc SRC=((Transition)it.next()).getSourceActivity();
857                         if (src.equals(srcCell)) {
858                            JOptionPane.showMessageDialog(ED.getWindow(),
859                                                          ResourceManager.getLanguageDependentString(
860                                                             "ErrorActivityCannotHaveMoreThenOneIncomingOutgoingTransitionFromToTheSameActivity"),
861                                                          JaWE.getAppTitle(),JOptionPane.ERROR_MESSAGE);
862                            return false;
863                         }
864                      }
865                   }
866                }
867                return true;
868             }
869          }
870       }
871       // return false otherwise
872
return false;
873    }
874
875    /**
876     * Adds buttons created in PEMarqueHandler class to the group.
877     * This is a place to add special things.
878     */

879    public Hashtable getSpecialButtons() {
880       Hashtable buttons = new Hashtable();
881       ButtonGroup group = new ButtonGroup();
882       // ---------------------- toolbox buttons ----------------------------
883
if (ED instanceof ProcessEditor) {
884          buttons.put(JaWEConstants.SELECT_TOOL, selectButton);
885          buttons.put(JaWEConstants.PARTICIPANT_TOOL, participantButton);
886          buttons.put(JaWEConstants.SUBFLOW_ACTIVITY_TOOL, subflowActivityButton);
887          buttons.put(JaWEConstants.BLOCK_ACTIVITY_TOOL, blockActivityButton);
888          buttons.put(JaWEConstants.START_TOOL, startButton);
889          buttons.put(JaWEConstants.END_TOOL, endButton);
890          buttons.put(JaWEConstants.AUTOMATIC_START_END_TOOL, automaticStartEndButton);
891          buttons.put(JaWEConstants.GENERIC_ACTIVITY_TOOL, genericActivityButton);
892          buttons.put(JaWEConstants.ROUTE_ACTIVITY_TOOL, routeActivityButton);
893          buttons.put(JaWEConstants.TRANSITION_TOOL, transitionButton);
894          buttons.put(JaWEConstants.SELF_ROUTED_TRANSITION_TOOL, selfRoutedTransitionButton);
895          buttons.put(JaWEConstants.CIRCULAR_TRANSITION_TOOL, circularTransitionButton);
896       } else {
897          group.add(selectButton); buttons.put(JaWEConstants.SELECT_TOOL,selectButton);
898          group.add(processButton); buttons.put(JaWEConstants.PROCESS_ACTIVITY_TOOL,processButton);
899          group.add(automaticStartEndButton); buttons.put(JaWEConstants.AUTOMATIC_START_END_TOOL, automaticStartEndButton);
900       }
901       selectButton.doClick();
902       return buttons;
903    }
904
905    public JToggleButton getSelectButton () {
906       return selectButton;
907    }
908
909    public JToggleButton getProcessButton () {
910       return processButton;
911    }
912
913    public JToggleButton getParticipantButton () {
914       return participantButton;
915    }
916
917    public JToggleButton getSubflowActivityButton () {
918       return subflowActivityButton;
919    }
920
921    public JToggleButton getBlockActivityButton () {
922       return blockActivityButton;
923    }
924
925    public JToggleButton getStartButton () {
926       return startButton;
927    }
928
929    public JToggleButton getEndButton () {
930       return endButton;
931    }
932
933    public JToggleButton getGenericActivityButton () {
934       return genericActivityButton;
935    }
936
937    public JToggleButton getRouteActivityButton () {
938       return routeActivityButton;
939    }
940
941    public JToggleButton getTransitionButton () {
942       return transitionButton;
943    }
944
945    public JToggleButton getSelfRoutedTransitionButton () {
946       return selfRoutedTransitionButton;
947    }
948
949    public JToggleButton getCircularTransitionButton () {
950       return circularTransitionButton;
951    }
952
953    public void enableBubblesButtons (boolean enable) {
954       startButton.setEnabled(enable);
955       endButton.setEnabled(enable);
956       automaticStartEndButton.setEnabled(enable);
957    }
958
959    private void setProperCursor () {
960       if (persistent) {
961          Iterator it=ED.getSpecialButtons().values().iterator();
962          while (it.hasNext()) {
963             JToggleButton source=(JToggleButton)it.next();
964             if (source.isSelected()) {
965                setProperCursor(source);
966                return;
967             }
968          }
969       }
970    }
971
972    private void setProperCursor(JToggleButton source) {
973       if (source.equals(participantButton)) {
974          graph.setCursor(participantCursor);
975       } else if (source.equals(processButton)) {
976          graph.setCursor(processCursor);
977       } else if (source.equals(subflowActivityButton)) {
978          graph.setCursor(subflowActivityCursor);
979       } else if (source.equals(blockActivityButton)) {
980          graph.setCursor(blockActivityCursor);
981       } else if (source.equals(startButton)) {
982          graph.setCursor(startCursor);
983       } else if (source.equals(endButton)) {
984          graph.setCursor(endCursor);
985       } else if (source.equals(automaticStartEndButton)) {
986          automaticStartEndButton.setSelected(false);
987          selectButton.setSelected(true);
988       } else if (source.equals(genericActivityButton)) {
989          graph.setCursor(genericActivityCursor);
990       } else if (source.equals(routeActivityButton)) {
991          graph.setCursor(routeActivityCursor);
992       } else if (source.equals(transitionButton)) {
993          graph.setCursor(transitionCursor);
994       } else if (source.equals(selfRoutedTransitionButton)) {
995          graph.setCursor(selfRoutedTransitionCursor);
996       } else if (source.equals(circularTransitionButton)) {
997          graph.setCursor(circularTransitionCursor);
998       } else {
999          graph.setCursor(Cursor.getDefaultCursor());
1000      }
1001   }
1002
1003}
1004
Popular Tags