org.jgraph.graph.GraphLayoutCache Java Examples

The following examples show how to use org.jgraph.graph.GraphLayoutCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: View.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * When we initialize the sketch, we flush out all the data concerning the
 * sketch itself. Even the modelAdapter is reinitialized.
 *
 * This methods serves as a "new sketch" function.
 */
@Override
public void initialiseModel() {
	clearSelection();

	model = new ViewGraphModel(this);

	final GraphLayoutCache glc = new GraphLayoutCache(model,
			new ModelViewFactory<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>());

	setModel(model);
	setGraphLayoutCache(glc);

	_nodes = new LinkedHashMap<>();
	_edges = new LinkedHashMap<>();

	if (_Frame.getInfoTreeUI() != null) {
		_Frame.setInfoTreeUI(new ModelInfoTreeUI<>(_Frame)); // Wipe
																// Tree
		_Frame.getInfoTreeUI().refreshTree();
	}

	_docInfo.reset();

	model.discardUndo();
}
 
Example #2
Source File: ModelConstraint.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Sets if the constraint should be visible or not
 *
 * @param inIsVisible If the constraint should be visible or not.
 */
public void setVisible(boolean inIsVisible) {
	if (inIsVisible != _isVisible) {
		_isVisible = inIsVisible;

		_theModel.setDirty();
	}

	// GuideEdge<F, GM, M, N, E>[] visuals = _visuals.toArray(new GuideEdge[0]);
	@SuppressWarnings("unused")
	GraphLayoutCache glc = _theModel.getGraphLayoutCache();

	if (_isVisible && !_edgesVisualized) {
		addVisualsToModel();
	} else if (!_isVisible && _edgesVisualized) {
		removeVisualsFromModel();
	}

	_theModel.clearSelection();
}
 
Example #3
Source File: ModelConstraint.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Removes the visuals from the sketch (when hiding)
 */
private void removeVisualsFromModel() {
	// Push loading state
	_theModel.getStateManager().pushState(new LoadingState<>(_theModel));
	_theModel.getGraphModel().beginInsignificantUpdate();

	GraphLayoutCache glc = _theModel.getGraphLayoutCache();

	glc.remove(_visuals.toArray(new GuideEdge[0]));
	_visuals.clear();

	_edgesVisualized = false;

	GraphConstants.setSelectable(getAttributes(), false);
	_theModel.refresh();
	_theModel.getGraphModel().cancelInsignificantUpdate();

	// Pop state
	_theModel.getStateManager().popState();
}
 
Example #4
Source File: Sketch.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * When we initialise the sketch, we flush out all the data concerning the
 * sketch itself.
 *
 * This methods serves as a "new sketch" function.
 */
@Override
public void initialiseModel() {
	clearSelection();

	model = new SketchGraphModel(this);

	final GraphLayoutCache glc = new GraphLayoutCache(model,
			new ModelViewFactory<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>());

	setModel(model);
	setGraphLayoutCache(glc);

	_nodes = new LinkedHashMap<>();
	_edges = new LinkedHashMap<>();

	if (_Frame.getInfoTreeUI() != null) {
		_Frame.setInfoTreeUI(new ModelInfoTreeUI<>(_Frame)); // Wipe
																// Tree
		_Frame.getInfoTreeUI().refreshTree();
	}

	_docInfo.reset();

	_views = new HashMap<>();
	_connParams = new HashMap<>();

	model.discardUndo();
}
 
Example #5
Source File: ERDesignerGraph.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
public ERDesignerGraph(Model aDBModel, GraphModel aModel,
                       GraphLayoutCache aLayoutCache) {
    super(aModel, aLayoutCache);
    model = aDBModel;

    setMoveIntoGroups(true);
    setMoveOutOfGroups(true);
}
 
Example #6
Source File: Birdview.java    From microba with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Makes this component track the provided graph and scroller. Set
 * parameters to <code>null</code> to unbind thie component.
 * 
 * @param graph
 *            the graph component. May be <code>null</code>
 * @param scroller
 *            the croller, usually the one that holds the graph. May be
 *            <code>null</code>
 */
public void setTrackingFor(JGraph graph, JScrollPane scroller) {
	if (this.peerGraph != null) {
		this.peerGraph.getModel().removeGraphModelListener(scrollerListener);
		this.peerGraph.removePropertyChangeListener(graphPropertyChangeListener);
	}

	this.peerGraph = graph;

	if (this.peerGraph != null) {
		this.peerGraph.getModel().addGraphModelListener(scrollerListener);
		this.peerGraph.addPropertyChangeListener(graphPropertyChangeListener);

		this.displayGraph.setGraphLayoutCache(peerGraph.getGraphLayoutCache());

	} else {
		this.displayGraph.setGraphLayoutCache(new GraphLayoutCache());
	}

	//
	if (this.peerScroller != null) {
		this.peerScroller.getHorizontalScrollBar().removeAdjustmentListener(
				scrollerListener);
		this.peerScroller.getVerticalScrollBar().removeAdjustmentListener(
				scrollerListener);
	}

	this.peerScroller = scroller;

	if (this.peerScroller != null) {
		this.peerScroller.getHorizontalScrollBar().addAdjustmentListener(
				scrollerListener);
		this.peerScroller.getVerticalScrollBar().addAdjustmentListener(
				scrollerListener);
	}

	update();
	repaint();

}
 
Example #7
Source File: GraphView.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void loadGraph(String fileName) throws FileNotFoundException, IOException, Throwable {
    ASTGraph ast = new ASTGraph();
    ParseOutput objects = ast.parseFile(fileName);

    graph.setGraphLayoutCache(new GraphLayoutCache());
    DefaultGraphCell[] cells = ast.generateTree((SimpleNode) objects.ast);

    graph.getGraphLayoutCache().insert(cells);
    graph.clearSelection();
}
 
Example #8
Source File: MicroarrayGraph.java    From chipster with MIT License 5 votes vote down vote up
public MicroarrayGraph(GraphModel model, GraphLayoutCache cache, GraphPanel graphPanel) {
	super(model, cache);

	this.model = model;
	this.graphPanel = graphPanel;
	this.setBackground(Color.WHITE);

	// Direct call to parents L&F update, see this.updateUI()
	super.updateUI();

	/*
	 * Regardles of the updateUI-call jus before the font size of graph cell is fixed only when the first cell is added. To handle
	 * situations when the font size is changed before importing any data we force the jgraph to initialise itself by inserting dummy
	 * vertex and removing it. This *should* happen before any repaint operation, and thus the vertex won't ever show.
	 */
	GroupVertex vertex = new GroupVertex(0, 0, null, this);
	getGraphLayoutCache().insert(vertex);
	getGraphLayoutCache().remove(new Object[] { vertex });

	// registers the graph object with the tooltip manager
	ToolTipManager.sharedInstance().registerComponent(this);
	
	model.addGraphModelListener(this);

	// start listening
	application.getDataManager().addDataChangeListener(this);
	application.addClientEventListener(this);
}
 
Example #9
Source File: EdgeRouter.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Calculates intermediate points for multiple loops. This is the same algorithm
 * used by DefaultEdge.LoopRouting, but we scale the loop box for parallel
 * self-referencing edges.
 *
 * @param cache
 * @param edge
 *
 * @return
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List routeLoop(final GraphLayoutCache cache, final EdgeView edge) {
	final CellView sourceNode = edge.getSource();
	final List newPoints = new ArrayList();

	newPoints.add(sourceNode);

	final CellView sourceParent = (sourceNode != null) ? sourceNode.getParentView() : edge.getSourceParentView();
	if (sourceNode == null) {
		throw new RuntimeException("Internal EASIK error, please report");
	}
	final Object[] edges = DefaultGraphModel.getEdgesBetween(cache.getModel(), sourceNode.getCell(),
			sourceNode.getCell(), true);
	int position = 0;

	if (edges != null) {
		for (int i = 0; i < edges.length; i++) {
			if (edges[i] == edge.getCell()) {
				position = i;

				break;
			}
		}
	}

	if (sourceParent != null) {
		final Point2D from = AbstractCellView.getCenterPoint(sourceParent);
		final Rectangle2D rect = sourceParent.getBounds();
		final double posWidthFactor = 1.25 + 0.75 * position;
		final double posHeightFactor = 1.5 + position;
		final double width = rect.getWidth();
		final double height2 = rect.getHeight() / 2;
		double loopWidth = Math.min(20, Math.max(10, width / 8));
		double loopHeight = Math.min(30, Math.max(12, Math.max(loopWidth + 4, height2 / 2)));

		loopWidth *= posWidthFactor;
		loopHeight *= posHeightFactor;

		newPoints.add(edge.getAttributes().createPoint(from.getX() - loopWidth,
				from.getY() - height2 - loopHeight * 1.0));

		final double midpointY = from.getY() - height2 - 1.5 * loopHeight;

		newPoints.add(edge.getAttributes().createPoint(from.getX(), midpointY));
		newPoints.add(edge.getAttributes().createPoint(from.getX() + loopWidth,
				from.getY() - height2 - loopHeight * 1.0));
		newPoints.add(edge.getTarget());

		return newPoints;
	}

	return null;
}