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

📄 svgcircle.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		private final CircleActionListener action=this;				/**		 * the cursor used when creating a rectangle		 */		private Cursor createCursor;				/**		 * the source component		 */		private Object source=null;				private boolean isActive=false;		/**		 * the constructor of the class		 */		protected CircleActionListener(){						createCursor=getSVGEditor().getCursors().getCursor("circle");		}				/**		 * 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){}				}				CircleMouseListener cml=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)){										cml=new CircleMouseListener(frm);						try{							frm.getScrollPane().getSVGCanvas().addMouseListener(cml);							frm.getScrollPane().getSVGCanvas().addMouseMotionListener(cml);							frm.getScrollPane().getSVGCanvas().setSVGCursor(createCursor);						}catch (Exception ex){}												mouseAdapterFrames.put(frm, cml);					}				}							}		}				/**		 * 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 && ((CircleMouseListener)mouseListener).paintListener!=null){							    								//removes the paint listener								frm.getScrollPane().getSVGCanvas().removePaintListener(((CircleMouseListener)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 action to be done		 * @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(circleAction);					toolItem.setSelected(true);					//toolItem.addActionListener(circleAction);								//the listener is active					isActive=true;										source=evt.getSource();					Collection frames=getSVGEditor().getFrameManager().getFrames();					Iterator it;					SVGFrame frm=null;					CircleMouseListener cml=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){								cml=new CircleMouseListener(frm);								try{								frm.getScrollPane().getSVGCanvas().addMouseListener(cml);								frm.getScrollPane().getSVGCanvas().addMouseMotionListener(cml);								frm.getScrollPane().getSVGCanvas().setSVGCursor(createCursor);								}catch (Exception ex){}														mouseAdapterFrames.put(frm, cml);						}					}				}			}		}					protected class CircleMouseListener 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 CircleMouseListener(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){					        							Rectangle2D.Double rect=getSVGEditor().getSVGToolkit().getComputedSquare(point1, point2);							Rectangle2D.Double computedBounds=fframe.getScaledRectangle(rect, false);														//draws the shape of the element that will be created if the user released the mouse button							svgCircle.drawGhost(fframe, (Graphics2D)g, computedBounds);						}					}				};								frame.getScrollPane().getSVGCanvas().addLayerPaintListener(SVGCanvas.DRAW_LAYER, paintListener, false);			}			/**			 * the method called when an event occurs			 * @param evt the event			 */			public void mouseDragged(MouseEvent evt) {			    				//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();			}							/**			 * the method called when an event occurs			 * @param evt the event			 */			public void mouseMoved(MouseEvent evt) {			}							/**			 * the method called when an event occurs			 * @param evt the event			 */			public void mousePressed(MouseEvent evt){			    				//sets the first point of the area corresponding to the future element				point1=frame.getAlignedWithRulersPoint(evt.getPoint());			}							/**			 * the method called when an event occurs			 * @param evt the event			 */			public void mouseReleased(MouseEvent evt){								Point2D.Double point=frame.getAlignedWithRulersPoint(evt.getPoint());								//creates the element in the SVG document				if(point1!=null && point1.x>=0 && point1.y>=0 && point!=null){										final Rectangle2D.Double rect=getSVGEditor().getSVGToolkit().getComputedSquare(point1, point);										Runnable runnable=new Runnable(){												public void run() {														svgCircle.drawCircle(frame, rect);						}					};										frame.enqueue(runnable);				}				getSVGEditor().cancelActions(true);				point1=null;				point2=null;			}		}	}}

⌨️ 快捷键说明

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