📄 backgrounddraggingmanipulator.java
字号:
package net.sourceforge.jpowergraph.manipulator.dragging;
import net.sourceforge.jpowergraph.lens.CursorLens;
import net.sourceforge.jpowergraph.manipulator.AbstractManipulator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
/**
* A manipulator enabling the dragging of the graph's background.
*/
public class BackgroundDraggingManipulator extends AbstractManipulator {
/** The name of this manipulator. */
public static final String NAME="BackgroundDraggingManipulator";
/** The position where the mouse was grabbed. */
protected Point m_grabPosition;
private int mouseEventKeyMask = SWT.NONE;
private CursorLens cursorLens;
private boolean disposed = false;
/**
* Creates an instance of this class.
*
* Dragging the background can be done by holding down the shift key
* and left clicking.
*/
public BackgroundDraggingManipulator(CursorLens theCursorLens) {
this(theCursorLens, SWT.SHIFT);
}
/**
* Creates an instance of this class.
*
* Dragging the background can be done by holding down the key specified in
* theMouseKeyAssist and left clicking. The key mask can be one of:
*
* SWT.SHIFT
* SWT.CTRL
* SWT.ALT
* SWT.NONE (for no key mask)
*
* @param theMouseEventKeyMask The Mouse MASK
*/
public BackgroundDraggingManipulator(CursorLens theCursorLens, int theMouseEventKeyMask) {
cursorLens = theCursorLens;
mouseEventKeyMask = theMouseEventKeyMask;
}
public String getName() {
return NAME;
}
public boolean isDragging() {
return m_grabPosition!=null;
}
public void mouseDown(MouseEvent e) {
if (m_graphPane.isEnabled() && e.button == 1 && isStartBackgroundDraggingEvent(e)) {
Point point = new Point(e.x, e.y);
if (m_graphPane.getNodeAtPoint(point)==null && m_graphPane.getNearestEdge(point)==null) {
m_grabPosition=point;
cursorLens.setCursor(CursorLens.hand);
}
}
}
public void mouseReleased(MouseEvent e) {
if (isDragging()) {
performDrag(new Point(e.x, e.y));
cursorLens.setCursor(null);
m_grabPosition=null;
}
}
public void mouseDragged(MouseEvent e) {
if (isDragging()) {
performDrag(new Point(e.x, e.y));
}
}
protected void performDrag(Point position) {
Rectangle rectangle=m_graphPane.getClientArea();
rectangle.x+=m_grabPosition.x-position.x;
rectangle.y+=m_grabPosition.y-position.y;
m_graphPane.scrollRectToVisible(rectangle);
m_grabPosition=position;
}
protected boolean isStartBackgroundDraggingEvent(MouseEvent e) {
if (mouseEventKeyMask == SWT.NONE){
return true;
}
return (e.stateMask & mouseEventKeyMask) != 0;
}
public void dispose(){
disposed = true;
}
public boolean isDisposed(){
return disposed ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -