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

📄 svgline.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
						getSVGEditor().getSVGToolkit().setTransformMatrix(elt, matrix);												elt.setAttributeNS(null,"x1", format.format(initX1));						elt.setAttributeNS(null,"y1", format.format(initY1));						elt.setAttributeNS(null,"x2", format.format(initX2));						elt.setAttributeNS(null,"y2", format.format(initY2));												//notifies that the selection has changed						if(getSVGEditor().getSVGSelection()!=null){														getSVGEditor().getSVGSelection().selectionChanged(true);						}					}					public void redo(){					    						//sets the matrix of the node with the old matrix						getSVGEditor().getSVGToolkit().setTransformMatrix(elt, new SVGTransformMatrix(1, 0, 0, 1, 0, 0));					    						elt.setAttributeNS(null,"x1", format.format(fx1));						elt.setAttributeNS(null,"y1", format.format(fy1));						elt.setAttributeNS(null,"x2", format.format(fx2));						elt.setAttributeNS(null,"y2", format.format(fy2));												//notifies that the selection has changed						if(getSVGEditor().getSVGSelection()!=null){														getSVGEditor().getSVGSelection().selectionChanged(true);						}					}				};								//gets or creates the undo/redo list and adds the action into it				SVGUndoRedoActionList actionlist=new SVGUndoRedoActionList((String)labels.get("undoredomodifypoint"));				actionlist.add(action);				getSVGEditor().getUndoRedo().addActionList(frame, actionlist);			}		}	    	}			/**	 * used to remove the listener added to draw a line when the user clicks on the menu item	 */	public void cancelActions(){	    		if(lineAction!=null){		    			toolItem.removeActionListener(lineAction);			toolItem.setSelected(false);			toolItem.addActionListener(lineAction);					    lineAction.cancelActions();		}	}		/**	 * 	 * @author Jordi SUC	 * the class allowing to get the position and size of the future drawn line	 */	protected class LineActionListener implements ActionListener{				/**		 * the hashtable associating a frame to its mouse adapter		 */		private final Hashtable mouseAdapterFrames=new Hashtable();				/**		 * an instance of this class		 */		private final LineActionListener action=this;				/**		 * the cursor used when creating a rectangle		 */		private Cursor createCursor;				private boolean isActive=false;				/**		 * the source component		 */		private Object source=null;				/**		 * the constructor of the class		 */		protected LineActionListener(){						createCursor=getSVGEditor().getCursors().getCursor("line");		}				/**		 * resets the listener		 */		protected void reset(){						if(isActive){			    				Collection frames=getSVGEditor().getFrameManager().getFrames();				Iterator it;				SVGFrame frm=null;				LinkedList toBeRemoved=new LinkedList();				Object mouseListener=null;								//removes all the motion adapters from the frames				for(it=mouseAdapterFrames.keySet().iterator(); it.hasNext();){				    					try{frm=(SVGFrame)it.next();}catch (Exception ex){frm=null;}								if(frm!=null && ! frames.contains(frm)){					    						try{							mouseListener=mouseAdapterFrames.get(frm);							frm.getScrollPane().getSVGCanvas().removeMouseListener((MouseAdapter)mouseListener);							frm.getScrollPane().getSVGCanvas().removeMouseMotionListener((MouseMotionListener)mouseListener);						}catch (Exception ex){}												toBeRemoved.add(frm);					}				}									//removes the frames that have been closed				for(it=toBeRemoved.iterator(); it.hasNext();){				    					try{mouseAdapterFrames.remove(it.next());}catch (Exception ex){}				}										LineMouseListener iml=null;								//adds the new motion adapters				for(it=frames.iterator(); it.hasNext();){				    					try{frm=(SVGFrame)it.next();}catch (Exception ex){frm=null;}								if(frm!=null && ! mouseAdapterFrames.containsKey(frm)){										iml=new LineMouseListener(frm);						try{							frm.getScrollPane().getSVGCanvas().addMouseListener(iml);							frm.getScrollPane().getSVGCanvas().addMouseMotionListener(iml);							frm.getScrollPane().getSVGCanvas().setSVGCursor(createCursor);						}catch (Exception ex){}												mouseAdapterFrames.put(frm, iml);					}				}							}		}				/**		 * used to remove the listener added to draw a rectangle when the user clicks on the menu item		 */			protected void cancelActions(){						if(isActive){								//removes the listeners				Iterator it;				SVGFrame frm=null;				LinkedList toBeRemoved=new LinkedList();				Object mouseListener=null;								//removes all the motion adapters from the frames				for(it=mouseAdapterFrames.keySet().iterator(); it.hasNext();){				    					try{frm=(SVGFrame)it.next();}catch (Exception ex){frm=null;}										if(frm!=null){					    						//resets the information displayed						frm.getStateBar().setSVGW("");						frm.getStateBar().setSVGH("");						frm.getScrollPane().getSVGCanvas().setSVGCursor(frm.getSVGEditor().getCursors().getCursor("default"));												try{							mouseListener=mouseAdapterFrames.get(frm);							frm.getScrollPane().getSVGCanvas().removeMouseListener((MouseAdapter)mouseListener);							frm.getScrollPane().getSVGCanvas().removeMouseMotionListener((MouseMotionListener)mouseListener);														if(mouseListener!=null && ((LineMouseListener)mouseListener).paintListener!=null){								//removes the paint listener								frm.getScrollPane().getSVGCanvas().removePaintListener(((LineMouseListener)mouseListener).paintListener, true);							}						}catch (Exception ex){}												toBeRemoved.add(frm);					}				}								//removes the frames that have been closed				for(it=toBeRemoved.iterator(); it.hasNext();){				    					try{mouseAdapterFrames.remove(it.next());}catch (Exception ex){}				}								isActive=false;			}					}				/**		 * the method called when an event occurs		 * @param evt the event		 */		public void actionPerformed(ActionEvent evt){			if((evt.getSource() instanceof JMenuItem && ! toolItem.isSelected()) || (evt.getSource() instanceof JToggleButton)){				getSVGEditor().cancelActions(false);								if(getSVGEditor().getFrameManager().getCurrentFrame()!=null){										toolItem.removeActionListener(lineAction);					toolItem.setSelected(true);					toolItem.addActionListener(lineAction);								//the listener is active					isActive=true;					source=evt.getSource();						Collection frames=getSVGEditor().getFrameManager().getFrames();					Iterator it;					SVGFrame frm=null;					LineMouseListener lml=null;					    					//adds the new motion adapters					for(it=frames.iterator(); it.hasNext();){					    						try{frm=(SVGFrame)it.next();}catch (Exception ex){frm=null;}											if(frm!=null){								lml=new LineMouseListener(frm);								try{								frm.getScrollPane().getSVGCanvas().addMouseListener(lml);								frm.getScrollPane().getSVGCanvas().addMouseMotionListener(lml);								frm.getScrollPane().getSVGCanvas().setSVGCursor(createCursor);							}catch (Exception ex){}														mouseAdapterFrames.put(frm, lml);						}					}				}			}		}					protected class LineMouseListener extends MouseAdapter implements MouseMotionListener{					/**			 * the points of the area corresponding to the future rectangle			 */					private Point2D.Double point1=null, point2=null;						private SVGFrame frame;						/**			 * the paint listener			 */			private CanvasPaintListener paintListener=null;					/**			 * the constructor of the class			 * @param frame a frame			 */			public LineMouseListener(SVGFrame frame){			    				this.frame=frame;				final SVGFrame fframe=frame;								//adds a paint listener				paintListener=new CanvasPaintListener(){					public void paintToBeDone(Graphics g) {						if(point1!=null && point2!=null){														Point2D.Double 	pt1=fframe.getScaledPoint(new Point2D.Double(point1.x, point1.y), false),																pt2=fframe.getScaledPoint(new Point2D.Double(point2.x, point2.y), false);														if(pt1!=null && pt2!=null){							    								//draws the shape of the element that will be created if the user released the mouse button								svgLine.drawGhost(fframe, (Graphics2D)g, pt1, pt2);							}						}					}				};								frame.getScrollPane().getSVGCanvas().addLayerPaintListener(SVGCanvas.DRAW_LAYER, paintListener, false);			}						public void mouseMoved(MouseEvent e) {							}			public void mouseDragged(MouseEvent evt) {							    if(evt.isControlDown()){			        			        point2=SVGToolkit.computeLinePointWhenCtrlDown(point1, frame.getAlignedWithRulersPoint(evt.getPoint()));			    			    }else{			        					//sets the second point of the element					point2=frame.getAlignedWithRulersPoint(evt.getPoint());			    }				//asks the canvas to be repainted to draw the shape of the future element				frame.getScrollPane().getSVGCanvas().delayedRepaint();			}							@Override			public void mousePressed(MouseEvent evt){			    				//sets the first point of the area corresponding to the future element				point1=frame.getAlignedWithRulersPoint(evt.getPoint());			}							@Override			public void mouseReleased(MouseEvent evt){								Point2D.Double pt=null;							    if(evt.isControlDown()){			        			        pt=SVGToolkit.computeLinePointWhenCtrlDown(point1, frame.getAlignedWithRulersPoint(evt.getPoint()));			        			    }else{			        					//sets the second point of the element					pt=frame.getAlignedWithRulersPoint(evt.getPoint());			    }			    			    final Point2D.Double point=pt, fpoint1=point1;								//creates the element in the SVG document				if(point1!=null && point!=null){					Runnable runnable=new Runnable(){												public void run() {							svgLine.drawLine(frame, fpoint1, point);						}					};										frame.enqueue(runnable);				}								getSVGEditor().cancelActions(true);				point1=null;				point2=null;			}		}		}}

⌨️ 快捷键说明

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