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

📄 gpgraph.java

📁 用JGraph编的软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * @(#)GPGraph.java	1.2 11/11/02
 *
 * Copyright (C) 2001 Gaudenz Alder
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

package org.jgraph.pad;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.print.PageFormat;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.swing.*;

import javax.swing.AbstractAction;
import javax.swing.AbstractCellEditor;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.border.Border;

import org.jgraph.JGraph;
import org.jgraph.graph.CellMapper;
import org.jgraph.graph.CellView;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.DefaultGraphCellEditor;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.Edge;
import org.jgraph.graph.GraphCellEditor;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.Port;
import org.jgraph.graph.VertexRenderer;
import org.jgraph.graph.VertexView;

import org.jgpd.jgraph.*;

public class GPGraph extends JGraph {

	public static String FILE_FORMAT_VERSION = "PAD-1.0";

	protected boolean pagevisible = false;

	protected transient PageFormat pageFormat = new PageFormat();

	protected Image background = null;

	protected Hashtable writeProperties = new Hashtable();

	protected transient Color defaultBorderColor = Color.black;

	public GPGraph() {
		this(null);


	}

	public GPGraph(GraphModel model) {
		this(model, null);
	}

	public GPGraph(GraphModel model, GraphLayoutCache view) {
		super(model, view, null);

	}

	public void setPageFormat(PageFormat format) {
		pageFormat = format;
	}

	public PageFormat getPageFormat() {
		return pageFormat;
	}

	public void setPageVisible(boolean flag) {
		pagevisible = flag;
	}

	public boolean isPageVisible() {
		return pagevisible;
	}

	public void setBackgroundImage(Image img) {
		background = img;
	}

	public Image getBackgroundImage() {
		return background;
	}

	/**
	 * Creates and returns a default <code>GraphView</code>.
	 *
	 * @return the default <code>GraphView</code>
	 */
	protected VertexView createVertexView(Object v, CellMapper cm) {
		if (v instanceof EllipseCell)
			return new EllipseView(v, this, cm);
        else if (v instanceof ActivityCell)
            return new ActivityView(v, this, cm);
        else if (v instanceof DecisionCell)
            return new DecisionView(v, this, cm);
          //如果是inclusive通路
        else if (v instanceof InclusiveGatewayCell)
            return new InclusiveGatewayView(v, this, cm);
          //如果是Coplex通路
      else if (v instanceof ComplexGatewayCell)
          return new ComplexGatewayView(v, this, cm);
        //如果是Parallel通路
   else if (v instanceof ParallelGatewayCell)
       return new ParallelGatewayView(v, this, cm);



          //如果是dataObj
      else if (v instanceof DataObjCell)
          return new DataObjView(v, this, cm);
        //如果是textAnnotation
    else if (v instanceof TextAnnotationCell)
        return new TextAnnotationView(v, this, cm);
      //如果是subProcess
          else if (v instanceof SubProcessCell)
              return new SubProcessView(v, this, cm);



        else if (v instanceof StartCell)
            return new StartView(v, this, cm);
          else if (v instanceof InterCell)
            return new InterView(v, this, cm);
          else if (v instanceof PoolCell)
            return new PoolView(v, this, cm);
          else if (v instanceof LaneCell)
                    return new LaneView(v, this, cm);

        else if (v instanceof EndCell)
            return new EndView(v, this, cm);
        else if (v instanceof SplitCell)
            return new SplitView(v, this, cm);
        else if (v instanceof JoinCell)
            return new JoinView(v, this, cm);
		else if ((v instanceof TextCell) &&
		 		  ((TextCell) v).isMultiLined())
		 	return new MultiLinedView(v, this, cm);
		return super.createVertexView(v, cm);
	}

	public static VertexRenderer renderer = new ScaledVertexRenderer();

	public class ScaledVertexView extends VertexView {

		public ScaledVertexView(Object v, JGraph graph, CellMapper cm) {
			super(v, graph, cm);
		}

		public CellViewRenderer getRenderer() {
			return GPGraph.renderer;
		}

	}

	public static class ScaledVertexRenderer extends VertexRenderer {

		public void paint(Graphics g) {
			Icon icon = getIcon();
			setIcon(null);
			Dimension d = getSize();
			Image img = null;
			if (icon instanceof ImageIcon)
				img = ((ImageIcon) icon).getImage();
			if (img != null)
				g.drawImage(img, 0, 0, d.width - 1, d.height - 1, graph);
			super.paint(g);
		}

	}

	//
	// Defines Semantics of the Graph
	//

	/**
	 * Returns true if <code>object</code> is a vertex, that is, if it
	 * is not an instance of Port or Edge, and all of its children are
	 * ports, or it has no children.
	 */
	public boolean isGroup(Object cell) {
		// Map the Cell to its View
		CellView view = getGraphLayoutCache().getMapping(cell, false);
		if (view != null)
			return !view.isLeaf();
		return false;
	}

	/**
	 * Returns true if <code>object</code> is a vertex, that is, if it
	 * is not an instance of Port or Edge, and all of its children are
	 * ports, or it has no children.
	 */
	public boolean isVertex(Object object) {
		if (!(object instanceof Port) && !(object instanceof Edge))
			return !isGroup(object) && object != null;
		return false;
	}

	public boolean isPort(Object object) {
		return (object instanceof Port);
	}

	public boolean isEdge(Object object) {
		return (object instanceof Edge);
	}

	public Object[] getSelectionVertices() {
		Object[] tmp = getSelectionCells();
		Object[] all =
			DefaultGraphModel.getDescendants(getModel(), tmp).toArray();
		return getVertices(all);
	}

	public Object[] getVertices(Object[] cells) {
		if (cells != null) {
			ArrayList result = new ArrayList();
			for (int i = 0; i < cells.length; i++)
				if (isVertex(cells[i]))
					result.add(cells[i]);
			return result.toArray();
		}
		return null;
	}

	public Object[] getSelectionEdges() {
		return getEdges(getSelectionCells());
	}

	public Object[] getAll() {
		return getDescendants(getRoots());
	}

	public Object[] getEdges(Object[] cells) {
		if (cells != null) {
			ArrayList result = new ArrayList();
			for (int i = 0; i < cells.length; i++)
				if (isEdge(cells[i]))
					result.add(cells[i]);
			return result.toArray();
		}
		return null;
	}

	public Object getNeighbour(Object edge, Object vertex) {
		Object source = getSourceVertex(edge);
		if (vertex == source)
			return getTargetVertex(edge);
		else
			return source;
	}

	public Object getSourceVertex(Object edge) {
		Object sourcePort = graphModel.getSource(edge);
		return graphModel.getParent(sourcePort);
	}

	public Object getTargetVertex(Object edge) {
		Object targetPort = graphModel.getTarget(edge);
		return graphModel.getParent(targetPort);
	}

	public CellView getSourceView(Object edge) {
		Object source = getSourceVertex(edge);
		return getGraphLayoutCache().getMapping(source, false);
	}

	public CellView getTargetView(Object edge) {
		Object target = getTargetVertex(edge);
		return getGraphLayoutCache().getMapping(target, false);
	}

	public Object[] getEdgesBetween(Object vertex1, Object vertex2) {
		ArrayList result = new ArrayList();

⌨️ 快捷键说明

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