All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mxgraph.view.mxTemporaryCellStates Maven / Gradle / Ivy

Go to download

JGraphX Swing Component - Java Graph Visualization Library This is a binary & source redistribution of the original, unmodified JGraphX library originating from: "https://github.com/jgraph/jgraphx/archive/v3.4.1.3.zip". The purpose of this redistribution is to make the library available to other Maven projects.

There is a newer version: 3.4.1.3
Show newest version
package com.mxgraph.view;

import java.util.Hashtable;

import com.mxgraph.model.mxCell;
import com.mxgraph.util.mxRectangle;

public class mxTemporaryCellStates
{
	/**
	 * 
	 */
	protected mxGraphView view;

	/**
	 * 
	 */
	protected Hashtable oldStates;

	/**
	 * 
	 */
	protected mxRectangle oldBounds;

	/**
	 * 
	 */
	protected double oldScale;

	/**
	 * Constructs a new temporary cell states instance.
	 */
	public mxTemporaryCellStates(mxGraphView view)
	{
		this(view, 1, null);
	}

	/**
	 * Constructs a new temporary cell states instance.
	 */
	public mxTemporaryCellStates(mxGraphView view, double scale)
	{
		this(view, scale, null);
	}

	/**
	 * Constructs a new temporary cell states instance.
	 */
	public mxTemporaryCellStates(mxGraphView view, double scale, Object[] cells)
	{
		this.view = view;

		// Stores the previous state
		oldBounds = view.getGraphBounds();
		oldStates = view.getStates();
		oldScale = view.getScale();

		// Creates space for the new states
		view.setStates(new Hashtable());
		view.setScale(scale);

		if (cells != null)
		{
			// Creates virtual parent state for validation
			mxCellState state = view.createState(new mxCell());

			// Validates the vertices and edges without adding them to
			// the model so that the original cells are not modified
			for (int i = 0; i < cells.length; i++)
			{
				view.validateBounds(state, cells[i]);
			}
			
			mxRectangle bbox = null;
			
			for (int i = 0; i < cells.length; i++)
			{
				mxRectangle bounds = view.validatePoints(state, cells[i]);
				
				if (bounds != null)
				{
					if (bbox == null)
					{
						bbox = bounds;
					}
					else
					{
						bbox.add(bounds);
					}
				}
			}
			
			if (bbox == null)
			{
				bbox = new mxRectangle();
			}

			view.setGraphBounds(bbox);
		}
	}

	/**
	 * Destroys the cell states and restores the state of the graph view.
	 */
	public void destroy()
	{
		view.setScale(oldScale);
		view.setStates(oldStates);
		view.setGraphBounds(oldBounds);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy