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

📄 svgframe.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			if(usedResources.containsKey(resourceId)){								try{					//getting the associated list of nodes					nodesList=usedResources.get(resourceId); 				}catch (Exception ex){}			}						if(nodesList!=null){								for(Element cur : list){										if(cur!=null){												//removing the node from the list						nodesList.remove(cur);					}				}			}		}	}		/**	 * redraws the node that use the resource of the given id	 * @param id the id of a resource	 */	public void refreshNodesUsingResource(String id){				if(id!=null && ! id.equals("")){						LinkedList<Element> list=null;						try{				list=usedResources.get(id);			}catch (Exception ex){}			if(list!=null){				for(Element cur : list){					if(cur!=null){												cur.setAttribute("display", "none");						cur.removeAttribute("display");					}				}			}		}	}		/**	 * modifies the id of a resource in the nodes that are using this resource	 * @param newId the new id for the resource	 * @param lastId the previous id for the resource	 */	public void modifyResourceId(String newId, String lastId){				if(		newId!=null && ! newId.equals("") && lastId!=null && ! lastId.equals("") && 				! lastId.equals(newId) && usedResources.containsKey(lastId)){						//getting the list of the nodes using the resource			LinkedList<Element> nodesList=null;						try{				nodesList=usedResources.get(lastId);			}catch (Exception ex){}						if(nodesList!=null){								String style="";								//for each node, replaces the last id of the resource with the new id				for(Element cur : nodesList){										if(cur!=null){												style=cur.getAttribute("style");												if(style!=null && ! style.equals("")){														style=style.replaceAll("#"+lastId+"[)]", "#"+newId+")");							cur.setAttribute("style", style);						}					}				}								//modifies the map of the used resources				usedResources.remove(lastId);				usedResources.put(newId, nodesList);			}		}	}		/**	 * checks if the resource denoted by the given id is used or not	 * @param resourceId the id of a resource	 * @return true if the resource is used	 */	public boolean isResourceUsed(String resourceId){				boolean isUsed=false;				if(resourceId!=null && ! resourceId.equals("")){						LinkedList<Element> list=null;						try{				list=usedResources.get(resourceId);			}catch (Exception ex){}						if(list!=null && list.size()>0){								isUsed=true;			}		}				return isUsed;	}		/**	 * @return Returns the usedResources.	 */	public Hashtable<String, LinkedList<Element>> getUsedResources() {				return new Hashtable<String, LinkedList<Element>>(usedResources);	}		/**	 *disposes this frame	 */	public void dispose(){				if(internalFrame!=null){						internalFrame.setVisible(false);			getSVGEditor().getDesktop().remove(internalFrame);		}				//removing the frame from the frame manager		getSVGEditor().getFrameManager().removeFrame(getName());				//removing each dom listener		Set<SVGDOMListener> domListenersSet=null;				for(Node node : new HashSet<Node>(domListeners.keySet())) {						if(node!=null) {								domListenersSet=new HashSet<SVGDOMListener>(domListeners.get(node));								if(domListenersSet!=null) {										for(SVGDOMListener listener : domListenersSet) {												listener.removeListener();					}				}			}		}				domListeners.clear();				//run the dispose runnables		Runnable runnable=null;				for(Iterator it=disposeRunnables.iterator(); it.hasNext();){						try{				runnable=(Runnable)it.next();			}catch (Exception ex){runnable=null;}						if(runnable!=null){								runnable.run();			}		}				disposeRunnables.clear();				framePanel.removeAll();		statebar.removeAll();		scrollpane.removeAll();	}		/**	 * registers a listener 	 * @param runnable a runnable	 */	public void addDisposeRunnable(Runnable runnable){				if(runnable!=null){						disposeRunnables.add(runnable);		}	}		/**	 * enqueues the given runnable into the batik runnable queue	 * @param runnable a runnable	 */	public void enqueue(final Runnable runnable){		if(runnable!=null){			SwingUtilities.invokeLater(new Runnable() {								public void run() {									runnable.run();					scrollpane.getSVGCanvas().requestUpdateContent();				}			});		}	}		/**	 * adding a listener to the svg dom of this frame	 * @param listener a listener	 */	public synchronized void addDOMListener(SVGDOMListener listener){				if(listener!=null){						HashSet<SVGDOMListener> set=null;						if(domListeners.containsKey(listener.getNode())) {								set=domListeners.get(listener.getNode());							}else {								//creating and putting the new set into the map				set=new HashSet<SVGDOMListener>();				domListeners.put(listener.getNode(), set);			}						set.add(listener);			listener.setFrame(this);		}	}		/**	 * removing a listener from the svg dom of this frame	 * @param listener a listener	 */	public synchronized void removeDOMListener(SVGDOMListener listener){		if(listener!=null && domListeners.containsKey(listener.getNode())){						HashSet<SVGDOMListener> set=domListeners.get(listener.getNode());						if(set!=null) {								set.remove(listener);						return;			}		}	}		/**	 * fires that the given node has been modified ( one of its attributes has been modified)	 * @param node a node	 */	public synchronized void fireNodeChanged(Node node){				if(node!=null) {						//getting the set associated with the given node			Set<SVGDOMListener> set=domListeners.get(node);						if(set!=null) {								for(SVGDOMListener listener : new HashSet<SVGDOMListener>(set)){										if(listener!=null){												//firing that the node has changed						listener.nodeChanged();					}				}			}		}	}		/**	 * fires that the given node has been removed 	 * @param node a node	 * @param removedNode the node that has been removed	 */	public synchronized void fireNodeRemoved(Node node, Node removedNode){				if(node!=null && removedNode!=null) {						//getting the set associated with the given node			Set<SVGDOMListener> set=domListeners.get(node);						if(set!=null) {								for(SVGDOMListener listener : new HashSet<SVGDOMListener>(set)){										if(listener!=null){												//firing that the node has changed						listener.nodeRemoved(removedNode);					}				}			}		}	}		/**	 * fires that the given node has been inserted	 * @param node a node	 * @param nodeInserted the node that has been inserted into the node children	 */	public synchronized void fireNodeInserted(Node node, Node nodeInserted){				if(node!=null) {						//getting the set associated with the given node			Set<SVGDOMListener> set=domListeners.get(node);						if(set!=null) {								for(SVGDOMListener listener : new HashSet<SVGDOMListener>(set)){										if(listener!=null){												//firing that the node has changed						listener.nodeInserted(nodeInserted);					}				}			}		}	}		/**	 * fires that the given sub tree has been modified	 * @param rootNode a node	 * @param lastModifiedNode the last node that has been modified	 */	public synchronized void fireStructureChanged(Node rootNode, Node lastModifiedNode){				if(rootNode!=null) {						//getting the set associated with the given node			Set<SVGDOMListener> set=domListeners.get(rootNode);						if(set!=null) {								for(SVGDOMListener listener : new HashSet<SVGDOMListener>(set)){										if(listener!=null){												//firing that the node has changed						listener.structureChanged(lastModifiedNode);					}				}			}		}	}		/**	 * @return true if the SVG picture has been modified	 */	public boolean isModified(){				return modified;	}		/**	 * sets that the svg document has been modified	 * @param modified must be true if the svg picture has been modified	 */	public void setModified(boolean modified){		this.modified=modified;		setSVGFrameLabel(name);	}		/**	 * 	 * @return the state bar	 */	public SVGStateBar getStateBar(){		return statebar;	}		/**	 * 	 * @return the editor	 */	public SVGEditor getSVGEditor(){		return editor;	}		/**	 * 	 * @return the SVGScrollpane contained in this frame	 */	public SVGScrollPane getScrollPane(){		return scrollpane;	}		/**	 * @return the name linked with the SVG picture	 */	public String getName(){		return name;	}		/**	 * sets the new name of the SVGFrame	 * @param name the new name	 */	public void setName(String name){		this.name=name;		setSVGFrameLabel(name);	}		/**	 * sets the label of the svg frame	 * @param name the string associated with the SVGFrame	 */	protected void setSVGFrameLabel(String name){				String label="";				try{			File file=new File(name);			label=file.getName();		}catch (Exception ex){label=null;}				if((label==null || (label!=null && label.equals(""))) && name!=null && ! name.equals("")){						label=name;			}				if(modified){						label=label.concat("*");		}				menuitem.setText(label);		getStateBar().setSVGName(label);				if(internalFrame!=null){						internalFrame.setTitle(label);		}	}		/**	 * @return the short name of this frame	 */	public String getShortName(){				String shortName="";				try{			File file=new File(name);			shortName=file.getName();		}catch (Exception ex){shortName=null;}				return shortName;	}		/**	 * @return the menu item that will be displayed in the menu bar to switch from one SVG picture to another 	 */	public JMenuItem getFrameMenuItem(){		return menuitem;	}		/**	 * hides this frame in the main frame	 */	public void moveToBack(){				if(editor.isMultiWindow()){						try{internalFrame.setSelected(false);}catch(Exception ex){}					}else{						framePanel.setVisible(false);			scrollpane.setVisible(false);			statebar.setVisible(false);		}	}		/**	 * shows this frame in the main frame	 */	public void moveToFront(){				if( (editor.isMultiWindow())){						try{internalFrame.setSelected(true);}catch(Exception ex){}					}else{						framePanel.setVisible(true);			scrollpane.setVisible(true);			statebar.setVisible(true);		}	}		/**	 * removes this SVGFrame from the desktop	 */	public void removeFromDesktop(){				if( (editor.isMultiWindow())){						editor.getDesktop().remove(internalFrame);					}else{						editor.getDesktop().remove(framePanel);

⌨️ 快捷键说明

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