📄 svgshape.java
字号:
setCanRepaintSelection(false); try{ validateTranslateNodes(fframe, (LinkedList<Node>)fargs[0], (Point2D.Double)fargs[1]); //sets that the svg has been modified fframe.setModified(true); }catch (Exception ex){return;} setCanRepaintSelection(true); } }; frame.enqueue(runnable); } }else{ //make a different action given the current type of selection if(type.equals("level1")){ if(action==DO_ACTION){ setCanRepaintSelection(false); try{ resizeNode(frame, (SVGSelectionSquare)args[0],(Point2D.Double)args[1],(Point2D.Double)args[2]); }catch (Exception e){return;} }else if(action==VALIDATE_ACTION){ Runnable runnable=new Runnable(){ public void run() { try{ validateResizeNode(fframe, (SVGSelectionSquare)fargs[0],(Point2D.Double)fargs[1],(Point2D.Double)fargs[2]); //sets that the svg has been modified fframe.setModified(true); }catch (Exception e){return;} setCanRepaintSelection(true); } }; frame.enqueue(runnable); } }else if(type.equals("level2")){ if(action==DO_ACTION){ setCanRepaintSelection(false); try{ rotateSkewNode(frame, (SVGSelectionSquare)args[0],(Point2D.Double)args[3],(Point2D.Double)args[4]); }catch (Exception e){return;} }else if(action==VALIDATE_ACTION){ Runnable runnable=new Runnable(){ public void run() { try{ validateRotateSkewNode(fframe, (SVGSelectionSquare)fargs[0],(Point2D.Double)fargs[3],(Point2D.Double)fargs[4]); //sets that the svg has been modified fframe.setModified(true); }catch (Exception e){return;} setCanRepaintSelection(true); } }; frame.enqueue(runnable); } }else if(type.equals("level3")){ if(action==DO_ACTION){ setCanRepaintSelection(false); try{ modifyPoint(frame, (SVGSelectionSquare)args[0],(Point2D.Double)args[1],(Point2D.Double)args[2]); }catch (Exception e){return;} }else if(action==VALIDATE_ACTION){ Runnable runnable=new Runnable(){ public void run() { try{ validateModifyPoint(fframe, (SVGSelectionSquare)fargs[0], (Point2D.Double)fargs[1], (Point2D.Double)fargs[2]); //sets that the svg document has been modified fframe.setModified(true); }catch (Exception e){return;} setCanRepaintSelection(true); } }; frame.enqueue(runnable); } }else if(type.equals("locked")){ } } } } /** * @param opoint the origin point * @param place the place of the selection square * @param type the type of the selection * @return the shape of the selection square */ protected Shape getArrow(Point2D.Double opoint, String place, int type){ Shape shape=null; AffineTransform af=new AffineTransform(); if(place!=null && place.equals("C")){ GeneralPath path=new GeneralPath(); path.moveTo(0, -4); path.lineTo(-3, -4); path.lineTo(-4, -3); path.lineTo(-4, 3); path.lineTo(-3, 4); path.lineTo(4, 4); path.lineTo(4, 0); path.lineTo(6, 0); path.lineTo(3, -2); path.lineTo(0, 0); path.lineTo(2, 0); path.lineTo(2, 2); path.lineTo(-1, 2); path.lineTo(-2, 1); path.lineTo(-2, -2); path.lineTo(0, -2); path.lineTo(0, -4); af.preConcatenate(AffineTransform.getTranslateInstance(opoint.x, opoint.y)); shape=path.createTransformedShape(af); }else if(place!=null && (place.equals("P") || place.equals("Begin") || place.equals("End"))){ Rectangle2D.Double rect=new Rectangle2D.Double(-2.5, -2.5, 5, 5); af.preConcatenate(AffineTransform.getTranslateInstance(opoint.x, opoint.y)); shape=af.createTransformedShape(rect); }else if(place!=null && place.equals("Ctrl")){ GeneralPath path=new GeneralPath(); path.moveTo(0, -4); path.lineTo(-3, 0); path.lineTo(0, 4); path.lineTo(3, 0); path.lineTo(0, -4); af.preConcatenate(AffineTransform.getTranslateInstance(opoint.x, opoint.y)); shape=path.createTransformedShape(af); }else if(place!=null){ GeneralPath path=new GeneralPath(); path.moveTo(0, -5); path.lineTo(-3, -2); path.lineTo(-1, -2); path.lineTo(-1, 2); path.lineTo(-3, 2); path.lineTo(0, 5); path.lineTo(3, 2); path.lineTo(1, 2); path.lineTo(1, -2); path.lineTo(3, -2); path.lineTo(0, -5); double angle=0; if(place.equals("N") || place.equals("S")){ if(type==REGULAR_SELECTION){ angle=0; }else if(type==ROTATE_SELECTION){ angle=Math.PI/2; } }else if(place.equals("E") || place.equals("W")){ if(type==REGULAR_SELECTION){ angle=Math.PI/2; }else if(type==ROTATE_SELECTION){ angle=0; } }else if(place.equals("NW") || place.equals("SE")){ angle=-Math.PI/4; }else if(place.equals("NE") || place.equals("SW")){ angle=Math.PI/4; } af.preConcatenate(AffineTransform.getRotateInstance(angle)); af.preConcatenate(AffineTransform.getTranslateInstance(opoint.x, opoint.y)); shape=path.createTransformedShape(af); } return shape; } /** * draws the selection around the node * @param frame the current SVGFrame * @param graphics the graphics * @param node the node to be selected * @return the list of the selection squares */ protected LinkedList<SVGSelectionSquare> drawSelection(SVGFrame frame, Graphics graphics, Node node){ LinkedList<SVGSelectionSquare> squarelist=new LinkedList<SVGSelectionSquare>(); Graphics2D g=(Graphics2D)graphics; if(frame!=null && g!=null && node!=null){ int sqd=5; Rectangle2D rect=frame.getNodeBounds((Element)node); if(rect!=null){ //computes and draws the new awt rectangle to be displayed Rectangle2D.Double scRect=new Rectangle2D.Double(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); if(scRect!=null){ double x=scRect.getX(), y=scRect.getY(), w=scRect.getWidth(), h=scRect.getHeight(); int[] sqx=new int[8]; int[] sqy=new int[8]; //the coordinates of the selection points sqx[0]=(int)x-2*sqd; sqx[1]=(int)(x+w/2)-sqd; sqx[2]=(int)(x+w); sqx[3]=sqx[2]; sqx[4]=sqx[2]; sqx[5]=sqx[1]; sqx[6]=sqx[0]; sqx[7]=sqx[0]; sqy[0]=(int)y-2*sqd; sqy[3]=(int)(y+h/2)-sqd; sqy[4]=(int)(y+h); sqy[1]=sqy[0]; sqy[2]=sqy[0]; sqy[5]=sqy[4]; sqy[6]=sqy[4]; sqy[7]=sqy[3]; //the ids of the selection squares String[] types=new String[8]; types[0]="NW"; types[1]="N"; types[2]="NE"; types[3]="E"; types[4]="SE"; types[5]="S"; types[6]="SW"; types[7]="W"; //the cursors associated with the selection square Cursor[] cursors=new Cursor[8]; cursors[0]=new Cursor(Cursor.NW_RESIZE_CURSOR); cursors[1]=new Cursor(Cursor.N_RESIZE_CURSOR); cursors[2]=new Cursor(Cursor.NE_RESIZE_CURSOR); cursors[3]=new Cursor(Cursor.E_RESIZE_CURSOR); cursors[4]=new Cursor(Cursor.SE_RESIZE_CURSOR); cursors[5]=new Cursor(Cursor.S_RESIZE_CURSOR); cursors[6]=new Cursor(Cursor.SW_RESIZE_CURSOR); cursors[7]=new Cursor(Cursor.W_RESIZE_CURSOR); //an array of indices int i; int[] tin=null; if(w>2*sqd && h>2*sqd){ int[] tmp=new int[8]; for(i=0;i<8;i++){ tmp[i]=i; } tin=tmp; }else if((w<=2*sqd && h>2*sqd) || (w>2*sqd && h<=2*sqd) || (w<=2*sqd && h<=2*sqd)){ int[] tmp={1,3,5,7}; tin=tmp; } //draws the graphic elements Shape shape=null; GradientPaint gradient=null; for(i=0;i<tin.length;i++){ if(editor.getSVGSelection()!=null){ squarelist.add(new SVGSelectionSquare(node, types[tin[i]], new Rectangle2D.Double(sqx[tin[i]],sqy[tin[i]],2*sqd,2*sqd), cursors[tin[i]])); } shape=getArrow(new Point2D.Double(sqx[tin[i]]+sqd, sqy[tin[i]]+sqd), types[tin[i]], REGULAR_SELECTION); if(shape!=null){ gradient=new GradientPaint(sqx[tin[i]], sqy[tin[i]], SQUARE_SELECTION_COLOR1, sqx[tin[i]]+2*sqd, sqy[tin[i]]+2*sqd, SQUARE_SELECTION_COLOR2, true); g.setPaint(gradient); g.fill(shape); g.setColor(LINE_SELECTION_COLOR); g.draw(shape); } } } } } return squarelist; } /** * draws the selection around the node * @param frame the current SVGFrame * @param graphics the graphics * @param node the node to be selected * @return the list of the selection squares */ protected LinkedList<SVGSelectionSquare> drawRotateSelection(SVGFrame frame, Graphics graphics, Node node){ LinkedList<SVGSelectionSquare> squarelist=new LinkedList<SVGSelectionSquare>(); Graphics2D g=(Graphics2D)graphics; if(frame!=null && g!=null && node!=null){ int sqd=5; Rectangle2D rect=frame.getNodeBounds((Element)node); if(rect!=null){ //computes and draws the new awt rectangle to be displayed Rectangle2D.Double scRect=new Rectangle2D.Double(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); double x=scRect.getX(), y=scRect.getY(), w=scRect.getWidth(), h=scRect.getHeight(); int[] sqx=new int[5]; int[] sqy=new int[5]; //the coordinates of the selection points sqx[0]=(int)(x+w/2)-sqd; sqx[1]=(int)(x+w); sqx[2]=sqx[0]; sqx[3]=(int)x-2*sqd; sqx[4]=(int)(x+w/2-sqd); sqy[0]=(int)y-2*sqd; sqy[1]=(int)(y+h/2)-sqd; sqy[2]=(int)(y+h); sqy[3]=sqy[1]; sqy[4]=(int)(y+h/2-sqd); //the ids of the selection points String[] types=new String[5]; types[0]="N"; types[1]="E"; types[2]="S"; types[3]="W"; types[4]="C"; Cursor[] cursors=new Cursor[5]; cursors[0]=new Cursor(Cursor.HAND_CURSOR); cursors[1]=new Cursor(Cursor.HAND_CURSOR); cursors[2]=new Cursor(Cursor.HAND_CURSOR); cursors[3]=new Cursor(Cursor.HAND_CURSOR); cursors[4]=new Cursor(Cursor.HAND_CURSOR); //an array of indices int i; int[] tin=null; if(w>2*sqd && h>2*sqd){ int[] tmp=new int[5]; for(i=0;i<5;i++){ tmp[i]=i; } tin=tmp; }else{ int[] tmp={0,1,2,3}; tin=tmp; } //draws the graphic elements Shape shape=null; GradientPaint gradient=null; for(i=0;i<tin.length;i++){ if(editor.getSVGSelection()!=null){ squarelist.add(new SVGSelectionSquare(node,types[tin[i]], new Rectangle2D.Double(sqx[tin[i]],sqy[tin[i]],2*sqd,2*sqd), cursors[tin[i]])); } shape=getArrow(new Point2D.Double(sqx[tin[i]]+sqd, sqy[tin[i]]+sqd), types[tin[i]], ROTATE_SELECTION); if(shape!=null){ gradient=new GradientPaint(sqx[tin[i]], sqy[tin[i]], SQUARE_SELECTION_COLOR1, sqx[tin[i]]+2*sqd, sqy[tin[i]]+2*sqd, SQUARE_SELECTION_COLOR2, true); g.setPaint(gradient); g.fill(shape); g.setColor(LINE_SELECTION_COLOR); g.draw(shape); } } } } return squarelist; } /** * draws the selection around the node * @param frame the current SVGFrame * @param graphics the graphics * @param node the node to be selected * @return the list of the selection squares */ protected LinkedList<SVGSelectionSquare> drawModifyPointsSelection(SVGFrame frame, Graphics graphics, Node node){ return null; } /** * draws the selection around the node * @param frame the current SVGFrame * @param graphics the graphics * @param node the node to be selected * @return the list of the selection squares */ protected LinkedList<SVGSelectionSquare> drawLockedSelection(SVGFrame frame, Graphics graphics, Node node){ Graphics2D g=(Graphics2D)graphics; if(frame!=null && g!=null && node!=null){ int sqd=5; Rectangle2D rect=frame.getNodeBounds((Element)node); if(rect!=null){ //computes and draws the new awt rectangle to be displayed Rectangle2D.Double scRect=new Rectangle2D.Double(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); double x=scRect.getX(), y=scRect.getY(), w=scRect.getWidth(), h=scRect.getHeight(); int[] sqx=new int[8]; int[] sqy=new int[8]; //the coordinates of the selection points sqx[0]=(int)x-2*sqd; sqx[1]=(int)(x+w/2)-sqd; sqx[2]=(int)(x+w); sqx[3]=sqx[2];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -