API proposal: drag view
steve.x.northover at oracle.com
steve.x.northover at oracle.com
Mon Jan 14 13:52:16 PST 2013
I think we should set the image for free in an ImageView only, do you agree?
On 14/01/2013 4:31 PM, Richard Bair wrote:
> Right, gotcha. I would agree with that.
>
> On Jan 14, 2013, at 1:31 PM, steve.x.northover at oracle.com wrote:
>
>> It is different in that the drag image reflects what the widget is showing, not the content. If we set the image for free in an ImageView, that would be fine.
>>
>> Steve
>>
>> On 14/01/2013 4:23 PM, Richard Bair wrote:
>>> How is it any different than showing an image for free for List/Tree/Table? It seems like as long as we are consistent and the developer can override the behavior then it should be good?
>>>
>>> On Jan 14, 2013, at 1:15 PM, steve.x.northover at oracle.com wrote:
>>>
>>>> Showing the image for free when an image is placed on the drag board seems wrong. We don't show an image for free when other types are dragged.
>>>>
>>>> On 14/01/2013 3:12 PM, Petr Pchelko wrote:
>>>>> Hello, everyone.
>>>>>
>>>>> Steve wrote:
>>>>>> BTW, the last time I looked, on Windows, when you set image content, then you will get a drag image for free. This doesn't happen on the Mac. We should stop doing this on Windows.
>>>>> I am currently working on RT-27660 which is about this behavior on Mac. So you think we should not show the image content but show only the image explicitly set as the dragView instead?
>>>>>
>>>>> With best regards, Petr.
>>>>>
>>>>>
>>>>> 14.01.2013, в 23:51, steve.x.northover at oracle.com написал(а):
>>>>>
>>>>>> +1
>>>>>>
>>>>>> I'd like to see some example code where the tree and table set a default image as part of the implementation of these controls. Applications would get a reasonable image for free and be able to override it as necessary. Having and getter is necessary for this.
>>>>>>
>>>>>> BTW, the last time I looked, on Windows, when you set image content, then you will get a drag image for free. This doesn't happen on the Mac. We should stop doing this on Windows.
>>>>>>
>>>>>> Steve
>>>>>>
>>>>>> On 14/01/2013 2:09 PM, Richard Bair wrote:
>>>>>>> HI Pavel!
>>>>>>>
>>>>>>> Overall great. I don't see why you can't have a getter. The only way to set the drag view is via an API we control so it seems pretty easy to implement the getter as well. You could either have a DragView class which encapsulates the node/image and the offsetX and offsetY, or you could just break it out into three properties on the DragBoard and save yourself the extra class.
>>>>>>>
>>>>>>> I think you should just have an image based dragImage property and dragImageOffsetX and dragImageOffsetY properties. We shouldn't by default put anything in as the drag image, except for a few UI controls. We'll want a ListView, TreeView, TableView, TreeTableView to automatically pre-populate the DragBoard before the onDragDetected code is called, so that those control give you a nice drag image for free but the developer is free to replace it or clear it as they see fit.
>>>>>>>
>>>>>>> The developer could use the synchronous version of snapshot. But I think either snapshot should be fixed to be transparent by default instead of a white fill by default or add another snapshot method which produces a transparent fill by default. Basically:
>>>>>>>
>>>>>>> source.setOnDragDetected(new EventHandler<MouseEvent>() {
>>>>>>> public void handle(MouseEvent event) {
>>>>>>> DragBoard db = source.startDragAndDrop(TransferMode.ANY);
>>>>>>> db.setContent(…);
>>>>>>> db.setDragImage(source.snapshot());
>>>>>>> db.setDragImageOffsetX(event.getX());
>>>>>>> db.setDragImageOffsetY(event.getY());
>>>>>>> event.consume();
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> Maybe also have a convenience method on DragBoard:
>>>>>>>
>>>>>>> db.updateDragImage(node, x, y);
>>>>>>>
>>>>>>> which then just calls the 3 setters as appropriate.
>>>>>>>
>>>>>>> Richard
>>>>>>>
>>>>>>> On Jan 13, 2013, at 11:59 PM, Pavel Safrata<pavel.safrata at oracle.com> wrote:
>>>>>>>
>>>>>>>> Hello,
>>>>>>>> this is a proposal of an API allowing to specify the image floating with mouse cursor during a drag&drop operation.
>>>>>>>>
>>>>>>>> Jira: http://javafx-jira.kenai.com/browse/RT-14730
>>>>>>>>
>>>>>>>> I propose to add two methods to DragBoard:
>>>>>>>> setDragView(Image image, double offsetX, double offsetY)
>>>>>>>> setDragView(Node node, double offsetX, double offsetY)
>>>>>>>>
>>>>>>>> The first one simply uses the given image for the drag view with the offsetX and offsetY specifying cursor position over the image. The second one renders the given node to an image and uses the result (the coordinates being in the node's local space).
>>>>>>>>
>>>>>>>> The typical usage will look like this:
>>>>>>>> sourceNode.setOnDragDetected(new EventHandler<MouseEvent>() {
>>>>>>>> public void handle(MouseEvent event) {
>>>>>>>> Dragboard db = source.startDragAndDrop(TransferMode.ANY);
>>>>>>>> ClipboardContent content = ...
>>>>>>>> db.setContent(content);
>>>>>>>> db.setDragView(sourceNode, event.getX(), event.getY()); // that's it
>>>>>>>> event.consume();
>>>>>>>> }
>>>>>>>> });
>>>>>>>>
>>>>>>>>
>>>>>>>> This API is meant for telling the operating system what visual cues to provide, I don't think it is useful (and I'm not sure it is even possible) to provide getters.
>>>>>>>>
>>>>>>>> There is a possibility to provide default drag view - if none of those methods is called, the default drag view would be an image of the drag gesture source. This should work nice most of the times. However, it may cause inconveniences to some existing apps - for instance a text editor node which puts the selected text on the DragBoard - after updating FX the application starts to show the entire editor in the drag view. For this reason I think the default behavior should remain unchanged.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Pavel
More information about the openjfx-dev
mailing list