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

📄 svgsame.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Created on 30 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 * * Sets the nodes size to the same size as the first selected node size */public class SVGSame extends SVGModuleAdapter{		/**	 * the id of the module	 */	final private String idsame="Same", idsamewidth="SameWidth", idsameheight="SameHeight", idsamesize="SameSize";		/**	 * the labels	 */	private String labelsame="", labelsamewidth="", labelsameheight="", labelsamesize="";		/**	 * the undo/redo labels	 */	private String undoredosamewidth="", undoredosameheight="", undoredosamesize="";		/**	 * the constant defining the same width action	 */	final private int SAME_WIDTH=0;		/**	 * the constant defining the same height action	 */	final private int SAME_HEIGHT=1;		/**	 * the constant defining the same size action	 */	final private int SAME_SIZE=2;	/**	 * the menu items that will be contained in the menu	 */	private JMenuItem samewidth, sameheight, samesize;		/**	 * the listeners to the menu items	 */	private ActionListener sameWidthListener, sameHeightListener, sameSizeListener;		/**	 * the menu in which the menu items will be inserted	 */	private JMenu same;		/**	 * 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 SVGSame(SVGEditor editor) {				this.editor=editor;				//gets the labels from the resources		ResourceBundle bundle=SVGEditor.getBundle();				if(bundle!=null){		    			try{				labelsame=bundle.getString("labelsame");				labelsamewidth=bundle.getString("labelsamewidth");				labelsameheight=bundle.getString("labelsameheight");				labelsamesize=bundle.getString("labelsamesize");				undoredosamewidth=bundle.getString("undoredosamewidth");				undoredosameheight=bundle.getString("undoredosameheight");				undoredosamesize=bundle.getString("undoredosamesize");			}catch (Exception ex){}		}				//getting the icons		ImageIcon sameWidthIcon=SVGResource.getIcon("SameWidth", false),						dsameWidthIcon=SVGResource.getIcon("SameWidth", true),						sameHeightIcon=SVGResource.getIcon("SameHeight", false),						dsameHeightIcon=SVGResource.getIcon("SameHeight", true),						sameSizeIcon=SVGResource.getIcon("SameSize", false),						dsameSizeIcon=SVGResource.getIcon("SameSize", true);				//creates the menu items, sets the keyboard shortcuts		samewidth=new JMenuItem(labelsamewidth, sameWidthIcon);		samewidth.setDisabledIcon(dsameWidthIcon);		samewidth.setAccelerator(KeyStroke.getKeyStroke(""));		samewidth.setEnabled(false);				sameheight=new JMenuItem(labelsameheight, sameHeightIcon);		sameheight.setDisabledIcon(dsameHeightIcon);		sameheight.setAccelerator(KeyStroke.getKeyStroke(""));		sameheight.setEnabled(false);				samesize=new JMenuItem(labelsamesize, sameSizeIcon);		samesize.setDisabledIcon(dsameSizeIcon);		samesize.setAccelerator(KeyStroke.getKeyStroke(""));		samesize.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				samewidth.setEnabled(false);				sameheight.setEnabled(false);				samesize.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 evt) {						    							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											samewidth.setEnabled(false);				sameheight.setEnabled(false);				samesize.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){				    					samewidth.setEnabled(true);					sameheight.setEnabled(true);					samesize.setEnabled(true);					}											}		};				//adds the SVGFrame change listener		editor.getFrameManager().addSVGFrameChangedListener(svgframeListener);		//adds the listeners		sameWidthListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>1){					    						same(selectednodes,SAME_WIDTH);						//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};				samewidth.addActionListener(sameWidthListener);		sameHeightListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>1){					    						same(selectednodes,SAME_HEIGHT);						//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};				sameheight.addActionListener(sameHeightListener);				sameSizeListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>1){					    						same(selectednodes,SAME_SIZE);						//sets that the svg has been modified						getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);					}			    }			}		};				samesize.addActionListener(sameSizeListener);					//adds the menu items to the menu		same=new JMenu(labelsame);		same.add(samewidth);		same.add(sameheight);		same.add(samesize);	}		/**	 * @return the editor	 */	public SVGEditor getSVGEditor(){		return editor;	}		/**	 * @return a map associating a menu item id to its menu item object

⌨️ 快捷键说明

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