⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgalign.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Created on 27 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 fr.itris.glips.svgeditor.resources.*;import javax.swing.*;import java.awt.geom.*;import java.awt.*;import java.awt.event.*;import java.util.*;import org.w3c.dom.*;/** * @author Jordi SUC * * the class used to align items to the left, right or to the upper or the lower item  */public class SVGAlign extends SVGModuleAdapter{		/**	 * the ids of the module	 */	final private String idalign="Align", idleft="Left", idright="Right", idtop="Top", idbottom="Bottom", idcenter="Center", idhorizontalcenter="HorizontalCenter", idverticalcenter="VerticalCenter";		/**	 * the labels	 */	private String labelalign="", labelalignleft="", labelalignright="", labelaligntop="", labelalignbottom="", labelaligncenter="", labelalignhorizontalcenter="", labelalignverticalcenter="";		/**	 * the undo/redo labels	 */	private String undoredoalignleft="", undoredoalignright="", undoredoaligntop="", undoredoalignbottom="", undoredoaligncenter="", undoredoalignhorizontalcenter="", undoredoalignverticalcenter="";		/**	 * the constant defining the left alignment	 */	public final int ALIGN_LEFT=0;		/**	 * the constant defining the right alignment	 */	public final int ALIGN_RIGHT=1;		/**	 * the constant defining the top alignment	 */	public final int ALIGN_TOP=2;		/**	 * the constant defining the bottom alignment	 */	public final int ALIGN_BOTTOM=3;		/**	 * the constant defining the center alignment	 */	public final int ALIGN_CENTER=4;		/**	 * the constant defining the horizontal center alignment	 */	public final int ALIGN_HORIZONTAL_CENTER=5;		/**	 * the constant defining the vertical center alignment	 */	public final int ALIGN_VERTICAL_CENTER=6;		/**	 * the menu items that will be contained in the menu	 */	private JMenuItem alignLeft, alignRight, alignTop, alignBottom, alignCenter, alignHorizontalCenter, alignVerticalCenter;		/**	 * the menu items listeners	 */	private ActionListener alignLeftListener, alignRightListener, alignTopListener, alignBottomListener, alignCenterListener, 										alignHorizontalCenterListener, alignVerticalCenterListener;		/**	 * the menu in which the menu items will be inserted	 */	private JMenu align;	/**	 * 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 SVGAlign(SVGEditor editor) {				this.editor=editor;				//gets the labels from the resources		ResourceBundle bundle=SVGEditor.getBundle();				if(bundle!=null){			try{				labelalign=bundle.getString("labelalign");				labelalignleft=bundle.getString("labelalignleft");				labelalignright=bundle.getString("labelalignright");				labelaligntop=bundle.getString("labelaligntop");				labelalignbottom=bundle.getString("labelalignbottom");				labelaligncenter=bundle.getString("labelaligncenter");				labelalignhorizontalcenter=bundle.getString("labelalignhorizontalcenter");				labelalignverticalcenter=bundle.getString("labelalignverticalcenter");				undoredoalignleft=bundle.getString("undoredoalignleft");				undoredoalignright=bundle.getString("undoredoalignright");				undoredoaligntop=bundle.getString("undoredoaligntop");				undoredoalignbottom=bundle.getString("undoredoalignbottom");				undoredoaligncenter=bundle.getString("undoredoaligncenter");				undoredoaligncenter=bundle.getString("undoredoalignhorizontalcenter");				undoredoaligncenter=bundle.getString("undoredoalignverticalcenter");			}catch (Exception ex){}		}				//getting the icons		ImageIcon alignLeftIcon=SVGResource.getIcon("AlignLeft", false),						dalignLeftIcon=SVGResource.getIcon("AlignLeft", true),						alignRightIcon=SVGResource.getIcon("AlignRight", false),						dalignRightIcon=SVGResource.getIcon("AlignRight", true),						alignTopIcon=SVGResource.getIcon("AlignTop", false),						dalignTopIcon=SVGResource.getIcon("AlignTop", true),						alignBottomIcon=SVGResource.getIcon("AlignBottom", false),						dalignBottomIcon=SVGResource.getIcon("AlignBottom", true),						alignCenterIcon=SVGResource.getIcon("AlignCenter", false),						dalignCenterIcon=SVGResource.getIcon("AlignCenter", true),						alignHorizontalCenterIcon=SVGResource.getIcon("AlignHorizontalCenter", false),						dalignHorizontalCenterIcon=SVGResource.getIcon("AlignHorizontalCenter", true),						alignVerticalCenterIcon=SVGResource.getIcon("AlignVerticalCenter", false),						dalignVerticalCenterIcon=SVGResource.getIcon("AlignVerticalCenter", true);				//creates the menu items, sets the keyboard shortcuts		alignLeft=new JMenuItem(labelalignleft, alignLeftIcon);		alignLeft.setDisabledIcon(dalignLeftIcon);		alignLeft.setAccelerator(KeyStroke.getKeyStroke("shift LEFT"));		alignLeft.setEnabled(false);				alignRight=new JMenuItem(labelalignright, alignRightIcon);		alignRight.setDisabledIcon(dalignRightIcon);		alignRight.setAccelerator(KeyStroke.getKeyStroke("shift RIGHT"));		alignRight.setEnabled(false);				alignTop=new JMenuItem(labelaligntop, alignTopIcon);		alignTop.setDisabledIcon(dalignTopIcon);		alignTop.setAccelerator(KeyStroke.getKeyStroke("shift UP"));		alignTop.setEnabled(false);				alignBottom=new JMenuItem(labelalignbottom, alignBottomIcon);		alignBottom.setDisabledIcon(dalignBottomIcon);		alignBottom.setAccelerator(KeyStroke.getKeyStroke("shift DOWN"));		alignBottom.setEnabled(false);				alignCenter=new JMenuItem(labelaligncenter, alignCenterIcon);		alignCenter.setDisabledIcon(dalignCenterIcon);		alignCenter.setAccelerator(KeyStroke.getKeyStroke("shift C"));		alignCenter.setEnabled(false);				alignHorizontalCenter=new JMenuItem(labelalignhorizontalcenter, alignHorizontalCenterIcon);		alignHorizontalCenter.setDisabledIcon(dalignHorizontalCenterIcon);		alignHorizontalCenter.setEnabled(false);				alignVerticalCenter=new JMenuItem(labelalignverticalcenter, alignVerticalCenterIcon);		alignVerticalCenter.setDisabledIcon(dalignVerticalCenterIcon);		alignVerticalCenter.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				alignLeft.setEnabled(false);				alignRight.setEnabled(false);				alignTop.setEnabled(false);				alignBottom.setEnabled(false);				alignCenter.setEnabled(false);				alignHorizontalCenter.setEnabled(false);				alignVerticalCenter.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											alignLeft.setEnabled(false);				alignRight.setEnabled(false);				alignTop.setEnabled(false);				alignBottom.setEnabled(false);				alignCenter.setEnabled(false);				alignHorizontalCenter.setEnabled(false);				alignVerticalCenter.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){				    					alignLeft.setEnabled(true);					alignRight.setEnabled(true);					alignTop.setEnabled(true);					alignBottom.setEnabled(true);					alignCenter.setEnabled(true);					alignHorizontalCenter.setEnabled(true);					alignVerticalCenter.setEnabled(true);				}											}		};				//adds the SVGFrame change listener		editor.getFrameManager().addSVGFrameChangedListener(svgframeListener);					//adds the listeners		alignLeftListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){												align(selectednodes,ALIGN_LEFT);												//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};		alignLeft.addActionListener(alignLeftListener);				alignRightListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){												align(selectednodes,ALIGN_RIGHT);												//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};				alignRight.addActionListener(alignRightListener);				alignTopListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){						align(selectednodes,ALIGN_TOP);						//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};				alignTop.addActionListener(alignTopListener);				alignBottomListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){						align(selectednodes,ALIGN_BOTTOM);						//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};				alignBottom.addActionListener(alignBottomListener);				alignCenterListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){						align(selectednodes,ALIGN_CENTER);						//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};				alignCenter.addActionListener(alignCenterListener);				alignHorizontalCenterListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){						align(selectednodes, ALIGN_HORIZONTAL_CENTER);						//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};				alignHorizontalCenter.addActionListener(alignHorizontalCenterListener);				alignVerticalCenterListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){						align(selectednodes, ALIGN_VERTICAL_CENTER);						//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};				alignVerticalCenter.addActionListener(alignVerticalCenterListener);				//adds the menu items to the menu		align=new JMenu(labelalign);		align.add(alignLeft);		align.add(alignRight);		align.add(alignTop);		align.add(alignBottom);		align.add(alignCenter);		align.add(alignHorizontalCenter);		align.add(alignVerticalCenter);	}		/**	 * @return the editor	 */	public SVGEditor getSVGEditor(){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -