📄 svgspacing.java
字号:
/* * Created on 29 avr. 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 javax.swing.*;import java.awt.event.*;import java.awt.geom.*;import java.util.*;import org.w3c.dom.*;import fr.itris.glips.svgeditor.resources.*;/** * @author Jordi SUC * * the class used to center nodes horizontally or vertically */public class SVGSpacing extends SVGModuleAdapter{ /** * the id of the module */ final private String idspacing="Spacing", idspacinghorizontal="HorizontalSpacing", idspacingvertical="VerticalSpacing"; /** * the labels */ private String labelspacing="", labelspacinghorizontal="", labelspacingvertical=""; /** * the undo/redo labels */ private String undoredospacinghorizontal="", undoredospacingvertical=""; /** * the constant defining the horizontal center */ final private int HORIZONTAL_SPACING=0; /** * the constant defining the vertical center */ final private int VERTICAL_SPACING=1; /** * the menu items that will be contained in the menu */ private JMenuItem spacingh, spacingv; /** * the listeners to the menu items */ private ActionListener horizontalSpacingListener, verticalSpacingListener; /** * the menu in which the menu items will be inserted */ private JMenu spacing; /** * 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 SVGSpacing(SVGEditor editor) { this.editor=editor; //gets the labels from the resources ResourceBundle bundle=SVGEditor.getBundle(); if(bundle!=null){ try{ labelspacing=bundle.getString("labelspacing"); labelspacinghorizontal=bundle.getString("labelspacinghorizontal"); labelspacingvertical=bundle.getString("labelspacingvertical"); undoredospacinghorizontal=bundle.getString("undoredospacinghorizontal"); undoredospacingvertical=bundle.getString("undoredospacingvertical"); }catch (Exception ex){} } //getting the icons ImageIcon horizontalSpacingIcon=SVGResource.getIcon("HorizontalSpacing", false), dhorizontalSpacingIcon=SVGResource.getIcon("HorizontalSpacing", true), verticalSpacingIcon=SVGResource.getIcon("VerticalSpacing", false), dverticalSpacingIcon=SVGResource.getIcon("VerticalSpacing", true); //creates the menu items, sets the keyboard shortcuts spacingh=new JMenuItem(labelspacinghorizontal, horizontalSpacingIcon); spacingh.setDisabledIcon(dhorizontalSpacingIcon); spacingh.setAccelerator(KeyStroke.getKeyStroke("")); spacingh.setEnabled(false); spacingv=new JMenuItem(labelspacingvertical, verticalSpacingIcon); spacingv.setDisabledIcon(dverticalSpacingIcon); spacingv.setAccelerator(KeyStroke.getKeyStroke("")); spacingv.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 spacingh.setEnabled(false); spacingv.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 spacingh.setEnabled(false); spacingv.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()>1){ spacingh.setEnabled(true); spacingv.setEnabled(true); } } }; //adds the SVGFrame change listener editor.getFrameManager().addSVGFrameChangedListener(svgframeListener); //adds the listeners horizontalSpacingListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){ getSVGEditor().cancelActions(true); if(selectednodes.size()>1){ spacing(selectednodes,HORIZONTAL_SPACING); //sets that the svg has been modified getSVGEditor().getFrameManager().getCurrentFrame().setModified(true); } } } }; spacingh.addActionListener(horizontalSpacingListener); verticalSpacingListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){ getSVGEditor().cancelActions(true); if(selectednodes.size()>1){ spacing(selectednodes,VERTICAL_SPACING); //sets that the svg has been modified getSVGEditor().getFrameManager().getCurrentFrame().setModified(true); } } } }; spacingv.addActionListener(verticalSpacingListener); //adds the menu items to the menu spacing=new JMenu(labelspacing); spacing.add(spacingh); spacing.add(spacingv); } /** * @return the editor */ public SVGEditor getSVGEditor(){ return editor; } /** * @return a map associating a menu item id to its menu item object */ public Hashtable getMenuItems(){ Hashtable menuItems=new Hashtable(); menuItems.put(idspacing, spacing); 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(), idspacing, labelspacing, ""); popupItems.add(subMenu); //creating the horizontal spacing popup item SVGPopupItem horizontalSpacingItem=new SVGPopupItem(getSVGEditor(), idspacinghorizontal, labelspacinghorizontal, "HorizontalSpacing"){ public JMenuItem getPopupItem(LinkedList nodes) { if(nodes!=null && nodes.size()>1){ menuItem.setEnabled(true); //adds the action listeners if(menuItem.isEnabled()){ menuItem.addActionListener(horizontalSpacingListener); } }else{ menuItem.setEnabled(false); } return super.getPopupItem(nodes); } }; //creating the vertical spacing popup item SVGPopupItem verticalSpacingItem=new SVGPopupItem(getSVGEditor(), idspacingvertical, labelspacingvertical, "VerticalSpacing"){ public JMenuItem getPopupItem(LinkedList nodes) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -