📄 svgrotate.java
字号:
/* * Created on 4 mai 2004 * ============================================= GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 =============================================GLIPS Graffiti Editor, a SVG EditorCopyright (C) 2003 Jordi SUC, Philippe Gil, SARL ITRISThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAContact : jordi.suc@itris.fr; philippe.gil@itris.fr ============================================= */package fr.itris.glips.svgeditor.domactions;import fr.itris.glips.svgeditor.*;import fr.itris.glips.svgeditor.canvas.*;import fr.itris.glips.svgeditor.menutool.*;import fr.itris.glips.svgeditor.selection.*;import fr.itris.glips.svgeditor.undoredo.*;import org.apache.batik.util.*;import javax.swing.*;import java.awt.geom.*;import java.awt.event.*;import java.util.*;import org.w3c.dom.*;import fr.itris.glips.svgeditor.resources.*;/** * @author Jordi SUC * * the class allowing to rotate a node */public class SVGRotate extends SVGModuleAdapter{ /** * the id of the module */ final private String idrotate="Rotate", idrotate90="Rotate90", idrotatem90="Rotatem90", idrotate180="Rotate180"; /** * the labels */ private String labelrotate="", labelrotate90="", labelrotatem90="", labelrotate180=""; /** * the undo/redo labels */ private String undoredorotate=""; /** * the constant defining the 90 degrees rotation */ final private int ROTATE_90=0; /** * the constant defining the -90 degrees rotation */ final private int ROTATE_MINUS_90=1; /** * the constant defining the 180 degrees rotation */ final private int ROTATE_180=2; /** * the menu items that will be contained in the menu */ private JMenuItem rotate90, rotatem90, rotate180; /** * the listeners to the menu items */ private ActionListener rotate90Listener, rotatem90Listener, rotate180Listener; /** * the menu in which the menu items will be inserted */ private JMenu rotate; /** * the editor */ private SVGEditor editor=null; /** * the nodes that are currently selected */ private LinkedList selectedNodes=new LinkedList(); /** * the constructor of the class * @param editor the editor */ public SVGRotate(SVGEditor editor){ this.editor=editor; //gets the labels from the resources ResourceBundle bundle=SVGEditor.getBundle(); if(bundle!=null){ try{ labelrotate=bundle.getString("labelrotate"); labelrotate90=bundle.getString("labelrotate90"); labelrotatem90=bundle.getString("labelrotatem90"); labelrotate180=bundle.getString("labelrotate180"); undoredorotate=bundle.getString("undoredorotate"); }catch (Exception ex){} } //getting the icons ImageIcon rotate90Icon=SVGResource.getIcon("Rotate90", false), drotate90Icon=SVGResource.getIcon("Rotate90", true), rotatem90Icon=SVGResource.getIcon("Rotatem90", false), drotatem90Icon=SVGResource.getIcon("Rotatem90", true), rotate180Icon=SVGResource.getIcon("Rotate180", false), drotate180Icon=SVGResource.getIcon("Rotate180", true); //creates the menu items, sets the keyboard shortcuts rotate90=new JMenuItem(labelrotate90, rotate90Icon); rotate90.setDisabledIcon(drotate90Icon); rotate90.setAccelerator(KeyStroke.getKeyStroke("")); rotate90.setEnabled(false); rotatem90=new JMenuItem(labelrotatem90, rotatem90Icon); rotatem90.setDisabledIcon(drotatem90Icon); rotatem90.setAccelerator(KeyStroke.getKeyStroke("")); rotatem90.setEnabled(false); rotate180=new JMenuItem(labelrotate180, rotate180Icon); rotate180.setDisabledIcon(drotate180Icon); rotate180.setAccelerator(KeyStroke.getKeyStroke("")); rotate180.setEnabled(false); //a listener that listens to the changes of the SVGFrames final ActionListener svgframeListener=new ActionListener(){ /** * a listener on the selection changes */ private ActionListener selectionListener=null; /** * the current selection module */ private SVGSelection selection=null; public void actionPerformed(ActionEvent e) { //clears the list of the selected items selectedNodes.clear(); //disables the menuitems rotate90.setEnabled(false); rotatem90.setEnabled(false); rotate180.setEnabled(false); final SVGFrame frame=getSVGEditor().getFrameManager().getCurrentFrame(); //if a selection listener is already registered on a selection module, it is removed if(selection!=null && selectionListener!=null){ selection.removeSelectionListener(selectionListener); } //gets the current selection module if(frame!=null){ selection=getSVGEditor().getSVGSelection(); } if(frame!=null && selection!=null){ manageSelection(); //the listener of the selection changes selectionListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { manageSelection(); } }; //adds the selection listener if(selectionListener!=null){ selection.addSelectionListener(selectionListener); } } } /** * updates the selected items and the state of the menu items */ protected void manageSelection(){ //disables the menuitems rotate90.setEnabled(false); rotatem90.setEnabled(false); rotate180.setEnabled(false); LinkedList list=null; //gets the currently selected nodes list if(selection!=null){ list=selection.getCurrentSelection(getSVGEditor().getFrameManager().getCurrentFrame()); } selectedNodes.clear(); //refresh the selected nodes list if(list!=null){ selectedNodes.addAll(list); } if(selectedNodes.size()>0){ rotate90.setEnabled(true); rotatem90.setEnabled(true); rotate180.setEnabled(true); } } }; //adds the SVGFrame change listener editor.getFrameManager().addSVGFrameChangedListener(svgframeListener); //adds the listeners rotate90Listener=new ActionListener(){ public void actionPerformed(ActionEvent e) { if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){ getSVGEditor().cancelActions(true); if(selectedNodes.size()>0){ rotate(selectedNodes,ROTATE_90); } } } }; rotate90.addActionListener(rotate90Listener); rotatem90Listener=new ActionListener(){ public void actionPerformed(ActionEvent e) { if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){ getSVGEditor().cancelActions(true); if(selectedNodes.size()>0){ rotate(selectedNodes,ROTATE_MINUS_90); } } } }; rotatem90.addActionListener(rotatem90Listener); rotate180Listener=new ActionListener(){ public void actionPerformed(ActionEvent e) { if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){ getSVGEditor().cancelActions(true); if(selectedNodes.size()>0){ rotate(selectedNodes,ROTATE_180); } } } }; rotate180.addActionListener(rotate180Listener); //adds the menu items to the menu rotate=new JMenu(labelrotate); rotate.add(rotate90); rotate.add(rotatem90); rotate.add(rotate180); } /** * @return the editor */ public SVGEditor getSVGEditor(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -