📄 svgvisualresourcevectorcirclechooserattributewidget.java
字号:
this.otherRadius = otherRadius; } protected boolean isVectorChooser() { return isVectorChooser; } protected void setVectorChooser(boolean isVectorChooser) { this.isVectorChooser = isVectorChooser; } } /** * the class describing a point in a vector chooser widget * * @author Jordi SUC * */ public class SVGVectorCircleChooserItems{ /** * the constant value for telling that no point has been hit */ protected static final int NO_POINT=0; /** * the constant value for describing the first point */ protected static final int POINT1=1; /** * the constant value for describing the second point */ protected static final int POINT2=2; /** * the constant value for describing the circle */ protected static final int CIRCLE=3; /** * the two points in percentage values */ private Point2D.Double point1=new Point2D.Double(0, 0), point2=new Point2D.Double(0, 0); /** * the radius of the circle in percentage values */ private double radius=0; /** * the size of the panel in which the vector will be displayed */ private Dimension vectorPanelSize=null; /** * the average int */ private int average=5; /** * the boolean teeling if the vector items are enabled or not */ private boolean enabled=true; /** * the boolean telling the state of the items */ private boolean isVectorChooser=true; /** * the object containing information on the vector and circle chooser */ private SVGVectorCircleChooserValues vectCircleChooser=null; /** * the constructor of the class * @param point1 the first point in percentage values * @param point2 the second point in percentage values * @param radius the radius in percentage values * @param vectorPanelSize the size of the vector panel * @param isVectorChooser the boolean telling the state of the items * @param vectCircleChooser the object containing information on the vector and circle chooser */ public SVGVectorCircleChooserItems( Point2D.Double point1, Point2D.Double point2, double radius, Dimension vectorPanelSize, boolean isVectorChooser, SVGVectorCircleChooserValues vectCircleChooser){ this.vectorPanelSize=vectorPanelSize; //the two points in percentage values if(point1!=null){ this.point1=point1; } if(point2!=null){ this.point2=point2; } this.radius=radius; this.isVectorChooser=isVectorChooser; this.vectCircleChooser=vectCircleChooser; } /** * @return the first point in the percentage format */ protected Point2D.Double getPoint1(){ return point1; } /** * @return the second point in the percentage format */ protected Point2D.Double getPoint2(){ return point2; } /** * @return the radius of the circle */ protected double getRadius(){ return radius; } /** * sets the radius * @param rad the radius */ protected void setRadius(double rad){ if(rad<0){ rad=0; } if(rad>100){ rad=100; } this.radius=rad; } /** * sets one of the points * @param point a point * @param type the type of the point (point1 or point2) */ protected void setPoint(Point2D.Double point, int type){ if(point!=null){ if(point.x<0){ point.x=0; } if(point.x>100){ point.x=100; } if(point.y<0){ point.y=0; } if(point.y>100){ point.y=100; } //sets the point if(type==POINT1){ point1.x=point.x; point1.y=point.y; }else if(type==POINT2){ point2.x=point.x; point2.y=point.y; } } } /** * @return the first point in the vector panel coordinates */ protected Point2D.Double getPanelPoint1(){ Point2D.Double point=new Point2D.Double(0, 0); if(point1!=null && vectorPanelSize!=null){ point.x=point1.x*vectorPanelSize.width/100; point.y=point1.y*vectorPanelSize.height/100; } return point; } /** * @return the second point in the vector panel coordinates */ protected Point2D.Double getPanelPoint2(){ Point2D.Double point=new Point2D.Double(0, 0); if(point2!=null && vectorPanelSize!=null){ point.x=point2.x*vectorPanelSize.width/100; point.y=point2.y*vectorPanelSize.height/100; } return point; } /** * @return the radius of the circle in the vector panel coordinates */ protected double getPanelRadius(){ double rad=0; if(point2!=null && vectorPanelSize!=null){ rad=radius*vectorPanelSize.width/100; } return rad; } /** * tells whether the given point corresponds to one of the vector's point * @param point a point * @return an int telling if it corresp */ protected int hasHitAPoint(Point point){ int res=NO_POINT; if(point!=null){ Point2D.Double vPoint1=getPanelPoint1(), vPoint2=getPanelPoint2(); double vRadius=getPanelRadius(); Rectangle2D.Double rect1=new Rectangle2D.Double(vPoint1.x-average, vPoint1.y-average, 2*average, 2*average), rect2=new Rectangle2D.Double(vPoint2.x-average, vPoint2.y-average, 2*average, 2*average), rectRadius=new Rectangle2D.Double(vPoint1.x-average, vPoint1.y-vRadius-average, 2*average, 2*average); if(rectRadius.contains(point)){ res=CIRCLE; }else if(rect1.contains(point)){ res=POINT1; }else if(rect2.contains(point)){ res=POINT2; } } return res; } /** * enables or disables the display * @param enabled */ protected void setEnabled(boolean enabled){ this.enabled=enabled; } /** * paints the vector * @param g a graphics object */ protected void paintVectorOrCircle(Graphics2D g){ if(g!=null){ if(enabled){ Point2D.Double vPoint1=getPanelPoint1(), vPoint2=getPanelPoint2(); //the elements that will be painted in the vector chooser version if(isVectorChooser){ g.setColor(Color.darkGray); g.drawLine((int)vPoint1.x, (int)vPoint1.y, (int)vPoint2.x, (int)vPoint2.y); g.setColor(vectCircleChooser.getPoint1Color()); g.drawLine((int)(vPoint1.x-average), (int)(vPoint1.y-average), (int)(vPoint1.x+average), (int)(vPoint1.y+average)); g.drawLine((int)(vPoint1.x+average), (int)(vPoint1.y-average), (int)(vPoint1.x-average), (int)(vPoint1.y+average)); g.setColor(vectCircleChooser.getPoint2Color()); g.drawOval((int)(vPoint2.x-average), (int)(vPoint2.y-average), 2*average, 2*average); }else{ //the elements that will be painted in the circle chooser version double vRadius=getPanelRadius(); g.setColor(vectCircleChooser.getPoint2Color()); g.drawLine((int)(vPoint2.x-average), (int)(vPoint2.y-average), (int)(vPoint2.x+average), (int)(vPoint2.y+average)); g.drawLine((int)(vPoint2.x+average), (int)(vPoint2.y-average), (int)(vPoint2.x-average), (int)(vPoint2.y+average)); g.setColor(vectCircleChooser.getPoint1Color()); g.drawLine((int)(vPoint1.x-average), (int)(vPoint1.y-average), (int)(vPoint1.x+average), (int)(vPoint1.y+average)); g.drawLine((int)(vPoint1.x+average), (int)(vPoint1.y-average), (int)(vPoint1.x-average), (int)(vPoint1.y+average)); g.setColor(Color.darkGray); g.drawOval((int)(vPoint1.x-vRadius), (int)(vPoint1.y-vRadius), (int)(2*vRadius), (int)(2*vRadius)); g.setColor(vectCircleChooser.getRadiusColor()); g.drawLine((int)vPoint1.x, (int)vPoint1.y, (int)vPoint1.x, (int)(vPoint1.y-vRadius)); g.drawLine((int)(vPoint1.x-average/2), (int)(vPoint1.y-vRadius-average/2), (int)(vPoint1.x+average/2), (int)(vPoint1.y-vRadius+average/2)); g.drawLine((int)(vPoint1.x+average/2), (int)(vPoint1.y-vRadius-average/2), (int)(vPoint1.x-average/2), (int)(vPoint1.y-vRadius+average/2)); } }else{ if(vectorPanelSize!=null){ g.setColor(Color.darkGray); g.fillRect(0, 0, vectorPanelSize.width, vectorPanelSize.height); } } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -