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

📄 transition.java

📁 Petri网分析工具PIPE is open-source
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}//###################################################################################### 	/** Returns the height bounds we want to use when initially creating the place on the gui */	public int boundsHeight() {		return HEIGHT+15;	}//###################################################################################### 	/** Returns the distance between the outside of the component to the centre, in order to position the centre of the place where the mouse clicks on the screen */	public int topOffset() {		return boundsHeight() /2;	}//###################################################################################### 	/** Returns the distance between the outside of the component to the centre, in order to position the centre of the place where the mouse clicks on the screen */	public int leftOffset() {		return boundsWidth() /2;	}//###################################################################################### 	public void setRate(double _rate){		rate = _rate;	}//###################################################################################### 	public double getRate() {		return rate;	}//######################################################################################	public int getAngle(){		return angle;	}//###################################################################################### 	/**Set the timed transition attribute (for GSPNs)*/	public void setTimed (boolean change) {		if (timed != change)		{				timed = change;			repaint();		}	}//###################################################################################### 	/**Get the timed transition attribute (for GSPNs)*/	public boolean getTimed () {		return timed;	}//###################################################################################### 	private void constructTransition() {		transition = new GeneralPath();		transition.append(new Rectangle2D.Double((componentWidth-TRANSITION_WIDTH)/2,0,				TRANSITION_WIDTH, TRANSITION_HEIGHT), false);		outlineTransition();	}//###################################################################################### 	public boolean contains(int x, int y) {				someArc = CreateGui.getView().createArc;		if (someArc != null)			// Must be drawing a new Arc if non-NULL.		{			if ((proximityTransition.contains(x-COMPONENT_DRAW_OFFSET, y-COMPONENT_DRAW_OFFSET)					|| transition.contains(x-COMPONENT_DRAW_OFFSET, y-COMPONENT_DRAW_OFFSET))					&& areNotSameType(someArc.getSource())){				// assume we are only snapping the target...				if (someArc.getTarget() != this)					someArc.setTarget(this);        someArc.updateArcPosition();				return true;			}			else {				if (someArc.getTarget() == this) {					someArc.setTarget(null);					removeArcCompareObject(someArc);					updateConnected();				}				return false;			}			}		else		return transition.contains(x-COMPONENT_DRAW_OFFSET,y-COMPONENT_DRAW_OFFSET);	}//###################################################################################### 		public void removeArcCompareObject(Arc a)	{		Iterator arcIterator = arcAngleList.iterator();		while (arcIterator.hasNext())		{			if (((ArcAngleCompare)arcIterator.next()).arc == a)				arcIterator.remove();		}	}//###################################################################################### 	/* (non-Javadoc)	 * @see pipe.dataLayer.PlaceTransitionObject#updateEndPoint(pipe.dataLayer.Arc)	 */		public void updateEndPoint(Arc arc) {		Iterator arcIterator = arcAngleList.iterator();		boolean match = false;		while (arcIterator.hasNext()) {			ArcAngleCompare thisArc = (ArcAngleCompare)arcIterator.next();			if (thisArc.arc == arc) {				thisArc.calcAngle();				match = true;				break;			}		}		if (!match)			arcAngleList.add(new ArcAngleCompare(arc, this));		Collections.sort(arcAngleList);				updateEndPoints();	}	public void updateEndPoints() {		Iterator arcIterator = arcAngleList.iterator();		ArrayList top = new ArrayList();		ArrayList bottom = new ArrayList();		ArrayList left = new ArrayList();		ArrayList right = new ArrayList();				arcIterator = arcAngleList.iterator();		while (arcIterator.hasNext()) {			ArcAngleCompare thisArc = (ArcAngleCompare)arcIterator.next();			double thisAngle = thisArc.angle - Math.toRadians(angle);			if (Math.cos(thisAngle) > (rootThreeOverTwo)){				top.add(thisArc);				thisArc.arc.setPathToTransitionAngle(angle+90);			}			else if (Math.cos(thisAngle) < -rootThreeOverTwo){				bottom.add(thisArc);				thisArc.arc.setPathToTransitionAngle(angle+270);			}			else if (Math.sin(thisAngle) > 0){				left.add(thisArc);				thisArc.arc.setPathToTransitionAngle(angle+180);			}			else{				right.add(thisArc);				thisArc.arc.setPathToTransitionAngle(angle);			}		}				AffineTransform transform = AffineTransform.getRotateInstance(Math.toRadians(angle+Math.PI));		Point2D.Double transformed = new Point2D.Double();				arcIterator = top.iterator();		transform.transform(new Point2D.Double(1, 0.5*TRANSITION_HEIGHT), transformed); // +1 due to rounding making it off by 1		while (arcIterator.hasNext()) {			ArcAngleCompare thisArc = (ArcAngleCompare)arcIterator.next();			if (thisArc.sourceOrTarget())				thisArc.arc.setTargetLocation(positionX+centreOffsetLeft()+transformed.x, positionY+centreOffsetTop()+transformed.y);			else				thisArc.arc.setSourceLocation(positionX+centreOffsetLeft()+transformed.x, positionY+centreOffsetTop()+transformed.y);			thisArc.arc.updateArrow();		}		arcIterator = bottom.iterator();		transform.transform(new Point2D.Double(0, -0.5*TRANSITION_HEIGHT), transformed);		while (arcIterator.hasNext()) {			ArcAngleCompare thisArc = (ArcAngleCompare)arcIterator.next();			if (thisArc.sourceOrTarget())				thisArc.arc.setTargetLocation(positionX+centreOffsetLeft()+transformed.x, positionY+centreOffsetTop()+transformed.y);			else				thisArc.arc.setSourceLocation(positionX+centreOffsetLeft()+transformed.x, positionY+centreOffsetTop()+transformed.y);			thisArc.arc.updateArrow();		}		arcIterator = left.iterator();		double inc = TRANSITION_HEIGHT/(left.size()+1);		double current = TRANSITION_HEIGHT/2 - inc;		while (arcIterator.hasNext()) {			ArcAngleCompare thisArc = (ArcAngleCompare)arcIterator.next();			transform.transform(new Point2D.Double(-0.5*TRANSITION_WIDTH, current+1), transformed); // +1 due to rounding making it off by 1			if (thisArc.sourceOrTarget())				thisArc.arc.setTargetLocation(positionX+centreOffsetLeft()+transformed.x, positionY+centreOffsetTop()+transformed.y);			else				thisArc.arc.setSourceLocation(positionX+centreOffsetLeft()+transformed.x, positionY+centreOffsetTop()+transformed.y);			current-=inc;			thisArc.arc.updateArrow();		}		inc = TRANSITION_HEIGHT/(right.size()+1);		current = -TRANSITION_HEIGHT/2 + inc;		arcIterator = right.iterator();		while (arcIterator.hasNext()) {			ArcAngleCompare thisArc = (ArcAngleCompare)arcIterator.next();			transform.transform(new Point2D.Double(+0.5*TRANSITION_WIDTH, current), transformed);			if (thisArc.sourceOrTarget())				thisArc.arc.setTargetLocation(positionX+centreOffsetLeft()+transformed.x, positionY+centreOffsetTop()+transformed.y);			else				thisArc.arc.setSourceLocation(positionX+centreOffsetLeft()+transformed.x, positionY+centreOffsetTop()+transformed.y);			current+=inc;			thisArc.arc.updateArrow();		}	}		class ArcAngleCompare implements Comparable {		public final static boolean SOURCE = false;		public final static boolean TARGET = true;		Arc arc;		private Transition transition;		double angle;				public ArcAngleCompare(Arc _arc, Transition _transition) {			arc = _arc;			transition = _transition;			calcAngle();		}		public int compareTo(Object arg0) {			double angle2 = ((ArcAngleCompare)arg0).angle;			return (angle < angle2 ? -1 : (angle == angle2 ? 0 : 1));		}				void calcAngle() {			int index = sourceOrTarget() ? arc.getArcPath().getEndIndex()-1 : 1;			Point2D.Double p1 = new Point2D.Double(positionX+centreOffsetLeft(), positionY+centreOffsetTop());			Point2D.Double p2 = new Point2D.Double(arc.getArcPath().getPoint(index).x, arc.getArcPath().getPoint(index).y);						if (p1.y <= p2.y)				angle = Math.atan((p1.x - p2.x) / (p2.y - p1.y));			else				angle = Math.atan((p1.x - p2.x) / (p2.y - p1.y))+Math.PI;						// This makes sure the angle overlap lies at the intersection between edges of a transition			// Yes it is a nasty hack (aka ingeneous solution). But it works!			if (angle<(Math.toRadians(30+transition.getAngle()))) angle+=(2*Math.PI);			// Needed to eliminate an exception on Windows			if (p1.equals(p2))				angle = 0;			//			if (sourceOrTarget())//				angle = arc.getArcPath().getEndAngle();//			else //				angle = arc.getArcPath().getStartAngle();		}				public boolean sourceOrTarget() {			return (arc.getSource() == transition ? SOURCE : TARGET);		}	}}//###################################################################################### 

⌨️ 快捷键说明

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