01: /*
02: * Lucane - a collaborative platform
03: * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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;
22: import java.awt.Graphics;
23: import java.awt.Point;
24: import java.awt.event.MouseEvent;
25:
26: import org.jgraph.graph.BasicMarqueeHandler;
27: import org.lucane.applications.whiteboard.graph.shapes.ShapeManager;
28: import org.lucane.applications.whiteboard.gui.ShapeToolBar;
29:
30: public class MyMarqueeHandler extends BasicMarqueeHandler {
31: private MyGraph graph;
32: private ShapeToolBar toolBar;
33: private ShapeManager shapes;
34: private Point mouseStart = null;
35: private Point mouseCurrent = null;
36:
37: public MyMarqueeHandler(MyGraph graph, ShapeToolBar toolBar,
38: ShapeManager shapes) {
39: this .graph = graph;
40: this .toolBar = toolBar;
41: this .shapes = shapes;
42: }
43:
44: public void mousePressed(MouseEvent event) {
45: if (shapes.getSelectedShape() == null) {
46: super .mousePressed(event);
47: return;
48: }
49:
50: if (!graph.isEditable())
51: return;
52:
53: this .mouseStart = event.getPoint();
54: }
55:
56: public void mouseDragged(MouseEvent event) {
57: if (shapes.getSelectedShape() == null) {
58: super .mouseDragged(event);
59: return;
60: }
61:
62: if (!graph.isEditable())
63: return;
64:
65: Graphics g = graph.getGraphics();
66: Color bg = graph.getBackground();
67: Color fg = Color.black;
68: g.setColor(fg);
69: g.setXORMode(bg);
70:
71: //remove old
72: if (mouseCurrent != null)
73: this .shapes.paintSelectedShape(g, mouseStart, mouseCurrent);
74:
75: //draw new
76: mouseCurrent = event.getPoint();
77: this .shapes.paintSelectedShape(g, mouseStart, mouseCurrent);
78: }
79:
80: public void mouseReleased(MouseEvent event) {
81: if (shapes.getSelectedShape() == null) {
82: super .mouseReleased(event);
83: return;
84: }
85:
86: if (!graph.isEditable())
87: return;
88:
89: this .shapes.addSelectedShape(graph, mouseStart, event
90: .getPoint());
91:
92: //this was a bad idea, it seems better to stay on the current shape
93: //this.toolBar.resetToSelection();
94: mouseStart = null;
95: mouseCurrent = null;
96: }
97: }
|