blob: 528b0f85923ce2b003a8b71155ffed0d7294802b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
package org.eclipse.ecf.tutorial.scribbleshare.toolbox;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
/*******************************************************************************
* Copyright (c) 2006 IBM, Inc and Composent, Inc. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Ken Gilmer <kgilmer@gmail.com> - initial API and implementation
******************************************************************************/
/**
* A line shape.
* @author kgilmer
*
*/
public class Line extends AbstractTool {
private static final long serialVersionUID = -165859440014182966L;
//private boolean dragging = false;
private boolean dragging = false;
public String getName() {
return "Line";
}
public Image getImage() {
return null;
}
public void draw(final Canvas canvas) {
Display display = canvas.getDisplay();
display.asyncExec(new Runnable() {
public void run() {
GC gc = new GC(canvas);
setupGC(gc);
// gc.setForeground(new Color(display,new RGB(128,128,128)));
gc.drawLine(startX, startY, endX, endY);
gc.dispose();
}
});
}
public void handleUIEvent(Event event, Canvas canvas) {
switch (event.type) {
case SWT.MouseUp:
draw(canvas);
penDown = false;
dragging = false;
isComplete = true;
break;
case SWT.MouseMove:
if (dragging) {
endX = event.x;
endY = event.y;
penDown = true;
}
break;
case SWT.MouseDown:
if (!dragging) {
startX = event.x;
startY = event.y;
dragging = true;
isComplete = false;
}
break;
}
}
}
|