KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > graph > MultiLinedRenderer


1 /*
2  * @(#)MultiLinedRenderer.java 1.0 12-MAY-2004
3  *
4  * Copyright (c) 2001-2004, Jenya Burstein All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * - Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer. - Redistributions in
10  * binary form must reproduce the above copyright notice, this list of
11  * conditions and the following disclaimer in the documentation and/or other
12  * materials provided with the distribution. - Neither the name of JGraph nor
13  * the names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  *
28  */

29
30 package org.enhydra.jawe.graph;
31
32 import java.awt.Color JavaDoc;
33 import java.awt.Component JavaDoc;
34 import java.awt.Font JavaDoc;
35 import java.util.Map JavaDoc;
36 import javax.swing.BorderFactory JavaDoc;
37 import javax.swing.JTextArea JavaDoc;
38 import javax.swing.UIManager JavaDoc;
39 import javax.swing.border.Border JavaDoc;
40 import org.jgraph.JGraph;
41 import org.jgraph.graph.CellView;
42 import org.jgraph.graph.CellViewRenderer;
43 import org.jgraph.graph.GraphConstants;
44 import org.jgraph.graph.VertexView;
45 import org.enhydra.jawe.JaWEConfig;
46
47 // adjusted for JaWE by Sasa Bojanic
48
public class MultiLinedRenderer extends JTextArea JavaDoc implements CellViewRenderer {
49
50    /** Cache the current graph for drawing. */
51    transient protected JGraph graph;
52
53    /** Cache the current shape for drawing. */
54    transient protected VertexView view;
55
56    /** Cached hasFocus and selected value. */
57    transient protected boolean hasFocus,
58       selected,
59       preview,
60       opaque;
61
62    /** Cached default foreground and default background. */
63    transient protected Color JavaDoc defaultForeground, defaultBackground, bordercolor;
64
65    /** Cached borderwidth. */
66    transient protected int borderWidth;
67
68    /** Cached value of the double buffered state */
69    transient boolean isDoubleBuffered = false;
70
71    public MultiLinedRenderer () {
72       defaultForeground = UIManager.getColor("Tree.textForeground");
73       defaultBackground = UIManager.getColor("Tree.textBackground");
74       setLineWrap(JaWEConfig.getInstance().getNameWrappingStatus());
75       setWrapStyleWord(JaWEConfig.getInstance().getWrappingStyleWordStatus());
76    }
77
78    public Component JavaDoc getRendererComponent(
79       JGraph graph,
80       CellView view,
81       boolean sel,
82       boolean focus,
83       boolean preview) {
84
85       setLineWrap(JaWEConfig.getInstance().getNameWrappingStatus());
86       setWrapStyleWord(JaWEConfig.getInstance().getWrappingStyleWordStatus());
87
88       this.graph = graph;
89       isDoubleBuffered = graph.isDoubleBuffered();
90       if (view instanceof VertexView) {
91          this.view = (VertexView) view;
92          setText(view.getCell().toString());
93
94          if (graph.getEditingCell() != view.getCell()) {
95             Object JavaDoc label = graph.convertValueToString(view);
96             if (label != null)
97                setText(label.toString());
98             else
99                setText(null);
100          } else
101             setText(null);
102          this.graph = graph;
103          this.hasFocus = focus;
104          this.selected = sel;
105          this.preview = preview;
106          Map JavaDoc attributes = view.getAllAttributes();
107          installAttributes(graph, attributes);
108          return this;
109       }
110       return null;
111
112    }
113
114    protected void installAttributes(JGraph graph, Map JavaDoc attributes) {
115       setOpaque(GraphConstants.isOpaque(attributes));
116       Color JavaDoc foreground = GraphConstants.getForeground(attributes);
117       setForeground((foreground != null) ? foreground : graph.getForeground());
118       Color JavaDoc background = GraphConstants.getBackground(attributes);
119       setBackground((background != null) ? background : graph.getBackground());
120       Font JavaDoc font = GraphConstants.getFont(attributes);
121       setFont((font != null) ? font : graph.getFont());
122       Border JavaDoc border= GraphConstants.getBorder(attributes);
123       bordercolor = GraphConstants.getBorderColor(attributes);
124       if(border != null)
125          setBorder(border);
126       else if (bordercolor != null) {
127          borderWidth = Math.max(1, Math.round(GraphConstants.getLineWidth(attributes)));
128          setBorder(BorderFactory.createLineBorder(bordercolor, borderWidth));
129       }
130    }
131
132 }
133
134
Popular Tags