Author: julien(a)jboss.com
Date: 2008-07-09 10:14:40 -0400 (Wed, 09 Jul 2008)
New Revision: 11368
Added:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Droppable.java
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDContext.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDPanel.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/public/style.css
Log:
add droppable interface
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDContext.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDContext.java 2008-07-09
13:46:18 UTC (rev 11367)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDContext.java 2008-07-09
14:14:40 UTC (rev 11368)
@@ -34,7 +34,7 @@
Draggable findDraggableByHandle(Panel panel, Element element);
- Object findDroppable(Element element, int x, int y);
+ Droppable findDroppable(int x, int y);
}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDPanel.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDPanel.java 2008-07-09
13:46:18 UTC (rev 11367)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDPanel.java 2008-07-09
14:14:40 UTC (rev 11368)
@@ -44,6 +44,9 @@
private Drag drag;
/** . */
+ private Droppable droppable;
+
+ /** . */
private DnDContext context;
public DnDPanel(DnDContext context)
@@ -114,6 +117,9 @@
);
//
+ updateDroppable(x, y);
+
+ //
// DOM.setCapture(element);
}
@@ -142,12 +148,7 @@
" on element " + element);
//
- Object droppable = context.findDroppable(element, x, y);
- if (droppable != null)
- {
- log.debug("Found droppable " + droppable);
- }
-
+ updateDroppable(x, y);
}
//
@@ -168,12 +169,62 @@
}
}
+ private void updateDroppable(int x, int y)
+ {
+ Droppable newDroppable = context.findDroppable(x, y);
+
+ //
+ if (newDroppable != null)
+ {
+ log.debug("Found droppable " + newDroppable);
+ }
+ //
+ if (droppable != newDroppable)
+ {
+ if (droppable != null)
+ {
+ droppable.leave(drag.draggable);
+ }
+ if (newDroppable != null)
+ {
+ newDroppable.enter(drag.draggable);
+ }
+ }
+
+ //
+ droppable = newDroppable;
+ }
+
private void stopDrag()
{
log.debug("Stopping drag with draggable " + drag.draggable);
+
+ //
+ if (droppable != null)
+ {
+ droppable.leave(drag.draggable);
+ drag.draggable.stopDragging();
+
+ //
+ if (droppable.accept(drag.draggable))
+ {
+ drag.draggable.accepted(droppable);
+ }
+ else
+ {
+ drag.draggable.rejected(droppable);
+ }
+
+ //
+ droppable = null;
+ }
+ else
+ {
+ drag.draggable.stopDragging();
+ }
+
// DOM.releaseCapture(drag.element);
Element containerElement = drag.draggable.getContainer();
- drag.draggable.stopDragging();
DOM.setStyleAttribute(containerElement, "position", null);
drag = null;
}
Added:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Droppable.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Droppable.java
(rev 0)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Droppable.java 2008-07-09
14:14:40 UTC (rev 11368)
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.ajax.client.dnd;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface Droppable
+{
+
+ void enter(Draggable draggable);
+
+ void leave(Draggable draggable);
+
+ boolean accept(Draggable draggable);
+
+}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java 2008-07-09
13:46:18 UTC (rev 11367)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java 2008-07-09
14:14:40 UTC (rev 11368)
@@ -34,6 +34,7 @@
import org.jboss.portal.presentation.ajax.client.Constants;
import org.jboss.portal.presentation.ajax.client.dnd.Draggable;
+import org.jboss.portal.presentation.ajax.client.dnd.Droppable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -115,15 +116,33 @@
this.layout = layout;
}
- protected Object doFindDroppable(int x, int y)
+ private final Droppable droppable = new Droppable()
{
+ public void enter(Draggable draggable)
+ {
+ layout.addStyleName("dnd-selected");
+ }
+
+ public void leave(Draggable draggable)
+ {
+ layout.removeStyleName("dnd-selected");
+ }
+
+ public boolean accept(Draggable draggable)
+ {
+ return false;
+ }
+ };
+
+ protected Droppable doFindDroppable(int x, int y)
+ {
int left = layout.getAbsoluteLeft();
int right = left + layout.getOffsetWidth();
int top = layout.getAbsoluteTop();
int bottom = top + layout.getOffsetHeight();
if (x >= left && x <= right && y >= top && y <=
bottom)
{
- return this;
+ return droppable;
}
//
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java 2008-07-09
13:46:18 UTC (rev 11367)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java 2008-07-09
14:14:40 UTC (rev 11368)
@@ -41,6 +41,7 @@
import org.jboss.portal.presentation.ajax.client.util.logging.Logger;
import org.jboss.portal.presentation.ajax.client.AgentContext;
import org.jboss.portal.presentation.ajax.client.dnd.Draggable;
+import org.jboss.portal.presentation.ajax.client.dnd.Droppable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -146,14 +147,14 @@
return draggable;
}
- public final Object findDroppable(int x, int y)
+ public final Droppable findDroppable(int x, int y)
{
for (Iterator i = getChildren().iterator();i.hasNext();)
{
AjaxObject child = (AjaxObject)i.next();
//
- Object droppable = child.findDroppable(x, y);
+ Droppable droppable = child.findDroppable(x, y);
//
if (droppable != null)
@@ -246,7 +247,7 @@
protected abstract Draggable doFindDraggable(Element element);
- protected abstract Object doFindDroppable(int x, int y);
+ protected abstract Droppable doFindDroppable(int x, int y);
public abstract Widget getWidget();
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java 2008-07-09
13:46:18 UTC (rev 11367)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java 2008-07-09
14:14:40 UTC (rev 11368)
@@ -33,6 +33,7 @@
import org.jboss.portal.presentation.ajax.client.dnd.DnDPanel;
import org.jboss.portal.presentation.ajax.client.dnd.DnDContext;
import org.jboss.portal.presentation.ajax.client.dnd.Draggable;
+import org.jboss.portal.presentation.ajax.client.dnd.Droppable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -96,7 +97,7 @@
return findDraggabble(element);
}
- public Object findDroppable(Element element, int x, int y)
+ public Droppable findDroppable(int x, int y)
{
return AjaxPage.this.findDroppable(x, y);
}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java 2008-07-09
13:46:18 UTC (rev 11367)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java 2008-07-09
14:14:40 UTC (rev 11368)
@@ -85,12 +85,12 @@
public void startDragging()
{
- widget.addStyleName("dragged");
+ widget.addStyleName("dnd-dragged");
}
public void stopDragging()
{
- widget.removeStyleName("dragged");
+ widget.removeStyleName("dnd-dragged");
}
public void enter(Droppable droppable)
@@ -264,7 +264,7 @@
{
}
- protected Object doFindDroppable(int x, int y)
+ protected Droppable doFindDroppable(int x, int y)
{
return null;
}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/public/style.css
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/public/style.css 2008-07-09
13:46:18 UTC (rev 11367)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/public/style.css 2008-07-09
14:14:40 UTC (rev 11368)
@@ -31,7 +31,7 @@
padding: 1px;
}
-.pf-Window.dragged {
+.pf-Window.dnd-dragged {
background-color: blue;
}
@@ -52,6 +52,10 @@
padding: 1px;
}
+.pf-Layout.dnd-selected {
+background-color: red;
+}
+
.pf-Pane {
border: 1px solid black;
padding: 1px;