1 19 package org.lucane.applications.whiteboard.graph.shapes; 20 21 import java.awt.Graphics ; 22 import java.awt.Point ; 23 import java.util.Date ; 24 import java.util.Hashtable ; 25 import java.util.Map ; 26 27 import org.jgraph.graph.AttributeMap; 28 import org.jgraph.graph.DefaultGraphCell; 29 import org.jgraph.graph.DefaultPort; 30 import org.jgraph.graph.GraphConstants; 31 import org.lucane.applications.whiteboard.graph.MyGraph; 32 33 class Rectangle implements Shape 34 { 35 public void paint(Graphics g, Point start, Point end) 36 { 37 java.awt.Rectangle bounds = ShapeUtils.getBounds(start, end); 38 g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height); 39 } 40 41 public void addToGraph(MyGraph graph, Point start, Point end) 42 { 43 DefaultGraphCell cell = new DefaultGraphCell(""); 44 AttributeMap attrs = new AttributeMap(); 45 attrs.put("timestamp", new Date ()); 46 47 GraphConstants.setBounds(attrs, ShapeUtils.getBounds(start, end)); 48 GraphConstants.setLineWidth(attrs, graph.getLineWidth()); 49 GraphConstants.setBorderColor(attrs, graph.getCellBorder()); 50 if(graph.getCellBackground()!=null) 51 { 52 GraphConstants.setBackground(attrs, graph.getCellBackground()); 53 GraphConstants.setOpaque(attrs, true); 54 } 55 56 DefaultPort hp = new DefaultPort(); 57 cell.add(hp); 58 59 Object [] cells = new Object [] { cell }; 60 61 Map attributes = new Hashtable (); 62 attributes.put(cell, attrs); 63 graph.getModel().insert(cells, attributes, null, null, null); 64 } 65 } | Popular Tags |