📄 svgrotate.java
字号:
return editor; } /** * @return a map associating a menu item id to its menu item object */ public Hashtable getMenuItems(){ Hashtable menuItems=new Hashtable(); menuItems.put(idrotate, rotate); return menuItems; } /** * @return a map associating a tool item id to its tool item object */ public Hashtable getToolItems(){ return null; } /** * Returns the collection of the popup items * @return the collection of the popup items */ public Collection getPopupItems(){ LinkedList popupItems=new LinkedList(); SVGPopupSubMenu subMenu=new SVGPopupSubMenu(getSVGEditor(), idrotate, labelrotate, ""); popupItems.add(subMenu); //creating the rotate90 popup item SVGPopupItem rotate90Item=new SVGPopupItem(getSVGEditor(), idrotate90, labelrotate90, "Rotatem90"){ public JMenuItem getPopupItem(LinkedList nodes) { if(nodes!=null && nodes.size()>0){ menuItem.setEnabled(true); //adds the action listeners if(menuItem.isEnabled()){ menuItem.addActionListener(rotate90Listener); } }else{ menuItem.setEnabled(false); } return super.getPopupItem(nodes); } }; //creating the rotatem90 popup item SVGPopupItem rotatem90Item=new SVGPopupItem(getSVGEditor(), idrotatem90, labelrotatem90, "Rotatem90"){ public JMenuItem getPopupItem(LinkedList nodes) { if(nodes!=null && nodes.size()>0){ menuItem.setEnabled(true); //adds the action listeners if(menuItem.isEnabled()){ menuItem.addActionListener(rotatem90Listener); } }else{ menuItem.setEnabled(false); } return super.getPopupItem(nodes); } }; //creating the rotatem180 popup item SVGPopupItem rotatem180Item=new SVGPopupItem(getSVGEditor(), idrotate180, labelrotate180, "Rotate180"){ public JMenuItem getPopupItem(LinkedList nodes) { if(nodes!=null && nodes.size()>0){ menuItem.setEnabled(true); //adds the action listeners if(menuItem.isEnabled()){ menuItem.addActionListener(rotate180Listener); } }else{ menuItem.setEnabled(false); } return super.getPopupItem(nodes); } }; //adding the popup items to the sub menu subMenu.addPopupItem(rotate90Item); subMenu.addPopupItem(rotatem90Item); subMenu.addPopupItem(rotatem180Item); return popupItems; } /** * used to horizontally or vertically flip a the nodes contained in the given list * @param list the list of nodes * @param type the type of the flip (HORIZONTAL_FLIP or VERTICAL_FLIP) */ protected void rotate(LinkedList list, int type){ final SVGFrame frame=editor.getFrameManager().getCurrentFrame(); if(list!=null && list.size()>0 && frame!=null){ final LinkedList snodes=new LinkedList(list); final int ftype=type; Runnable runnable=new Runnable(){ public void run(){ //the map associating a node to its old affine transform final Hashtable oldTransformMap=new Hashtable(); //the map associating a node to its new affine transform final Hashtable transformMap=new Hashtable(); Node current=null; SVGTransformMatrix matrix=null; AffineTransform af=null; Rectangle2D rect=null; double cx=0, cy=0; //gets or creates the undo/redo list SVGUndoRedoActionList actionlist=new SVGUndoRedoActionList(undoredorotate); //for each selected node for(Iterator it=snodes.iterator(); it.hasNext();){ try{current=(Node)it.next();}catch(Exception ex){current=null;} if(current!=null){ rect=frame.getNodeGeometryBounds((Element)current); if(rect!=null){ Point2D.Double centerpoint=new Point2D.Double(rect.getX()+rect.getWidth()/2, rect.getY()+rect.getHeight()/2); //getting the matrix and the affine transform associated with the current node matrix=editor.getSVGToolkit().getTransformMatrix(current); af=matrix.getTransform(); oldTransformMap.put(current, new AffineTransform(af)); af.preConcatenate(AffineTransform.getTranslateInstance(-centerpoint.x, -centerpoint.y)); if(ftype==ROTATE_90){ af.preConcatenate(AffineTransform.getRotateInstance(Math.PI/2)); }else if(ftype==ROTATE_MINUS_90){ af.preConcatenate(AffineTransform.getRotateInstance(-Math.PI/2)); }else if(ftype==ROTATE_180){ af.preConcatenate(AffineTransform.getRotateInstance(Math.PI)); } af.preConcatenate(AffineTransform.getTranslateInstance(centerpoint.x, centerpoint.y)); transformMap.put(current, af); //creating the new transform matrix matrix=new SVGTransformMatrix(1, 0, 0, 1, 0, 0); matrix.concatenateTransform(af); if(matrix.isMatrixCorrect()){ editor.getSVGToolkit().setTransformMatrix(current, matrix); //creates the undo/redo action and insert it into the undo/redo stack if(editor.getUndoRedo()!=null){ SVGUndoRedoAction action=new SVGUndoRedoAction(undoredorotate){ public void undo(){ //sets the nodes transformation matrix if(transformMap.size()>0){ Node current=null; SVGTransformMatrix matrix=null; AffineTransform af=null; for(Iterator it=oldTransformMap.keySet().iterator(); it.hasNext();){ try{current=(Node)it.next();}catch (Exception ex){current=null;} if(current!=null){ //getting the old affine transform associated with this node try{af=(AffineTransform)oldTransformMap.get(current);}catch (Exception ex){af=null;} if(af!=null){ matrix=new SVGTransformMatrix(1, 0, 0, 1, 0, 0); matrix.concatenateTransform(af); //sets the old matrix editor.getSVGToolkit().setTransformMatrix(current, matrix); } } } frame.getScrollPane().getSVGCanvas().delayedRepaint(); } } public void redo(){ //sets the nodes transformation matrix if(transformMap.size()>0){ Node current=null; SVGTransformMatrix matrix=null; AffineTransform af=null; for(Iterator it=transformMap.keySet().iterator(); it.hasNext();){ try{current=(Node)it.next();}catch (Exception ex){current=null;} if(current!=null){ //getting the new affine transform associated with this node try{af=(AffineTransform)transformMap.get(current);}catch (Exception ex){af=null;} if(af!=null){ matrix=new SVGTransformMatrix(1, 0, 0, 1, 0, 0); matrix.concatenateTransform(af); //sets the new matrix editor.getSVGToolkit().setTransformMatrix(current, matrix); } } } frame.getScrollPane().getSVGCanvas().delayedRepaint(); } } }; //adds the undo/redo action into the action list actionlist.add(action); } } } } } //adding the action list to the undo/redo module editor.getUndoRedo().addActionList(frame, actionlist); frame.getScrollPane().getSVGCanvas().delayedRepaint(); //sets that the svg has been modified getSVGEditor().getFrameManager().getCurrentFrame().setModified(true); } }; frame.enqueue(runnable); } } /** * gets the name of the module * @return the name of the module */ public String getName(){ return idrotate; } /** * cancels all the actions that could be running */ public void cancelActions(){ } /** * layout some elements in the module */ public void initialize(){ }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -