KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > whiteboard > graph > MyMarqueeHandler


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.whiteboard.graph;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Graphics JavaDoc;
23 import java.awt.Point JavaDoc;
24 import java.awt.event.MouseEvent JavaDoc;
25
26
27 import org.jgraph.graph.BasicMarqueeHandler;
28 import org.lucane.applications.whiteboard.graph.shapes.ShapeManager;
29 import org.lucane.applications.whiteboard.gui.ShapeToolBar;
30
31 public class MyMarqueeHandler extends BasicMarqueeHandler
32 {
33     private MyGraph graph;
34     private ShapeToolBar toolBar;
35     private ShapeManager shapes;
36     private Point JavaDoc mouseStart = null;
37     private Point JavaDoc mouseCurrent = null;
38     
39     public MyMarqueeHandler(MyGraph graph, ShapeToolBar toolBar, ShapeManager shapes)
40     {
41         this.graph = graph;
42         this.toolBar = toolBar;
43         this.shapes = shapes;
44     }
45     
46     public void mousePressed(MouseEvent JavaDoc event)
47     {
48         if(shapes.getSelectedShape() == null)
49         {
50             super.mousePressed(event);
51             return;
52         }
53
54         if(!graph.isEditable())
55             return;
56         
57         this.mouseStart = event.getPoint();
58     }
59     
60     public void mouseDragged(MouseEvent JavaDoc event)
61     {
62         if(shapes.getSelectedShape() == null)
63         {
64             super.mouseDragged(event);
65             return;
66         }
67
68         if(!graph.isEditable())
69             return;
70         
71         Graphics JavaDoc g = graph.getGraphics();
72         Color JavaDoc bg = graph.getBackground();
73         Color JavaDoc fg = Color.black;
74         g.setColor(fg);
75         g.setXORMode(bg);
76
77         
78         //remove old
79
if(mouseCurrent != null)
80             this.shapes.paintSelectedShape(g, mouseStart, mouseCurrent);
81         
82         //draw new
83
mouseCurrent = event.getPoint();
84         this.shapes.paintSelectedShape(g, mouseStart, mouseCurrent);
85     }
86     
87     public void mouseReleased(MouseEvent JavaDoc event)
88     {
89         if(shapes.getSelectedShape() == null)
90         {
91             super.mouseReleased(event);
92             return;
93         }
94
95         if(!graph.isEditable())
96             return;
97         
98         this.shapes.addSelectedShape(graph, mouseStart, event.getPoint());
99         
100         //this was a bad idea, it seems better to stay on the current shape
101
//this.toolBar.resetToSelection();
102
mouseStart = null;
103         mouseCurrent = null;
104     }
105 }
Popular Tags