01: /*
02: * @(#)DefaultCellViewFactory.java 1.0 29-NOV-04
03: *
04: * Copyright (c) 2001-2005 Gaudenz Alder
05: *
06: */
07: package org.jgraph.graph;
08:
09: import java.io.Serializable;
10:
11: /**
12: * The default implementation of a cell view factory that returns the default
13: * views for vertices, edges and ports.
14: */
15: public class DefaultCellViewFactory implements CellViewFactory,
16: Serializable {
17:
18: /**
19: * Constructs a view for the specified cell and associates it with the
20: * specified object using the specified CellMapper. This calls refresh on
21: * the created CellView to create all dependent views.
22: * <p>
23: * Note: The mapping needs to be available before the views of child cells
24: * and ports are created.
25: * <b>Note: This method must return new instances!</b>
26: *
27: * @param cell
28: * reference to the object in the model
29: */
30: public CellView createView(GraphModel model, Object cell) {
31: CellView view = null;
32: if (model.isPort(cell))
33: view = createPortView(cell);
34: else if (model.isEdge(cell))
35: view = createEdgeView(cell);
36: else
37: view = createVertexView(cell);
38: return view;
39: }
40:
41: /**
42: * Constructs a VertexView view for the specified object.
43: */
44: protected VertexView createVertexView(Object cell) {
45: return new VertexView(cell);
46: }
47:
48: /**
49: * Constructs an EdgeView view for the specified object.
50: */
51: protected EdgeView createEdgeView(Object cell) {
52: if (cell instanceof Edge)
53: return createEdgeView((Edge) cell);
54: else
55: return new EdgeView(cell);
56: }
57:
58: /**
59: * Constructs a PortView view for the specified object.
60: */
61: protected PortView createPortView(Object cell) {
62: if (cell instanceof Port)
63: return createPortView((Port) cell);
64: else
65: return new PortView(cell);
66: }
67:
68: /**
69: * Constructs an EdgeView view for the specified object.
70: *
71: * @deprecated replaced by {@link #createEdgeView(Object)}since
72: * JGraph no longer exposes dependecies on GraphCell subclasses
73: * (Port, Edge)
74: */
75: protected EdgeView createEdgeView(Edge cell) {
76: return new EdgeView(cell);
77: }
78:
79: /**
80: * Constructs a PortView view for the specified object.
81: *
82: * @deprecated replaced by {@link #createPortView(Object)}since
83: * JGraph no longer exposes dependecies on GraphCell subclasses
84: * (Port, Edge)
85: */
86: protected PortView createPortView(Port cell) {
87: return new PortView(cell);
88: }
89: }
|