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

📄 svgorder.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Created on 23 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.util.*;import org.w3c.dom.*;import org.w3c.dom.svg.*;import fr.itris.glips.svgeditor.resources.*;/** * @author Jordi SUC * * the class allowing to put a node over or behind another, or at the top or the bottom of the document */public class SVGOrder extends SVGModuleAdapter{	/**	 * the constants	 */	private final int TO_TOP=0;	private final int TO_UP=1;	private final int TO_DOWN=2;	private final int TO_BOTTOM=3;		/**	 * the id of the module	 */	final private String idorder="Order", idordertop="OrderTop", idorderup="OrderUp", idorderdown="OrderDown", idorderbottom="OrderBottom";		/**	 * the labels	 */	private String labelorder="", labelordertop="", labelorderup="", labelorderdown="",  labelorderbottom="";		/**	 * the undo/redo labels	 */	private String undoredoordertop="", undoredoorderup="", undoredoorderdown="",  undoredoorderbottom="";	/**	 * the menu items that will be contained in the menu	 */	private JMenuItem toTop, toUp, toDown, toBottom;		/**	 * the listeners to the menu items	 */	private ActionListener toTopListener, toUpListener, toDownListener, toBottomListener;		/**	 * the menu in which the menu items will be inserted	 */	private JMenu order;		/**	 * 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 SVGOrder(SVGEditor editor) {				this.editor=editor;				//gets the labels from the resources		ResourceBundle bundle=SVGEditor.getBundle();				if(bundle!=null){		    			try{				labelorder=bundle.getString("labelorder");				labelordertop=bundle.getString("labelordertop");				labelorderup=bundle.getString("labelorderup");				labelorderdown=bundle.getString("labelorderdown");				labelorderbottom=bundle.getString("labelorderbottom");				undoredoordertop=bundle.getString("undoredoordertop");				undoredoorderup=bundle.getString("undoredoorderup");				undoredoorderdown=bundle.getString("undoredoorderdown");				undoredoorderbottom=bundle.getString("undoredoorderbottom");			}catch (Exception ex){}		}				//getting the icons		ImageIcon orderTopIcon=SVGResource.getIcon("OrderTop", false),						dorderTopIcon=SVGResource.getIcon("OrderTop", true),						orderUpIcon=SVGResource.getIcon("OrderUp", false),						dorderUpIcon=SVGResource.getIcon("OrderUp", true),						orderDownIcon=SVGResource.getIcon("OrderDown", false),						dorderDownIcon=SVGResource.getIcon("OrderDown", true),						orderBottomIcon=SVGResource.getIcon("OrderBottom", false),						dorderBottomIcon=SVGResource.getIcon("OrderBottom", true);		toTop=new JMenuItem(labelordertop, orderTopIcon);		toTop.setDisabledIcon(dorderTopIcon);		toTop.setAccelerator(KeyStroke.getKeyStroke("ctrl shift UP"));		toTop.setEnabled(false);				toUp=new JMenuItem(labelorderup, orderUpIcon);		toUp.setDisabledIcon(dorderUpIcon);		toUp.setAccelerator(KeyStroke.getKeyStroke("ctrl UP"));		toUp.setEnabled(false);				toDown=new JMenuItem(labelorderdown, orderDownIcon);		toDown.setDisabledIcon(dorderDownIcon);		toDown.setAccelerator(KeyStroke.getKeyStroke("ctrl DOWN"));		toDown.setEnabled(false);				toBottom=new JMenuItem(labelorderbottom, orderBottomIcon);		toBottom.setDisabledIcon(dorderBottomIcon);		toBottom.setAccelerator(KeyStroke.getKeyStroke("ctrl shift DOWN"));		toBottom.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				toTop.setEnabled(false);				toUp.setEnabled(false);				toDown.setEnabled(false);				toBottom.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											toTop.setEnabled(false);				toUp.setEnabled(false);				toDown.setEnabled(false);				toBottom.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){				    					toTop.setEnabled(true);					toUp.setEnabled(true);					toDown.setEnabled(true);					toBottom.setEnabled(true);				}											}		};				//adds the SVGFrame change listener		editor.getFrameManager().addSVGFrameChangedListener(svgframeListener);		//adds the listeners		toTopListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){					    						order(selectednodes, TO_TOP);					}			    }			}		};				toTop.addActionListener(toTopListener);				toUpListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){					    						order(selectednodes, TO_UP);					}			    }			}		};				toUp.addActionListener(toUpListener);				toDownListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){					    						order(selectednodes, TO_DOWN);					}			    }			}		};				toDown.addActionListener(toDownListener);				toBottomListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e) {			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										if(selectednodes.size()>0){					    						order(selectednodes, TO_BOTTOM);					}			    }			}		};				toBottom.addActionListener(toBottomListener);						//adds the menu items to the menu		order=new JMenu(labelorder);		order.add(toTop);		order.add(toUp);		order.add(toDown);		order.add(toBottom);	}		/**	 * @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(idorder, order);				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(), idorder, labelorder, "");				popupItems.add(subMenu);				//creating the top popup item		SVGPopupItem toTopItem=new SVGPopupItem(getSVGEditor(), idordertop, labelordertop, "OrderTop"){					public JMenuItem getPopupItem(LinkedList nodes) {				if(nodes!=null && nodes.size()>0){										menuItem.setEnabled(true);										//adds the action listeners					if(menuItem.isEnabled()){												menuItem.addActionListener(toTopListener);					}									}else{										menuItem.setEnabled(false);				}								return super.getPopupItem(nodes);			}		};				//creating the up popup item		SVGPopupItem toUpItem=new SVGPopupItem(getSVGEditor(), idorderup, labelorderup, "OrderUp"){					public JMenuItem getPopupItem(LinkedList nodes) {				if(nodes!=null && nodes.size()>0){										menuItem.setEnabled(true);										//adds the action listeners					if(menuItem.isEnabled()){												menuItem.addActionListener(toUpListener);					}									}else{										menuItem.setEnabled(false);				}								return super.getPopupItem(nodes);

⌨️ 快捷键说明

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