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

📄 svgclipboard.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Created on 15 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.clipboard;import fr.itris.glips.svgeditor.selection.*;import fr.itris.glips.svgeditor.undoredo.*;import fr.itris.glips.svgeditor.canvas.*;import fr.itris.glips.svgeditor.menutool.*;import fr.itris.glips.svgeditor.resources.*;import fr.itris.glips.svgeditor.*;import org.w3c.dom.*;import org.w3c.dom.svg.*;import java.awt.event.*;import java.util.*;import javax.swing.*;/** * @author Jordi SUC * the class managing all the copy, paste, cut, delete actions */public class SVGClipboard extends SVGModuleAdapter{    	/**	 * the ids of the module	 */	final private String idclipboard="Clipboard", idcopy="Copy", idpaste="Paste", idcut="Cut", iddelete="Delete";		/**	 * the labels	 */	private String labelcopy="", labelpaste="", labelcut="", labeldelete="";		/**	 * the undo/redo labels	 */	private String undoredopaste="", undoredocut="", undoredodelete="";		/**	 * the editor	 */	private SVGEditor editor=null;		/**	 * the menu items that will be added to the menubar	 */	private JMenuItem copy=null, paste=null, cut=null, delete=null;	/**	 * the listeners the the copy, paste, cut and delete menu items	 */	private ActionListener copyListener=null, pasteListener=null, cutListener=null, deleteListener=null;		/**	 * the nodes that are added to the clipboard	 */	private final LinkedList<Element> clipboardContent=new LinkedList<Element>();		/**	 * the nodes that are currently selected	 */	private final LinkedList<Element> selectedNodes=new LinkedList<Element>();		/**	 * the constructor of the class	 * @param editor the editor	 */	public SVGClipboard(SVGEditor editor){				//gets the labels from the resources		ResourceBundle bundle=SVGEditor.getBundle();				if(bundle!=null){		    			try{				labelcopy=bundle.getString("labelcopy");				labelpaste=bundle.getString("labelpaste");				labelcut=bundle.getString("labelcut");				labeldelete=bundle.getString("labeldelete");				undoredopaste=bundle.getString("undoredopaste");				undoredocut=bundle.getString("undoredocut");				undoredodelete=bundle.getString("undoredodelete");			}catch (Exception ex){}		}				this.editor=editor;				//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) {								//clearing the selected nodes				selectedNodes.clear();								//disables the menuitems				copy.setEnabled(false);				cut.setEnabled(false);				delete.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(clipboardContent.size()>0){					    					    paste.setEnabled(true);					}									}else{				    					paste.setEnabled(false);				}								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											copy.setEnabled(false);				cut.setEnabled(false);				delete.setEnabled(false);				LinkedList<Element> 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){				    					copy.setEnabled(true);					cut.setEnabled(true);					delete.setEnabled(true);				}											}		};				//adds the SVGFrame change listener		editor.getFrameManager().addSVGFrameChangedListener(svgframeListener);				//getting the icons		ImageIcon copyIcon=SVGResource.getIcon("Copy", false),						dcopyIcon=SVGResource.getIcon("Copy", true),						pasteIcon=SVGResource.getIcon("Paste", false),						dpasteIcon=SVGResource.getIcon("Paste", true),						cutIcon=SVGResource.getIcon("Cut", false),						dcutIcon=SVGResource.getIcon("Cut", true),						deleteIcon=SVGResource.getIcon("Delete", false),						ddeleteIcon=SVGResource.getIcon("Delete", true);										//initializes the menuitems, the popup items and adds the listeners on them//				copy=new JMenuItem(labelcopy, copyIcon);		copy.setDisabledIcon(dcopyIcon);		copy.setAccelerator(KeyStroke.getKeyStroke("ctrl C"));		copy.setEnabled(false);				copyListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e){			    				getSVGEditor().cancelActions(true);				copy();				paste.setEnabled(true);			}		};				copy.addActionListener(copyListener);				paste=new JMenuItem(labelpaste, pasteIcon);		paste.setDisabledIcon(dpasteIcon);		paste.setAccelerator(KeyStroke.getKeyStroke("ctrl V"));		paste.setEnabled(false);				pasteListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e){			    				getSVGEditor().cancelActions(true);								//sets that the svg document has been modified				getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);								paste();			}		};				paste.addActionListener(pasteListener);				cut=new JMenuItem(labelcut, cutIcon);		cut.setDisabledIcon(dcutIcon);		cut.setAccelerator(KeyStroke.getKeyStroke("ctrl X"));		cut.setEnabled(false);				cutListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e){			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										//sets that the svg document has been modified					getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);										cut();					paste.setEnabled(true);			    }			}		};				cut.addActionListener(cutListener);				delete=new JMenuItem(labeldelete, deleteIcon);		delete.setDisabledIcon(ddeleteIcon);		delete.setAccelerator(KeyStroke.getKeyStroke("DELETE"));		delete.setEnabled(false);				deleteListener=new ActionListener(){		    			public void actionPerformed(ActionEvent e){			    			    if(getSVGEditor().getSVGSelection()!=null && ! getSVGEditor().getSVGSelection().isActing()){			        					getSVGEditor().cancelActions(true);										//sets that the svg document has been modified					getSVGEditor().getFrameManager().getCurrentFrame().setModified(true);										delete(true);			    }			}		};				delete.addActionListener(deleteListener);	}		/**	 * @return the editor	 */	public SVGEditor getSVGEditor(){	    		return editor;	}		@Override	public Hashtable<String, JMenuItem> getMenuItems() {		Hashtable<String, JMenuItem> menuItems=new Hashtable<String, JMenuItem>();		menuItems.put(idcopy,copy);		menuItems.put(idpaste,paste);		menuItems.put(idcut,cut);		menuItems.put(iddelete,delete);				return menuItems;	}		@Override	public Collection<SVGPopupItem> getPopupItems() {		LinkedList<SVGPopupItem> popupItems=new LinkedList<SVGPopupItem>();				//creating the copy popup item		SVGPopupItem item=new SVGPopupItem(getSVGEditor(), idcopy, labelcopy, "Copy"){					public JMenuItem getPopupItem(LinkedList nodes) {								if(nodes!=null && nodes.size()>0){										menuItem.setEnabled(true);										//adds the action listeners					menuItem.addActionListener(copyListener);									}else{										menuItem.setEnabled(false);				}				return super.getPopupItem(nodes);			}		};				popupItems.add(item);				//creating the paste popup item		item=new SVGPopupItem(getSVGEditor(), idpaste, labelpaste, "Paste"){					public JMenuItem getPopupItem(LinkedList nodes) {								if(clipboardContent.size()>0){										menuItem.setEnabled(true);										//adds the action listeners					menuItem.addActionListener(pasteListener);									}else{										menuItem.setEnabled(false);				}								return super.getPopupItem(nodes);			}		};				popupItems.add(item);				//creating the cut popup item		item=new SVGPopupItem(getSVGEditor(), idcut, labelcut, "Cut"){						public JMenuItem getPopupItem(LinkedList nodes) {								if(nodes!=null && nodes.size()>0){										menuItem.setEnabled(true);										//adds the action listeners					menuItem.addActionListener(cutListener);									}else{										menuItem.setEnabled(false);				}				return super.getPopupItem(nodes);			}		};				popupItems.add(item);				//creating the delete popup item		item=new SVGPopupItem(getSVGEditor(), iddelete, labeldelete, "Delete"){						public JMenuItem getPopupItem(LinkedList nodes) {								if(nodes!=null && nodes.size()>0){										menuItem.setEnabled(true);										//adds the action listeners					menuItem.addActionListener(deleteListener);									}else{										menuItem.setEnabled(false);				}				return super.getPopupItem(nodes);			}		};				popupItems.add(item);		return popupItems;	}	/**	 * @return a map associating a tool item id to its tool item object	 */	public Hashtable getToolItems(){				return null;	}		/**	 * copies the selected nodes of the current frame into the clipboard	 */	public synchronized void copy(){	    	    clipboardContent.clear();	    Node clonedNode=null;				//orders the nodes in the list and clones them		for(Element cur : new LinkedList<Element>(selectedNodes)){			if(cur!=null){			    			    clonedNode=getSVGEditor().getSVGToolkit().getClonedNodeWithoutUseNodes(cur);			    			    if(clonedNode!=null){			        				    clipboardContent.add((Element)clonedNode);			    }			}		}	}		/**	 * pastes the copied nodes	 */	public void paste(){				final SVGFrame frame=editor.getFrameManager().getCurrentFrame();				if(clipboardContent.size()>0 && frame!=null){

⌨️ 快捷键说明

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