1 29 30 package org.enhydra.jawe.graph; 31 32 import java.awt.Color ; 33 import java.awt.Component ; 34 import java.awt.Font ; 35 import java.util.Map ; 36 import javax.swing.BorderFactory ; 37 import javax.swing.JTextArea ; 38 import javax.swing.UIManager ; 39 import javax.swing.border.Border ; 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 public class MultiLinedRenderer extends JTextArea implements CellViewRenderer { 49 50 51 transient protected JGraph graph; 52 53 54 transient protected VertexView view; 55 56 57 transient protected boolean hasFocus, 58 selected, 59 preview, 60 opaque; 61 62 63 transient protected Color defaultForeground, defaultBackground, bordercolor; 64 65 66 transient protected int borderWidth; 67 68 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 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 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 attributes = view.getAllAttributes(); 107 installAttributes(graph, attributes); 108 return this; 109 } 110 return null; 111 112 } 113 114 protected void installAttributes(JGraph graph, Map attributes) { 115 setOpaque(GraphConstants.isOpaque(attributes)); 116 Color foreground = GraphConstants.getForeground(attributes); 117 setForeground((foreground != null) ? foreground : graph.getForeground()); 118 Color background = GraphConstants.getBackground(attributes); 119 setBackground((background != null) ? background : graph.getBackground()); 120 Font font = GraphConstants.getFont(attributes); 121 setFont((font != null) ? font : graph.getFont()); 122 Border 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 |