📄 mousehandler.java
字号:
/****************************************************************** * Copyright (C) 2002-2006 Andrew Girow. All rights reserved. * * ---------------------------------------------------------------* * This software is published under the terms of the TinyLine * * License, a copy of which has been included with this * * distribution in the TINYLINE_LICENSE.TXT file. * * * * For more information on the TinyLine, * * please see <http://www.tinyline.com/>. * *****************************************************************/package com.tinyline.app;import java.awt.event.*;import java.awt.Graphics;import java.awt.Color;import java.net.URL;import com.tinyline.svg.*;import com.tinyline.tiny2d.*;/** * This class represents the MouseListener associated with the * PPSVGCanvas and used for the Personal Profile SVG Player. * <p> * @author (C) Andrew Girow * @version 1.9 * <p> */public class MouseHandler implements MouseListener, MouseMotionListener{ /** * The Canvas that this mouse handler uses */ PPSVGCanvas canvas; /** * Type of the MouseHandler */ public static final int LINK_MOUSE = 0; public static final int PAN_MOUSE = 1; public static final int ZOOM_IN_MOUSE = 2; public static final int ZOOM_OUT_MOUSE = 3; public int type = LINK_MOUSE; /** * The original values to calculate pan. */ int pressedX; int pressedY; int draggedX; int draggedY; /** * Constructs a Mouse Handler object with the given canvas. The * handler will perform some function on the canvas when it * is given mouse events. * * @param canvas The canvas this mouse handler is handling. */ public MouseHandler(PPSVGCanvas canvas) { this.canvas = canvas; } /** * Invoked when the mouse has been clicked in the Canvas canvas. */ public void mouseClicked(MouseEvent e) { } /** * Invoked when the mouse has been pressed in the canvas. */ public void mousePressed(MouseEvent e) { if(type == PAN_MOUSE) { pressedX = e.getX(); pressedY = e.getY(); draggedX = pressedX; draggedY = pressedY; } } /** * Invoked when the mouse has been released in the canvas. */ public void mouseReleased(MouseEvent e) { if(type == ZOOM_OUT_MOUSE) { SVGEvent event = new SVGEvent(SVGEvent.EVENT_ZOOM, new TinyNumber(1)); canvas.postEvent(event); } else if(type == ZOOM_IN_MOUSE) { SVGEvent event = new SVGEvent(SVGEvent.EVENT_ZOOM, new TinyNumber(0)); canvas.postEvent(event); } else if(type == LINK_MOUSE) { SVGEvent event = new SVGEvent(SVGEvent.EVENT_CLICK, new TinyPoint(e.getX(),e.getY()) ); canvas.postEvent(event); } else if(type == PAN_MOUSE) { SVGEvent event = new SVGEvent(SVGEvent.EVENT_SCROLL,new TinyPoint(pressedX -e.getX(),pressedY -e.getY())); canvas.postEvent(event); } } /** * Invoked when the mouse has entered the canvas. */ public void mouseEntered(MouseEvent e) {} /** * Invoked when the mouse has exited the canvas. */ public void mouseExited(MouseEvent e) {} /** * Invoked when a mouse button is pressed within the Canvas canvas and then * dragged. */ public void mouseDragged(MouseEvent e) { if(type == PAN_MOUSE && canvas.raster.document.isZoomAndPanAnable() ) { drawXORLine(pressedX,pressedY,draggedX,draggedY); draggedX = e.getX(); draggedY = e.getY(); drawXORLine(pressedX,pressedY,draggedX,draggedY); } } /** * Invoked when the mouse button has been moved in the Canvas canvas, * when there are no buttons pressed. */ public void mouseMoved ( MouseEvent e ) {} public void drawXORLine(int x0, int y0, int x1, int y1) { Graphics g = canvas.getGraphics(); if(g!=null) { g.setXORMode(Color.white); g.setColor(Color.black); g.drawLine(x0,y0,x1,y1); g.dispose(); g = null; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -