File: BusinessObjectEditor2.java

package info (click to toggle)
libjgraph-java 5.12.4.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 7,884 kB
  • ctags: 7,321
  • sloc: java: 20,619; xml: 135; sh: 51; makefile: 10
file content (85 lines) | stat: -rw-r--r-- 2,513 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.jgraph.example.panelexample;

import java.awt.Component;

import javax.swing.AbstractCellEditor;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.tree.DefaultMutableTreeNode;

import org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphCellEditor;
import org.jgraph.graph.GraphCellEditor;

import com.jgraph.example.panelexample.FlyweightUIComponent;


/**
 * basic in-place editor for custom business objects
 */
public class BusinessObjectEditor2 extends DefaultGraphCellEditor {
	
	public static boolean editorInsideCell = true;
	
	/**
	 * Returns a new RealCellEditor.
	 */
	protected GraphCellEditor createGraphCellEditor() {
		return new RealCellEditor();
	}

	/**
	 * Utlitiy editor for rich text values.
	 */
	class RealCellEditor extends AbstractCellEditor implements
			GraphCellEditor {

		/**
		 * Holds the component used for editing.
		 */
		FlyweightUIComponent editorComponent = new FlyweightUIComponent(this);

		public Component getGraphCellEditorComponent(JGraph graph,
				Object value, boolean isSelected) {
			Object cell = value;
			value = graph.getModel().getValue(value);
			if (value instanceof BusinessObjectWrapper2)
				editorComponent.installAttributes((BusinessObjectWrapper2) value, graph.getGraphLayoutCache().getMapping(cell, false), true, graph);
			else {
				BusinessObjectWrapper2 wrapper = new BusinessObjectWrapper2();
				/*GraphModel model = graph.getModel();
				int childCount = model.getChildCount(cell);
				List result = new ArrayList(childCount);
				for (int i = 0; i < childCount; i++) {
					Object child = model.getChild(cell, i);
					if (model.isPort(child)) {
						CellView portView = graph.getGraphLayoutCache().getMapping(
								child, false);
						if (portView != null) {
							result.add(portView);
						}
					}
				}
				
				CellView[] ports = new CellView[result.size()];
				result.toArray(ports);
				wrapper.setPortviews(ports);*/
				if (value instanceof DefaultMutableTreeNode)
					wrapper.setValue((DefaultMutableTreeNode) value);
				wrapper.setLabel(value.toString());
				editorComponent.installAttributes(wrapper, graph.getGraphLayoutCache().getMapping(cell, false), true, graph);
			}
			Border aBorder = UIManager.getBorder("Tree.editorBorder");
			editorComponent.setBorder(aBorder);
			return editorComponent;
		}

		/**
		 * Returns the rich text value to be stored in the user object.
		 */
		public Object getCellEditorValue() {
			return editorComponent.getValue();
		}
	}
}