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

📄 svgsame.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 */	public Hashtable getMenuItems(){				Hashtable menuItems=new Hashtable();		menuItems.put(idsame, same);				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(), idsame, labelsame, "");				popupItems.add(subMenu);				//creating the same width popup item		SVGPopupItem sameWidthItem=new SVGPopupItem(getSVGEditor(), idsamewidth, labelsamewidth, "SameWidth"){					public JMenuItem getPopupItem(LinkedList nodes) {				if(nodes!=null && nodes.size()>1){										menuItem.setEnabled(true);										//adds the action listeners					if(menuItem.isEnabled()){												menuItem.addActionListener(sameWidthListener);					}									}else{										menuItem.setEnabled(false);				}								return super.getPopupItem(nodes);			}		};				//creating the same height popup item		SVGPopupItem sameHeightItem=new SVGPopupItem(getSVGEditor(), idsameheight, labelsameheight, "SameHeight"){					public JMenuItem getPopupItem(LinkedList nodes) {				if(nodes!=null && nodes.size()>1){										menuItem.setEnabled(true);										//adds the action listeners					if(menuItem.isEnabled()){												menuItem.addActionListener(sameHeightListener);					}									}else{										menuItem.setEnabled(false);				}								return super.getPopupItem(nodes);			}		};				//creating the same size popup item		SVGPopupItem sameSizeItem=new SVGPopupItem(getSVGEditor(), idsamesize, labelsamesize, "SameSize"){					public JMenuItem getPopupItem(LinkedList nodes) {				if(nodes!=null && nodes.size()>1){										menuItem.setEnabled(true);										//adds the action listeners					if(menuItem.isEnabled()){												menuItem.addActionListener(sameSizeListener);					}									}else{										menuItem.setEnabled(false);				}								return super.getPopupItem(nodes);			}		};				//adding the popup items to the sub menu		subMenu.addPopupItem(sameWidthItem);		subMenu.addPopupItem(sameHeightItem);		subMenu.addPopupItem(sameSizeItem);				return popupItems;	}		/**	 * allows to set the nodes given in the list to the same width, height or size of the first node in the list	 * @param list the nodes 	 * @param type the type of the resizement	 */	protected void same(LinkedList list, int type){				final SVGFrame frame=editor.getFrameManager().getCurrentFrame();				if(list!=null && list.size()>1 && frame!=null){						final LinkedList snodes=new LinkedList(list);			final int ftype=type;			Node reference=null;						try{				reference=(Node)snodes.getFirst();			}catch (Exception e){reference=null;}						//gets the bounds of the first node in the selected list, that will be used to resize the other nodes			final Rectangle2D refrect=frame.getNodeGeometryBounds((Element)reference);						if(reference!=null && refrect!=null){								//the map associating a node to a transform map				final Hashtable transformMap=new Hashtable();				//for each node of the list, the scale and translators factors are 				//computed and the transform matrix is modified				Runnable runnable=new Runnable(){				    					public void run(){					    						Iterator it=snodes.iterator();												//the first node of the list is not handled						if(it.hasNext()){						    						    it.next();						}							SVGTransformMatrix matrix=null;						AffineTransform af=null;						Rectangle2D rect=null;						Node current=null;						double a=1, d=1, tx=0, ty=0;														while(it.hasNext()){						    							try{								current=(Node)it.next();							}catch (Exception ex){current=null;}													if(current!=null){																//computes the bounds of the current node								rect=frame.getNodeGeometryBounds((Element)current);								a=1; d=1;																//computes the transform factors								if(rect!=null){								    									a=refrect.getWidth()/rect.getWidth();									d=refrect.getHeight()/rect.getHeight();									tx=rect.getX()*(1-a);									ty=rect.getY()*(1-d);								}															if(ftype==SAME_WIDTH){								    									d=1;									ty=0;																	}else if(ftype==SAME_HEIGHT){								    									a=1;									tx=0;								}																//the transform								af=AffineTransform.getScaleInstance(a, d);								af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty));																transformMap.put(current, af);															//gets, modifies and sets the transformation matrix								if(af!=null && ! af.isIdentity()){								    									//gets, modifies and sets the transform matrix									matrix=editor.getSVGToolkit().getTransformMatrix(current);									matrix.concatenateTransform(af);									editor.getSVGToolkit().setTransformMatrix(current, matrix);									}							}						}											    frame.getScrollPane().getSVGCanvas().delayedRepaint();					}				};								frame.enqueue(runnable);				//sets the name of the undo/redo action				String actionName="";								if(type==SAME_WIDTH){				    					actionName=undoredosamewidth;									}else if(type==SAME_HEIGHT){				    					actionName=undoredosameheight;									}else if(type==SAME_SIZE){				    					actionName=undoredosamesize;				}						//creates the undo/redo action and insert it into the undo/redo stack				if(editor.getUndoRedo()!=null){					SVGUndoRedoAction action=new SVGUndoRedoAction(actionName){						@Override						public void undo(){						    							//sets the nodes transformation matrix 							if(transformMap.size()>0){								Node current=null;								SVGTransformMatrix matrix=null;								AffineTransform af=null;																for(Iterator it=transformMap.keySet().iterator(); it.hasNext();){								    									try{										current=(Node)it.next();									}catch (Exception ex){current=null;}																		if(current!=null){									    										try{											af=(AffineTransform)transformMap.get(current);										}catch (Exception ex){af=null;}																if(af!=null){										    											//gets, modifies and sets the transform matrix											matrix=editor.getSVGToolkit().getTransformMatrix(current);											try{matrix.concatenateTransform(af.createInverse());}catch (Exception ex){}											editor.getSVGToolkit().setTransformMatrix(current, matrix);											}									}								}															    frame.getScrollPane().getSVGCanvas().delayedRepaint();							}						}						@Override						public void redo(){						    							//sets the nodes transformation matrix 							if(transformMap.size()>0){								Node current=null;								SVGTransformMatrix matrix=null;								AffineTransform af=null;																for(Iterator it=transformMap.keySet().iterator(); it.hasNext();){								    									try{										current=(Node)it.next();									}catch (Exception ex){current=null;}																		if(current!=null){									    										try{											af=(AffineTransform)transformMap.get(current);										}catch (Exception ex){af=null;}																if(af!=null){										    											//gets, modifies and sets the transform matrix											matrix=editor.getSVGToolkit().getTransformMatrix(current);											matrix.concatenateTransform(af);											editor.getSVGToolkit().setTransformMatrix(current, matrix);											}									}								}															    frame.getScrollPane().getSVGCanvas().delayedRepaint();							}						}					};								//gets or creates the undo/redo list and adds the action into it					SVGUndoRedoActionList actionlist=new SVGUndoRedoActionList(actionName);					actionlist.add(action);					editor.getUndoRedo().addActionList(frame, actionlist);				}			}		}	}		/**	 * gets the name of the module	 * @return the name of the module	 */	public String getName(){		return idsame;	}}

⌨️ 快捷键说明

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