File: FastGraphFactory.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,238 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
/*
 * Copyright (c) 2005-2006, David Benson
 *
 * See LICENSE file in distribution for licensing details of this source file
 */
package com.jgraph.example.fastgraph;

import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Map;

import org.jgraph.graph.AttributeMap;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.Edge;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.Port;

import com.jgraph.example.JGraphGraphFactory;

public class FastGraphFactory extends JGraphGraphFactory {

	/**
	 * Default Constructor
	 */
	public FastGraphFactory() {
		dialog = new FastFactoryConfigDialog();
	}

	/**
	 * Method hook to create custom vertices
	 * 
	 * @param userObject
	 *            the user object to pass to the cell
	 * @return the new vertex instance
	 */
	protected DefaultGraphCell createVertex(Object userObject, Point2D position, Map defaultVertexAttributes) {
		AttributeMap attributes = new AttributeMap(defaultVertexAttributes);
		GraphConstants.setBounds(attributes, new Rectangle2D.Double(
				position.getX()*2, position.getY()*2, 60, 60 ));
		// Restrict to a square shape
		GraphConstants.setConstrained(attributes, true);
		Point2D point = new Point2D.Double(GraphConstants.PERMILLE / 2,
				GraphConstants.PERMILLE / 2);
		DefaultGraphCell cell = new FastCircleCell(userObject, attributes);
		// Add one central fixed port
		cell.addPort(point);

		return cell;
	}

	/**
	 * Method hook to create custom edges
	 * 
	 * @return the new vertex instance
	 */
	protected Edge createEdge(Map defaultEdgeAttributes,
	Port sourcePort, Port targetPort) {
		AttributeMap edgeAttrib = null;
		if (defaultEdgeAttributes != null) {
			edgeAttrib = new AttributeMap(defaultEdgeAttributes);
		} else {
			edgeAttrib = new AttributeMap(4);
		}
		Edge edge = new FastEdge(null, edgeAttrib);
		
		edge.setSource(sourcePort);
		edge.setTarget(targetPort);

		return edge;

	}
	
	public class FastFactoryConfigDialog extends FactoryConfigDialog {
		public FastFactoryConfigDialog() {
			super();
		}
		
		protected void applyValues() {
			super.applyValues();
			System.out.println("Insert pressed on factory dialog, timestamp="
					+ System.currentTimeMillis() + "ms");
		}

	}
}