📄 arcpathpoint.java
字号:
//######################################################################################/* * Created on 28-Feb-2004 * Author is Michael Camacho (and whoever wrote the first bit!) * *///######################################################################################package pipe.dataLayer;//######################################################################################import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.geom.Ellipse2D;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.awt.geom.RectangularShape;import pipe.gui.Constants;//######################################################################################public class ArcPathPoint extends PetriNetObject implements Constants{ public static final boolean STRAIGHT = false; public static final boolean CURVED = true; public static final int SIZE = 4; public static final int SIZE_OFFSET = 4; private static RectangularShape shape; private ArcPath myArcPath; private Point2D.Float point = new Point2D.Float(); private Point2D.Float control1 = new Point2D.Float(); private Point2D.Float control2 = new Point2D.Float(); private boolean pointType;//###################################################################################### ArcPathPoint(ArcPath a) { myArcPath = a; setPointLocation(0,0); }//###################################################################################### ArcPathPoint(float x, float y, boolean _pointType, ArcPath a) { this(a); point = new Point2D.Float(x,y); pointType = _pointType; }//###################################################################################### public Point2D.Float getPoint() { return point; }//###################################################################################### public void setPointLocation(float x, float y) {// System.err.println("Setting ArcPathPoint to position "+x+", "+y); point.setLocation(x,y); setBounds((int)x - SIZE, (int)y - SIZE, 2*SIZE + SIZE_OFFSET, 2*SIZE + SIZE_OFFSET); }//###################################################################################### public boolean getPointType() { return pointType; } //###################################################################################### public void updatePointLocation() { setPointLocation(point.x, point.y); }//###################################################################################### public void setPointType(boolean type) { if (pointType != type) { pointType = type; myArcPath.createPath(); myArcPath.getArc().updateArcPosition(); } }//###################################################################################### public void togglePointType() { pointType = !pointType; myArcPath.createPath(); myArcPath.getArc().updateArcPosition(); }//###################################################################################### public void setVisibilityLock(boolean lock) { myArcPath.setPointVisibilityLock(lock); }//###################################################################################### public double getAngle(ArcPathPoint p2) { double angle; if (point.y <= p2.point.y) angle = Math.atan((point.x - p2.point.x) / (p2.point.y - point.y)); else angle = Math.atan((point.x - p2.point.x) / (p2.point.y - point.y))+Math.PI; // Needed to eliminate an exception on Windows if (point.equals(p2.point)) angle = 0; return angle; }// ###################################################################################### public double getAngle(Point2D.Float p2) { double angle; if (point.y <= p2.y) angle = Math.atan((point.x - p2.x) / (p2.y - point.y)); else angle = Math.atan((point.x - p2.x) / (p2.y - point.y))+Math.PI; // Needed to eliminate an exception on Windows if (point.equals(p2)) angle = 0; return angle; }//###################################################################################### public void paintComponent(Graphics g) { if (!ignoreSelection) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g;// g2.setStroke(new BasicStroke(1.0f)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); // RectangularShape shape; if (pointType == CURVED) shape = new Ellipse2D.Double(0,0,2*SIZE,2*SIZE);// else if(myArcPath.getPathPoint(0)==this)// shape = new Rectangle2D.Double(SIZE/2,SIZE/2,SIZE*3/2,SIZE*3/2); else shape = new Rectangle2D.Double(0,0,2*SIZE,2*SIZE); if (selected) { g2.setPaint(SELECTION_FILL_COLOUR); g2.fill(shape); g2.setPaint(SELECTION_LINE_COLOUR); g2.draw(shape); } else { g2.setPaint(ELEMENT_FILL_COLOUR); g2.fill(shape); g2.setPaint(ELEMENT_LINE_COLOUR); g2.draw(shape); } } }//###################################################################################### public int getIndex() { for(int i=0;i<myArcPath.getNumPoints();i++) if(myArcPath.getPathPoint(i)==this) return i; return -1; } public boolean isDeleteable() { int i=getIndex(); return(i>0 && i!=myArcPath.getNumPoints()-1); } public void delete() // Won't delete if only two points left. General delete. { if(isDeleteable()) { kill(); myArcPath.updateArc(); } }//###################################################################################### public void kill() // delete without the safety check :) { // called internally by ArcPoint and parent ArcPath super.removeFromContainer(); myArcPath.deletePoint(this); }//###################################################################################### public Point2D.Float getControl1() { return control1; }//###################################################################################### public Point2D.Float getControl2() { return control2; }//###################################################################################### public void setControl1(float _x, float _y) { control1.x = _x; control1.y = _y; }//###################################################################################### public void setControl2(float _x, float _y) { control2.x = _x; control2.y = _y; }//###################################################################################### public void setControl1(Point2D.Float p) { control1.x = p.x; control1.y = p.y; }//##################################################################################### public void setControl2(Point2D.Float p) { control2.x = p.x; control2.y = p.y; }//###################################################################################### public ArcPath getArcPath(){ return myArcPath; }//######################################################################################}//######################################################################################
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -