Mercurial > hg > de.mpg.mpiwg.itgroup.digilib.plugin
view 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 |
line wrap: on
line source
package de.mpg.mpiwg.itgroup.digilib.manipulator.extensions; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Label; import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageController; import de.mpg.mpiwg.itgroup.digilib.plugin.editors.DigilibLinkEditorObservable; /** * Listener to select the zoom area for the zoomarea function on digiimage. * calls zoom area after an area on the image was selected. * @author dwinter * */ public class ZoomAreaRectangleListener implements MouseListener { static int FIRST_CLICK=1; static int SECOND_CLICK=2; static int NO_CLICK=0; int status=NO_CLICK; private Label label; private Point firstPoint; private DigiImageController dc; private ZoomAreaRectangleListener() {}; public ZoomAreaRectangleListener(DigiImageController dc){ this.label = dc.digiImage.getLabel(); this.dc=dc; } public void reset(){ status=0; } public void mouseDoubleClick(MouseEvent e) { // TODO Auto-generated method stub } public void mouseDown(MouseEvent e) { // TODO Auto-generated method stub } public void mouseUp(MouseEvent e) { if (status==NO_CLICK){ handleFirstClick(e); } else if (status==FIRST_CLICK){ handleSecondClick(e); } } private void handleSecondClick(MouseEvent e) { //Canvas canvas = new Canvas(label.getParent(),SWT.NO_BACKGROUND); GC gc = new GC(label.getImage()); gc.setForeground(new Color(label.getDisplay(),255,0,0)); gc.drawRectangle(firstPoint.x, firstPoint.y, e.x-firstPoint.x, e.y-firstPoint.y); gc.dispose(); label.redraw(); status=SECOND_CLICK; dc.zoomArea(firstPoint.x,firstPoint.y,e.x,e.y); dc.digiImage.getLabel().removeMouseListener(this); DigilibLinkEditorObservable.INSTANCE.setCursorStatus(SWT.CURSOR_ARROW); DigilibLinkEditorObservable.INSTANCE.imageHasChanged(dc.digiImage); } private void handleFirstClick(MouseEvent e) { //Canvas canvas = new Canvas(label.getParent(),SWT.NO_BACKGROUND); GC gc = new GC(label.getImage()); gc.setForeground(new Color(label.getDisplay(),255,0,0)); firstPoint = new Point(e.x,e.y); gc.drawOval(e.x, e.y, 10, 10); gc.dispose(); status=FIRST_CLICK; label.redraw(); DigilibLinkEditorObservable.INSTANCE.setCursorStatus(SWT.CURSOR_CROSS); } }