001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * troger 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.annotations.gwt.client.view.annotater; 023 024import org.nuxeo.ecm.platform.annotations.gwt.client.controler.AnnotationController; 025 026import com.google.gwt.user.client.DOM; 027import com.google.gwt.user.client.Event; 028 029/** 030 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 031 */ 032public abstract class AbstractAnnotater implements Annotater { 033 034 protected final AnnotationController controller; 035 036 private final boolean eventPreventDefault; 037 038 private boolean onMouseDown, onMouseMove = false; 039 040 public AbstractAnnotater(AnnotationController controller, boolean eventPreventDefault) { 041 this.controller = controller; 042 this.eventPreventDefault = eventPreventDefault; 043 } 044 045 public void manageEvent(Event event) { 046 if (!controller.canCreateNewCreationPopup() || !controller.canAnnotate()) { 047 return; 048 } 049 050 if (eventPreventDefault) { 051 DOM.eventPreventDefault(event); 052 } 053 054 switch (event.getTypeInt()) { 055 case Event.ONMOUSEDOWN: 056 onMouseDown(event); 057 break; 058 case Event.ONMOUSEMOVE: 059 onMouseMove(event); 060 break; 061 case Event.ONMOUSEUP: 062 onMouseUp(event); 063 break; 064 case Event.ONMOUSEOUT: 065 onMouseOut(event); 066 break; 067 } 068 } 069 070 public void onMouseDown(Event event) { 071 onMouseDown = true; 072 } 073 074 public void onMouseMove(Event event) { 075 if (onMouseDown) { 076 onMouseMove = true; 077 } 078 } 079 080 public void onMouseUp(Event event) { 081 onMouseDown = onMouseMove = false; 082 } 083 084 public void onMouseOut(Event event) { 085 onMouseUp(event); 086 } 087 088 public boolean hasMoved() { 089 return onMouseMove; 090 } 091 092 protected void addAnnotationPopup() { 093 controller.addNewAnnotation(); 094 } 095 096}