Mercurial > hg > de.mpg.mpiwg.itgroup.digilib.plugin
comparison src/de/mpg/mpiwg/itgroup/digilib/manipulator/extensions/RectangleListener.java @ 1:83c58ea33792
first release (continued)
author | dwinter |
---|---|
date | Mon, 03 Jan 2011 09:11:25 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:6829553d2378 | 1:83c58ea33792 |
---|---|
1 package de.mpg.mpiwg.itgroup.digilib.manipulator.extensions; | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 import org.eclipse.swt.SWT; | |
8 import org.eclipse.swt.events.MouseEvent; | |
9 import org.eclipse.swt.events.MouseListener; | |
10 import org.eclipse.swt.graphics.Color; | |
11 import org.eclipse.swt.graphics.GC; | |
12 import org.eclipse.swt.graphics.Point; | |
13 import org.eclipse.swt.widgets.Canvas; | |
14 import org.eclipse.swt.widgets.Label; | |
15 import org.eclipse.swt.graphics.Device; | |
16 | |
17 import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImage; | |
18 import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageController; | |
19 import de.mpg.mpiwg.itgroup.digilib.plugin.editors.DigilibLinkEditorObservable; | |
20 | |
21 public class RectangleListener implements MouseListener { | |
22 static int FIRST_CLICK=1; | |
23 static int SECOND_CLICK=2; | |
24 static int NO_CLICK=0; | |
25 int status=NO_CLICK; | |
26 private Label label; | |
27 private Point firstPoint; | |
28 private DigiImageController dc; | |
29 | |
30 | |
31 private RectangleListener() { | |
32 | |
33 } | |
34 | |
35 public RectangleListener(DigiImageController dc,Label label){ | |
36 this.label =label; | |
37 this.dc=dc; | |
38 } | |
39 public void reset(){ | |
40 status=0; | |
41 } | |
42 public void mouseDoubleClick(MouseEvent e) { | |
43 // TODO Auto-generated method stub | |
44 | |
45 } | |
46 | |
47 public void mouseDown(MouseEvent e) { | |
48 // TODO Auto-generated method stub | |
49 | |
50 } | |
51 | |
52 public void mouseUp(MouseEvent e) { | |
53 if (status==NO_CLICK){ | |
54 handleFirstClick(e); | |
55 } else if (status==FIRST_CLICK){ | |
56 handleSecondClick(e); | |
57 } | |
58 | |
59 } | |
60 | |
61 private void handleSecondClick(MouseEvent e) { | |
62 //Canvas canvas = new Canvas(label.getParent(),SWT.NO_BACKGROUND); | |
63 | |
64 GC gc = new GC(label.getImage()); | |
65 | |
66 gc.setForeground(new Color(label.getDisplay(),255,0,0)); | |
67 | |
68 gc.drawRectangle(firstPoint.x, firstPoint.y, e.x-firstPoint.x, e.y-firstPoint.y); | |
69 gc.dispose(); | |
70 label.redraw(); | |
71 status=SECOND_CLICK; | |
72 dc.zoomArea(firstPoint.x,firstPoint.y,e.x,e.y); | |
73 dc.digiImage.getLabel().removeMouseListener(this); | |
74 DigilibLinkEditorObservable.INSTANCE.setCursorStatus(SWT.CURSOR_ARROW); | |
75 DigilibLinkEditorObservable.INSTANCE.imageHasChanged(dc.digiImage); | |
76 | |
77 } | |
78 | |
79 private void handleFirstClick(MouseEvent e) { | |
80 //Canvas canvas = new Canvas(label.getParent(),SWT.NO_BACKGROUND); | |
81 | |
82 GC gc = new GC(label.getImage()); | |
83 | |
84 gc.setForeground(new Color(label.getDisplay(),255,0,0)); | |
85 firstPoint = new Point(e.x,e.y); | |
86 gc.drawOval(e.x, e.y, 10, 10); | |
87 gc.dispose(); | |
88 status=FIRST_CLICK; | |
89 label.redraw(); | |
90 DigilibLinkEditorObservable.INSTANCE.setCursorStatus(SWT.CURSOR_CROSS); | |
91 } | |
92 | |
93 | |
94 } |