1
|
1 package de.mpg.mpiwg.itgroup.digilib.manipulator.extensions;
|
|
2
|
|
3
|
|
4 import org.eclipse.swt.SWT;
|
|
5 import org.eclipse.swt.events.MouseEvent;
|
|
6 import org.eclipse.swt.events.MouseListener;
|
|
7 import org.eclipse.swt.graphics.Color;
|
|
8 import org.eclipse.swt.graphics.GC;
|
|
9 import org.eclipse.swt.graphics.Point;
|
|
10 import org.eclipse.swt.widgets.Label;
|
|
11
|
|
12 import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageController;
|
|
13 import de.mpg.mpiwg.itgroup.digilib.plugin.editors.DigilibLinkEditorObservable;
|
|
14
|
9
|
15 /**
|
|
16 * Listener to select the zoom area for the zoomarea function on digiimage.
|
|
17 * calls zoom area after an area on the image was selected.
|
|
18 * @author dwinter
|
|
19 *
|
|
20 */
|
|
21 public class ZoomAreaRectangleListener implements MouseListener {
|
1
|
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
|
24
|
31 @SuppressWarnings("unused")
|
9
|
32 private ZoomAreaRectangleListener() {};
|
1
|
33
|
9
|
34 public ZoomAreaRectangleListener(DigiImageController dc){
|
|
35 this.label = dc.digiImage.getLabel();
|
1
|
36 this.dc=dc;
|
|
37 }
|
|
38 public void reset(){
|
|
39 status=0;
|
|
40 }
|
|
41 public void mouseDoubleClick(MouseEvent e) {
|
|
42 // TODO Auto-generated method stub
|
|
43
|
|
44 }
|
|
45
|
|
46 public void mouseDown(MouseEvent e) {
|
|
47 // TODO Auto-generated method stub
|
|
48
|
|
49 }
|
|
50
|
|
51 public void mouseUp(MouseEvent e) {
|
|
52 if (status==NO_CLICK){
|
|
53 handleFirstClick(e);
|
|
54 } else if (status==FIRST_CLICK){
|
|
55 handleSecondClick(e);
|
|
56 }
|
|
57
|
|
58 }
|
|
59
|
|
60 private void handleSecondClick(MouseEvent e) {
|
|
61 //Canvas canvas = new Canvas(label.getParent(),SWT.NO_BACKGROUND);
|
|
62
|
|
63 GC gc = new GC(label.getImage());
|
|
64
|
|
65 gc.setForeground(new Color(label.getDisplay(),255,0,0));
|
|
66
|
|
67 gc.drawRectangle(firstPoint.x, firstPoint.y, e.x-firstPoint.x, e.y-firstPoint.y);
|
|
68 gc.dispose();
|
|
69 label.redraw();
|
|
70 status=SECOND_CLICK;
|
|
71 dc.zoomArea(firstPoint.x,firstPoint.y,e.x,e.y);
|
|
72 dc.digiImage.getLabel().removeMouseListener(this);
|
|
73 DigilibLinkEditorObservable.INSTANCE.setCursorStatus(SWT.CURSOR_ARROW);
|
21
|
74 //DigilibLinkEditorObservable.INSTANCE.imageHasChanged(dc.digiImage);
|
1
|
75
|
|
76 }
|
|
77
|
|
78 private void handleFirstClick(MouseEvent e) {
|
|
79 //Canvas canvas = new Canvas(label.getParent(),SWT.NO_BACKGROUND);
|
|
80
|
|
81 GC gc = new GC(label.getImage());
|
|
82
|
|
83 gc.setForeground(new Color(label.getDisplay(),255,0,0));
|
|
84 firstPoint = new Point(e.x,e.y);
|
|
85 gc.drawOval(e.x, e.y, 10, 10);
|
|
86 gc.dispose();
|
|
87 status=FIRST_CLICK;
|
|
88 label.redraw();
|
|
89 DigilibLinkEditorObservable.INSTANCE.setCursorStatus(SWT.CURSOR_CROSS);
|
|
90 }
|
|
91
|
|
92
|
|
93 }
|