Methods Summary |
---|
public void | dragDropEnd(java.awt.dnd.DragSourceDropEvent dsde)
System.out.println ("dragDropEnd()");
dropTargetCell = null;
draggedIndex = -1;
repaint();
|
public void | dragEnter(java.awt.dnd.DragSourceDragEvent dsde)
|
public void | dragEnter(java.awt.dnd.DropTargetDragEvent dtde)
System.out.println ("dragEnter");
if (dtde.getSource() != dropTarget)
dtde.rejectDrag();
else {
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
System.out.println ("accepted dragEnter");
}
|
public void | dragExit(java.awt.dnd.DragSourceEvent dse)
|
public void | dragExit(java.awt.dnd.DropTargetEvent dte)
|
public void | dragGestureRecognized(java.awt.dnd.DragGestureEvent dge)
System.out.println ("dragGestureRecognized");
// find object at this x,y
Point clickPoint = dge.getDragOrigin();
int index = locationToIndex(clickPoint);
if (index == -1)
return;
Object target = getModel().getElementAt(index);
Transferable trans = new RJLTransferable (target);
draggedIndex = index;
dragSource.startDrag (dge,Cursor.getDefaultCursor(),
trans, this);
|
public void | dragOver(java.awt.dnd.DropTargetDragEvent dtde)
// figure out which cell it's over, no drag to self
if (dtde.getSource() != dropTarget)
dtde.rejectDrag();
Point dragPoint = dtde.getLocation();
int index = locationToIndex (dragPoint);
if (index == -1)
dropTargetCell = null;
else
dropTargetCell = getModel().getElementAt(index);
repaint();
|
public void | dragOver(java.awt.dnd.DragSourceDragEvent dsde)
|
public void | drop(java.awt.dnd.DropTargetDropEvent dtde)
System.out.println ("drop()!");
if (dtde.getSource() != dropTarget) {
System.out.println ("rejecting for bad source (" +
dtde.getSource().getClass().getName() + ")");
dtde.rejectDrop();
return;
}
Point dropPoint = dtde.getLocation();
int index = locationToIndex (dropPoint);
System.out.println ("drop index is " + index);
boolean dropped = false;
try {
if ((index == -1) || (index == draggedIndex)) {
System.out.println ("dropped onto self");
dtde.rejectDrop();
return;
}
dtde.acceptDrop (DnDConstants.ACTION_MOVE);
System.out.println ("accepted");
Object dragged =
dtde.getTransferable().getTransferData(localObjectFlavor);
// move items - note that indicies for insert will
// change if [removed] source was before target
System.out.println ("drop " + draggedIndex + " to " + index);
boolean sourceBeforeTarget = (draggedIndex < index);
System.out.println ("source is" +
(sourceBeforeTarget ? "" : " not") +
" before target");
System.out.println ("insert at " +
(sourceBeforeTarget ? index-1 : index));
DefaultListModel mod = (DefaultListModel) getModel();
mod.remove (draggedIndex);
mod.add ((sourceBeforeTarget ? index-1 : index), dragged);
dropped = true;
} catch (Exception e) {
e.printStackTrace();
}
dtde.dropComplete (dropped);
|
public void | dropActionChanged(java.awt.dnd.DropTargetDragEvent dtde)
|
public void | dropActionChanged(java.awt.dnd.DragSourceDragEvent dsde)
|
public static void | main(java.lang.String[] args)
JList list = new ReorderableJList ();
DefaultListModel defModel = new DefaultListModel();
list.setModel (defModel);
String[] listItems = {
"Chris", "Joshua", "Daniel", "Michael",
"Don", "Kimi", "Kelly", "Keagan"
};
Iterator it = Arrays.asList(listItems).iterator();
while (it.hasNext())
defModel.addElement (it.next());
// show list
JScrollPane scroller =
new JScrollPane (list,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
JFrame frame = new JFrame ("Checkbox JList");
frame.getContentPane().add (scroller);
frame.pack();
frame.setVisible(true);
|