⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphcodeformat.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
字号:
/**
 * 
 */
package flow.graph.gui.graph.item;

import java.awt.geom.Rectangle2D;
import java.io.OutputStream;
import java.io.PrintWriter;

import org.jgraph.JGraph;
import org.jgraph.graph.CellView;
import org.jgraph.graph.DefaultGraphModel;

/**
 * @author Administrator
 *
 */
public class GraphCodeFormat {
	public static int writeMap(JGraph graph, String mapName, int inset,
			OutputStream out) {
		PrintWriter writer = new PrintWriter(out);
		int written = 0;
		if (graph.getModel().getRootCount() > 0) {
			writer.println("<MAP NAME=\"" + mapName + "\">");
			Rectangle2D bounds = graph.getCellBounds(graph.getRoots());
			Object[] vertices = DefaultGraphModel.getAll(graph.getModel());
			for (int i = 0; i < vertices.length; i++) {
				String alt = getAlt(graph, vertices[i]);
				String href = getURL(graph, vertices[i]);
				CellView view = graph.getGraphLayoutCache().getMapping(
						vertices[i], false);
				if (view != null && href != null && href.length() > 0) {
					written++;
					Rectangle2D b = (Rectangle2D) graph
							.toScreen((Rectangle2D) ((Rectangle2D) view
									.getBounds()).clone());
					b.setFrame(b.getX() - bounds.getX() + inset, b.getY()
							- bounds.getY() + inset, b.getWidth(), b
							.getHeight());
					String rect = (int) b.getX() + "," + (int) b.getY() + ","
							+ (int) (b.getX() + b.getWidth()) + ","
							+ (int) (b.getY() + b.getHeight());
					String shape = "RECT";
					writer.println("<AREA SHAPE=" + shape + " COORDS=\"" + rect
							+ "\" HREF=\"" + href + "\" ALT=\"" + alt + "\">");
				}
			}
			writer.println("</MAP>");
			writer.flush();
			writer.close();
		}
		return written;
	}

	protected static String getURL(JGraph graph, Object cell) {
		/*
		String url = getAlt(graph, cell);
		if (JGraphEditor.isURL(url))
			return url;
		Object value = graph.getModel().getValue(cell);
		if (JGraphEditor.isURL(value))
			return String.valueOf(value);
		if (value instanceof JGraphpadBusinessObject) {
			JGraphpadBusinessObject obj = (JGraphpadBusinessObject) value;
			Object property = obj.getProperty("url");
			if (JGraphEditor.isURL(property))
				return String.valueOf(property);
		}
		*/
		return "";
	}

	/**
	 * Returns the value for the alt tag to be used in the image map of
	 * <code>graph</code> for the specified cell.
	 * 
	 * @param graph
	 *            The graph for which the image map is being created for.
	 * @param cell
	 *            The cell to return the value of the alt tag for.
	 * @return Returns a alt tag for <code>cell</code>.
	 */
	protected static String getAlt(JGraph graph, Object cell) {
		return graph.convertValueToString(cell);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -