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

📄 mxgraphoutline.java

📁 经典的java图像处理程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * $Id: mxGraphOutline.java,v 1.18 2009/03/20 08:56:45 gaudenz Exp $ * Copyright (c) 2008, Gaudenz Alder */package com.mxgraph.swing;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Point;import java.awt.Rectangle;import java.awt.Stroke;import java.awt.event.AdjustmentEvent;import java.awt.event.AdjustmentListener;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.geom.AffineTransform;import java.awt.image.BufferedImage;import javax.swing.JComponent;import javax.swing.JScrollBar;import com.mxgraph.util.mxEvent;import com.mxgraph.util.mxEventObject;import com.mxgraph.util.mxPoint;import com.mxgraph.util.mxRectangle;import com.mxgraph.util.mxUtils;import com.mxgraph.util.mxEventSource.mxIEventListener;import com.mxgraph.view.mxGraphView;/** * An outline view for a specific graph component. */public class mxGraphOutline extends JComponent{	/**	 * 	 */	public static Color DEFAULT_ZOOMHANDLE_FILL = new Color(0, 255, 255);	/**	 * 	 */	protected mxGraphComponent graphComponent;	/**	 * TODO: Not yet implemented.	 */	protected BufferedImage tripleBuffer;	/**	 * Holds the graphics of the triple buffer.	 */	protected Graphics2D tripleBufferGraphics;	/**	 * True if the triple buffer needs a full repaint.	 */	protected boolean repaintBuffer = false;	/**	 * Clip of the triple buffer to be repainted.	 */	protected mxRectangle repaintClip = null;	/**	 * 	 */	protected boolean tripleBuffered = true;	/**	 * 	 */	protected Rectangle finderBounds = new Rectangle();	/**	 * 	 */	protected Point zoomHandleLocation = null;	/**	 * 	 */	protected boolean finderVisible = true;	/**	 * 	 */	protected boolean zoomHandleVisible = true;	/**	 * 	 */	protected boolean useScaledInstance = false;	/**	 * 	 */	protected boolean antiAlias = false;	/**	 * 	 */	protected boolean drawLabels = false;	/**	 * Specifies if the outline should be zoomed to the page if the graph	 * component is in page layout mode. Default is true.	 */	protected boolean fitPage = true;	/**	 * Not yet implemented.	 * 	 * Border to add around the page bounds if wholePage is true.	 * Default is 4.	 */	protected int outlineBorder = 10;	/**	 * 	 */	protected MouseTracker tracker = new MouseTracker();	/**	 * 	 */	protected double scale = 1;	/**	 * 	 */	protected Point translate = new Point();	/**	 * 	 */	protected transient boolean zoomGesture = false;	/**	 * 	 */	protected mxIEventListener repaintHandler = new mxIEventListener()	{		public void invoke(Object source, mxEventObject evt)		{			updateScaleAndTranslate();			mxRectangle dirty = (evt.getArgCount() > 0) ? (mxRectangle) evt					.getArgAt(0) : null;			if (dirty != null)			{				repaintClip = new mxRectangle(dirty);			}			else			{				repaintBuffer = true;			}			if (dirty != null)			{				updateFinder(true);				dirty.grow(1 / scale);				dirty.setX(dirty.getX() * scale + translate.x);				dirty.setY(dirty.getY() * scale + translate.y);				dirty.setWidth(dirty.getWidth() * scale);				dirty.setHeight(dirty.getHeight() * scale);				repaint(dirty.getRectangle());			}			else			{				updateFinder(false);				repaint();			}		}	};	/**	 * 	 */	protected ComponentListener componentHandler = new ComponentAdapter()	{		public void componentResized(ComponentEvent e)		{			if (updateScaleAndTranslate())			{				repaintBuffer = true;				updateFinder(false);				repaint();			}			else			{				updateFinder(true);			}		}	};	/**	 * 	 */	protected AdjustmentListener adjustmentHandler = new AdjustmentListener()	{		/**		 * 		 */		public void adjustmentValueChanged(AdjustmentEvent e)		{			if (updateScaleAndTranslate())			{				repaintBuffer = true;				updateFinder(false);				repaint();			}			else			{				updateFinder(true);			}		}	};	/**	 * 	 */	public mxGraphOutline(mxGraphComponent graphComponent)	{		addComponentListener(componentHandler);		addMouseMotionListener(tracker);		addMouseListener(tracker);		setGraphComponent(graphComponent);		setEnabled(true);		setOpaque(true);	}	/**	 * Fires a property change event for <code>tripleBuffered</code>.	 * 	 * @param tripleBuffered the tripleBuffered to set	 */	public void setTripleBuffered(boolean tripleBuffered)	{		boolean oldValue = this.tripleBuffered;		this.tripleBuffered = tripleBuffered;		if (!tripleBuffered)		{			destroyTripleBuffer();		}		firePropertyChange("tripleBuffered", oldValue, tripleBuffered);	}	/**	 * 	 */	public boolean isTripleBuffered()	{		return tripleBuffered;	}	/**	 * Fires a property change event for <code>drawLabels</code>.	 * 	 * @param drawLabels the drawLabels to set	 */	public void setDrawLabels(boolean drawLabels)	{		boolean oldValue = this.drawLabels;		this.drawLabels = drawLabels;		repaintTripleBuffer(null);		firePropertyChange("drawLabels", oldValue, drawLabels);	}	/**	 * 	 */	public boolean isDrawLabels()	{		return drawLabels;	}	/**	 * Fires a property change event for <code>antiAlias</code>.	 * 	 * @param antiAlias the antiAlias to set	 */	public void setAntiAlias(boolean antiAlias)	{		boolean oldValue = this.antiAlias;		this.antiAlias = antiAlias;		repaintTripleBuffer(null);		firePropertyChange("antiAlias", oldValue, antiAlias);	}	/**	 * @return the antiAlias	 */	public boolean isAntiAlias()	{		return antiAlias;	}	/**	 * 	 */	public void setVisible(boolean visible)	{		super.setVisible(visible);		// Frees memory if the outline is hidden		if (!visible)		{			destroyTripleBuffer();		}	}	/**	 * 	 */	public void setFinderVisible(boolean visible)	{		finderVisible = visible;	}	/**	 * 	 */	public void setZoomHandleVisible(boolean visible)	{		zoomHandleVisible = visible;	}	/**	 * Fires a property change event for <code>fitPage</code>.	 * 	 * @param fitPage the fitPage to set	 */	public void setFitPage(boolean fitPage)	{		boolean oldValue = this.fitPage;		this.fitPage = fitPage;		if (updateScaleAndTranslate())		{			repaintBuffer = true;			updateFinder(false);		}		firePropertyChange("fitPage", oldValue, fitPage);	}	/**	 * 	 */	public boolean isFitPage()	{		return fitPage;	}	/**	 * 	 */	public mxGraphComponent getGraphComponent()	{		return graphComponent;	}	/**	 * Fires a property change event for <code>graphComponent</code>.	 * 	 * @param graphComponent the graphComponent to set	 */	public void setGraphComponent(mxGraphComponent graphComponent)	{		mxGraphComponent oldValue = this.graphComponent;		if (this.graphComponent != null)		{			this.graphComponent.getGraph().removeListener(repaintHandler);			this.graphComponent.getGraphControl().removeComponentListener(					componentHandler);			this.graphComponent.getHorizontalScrollBar()					.removeAdjustmentListener(adjustmentHandler);			this.graphComponent.getVerticalScrollBar()					.removeAdjustmentListener(adjustmentHandler);		}		this.graphComponent = graphComponent;		if (this.graphComponent != null)		{			this.graphComponent.getGraph().addListener(mxEvent.REPAINT,					repaintHandler);			this.graphComponent.getGraphControl().addComponentListener(					componentHandler);			this.graphComponent.getHorizontalScrollBar().addAdjustmentListener(					adjustmentHandler);			this.graphComponent.getVerticalScrollBar().addAdjustmentListener(					adjustmentHandler);		}		if (updateScaleAndTranslate())		{			repaintBuffer = true;			repaint();		}		firePropertyChange("graphComponent", oldValue, graphComponent);	}	/**	 * Checks if the triple buffer exists and creates a new one if	 * it does not. Also compares the size of the buffer with the	 * size of the graph and drops the buffer if it has a	 * different size.	 */	public void checkTripleBuffer()	{		if (tripleBuffer != null)		{			if (tripleBuffer.getWidth() != getWidth()					|| tripleBuffer.getHeight() != getHeight())			{				// Resizes the buffer (destroys existing and creates new)				destroyTripleBuffer();			}		}		if (tripleBuffer == null)		{			createTripleBuffer(getWidth(), getHeight());		}	}	/**	 * Creates the tripleBufferGraphics and tripleBuffer for the given	 * dimension and draws the complete graph onto the triplebuffer.	 * 	 * @param width	 * @param height	 */	protected void createTripleBuffer(int width, int height)	{		try		{			tripleBuffer = mxUtils.createBufferedImage(width, height, null);			tripleBufferGraphics = tripleBuffer.createGraphics();			// Repaints the complete buffer			repaintTripleBuffer(null);		}		catch (OutOfMemoryError error)		{			// ignore		}	}	/**	 * Destroys the tripleBuffer and tripleBufferGraphics objects.	 */	public void destroyTripleBuffer()	{		if (tripleBuffer != null)		{			tripleBuffer = null;

⌨️ 快捷键说明

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