01: /*
02: * $Id: JGraphpadVertexView.java,v 1.8 2006/03/15 07:23:29 gaudenz Exp $
03: * Copyright (c) 2001-2005, Gaudenz Alder
04: *
05: * All rights reserved.
06: *
07: * See LICENSE file for license details. If you are unable to locate
08: * this file please contact info (at) jgraph (dot) com.
09: */
10: package com.jgraph.pad.graph;
11:
12: import javax.swing.tree.DefaultMutableTreeNode;
13:
14: import org.jgraph.graph.CellViewRenderer;
15: import org.jgraph.graph.GraphCellEditor;
16: import org.jgraph.graph.VertexView;
17:
18: /**
19: * Vertex view that supports {@link JGraphpadBusinessObject} rendering and
20: * in-place editing, that means it supports simple text, rich text and component
21: * values.
22: */
23: public class JGraphpadVertexView extends VertexView {
24:
25: /**
26: * Holds the static editor for views of this kind.
27: */
28: public static JGraphpadRichTextEditor editor = new JGraphpadRichTextEditor();
29:
30: /**
31: * Holds the static editor for views of this kind.
32: */
33: public static JGraphpadRedirectingEditor redirector = new JGraphpadRedirectingEditor();
34:
35: /**
36: * Holds the static renderer for views of this kind.
37: */
38: public static JGraphpadVertexRenderer renderer = new JGraphpadVertexRenderer();
39:
40: /**
41: * Empty constructor for persistence.
42: */
43: public JGraphpadVertexView() {
44: super ();
45: }
46:
47: /**
48: * Constructs a new vertex view for the specified cell.
49: *
50: * @param cell
51: * The cell to construct the vertex view for.
52: */
53: public JGraphpadVertexView(Object cell) {
54: super (cell);
55: }
56:
57: /**
58: * Returns {@link #editor} if the user object of the cell is a rich text
59: * value or {@link #redirector} if the user object is a component.
60: *
61: * @return Returns the editor for the cell view.
62: */
63: public GraphCellEditor getEditor() {
64: Object value = ((DefaultMutableTreeNode) getCell())
65: .getUserObject();
66: if (value instanceof JGraphpadBusinessObject) {
67: JGraphpadBusinessObject obj = (JGraphpadBusinessObject) value;
68: if (obj.isRichText())
69: return editor;
70: else if (obj.isComponent())
71: return redirector;
72: }
73: return super .getEditor();
74: }
75:
76: /**
77: * Returns the {@link #renderer}.
78: *
79: * @return Returns the renderer for the cell view.
80: */
81: public CellViewRenderer getRenderer() {
82: return renderer;
83: }
84: }
|