1
2
3
4
5
6
7 package com.vikash.firsttool.UI;
8
9
10 import java.awt.*;
11 import java.awt.geom.*;
12 import java.util.Map;
13 import java.net.URL;
14
15 import javax.swing.*;
16
17
18
19 import org.jgraph.JGraph;
20 import org.jgraph.graph.CellView;
21 import org.jgraph.graph.VertexView;
22 import org.jgraph.graph.CellViewRenderer;
23 import org.jgraph.graph.VertexRenderer;
24 import org.jgraph.graph.GraphConstants;
25 import org.jgraph.graph.GraphCellEditor;
26 /***
27 *
28 * @author studajb
29 */
30 public class RectangleCellView extends VertexView{
31
32 RectangleCellRenderer renderer = new RectangleCellRenderer();
33 ToolVertexEditor editor = new ToolVertexEditor();
34 public RectangleCellView() {
35 super();
36 }
37
38 public RectangleCellView(Object cell) {
39 super(cell);
40 }
41
42 public CellViewRenderer getRenderer() {
43 return renderer;
44 }
45 public GraphCellEditor getEditor() {
46 return editor;
47 }
48 class RectangleCellRenderer extends VertexRenderer {
49 JGraph graph;
50 public Component getRendererComponent(JGraph graph, CellView view,
51 boolean sel, boolean focus, boolean preview) {
52 Object cellname;
53 this.graph = graph;
54
55 isDoubleBuffered = graph.isDoubleBuffered();
56 if (view instanceof VertexView) {
57 this.view = (VertexView) view;
58 setComponentOrientation(graph.getComponentOrientation());
59 if (graph.getEditingCell() != view.getCell()) {
60 Object label = graph.convertValueToString(view);
61 if (this.view.isLeaf()
62 || GraphConstants.isOpaque(view.getAllAttributes()))
63 installAttributes(view);
64
65
66 else {
67 setText(null);
68 setBorder(null);
69 setOpaque(false);
70 setGradientColor(null);
71 setIcon(null);
72 }
73 Object[] labels=GraphConstants.getExtraLabels(view.getAllAttributes());
74 if(labels!=null){
75 cellname=graph.convertValueToString(labels[0]);
76 }
77 else
78 cellname=null;
79 if(cellname!=null){
80 if (label != null)
81
82 setText("<html><p align=\"center\"><<"+cellname.toString()+">><br>"+label.toString().replaceAll("\n","<br> ")+"</p></html>");
83 else
84 setText("<<"+cellname.toString()+">>");
85
86 }
87 } else
88 setText(null);
89 this.graph = graph;
90 this.hasFocus = focus;
91 this.childrenSelected = graph.getSelectionModel()
92 .isChildrenSelected(view.getCell());
93 this.selected = sel;
94 this.preview = preview;
95
96 return this;
97 }
98 return null;
99 }
100
101 protected void paintSelectionBorder(Graphics g){
102 URL icon;
103 Object cellname;
104 Object[] labels=GraphConstants.getExtraLabels(view.getAllAttributes());
105 if(labels != null){
106 cellname=graph.convertValueToString(labels[0]);
107
108 if(cellname.equals("TreatmentEffect"))
109 icon=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/TreatmentIcon.gif");
110
111 else if(cellname.equals("Risk"))
112 icon=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/riskicon.gif");
113
114 else
115 icon=null;
116
117 if(icon!=null) {
118 Graphics2D g2=(Graphics2D)g;
119 Rectangle r=g2.getClipBounds();
120 Dimension d = getSize();
121 Image img=Toolkit.getDefaultToolkit().getImage(icon);
122 Image img1=img.getScaledInstance((int)r.getWidth()/5,(int)r.getWidth()/5,4);
123 MediaTracker tracker=new MediaTracker(this);
124 tracker.addImage(img1,0);
125 try{tracker.waitForID(0);}
126 catch(InterruptedException exception) {}
127
128
129
130
131 g2.drawImage(img1,((int)(r.getX()+(d.width)/1.4)),((int)r.getY()),null);
132 super.paintSelectionBorder(g2);
133 }
134 else{
135 super.paintSelectionBorder(g);
136 }
137 }
138
139
140
141
142 }
143 }
144
145
146 }