comparison src/de/mpg/mpiwg/itgroup/digilib/manipulator/extensions/ZoomAreaRectangleListener.java @ 9:e63a64652f4d

added comments
author dwinter
date Mon, 03 Jan 2011 16:53:48 +0100
parents src/de/mpg/mpiwg/itgroup/digilib/manipulator/extensions/RectangleListener.java@83c58ea33792
children 643fa1daa70c
comparison
equal deleted inserted replaced
8:52023cf79d86 9:e63a64652f4d
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
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 {
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 ZoomAreaRectangleListener() {};
32
33 public ZoomAreaRectangleListener(DigiImageController dc){
34 this.label = dc.digiImage.getLabel();
35 this.dc=dc;
36 }
37 public void reset(){
38 status=0;
39 }
40 public void mouseDoubleClick(MouseEvent e) {
41 // TODO Auto-generated method stub
42
43 }
44
45 public void mouseDown(MouseEvent e) {
46 // TODO Auto-generated method stub
47
48 }
49
50 public void mouseUp(MouseEvent e) {
51 if (status==NO_CLICK){
52 handleFirstClick(e);
53 } else if (status==FIRST_CLICK){
54 handleSecondClick(e);
55 }
56
57 }
58
59 private void handleSecondClick(MouseEvent e) {
60 //Canvas canvas = new Canvas(label.getParent(),SWT.NO_BACKGROUND);
61
62 GC gc = new GC(label.getImage());
63
64 gc.setForeground(new Color(label.getDisplay(),255,0,0));
65
66 gc.drawRectangle(firstPoint.x, firstPoint.y, e.x-firstPoint.x, e.y-firstPoint.y);
67 gc.dispose();
68 label.redraw();
69 status=SECOND_CLICK;
70 dc.zoomArea(firstPoint.x,firstPoint.y,e.x,e.y);
71 dc.digiImage.getLabel().removeMouseListener(this);
72 DigilibLinkEditorObservable.INSTANCE.setCursorStatus(SWT.CURSOR_ARROW);
73 DigilibLinkEditorObservable.INSTANCE.imageHasChanged(dc.digiImage);
74
75 }
76
77 private void handleFirstClick(MouseEvent e) {
78 //Canvas canvas = new Canvas(label.getParent(),SWT.NO_BACKGROUND);
79
80 GC gc = new GC(label.getImage());
81
82 gc.setForeground(new Color(label.getDisplay(),255,0,0));
83 firstPoint = new Point(e.x,e.y);
84 gc.drawOval(e.x, e.y, 10, 10);
85 gc.dispose();
86 status=FIRST_CLICK;
87 label.redraw();
88 DigilibLinkEditorObservable.INSTANCE.setCursorStatus(SWT.CURSOR_CROSS);
89 }
90
91
92 }