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

📄 mxedgehandler.java

📁 经典的java图像处理程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if (!graph.isCellDisconnectable(state.getCell(), terminal,					isSource(index)))			{				first = null;			}		}	}	/**	 * 	 */	public void mouseDragged(MouseEvent e)	{		if (!e.isConsumed() && first != null)		{			gridEnabledEvent = graphComponent.isGridEnabledEvent(e);			constrainedEvent = graphComponent.isConstrainedEvent(e);			boolean isSource = isSource(index);			Object source = null;			Object target = null;			if (isLabel(index))			{				mxPoint abs = state.getAbsoluteOffset();				double dx = abs.getX() - first.x;				double dy = abs.getY() - first.y;				mxPoint pt = new mxPoint(e.getPoint());				if (gridEnabledEvent)				{					pt = graphComponent.snapScaledPoint(pt, dx, dy);				}				if (constrainedEvent)				{					if (Math.abs(e.getX() - first.x) > Math.abs(e.getY()							- first.y))					{						pt.setY(abs.getY());					}					else					{						pt.setX(abs.getX());					}				}				Rectangle rect = getPreviewBounds();				rect.translate((int) Math.round(pt.getX() - first.x),						(int) Math.round(pt.getY() - first.y));				preview.setBounds(rect);			}			else			{				// Clones the cell state and updates the absolute points using				// the current state of this handle. This is required for				// computing the correct perimeter points and edge style.				mxGeometry geometry = graphComponent.getGraph()						.getCellGeometry(state.getCell());				mxCellState clone = (mxCellState) state.clone();				List points = geometry.getPoints();				if (isSource || isTarget(index))				{					marker.process(e);					mxCellState currentState = marker.getValidState();					target = clone.getView().getVisibleTerminal(							state.getCell(), !isSource);					if (currentState != null)					{						source = currentState.getCell();					}					else					{						mxPoint pt = new mxPoint(e.getPoint());						if (gridEnabledEvent)						{							pt = graphComponent.snapScaledPoint(pt);						}						clone.setAbsoluteTerminalPoint(pt, isSource);					}					if (!isSource)					{						Object tmp = source;						source = target;						target = tmp;					}				}				else				{					mxPoint point = convertPoint(new mxPoint(e.getPoint()),							gridEnabledEvent);					if (points == null)					{						points = Arrays.asList(new Object[] { point });					}					else if (index - 1 < points.size())					{						points = new ArrayList(points);						points.set(index - 1, point);					}					source = clone.getView().getVisibleTerminal(							state.getCell(), true);					target = clone.getView().getVisibleTerminal(							state.getCell(), false);				}				// Computes the points for the edge style and terminals				clone.getView().updatePoints(clone, points, source, target);				clone.getView().updateTerminalPoints(clone, source, target);				// Uses the updated points from the cloned state to draw the preview				p = createPoints(clone);				preview.setBounds(getPreviewBounds());			}			if (!preview.isVisible()					&& graphComponent.isSignificant(e.getX() - first.x, e							.getY()							- first.y))			{				preview.setVisible(true);			}			else if (preview.isVisible())			{				preview.repaint();			}			e.consume();		}	}	/**	 * 	 */	public void mouseReleased(MouseEvent e)	{		mxGraph graph = graphComponent.getGraph();		if (!e.isConsumed() && first != null)		{			double dx = e.getX() - first.x;			double dy = e.getY() - first.y;			if (graphComponent.isSignificant(dx, dy))			{				if (error != null)				{					if (error.length() > 0)					{						JOptionPane.showMessageDialog(graphComponent, error);					}				}				else if (isLabel(index))				{					mxPoint abs = state.getAbsoluteOffset();					dx = abs.getX() - first.x;					dy = abs.getY() - first.y;					mxPoint pt = new mxPoint(e.getPoint());					if (gridEnabledEvent)					{						pt = graphComponent.snapScaledPoint(pt, dx, dy);					}					if (constrainedEvent)					{						if (Math.abs(e.getX() - first.x) > Math.abs(e.getY()								- first.y))						{							pt.setY(abs.getY());						}						else						{							pt.setX(abs.getX());						}					}					moveLabelTo(state, pt.getX() + dx, pt.getY() + dy);				}				else if (marker.hasValidState()						&& (isSource(index) || isTarget(index)))				{					connect(state.getCell(), marker.getValidState().getCell(),							isSource(index), e.isControlDown()									&& isCloneEnabled());				}				else if ((!isSource(index) && !isTarget(index))						|| graphComponent.getGraph().isAllowDanglingEdges())				{					movePoint(state.getCell(), index, convertPoint(new mxPoint(							e.getPoint()), gridEnabledEvent));				}				e.consume();			}			else if (isFlipEvent(e))			{				graph.flipEdge(state.getCell());				e.consume();			}		}		marker.reset();		error = null;		super.mouseReleased(e);	}	/**	 * Moves the edges control point with the given index to the given point.	 */	protected void movePoint(Object edge, int pointIndex, mxPoint point)	{		mxIGraphModel model = graphComponent.getGraph().getModel();		mxGeometry geometry = model.getGeometry(edge);		if (geometry != null)		{			model.beginUpdate();			try			{				geometry = (mxGeometry) geometry.clone();				if (isSource(index) || isTarget(index))				{					connect(edge, null, isSource(index), false);					geometry.setTerminalPoint(point, isSource(index));				}				else				{					List pts = geometry.getPoints();					if (pts == null)					{						pts = new ArrayList();						geometry.setPoints(pts);					}					if (pts != null)					{						if (pointIndex <= pts.size())						{							pts.set(pointIndex - 1, point);						}						else if (pointIndex - 1 <= pts.size())						{							pts.add(pointIndex - 1, point);						}					}				}				model.setGeometry(edge, geometry);			}			finally			{				model.endUpdate();			}		}	}	/**	 * Connects the given edge to the given source or target terminal.	 * 	 * @param edge	 * @param terminal	 * @param isSource	 */	protected void connect(Object edge, Object terminal, boolean isSource,			boolean isClone)	{		mxGraph graph = graphComponent.getGraph();		mxIGraphModel model = graph.getModel();		model.beginUpdate();		try		{			if (isClone)			{				Object clone = graph.cloneCells(new Object[] { edge })[0];				Object parent = model.getParent(edge);				graph.addCells(new Object[] { clone }, parent);				Object other = model.getTerminal(edge, !isSource);				graph.connectCell(clone, other, !isSource);				graph.setSelectionCell(clone);				edge = clone;			}			graph.connectCell(edge, terminal, isSource);		}		finally		{			model.endUpdate();		}	}	/**	 * Moves the label to the given position.	 */	protected void moveLabelTo(mxCellState edgeState, double x, double y)	{		mxGraph graph = graphComponent.getGraph();		mxIGraphModel model = graph.getModel();		mxGeometry geometry = model.getGeometry(state.getCell());		if (geometry != null)		{			geometry = (mxGeometry) geometry.clone();			// Resets the relative location stored inside the geometry			mxPoint pt = graph.getView().getRelativePoint(edgeState, x, y);			geometry.setX(pt.getX());			geometry.setY(pt.getY());			// Resets the offset inside the geometry to find the offset			// from the resulting point			double scale = graph.getView().getScale();			geometry.setOffset(new mxPoint(0, 0));			pt = graph.getView().getPoint(edgeState, geometry);			geometry.setOffset(new mxPoint(Math.round((x - pt.getX()) / scale),					Math.round((y - pt.getY()) / scale)));			model.setGeometry(edgeState.getCell(), geometry);		}	}	/**	 * 	 */	protected Cursor getCursor(MouseEvent e, int index)	{		Cursor cursor = null;		if (isSource(index) || isTarget(index))		{			cursor = mxConnectionHandler.DEFAULT_CURSOR;		}		else if (isLabel(index))		{			cursor = new Cursor(Cursor.MOVE_CURSOR);		}		else		{			cursor = new Cursor(Cursor.HAND_CURSOR);		}		return cursor;	}	/**	 * 	 */	public void paint(Graphics g)	{		Graphics2D g2 = (Graphics2D) g;		Stroke stroke = g2.getStroke();		g2.setStroke(mxConstants.SELECTION_STROKE);		g.setColor(mxConstants.SELECTION_COLOR);		Point last = state.getAbsolutePoint(0).getPoint();		for (int i = 1; i < state.getAbsolutePointCount(); i++)		{			Point current = state.getAbsolutePoint(i).getPoint();			g.drawLine(last.x, last.y, current.x, current.y);			last = current;		}		g2.setStroke(stroke);		super.paint(g);	}}

⌨️ 快捷键说明

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