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.shapes;
20:
21: import java.awt.Graphics;
22: import java.awt.Point;
23: import java.awt.Rectangle;
24: import java.util.Date;
25: import java.util.Hashtable;
26: import java.util.Map;
27:
28: import org.jgraph.graph.AttributeMap;
29: import org.jgraph.graph.DefaultPort;
30: import org.jgraph.graph.GraphConstants;
31: import org.lucane.applications.whiteboard.graph.MyGraph;
32: import org.lucane.applications.whiteboard.graph.cells.DiamondCell;
33:
34: class Diamond implements Shape {
35: public void paint(Graphics g, Point start, Point end) {
36: int size = Math.abs(start.x - end.x);
37:
38: int minX = Math.min(start.x, end.x);
39: int minY = Math.min(start.y, end.y);
40: int middleX = minX + size / 2;
41: int middleY = minY + size / 2;
42:
43: int[] x = new int[] { minX, middleX, minX + size, middleX };
44: int[] y = new int[] { middleY, minY, middleY, minY + size };
45:
46: g.drawPolygon(x, y, x.length);
47: }
48:
49: public void addToGraph(MyGraph graph, Point start, Point end) {
50: DiamondCell cell = new DiamondCell("");
51: AttributeMap attrs = new AttributeMap();
52: attrs.put("timestamp", new Date());
53:
54: GraphConstants.setBounds(attrs, getBounds(start, end));
55: GraphConstants.setLineWidth(attrs, graph.getLineWidth());
56: GraphConstants.setBorderColor(attrs, graph.getCellBorder());
57: if (graph.getCellBackground() != null) {
58: GraphConstants.setBackground(attrs, graph
59: .getCellBackground());
60: GraphConstants.setOpaque(attrs, true);
61: }
62:
63: DefaultPort hp = new DefaultPort();
64: cell.add(hp);
65:
66: Object[] cells = new Object[] { cell };
67:
68: Map attributes = new Hashtable();
69: attributes.put(cell, attrs);
70: graph.getModel().insert(cells, attributes, null, null, null);
71: }
72:
73: private Rectangle getBounds(Point start, Point end) {
74: int size = Math.abs(start.x - end.x);
75:
76: int minX = Math.min(start.x, end.x);
77: int minY = Math.min(start.y, end.y);
78:
79: return new Rectangle(minX, minY, size, size);
80: }
81: }
|