Showing posts with label dnd. Show all posts
Showing posts with label dnd. Show all posts

Tuesday, May 17, 2011

dnd mockup

I'm testing drag and drop for swinghtmltemplate.

The html code is like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:j="http://www.oracle.com/swing">
<head>
    <title>DND test</title>
    <meta name='display-as' content="frame"/>
    <meta name='size' content="800 600"/>
    <meta name='onclose' content="exit"/>
</head>
<body style="display: border;">

    <table>
        <tr>
            <td width="fill" height="fill">
                <div>
                    <input type="text" text='test' align="top" dragsource='true'/>
                    <j:scroll>
                        <j:list id='source' droptarget='true'
                                ondblclick='onDblclick' selectedElements='${model.selectedSource}'
                                dragsource='true' accept-mime='sht/tag-source' ondrop='onDrop'>
                            <j:selectItems value='${source}'/>
                        </j:list>
                    </j:scroll>
                </div>
            </td>
            <td width="fill">
                <j:scroll>
                    <j:list id='target' droptarget='true'
                            ondblclick='onDblclick' selectedElements='${model.selectedTarget}'
                            dragsource='true' accept-mime='sht/tag-source' ondrop='onDrop'>
                        <j:selectItems value='${target}'/>
                    </j:list>
                </j:scroll>
            </td>
        </tr>
    </table>

</body>
</html>


Object, that can be used as dnd source, a marked with attribute dragsource='true'. Dnd targets are marked with droptarget='true'. accept-mime specifies the mime for DataFlavor which will be accepted by component. If not specified it will accept any flavor.

The source tag must be able to produce data to be carried in transferData. Currently there is a helper service, which creates transfer data from selection in JTable, JTextComponent, JList and JTree (it depends in tag's component type, not on tag type). After merge to main project this creation process will move to tag. The mime for created transferable is sht/tag-source.

ondrop='onDrop' specifies method name to be invoked on dnd drop. It recieve DropTargetDropEvent as parameter and must return true on drop accept.


Controller's code is under the cut.