001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * troger 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.platform.annotations.gwt.client.view.annotater; 021 022import org.nuxeo.ecm.platform.annotations.gwt.client.controler.AnnotationController; 023 024import com.google.gwt.user.client.DOM; 025import com.google.gwt.user.client.Event; 026 027/** 028 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 029 */ 030public abstract class AbstractAnnotater implements Annotater { 031 032 protected final AnnotationController controller; 033 034 private final boolean eventPreventDefault; 035 036 private boolean onMouseDown, onMouseMove = false; 037 038 public AbstractAnnotater(AnnotationController controller, boolean eventPreventDefault) { 039 this.controller = controller; 040 this.eventPreventDefault = eventPreventDefault; 041 } 042 043 public void manageEvent(Event event) { 044 if (!controller.canCreateNewCreationPopup() || !controller.canAnnotate()) { 045 return; 046 } 047 048 if (eventPreventDefault) { 049 DOM.eventPreventDefault(event); 050 } 051 052 switch (event.getTypeInt()) { 053 case Event.ONMOUSEDOWN: 054 onMouseDown(event); 055 break; 056 case Event.ONMOUSEMOVE: 057 onMouseMove(event); 058 break; 059 case Event.ONMOUSEUP: 060 onMouseUp(event); 061 break; 062 case Event.ONMOUSEOUT: 063 onMouseOut(event); 064 break; 065 } 066 } 067 068 public void onMouseDown(Event event) { 069 onMouseDown = true; 070 } 071 072 public void onMouseMove(Event event) { 073 if (onMouseDown) { 074 onMouseMove = true; 075 } 076 } 077 078 public void onMouseUp(Event event) { 079 onMouseDown = onMouseMove = false; 080 } 081 082 public void onMouseOut(Event event) { 083 onMouseUp(event); 084 } 085 086 public boolean hasMoved() { 087 return onMouseMove; 088 } 089 090 protected void addAnnotationPopup() { 091 controller.addNewAnnotation(); 092 } 093 094}