Drag and Drop of multiple components at once
Hi everybody,
I need to select and drag multiple components (Eg. JLabels) at once, it is quite simple to manage just one drag at a time but how can be managed a multiple drag?
I mean something like Windows files selection mechanism : using Ctrl + Left mouse click to select the components and then start dragging them all to the drop target.
Beneath the code I'm using for testing , clicking and dragging each JLabel to JTextField just cause the copy of JLabel text to the JTextField contents.
In the sample a left click on each displayed label sets a border just to identify the selected status of the labels to drag but there's no implementation of the drop mechanism that should copy all the selected JLabels text to the drop target (the JTextField).
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.HashMap;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.TransferHandler;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
public class SelectableJLabel extends JPanel {
MouseListener listener = new DragMouseAdapter();
public Border getBorder(boolean getSelectedBorder) {
Border outsideBorder = BorderFactory.createEmptyBorder(2,2,2,2);
Border insideBorder = BorderFactory.createEmptyBorder(2,2,2,2);
if (getSelectedBorder)
insideBorder = BorderFactory.createEtchedBorder();
return BorderFactory.createCompoundBorder(outsideBorder, insideBorder);
private class DragMouseAdapter extends MouseAdapter {
public void mousePressed(MouseEvent e) {
System.out.println("Press!");
JComponent c = (JComponent) e.getSource();
JLabel lbl = (JLabel)c;
if (lbl.getBorder()==null || ((CompoundBorder)lbl.getBorder()).getInsideBorder() instanceof EmptyBorder) {
lbl.setBorder(getBorder(true));
TransferHandler handler = c.getTransferHandler();
handler.exportAsDrag(c, e, TransferHandler.COPY);
} else
lbl.setBorder(getBorder(false));
/* (non-Javadoc)
* @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
@Override
public void mouseClicked(MouseEvent e) {
public JLabel getSelectableLabel() {
JLabel selectableJLabel = new JLabel("You can't select me");
selectableJLabel.setBorder(getBorder(false));
selectableJLabel.setTransferHandler(new TransferHandler("text"));
selectableJLabel.addMouseListener(listener);
return selectableJLabel;
public SelectableJLabel() {
// a regular JLabel
add(getSelectableLabel());
add(getSelectableLabel());
add(getSelectableLabel());
// a look-alike JLabel
JTextField f = new JTextField("You can select me........................");
f.setDragEnabled(true);
//f.setEditable(false);
f.setBorder(null);
f.setForeground(UIManager.getColor("Label.foreground"));
f.setFont(UIManager.getFont("Label.font"));
add(f);
public Dimension getPreferredSize() {
return new Dimension(100, 100);
public static void main(String s[]) {
JFrame frame = new JFrame("SelectableJLabel");
SelectableJLabel panel = new SelectableJLabel();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel, "Center");
frame.setSize(panel.getPreferredSize());
frame.setVisible(true);
}Tnx in advance for HELP
Massimo
Edited by: JKut on May 2, 2010 10:48 AM
For multiple selections I recommend to use "JList". The "ListTransferHandler" provided in the "DropDemo" sample code supports multiple selections: [http://java.sun.com/docs/books/tutorial/uiswing/dnd/dropmodedemo.html]. To enable MULTIPLE_INTERVAL_SELECTION, simply remove the following statement in the "DropDemo" class:
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
Similar Messages
-
Drag and drop of multiple nodes between 2 trees
Hi,
I am trying to implement a drag and drop of multiple nodes between two different trees. A simple drag drop written on the lines of the demo code RSDEMO_DRAG_DROP_TREE_MULTI works perfectly fine. But my requirement is, when a child (leaf) node is dragged, if its parent is not present in the target tree, that too has to be dragged and dropped from left to right. When I try to manually add nodes to the target tree, it dumps because the node key table and drag drop object have fewer nodes than what I am trying to add. So it always dumps in the drag_drop_complete method.
I have also tried putting this code in the PBO of my screen, calling a subroutine to refresh my tree with all nodes required. But I realise that the PBO does not get called after a drag drop. Is there a way to achieve this? Any help would be greatly appreciated. Thank you.
Regards,
NithyaThere's a Multi-Select TreeView sample on the WindowsClient.com, you can download it. Then you can drag multi nodes as follows:
Code Snippet
private void Form2_Load(object sender, EventArgs e)
this.listBox1.AllowDrop = true;
this.listBox1.DragOver += new DragEventHandler(listBox1_DragOver);
this.listBox1.DragDrop += new DragEventHandler(listBox1_DragDrop);
this.multiSelectTreeView1.ItemDrag += new
ItemDragEventHandler(multiSelectTreeView1_ItemDrag);
void multiSelectTreeView1_ItemDrag(object sender, ItemDragEventArgs e)
this.multiSelectTreeView1.DoDragDrop(this.multiSelectTreeView1.SelectedNodes,
DragDropEffects.Move);
void listBox1_DragDrop(object sender, DragEventArgs e)
ArrayList selectNodes = e.Data.GetData(
e.Data.GetFormats()[0]) as ArrayList;
foreach (TreeNode node in selectNodes)
this.listBox1.Items.Add(node.Text);
void listBox1_DragOver(object sender, DragEventArgs e)
e.Effect = DragDropEffects.Move; -
I would like to archive hundreds of my emails that currently exist in my apple mail email filing system by moving them into file folders in the finder. I can do this easily with a single email but it wont let me do it with multiple emails or a complete folder. Is there any way of do this easily?
Thanks very much for this. However, I understand how dragging and dropping files normally works. It just seems the it wont work when you do it with emails when you are transfering them into a normal finder system folder. If you highlight one file and drag it to a finder folder it works, but when you drag multiple, it just wont let you do it.
Is there any work around for this? Thank you once again for your time. -
Drag and drop to multiple targets
Hi
Im trying to create a simple drag and drop app where you can drap a movieclip into multiple areas.
This is the code i have so far (taken from a tutorial i found) thats works perfectly for 1 target but not for multiples. I initially tried giving the targets the same instance name but that didnt work.
stop();
var startX:Number;
var startY:Number;
square_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
square_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
function pickUp(event:MouseEvent):void {
square_mc.gotoAndStop (2);
event.target.startDrag(true);
event.target.parent.addChild(event.target);
startX = event.target.x;
startY = event.target.y;
function dropIt(event:MouseEvent):void {
event.target.stopDrag();
var myTargetName:String = "target" + event.target.name;
var myTarget:DisplayObject = getChildByName(myTargetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){
reply_txt.text = "you have 5 days left";
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
event.target.buttonMode = false;
event.target.x = myTarget.x;
event.target.y = myTarget.y;
} else {
square_mc.gotoAndStop (1);
event.target.x = startX;
event.target.y = startY;
if(counter == 4){
reply_txt.text = "Congrats, you're finished!";
square_mc.buttonMode = true;
does anyone have any ideas?
Many thanks
SimonHere you go, I changed a couple things. First, I made the "decision" that all your drop targets would be named 'target'.
stop();
var startX:Number;
var startY:Number;
square_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
square_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
square_mc.buttonMode = true;
function pickUp(event:MouseEvent):void
square_mc.gotoAndStop (2);
event.target.startDrag()//true);
event.target.parent.addChild(event.target);
startX = event.target.x;
startY = event.target.y;
function dropIt(event:MouseEvent):void
// changed the bit here to set 'myTarget' after the null and name checks are made
event.target.stopDrag();
if (event.target.dropTarget != null && event.target.dropTarget.parent.name == "target")
var myTarget = event.target.dropTarget.parent;
reply_txt.text = "you have 5 days left";
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
event.target.buttonMode = false;
event.target.x = myTarget.x;
event.target.y = myTarget.y;
} else {
square_mc.gotoAndStop (1);
event.target.x = startX;
event.target.y = startY;
if(counter == 4)
reply_txt.text = "Congrats, you're finished!";
HTH!
-Ted -
Drag and drop between multiple instances of an executable
I want to know if there is a special way (not using Windows API) to drag and drop data between multiple instances of a same executable.
I have an application built in LabVIEW, where the main window can open a child window. Each window has a plot control. Between the two windows, a plot data of main window can be copied by drag and drop.
And I open another instance of the same executable. Now there are two executables(A and B).
I want to drag and drop a plot data from the main window of B to the child window of A. But in this case, Drag Enter Event is not fired. I think that the event seems to be fired only inside an executable.
http://digital.ni.com/public.nsf/allkb/AB268878693EF4B586257037004A6725 says that Queue or Semaphore is working only inside an executable. Is drag operation also valid only inside a process?Hi,
Placed images (as opposed to pasted images) in Indesign are by their very nature pointers to an external image file, so there is no way to slim down the size of your exported PDF other than by playing with the export settings. Other than that, ensure that your file is placed in Indesign at 100% and at the correct resolution for your desired output. If you open the PDF in Acrobat, you can also save as a reduced size PDF which may help.
Good luck!
Malcolm -
How can I learn "Drag and Drop" with Swing components?
Hello,
Im using swing components, so using paint() to draw a "drag icon" doesnt seem acceptable. Im basically trying to move a JPanel image to be dragged/dropped over another JPanel in the same program/applet.
I looked at Sun's Java Tutorial for information on doing drag and drop, but there was no trail completed yet.
Does anyone know of any good resources to learn? Or can at least give me a general idea of how to do drag and drop?Did you see this?
http://java.sun.com/docs/books/tutorial/dnd/index.html
http://java.sun.com/docs/books/tutorial/reallybigindex.html -
Drag and Drop in custom components..
hello friends,
I am trying to devlop a schedule component. on part of this i trying to develop a functionality where the user can reschedure the appointment by drag and drop. the dragdrop event in the container component is not triggered when ther user drag the appointment and drop it in the another container. can any one help me on this please. i have given below my source codes.
Testbox.as
package layouts.DayViewControl.containers
import mx.core.Container;
public class TestBox extends Container
private var __timeAndXYCoOrdArray:Array;
private var __xyDiff:int=0;
public function TestBox()
super();
__timeAndXYCoOrdArray=new Array();
protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth,unscaledHeight);
var totalSlots:int=24*2;
var __lineThickness:int=1;
var __lineAlpha:int=0.2;
var boxHeight:uint=unscaledHeight/totalSlots;
graphics.clear();
var xPos:int=0;
var ypos:int=0;
graphics.lineStyle(2,0x000000,0.5);
graphics.drawRect(0,0,unscaledWidth,unscaledHeight);
var __boxHeight:int=unscaledHeight/totalSlots;
var __minusCount:int=1;
for(var i:int=0;i<totalSlots;i++){
var timeStr:String="";
if(i%2 == 0){
__lineThickness=2;
graphics.lineStyle(__lineThickness,0x000000,0.4);
}else{
__lineThickness=1;
graphics.lineStyle(__lineThickness,0x000000,0.2);
graphics.moveTo(xPos,ypos);
var tempYpos:int=ypos;
if(__xyDiff == 0){
__xyDiff=ypos-xPos;
graphics.lineTo(xPos+unscaledWidth,tempYpos);
ypos+=boxHeight;
var newYPos:int=0;
if(i == 0){
timeStr="00:00";
}else if(i%2 != 0){
if(i<=9){
timeStr="0"+(i-__minusCount).toString()+":30";
}else{
timeStr=(i-__minusCount).toString()+":30";
newYPos=ypos-__xyDiff;
}else if(i%2 == 0){
if(i<=9){
timeStr="0"+(i-__minusCount).toString()+":00";
}else{
timeStr=(i-__minusCount).toString()+":00";
__minusCount+=1;
newYPos=ypos-__xyDiff;
__timeAndXYCoOrdArray.push({XPos:xPos,YPos:newYPos,Time:timeStr});
public function getXFromtime(inputTime:String):int{
var returnVal:int=0;
if(inputTime && inputTime != ""){
for (var j:int=0;j<__timeAndXYCoOrdArray.length;j++){
if(__timeAndXYCoOrdArray[j].Time.toString() == inputTime){
returnVal=parseInt(__timeAndXYCoOrdArray[j].XPos)
break;
return returnVal;
public function getYFromtime(inputTime:String):int{
var returnVal:int=0;
if(inputTime && inputTime != ""){
for (var j:int=0;j<__timeAndXYCoOrdArray.length;j++){
if(__timeAndXYCoOrdArray[j].Time.toString() == inputTime){
returnVal=parseInt(__timeAndXYCoOrdArray[j].YPos)
break;
return returnVal;
public function getTimeDifference():int{
return __xyDiff;
TimeDividerLines.as
package layouts.DayViewControl
import flash.events.MouseEvent;
import flash.utils.Dictionary;
import layouts.DayViewControl.containers.TestBox;
import mx.collections.ArrayCollection;
import mx.core.DragSource;
import mx.core.EventPriority;
import mx.core.UIComponent;
import mx.events.DragEvent;
import mx.managers.DragManager;
public class TimeDividerLines extends TestBox
private var __linesPerHour:int=4;
private var __currentDate:Date;
private var __timeAndXYCoOrdArray:Array;
private var __dataComponentArry:Array;
private var __totalAppointment:int=5;
private var __xyDiff:int=0;
private var __apptDataInfoArry:Array;
private var __dataProviderChanged:Boolean=false;
private var __reArrangeDataArrayCol:ArrayCollection;
private var __sortedArrayCollection:ArrayCollection;
private var __dragDropEnabled:Boolean=false;
public function TimeDividerLines()
super();
//__timeAndXYCoOrdArray=new Array();
__dataComponentArry=new Array();
__apptDataInfoArry=new Array();
__sortedArrayCollection=new ArrayCollection();
public function set dragDropEnabled(inputVal:Boolean):void{
if(inputVal){
//set youself for drag and drop event
this.addEventListener(DragEvent.DRAG_ENTER,dragEnterEventHandler,false,EventPriority.DEFA ULT_HANDLER);
this.addEventListener(DragEvent.DRAG_OVER,dragOverEventHandler,false,EventPriority.DEFAUL T_HANDLER);
this.addEventListener(DragEvent.DRAG_DROP,dragDropEventHandler,false,EventPriority.DEFAUL T_HANDLER);
this.addEventListener(DragEvent.DRAG_COMPLETE,dropCompleteHandler);
}else{
this.removeEventListener(DragEvent.DRAG_ENTER,dragEnterEventHandler,false);
this.removeEventListener(DragEvent.DRAG_OVER,dragOverEventHandler,false);
this.removeEventListener(DragEvent.DRAG_DROP,dragDropEventHandler,false);
__dragDropEnabled=inputVal;
private function dropCompleteHandler(event:DragEvent):void{
trace("inside drop complete handler");
private function dragEnterEventHandler(event:DragEvent):void{
if(event.dragSource.hasFormat("Appointment")){
var dropTarget:UIComponent=UIComponent(event.currentTarget);
DragManager.acceptDragDrop(dropTarget);
DragManager.showFeedback(event.ctrlKey ? DragManager.COPY : DragManager.MOVE);
return;
DragManager.showFeedback(DragManager.NONE);
private function dragOverEventHandler(event:DragEvent):void{
/* if(event.dragSource.hasFormat("Appointment")){
if(event.ctrlKey){
DragManager.showFeedback(DragManager.COPY);
return
}else{
DragManager.showFeedback(DragManager.MOVE);
return
DragManager.showFeedback(DragManager.NONE); */
private function dragDropEventHandler(event:DragEvent):void{
//We need to do two things here. you need to add the dropped data to the data provider list.
//and need need to update this entry to DB
/* if(event.dragSource.hasFormat("Appointment")){
var draggedbox:AppointmentDisplayBox=event.dragSource.dataForFormat("Appointment") as AppointmentDisplayBox;
var dropBox:TimeDividerLines=event.currentTarget as TimeDividerLines;
//create a new copy
var newBox:AppointmentDisplayBox=new AppointmentDisplayBox();
newBox=draggedbox;
newBox.x=dropBox.mouseX;
newBox.y=dropBox.mouseY;
this.addChild(newBox);
trace("11111111111111111111111111111111111111111")
private function mouseDownHandler(event:MouseEvent):void{
var draginit:AppointmentDisplayBox=AppointmentDisplayBox(event.currentTarget);
var ds:DragSource=new DragSource();
ds.addData(draginit,"Appointment");
DragManager.doDrag(draginit,ds,event);
override protected function createChildren():void{
super.createChildren();
override protected function commitProperties():void{
if(__dataProviderChanged){
__dataComponentArry=new Array();
for (var k:int=0;k<__apptDataInfoArry.length;k++){
var tempDispBox:AppointmentDisplayBox=new AppointmentDisplayBox();
tempDispBox.currentDate=this.currentDate;
tempDispBox.startTime=__apptDataInfoArry[k].StartTime.toString();
tempDispBox.endTime=__apptDataInfoArry[k].EndTime.toString();
tempDispBox.apptDataXml=__apptDataInfoArry[k].Data as XML;
tempDispBox.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
this.addChild(tempDispBox);
__dataComponentArry.push(tempDispBox);
__dataProviderChanged=false;
private function sortTheCollectionValues(__inputArrayCol:ArrayCollection):ArrayCollection{
var returnArrayCollection:ArrayCollection=new ArrayCollection();
var tempArray:Array=new Array();
for(var i:int=0;i<__inputArrayCol.length;i++){
tempArray.push({Length:(__inputArrayCol[i] as Array).length,Index:i});
tempArray.sortOn("Length",Array.DESCENDING|Array.NUMERIC);
for(var j:int=0;j<tempArray.length;j++){
returnArrayCollection.addItem(__inputArrayCol[tempArray[j].Index]);
return returnArrayCollection;
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth,unscaledHeight);
if(__dataComponentArry.length > 0){
__sortedArrayCollection=new ArrayCollection();
sortArray(__dataComponentArry);
if(__sortedArrayCollection.length > 0 ){
//you need to sort the arraycollection based on the length first to draw the highest no. child array first
__sortedArrayCollection=sortTheCollectionValues(__sortedArrayCollection);
var appGap:int=2;
var endGap:int=10;
//var drawnApptObj:Array=new Array();
var existingChildArray:Array=new Array();
var drawnApptObj:Dictionary=new Dictionary();
for(var l:int=0;l<__sortedArrayCollection.length;l++){
var apptWidth:int=0;
var innerArry:Array=__sortedArrayCollection[l] as Array;
existingChildArray=new Array();
//you need to recalculate the width
//for the first iteration you need to sort by height
//if(l == 0){
// innerArry.sortOn("apptHeight",Array.NUMERIC|Array.DESCENDING);
//}else{
innerArry.sortOn(["isChild","apptHeight"],Array.NUMERIC|Array.DESCENDING);
//innerArry.sortOn("apptHeight",Array.NUMERIC|Array.DESCENDING);
//first we need to find out any intersection appointment is there
var count:int=0;
for each(var tempApptDispBox:AppointmentDisplayBox in innerArry){
if(drawnApptObj[tempApptDispBox] == tempApptDispBox){
if(apptWidth < tempApptDispBox.width){
apptWidth=tempApptDispBox.width;
existingChildArray.push({index:count,object:tempApptDispBox});
count++;
if(apptWidth == 0){
apptWidth=(unscaledWidth - (endGap + (appGap*innerArry.length)))/innerArry.length;
//now you need to layout the childrens
var canDraw:Boolean=false;
var ismatch:Boolean=false;
for (var childCnt:int=0;childCnt < innerArry.length;childCnt++){
var tempDispBox:AppointmentDisplayBox=innerArry[childCnt] as AppointmentDisplayBox;
for (var i:int=0;i<existingChildArray.length;i++){
if(existingChildArray[i].index == childCnt){
ismatch=true;
break;
if(childCnt == 0 && !ismatch){
tempDispBox.x=this.getXFromtime(tempDispBox.startTime.toString())+2;
canDraw=true;
}else if(existingChildArray.indexOf(childCnt) > -1 && childCnt != 0){
//tempDispBox.x=(existingChildArray[childCnt] as AppointmentDisplayBox).x+apptWidth+appGap;
canDraw=false;
}else if(childCnt != 0 && !ismatch){
tempDispBox.x=((existingChildArray[childCnt-1].object) as AppointmentDisplayBox).x+apptWidth+appGap;
canDraw=true;
if(canDraw){
tempDispBox.y=this.getYFromtime(tempDispBox.startTime.toString());
tempDispBox.width=apptWidth;
tempDispBox.height=tempDispBox.apptHeight-2;
if(tempDispBox.isChild){
drawnApptObj[tempDispBox]=tempDispBox;
existingChildArray.push({index:childCnt,object:tempDispBox});
canDraw=false;
ismatch=false;
//first we need to sort the component array based on the height property to position the biggest appointment first
private function sortArray(tempArry:Array):void{
//var tempArry:Array=arrayClone(__datacompArray);
for(var i:int=0;i<tempArry.length;i++){
var tempDispBox:AppointmentDisplayBox=tempArry[i] as AppointmentDisplayBox;
var start:int=this.getYFromtime(tempDispBox.startTime.toString());
var end:int=this.getYFromtime(tempDispBox.endTime.toString());
tempDispBox.apptHeight=end-start;
var indexArray:Array=new Array();
var canContinue:Boolean=false;
var loopArray:Array=new Array();
loopArray=tempArry.concat(); // this will copy the array to loopArray
var copyArry:Array=new Array();
var k:int=0;
while(k<loopArray.length){
loopArray.sortOn("apptHeight",Array.NUMERIC|Array.DESCENDING);
if(indexArray.length > 0){
if(indexArray.indexOf(k) >= 0){
canContinue=false;
}else{
canContinue=true;
}else{
canContinue=true;
if(canContinue){
var newArry:Array=new Array();
//newArry.push(tempArry[k]);
for (var innerCnt:int=0;innerCnt<loopArray.length;innerCnt++){
var locCanContinue:Boolean=false;
if(indexArray.length > 0){
if(indexArray.indexOf(innerCnt) >= 0){
locCanContinue=false;
}else{
locCanContinue=true;
}else{
locCanContinue=true;
if(locCanContinue && k != innerCnt){
var outerstartTime:Number=parseFloat(loopArray[k].startTime.toString().replace(":","."));
var outerendtime:Number=parseFloat(loopArray[k].endTime.toString().replace(":","."));
var innerStartTime:Number=parseFloat(loopArray[innerCnt].startTime.toString().replace(":","." ));
var innerEndtime:Number=parseFloat(loopArray[innerCnt].endTime.toString().replace(":","."));
if(outerstartTime == innerStartTime && outerendtime == innerEndtime){
//newArry.push(tempArry.splice(innerCnt,1));
newArry.push(loopArray[innerCnt]);
indexArray.push(innerCnt);
}else if(outerstartTime == innerStartTime && outerendtime > innerEndtime){
//newArry.push(tempArry.splice(innerCnt,1));
newArry.push(loopArray[innerCnt]);
indexArray.push(innerCnt);
}else if(outerstartTime < innerStartTime && outerendtime == innerEndtime){
//newArry.push(tempArry.splice(innerCnt,1));
newArry.push(loopArray[innerCnt]);
indexArray.push(innerCnt);
}else if(outerstartTime < innerStartTime && outerendtime > innerEndtime){
//newArry.push(tempArry.splice(innerCnt,1));
newArry.push(loopArray[innerCnt]);
indexArray.push(innerCnt);
}else if(outerstartTime > innerStartTime && outerendtime > innerEndtime && innerEndtime > outerstartTime){
//newArry.push(tempArry.splice(innerCnt,1));
newArry.push(loopArray[innerCnt]);
loopArray[innerCnt].isChild=true;
//indexArray.push(innerCnt);
}else if(outerstartTime < innerStartTime && outerendtime < innerEndtime && innerStartTime < outerendtime){
//newArry.push(tempArry.splice(innerCnt,1));
newArry.push(loopArray[innerCnt]);
loopArray[innerCnt].isChild=true;
//indexArray.push(innerCnt);
}else if(outerstartTime == innerStartTime && outerendtime < innerEndtime){
newArry.push(loopArray[innerCnt]);
loopArray[innerCnt].isChild=true;
}else if(outerstartTime > innerStartTime && outerendtime == innerEndtime){
newArry.push(loopArray[innerCnt]);
loopArray[innerCnt].isChild=true;
//newArry.push(tempArry.splice(k,1));
indexArray.push(k);
newArry.push(loopArray[k]);
__sortedArrayCollection.addItem(newArry);
copyArry=loopArray.concat();
loopArray=new Array();
for (var j:int=0;j<copyArry.length;j++){
if(indexArray.indexOf(j) < 0){
loopArray.push(copyArry[j]);
indexArray=new Array();
private function arrayClone(source:Array):Array{
var returnArray:Array=new Array();
for(var j:int=0;j<source.length;j++){
returnArray.push(source[j]);
return returnArray;
public function set currentDate(inputVal:Date):void{
if(__currentDate != inputVal){
__currentDate=inputVal;
public function get currentDate():Date{
return __currentDate;
public function set apptDataArray(inputVal:Array):void{
if(!__dataProviderChanged && inputVal.length > 0){
__apptDataInfoArry=inputVal;
__dataProviderChanged=true;
invalidateProperties();
invalidateDisplayList();
AppointmentDisplayBox.as
package layouts.DayViewControl
import mx.controls.TextInput;
import mx.core.UIComponent;
public class AppointmentDisplayBox extends UIComponent
private var __startTime:String;
private var __EndTime:String;
private var __currentDate:Date;
private var __apptData:XML;
private var __height:Number;
private var __isChild:Boolean=false;
private var __modifiedWidth:Boolean=false;
private var __docNameLable:TextInput;
private var __appDetails:TextInput;
public function AppointmentDisplayBox()
super();
this.setStyle("horizontalScrollPolicy","off");
this.setStyle("verticalScrollPolicy","off");
this.setStyle("borderStyle","solid");
this.setStyle("verticalGap","0");
this.setStyle("borderStyle","outset");
this.buttonMode=true;
protected override function createChildren():void{
super.createChildren();
if(!__docNameLable){
__docNameLable=new TextInput();
__docNameLable.editable=false;
__docNameLable.setStyle("horizontalScrollPolicy","off");
__docNameLable.setStyle("verticalScrollPolicy","off");
__docNameLable.setStyle("borderStyle","none");
//__docNameLable.setStyle("borderThickness","0");
__docNameLable.buttonMode=true;
addChild(__docNameLable);
if(!__appDetails){
__appDetails=new TextInput();
__appDetails.editable=false;
__appDetails.setStyle("horizontalScrollPolicy","off");
__appDetails.setStyle("verticalScrollPolicy","off");
__appDetails.setStyle("borderStyle","none");
__appDetails.setStyle("backgroundColor","0xB1FB17");
__appDetails.buttonMode=true;
// __appDetails.setStyle("borderThickness","0");
addChild(__appDetails);
protected override function commitProperties():void{
super.commitProperties();
if(__apptData != null){
__docNameLable.text=__apptData.DocName.toString();
__appDetails.text=__apptData.PatientID.toString()+"\n"+__apptData.Description.toString();
invalidateDisplayList();
protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth,unscaledHeight);
__docNameLable.setActualSize(unscaledWidth-1,20);
__docNameLable.move(1,1);
graphics.clear();
var lineColor:uint=0x000000;
graphics.lineStyle(1,lineColor,1);
graphics.beginFill(0xFEFDFD,1)
graphics.drawRect(0,0,unscaledWidth,22);
graphics.endFill();
__appDetails.setActualSize(unscaledWidth-1,unscaledHeight-22);
__appDetails.move(1,23);
graphics.drawRect(0,22,unscaledWidth,unscaledHeight-20);
public function set startTime(inputVal:String):void{
__startTime=inputVal;
public function get startTime():String{
return __startTime;
public function set endTime(inputVal:String):void{
__EndTime=inputVal;
public function get endTime():String{
return __EndTime;
public function set currentDate(inputVal:Date):void{
__currentDate=inputVal;
public function get currentDate():Date{
return __currentDate;
public function set apptHeight(inputVal:Number):void{
__height=inputVal;
public function get apptHeight():Number{
return __height;
public function set isChild(inputVal:Boolean):void{
__isChild=inputVal;
public function get isChild():Boolean{
return __isChild;
public function set isModifiedWidth(inputVal:Boolean):void{
__modifiedWidth=inputVal;
public function get isModifiedWidth():Boolean{
return __modifiedWidth;
public function set apptDataXml(inputVal:XML):void{
if(__apptData != inputVal){
__apptData=inputVal;
invalidateProperties();
invalidateDisplayList();
public function get apptDataXml():XML{
return __apptData;
Test.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:layouts="layouts.*"
xmlns:DayViewControl="layouts.DayViewControl.*" xmlns:test="layouts.DayViewControl.containers.*">
<mx:Script>
<![CDATA[
import mx.controls.TextInput;
import layouts.DayViewControl.TimeDividerLines;
import mx.events.DragEvent;
import mx.managers.DragManager;
import mx.core.DragSource;
import layouts.DayViewControl.AppointmentDisplayBox;
private function mouseDownHandler(event:MouseEvent):void{
var dragint:AppointmentDisplayBox=AppointmentDisplayBox(event.currentTarget);
//var dragint:TextInput=TextInput(event.currentTarget);
var ds:DragSource=new DragSource();
ds.addData(dragint,"Appoitment");
DragManager.doDrag(dragint,ds,event);
private function dragEnterHandler(event:DragEvent):void{
if(event.dragSource.hasFormat("Appoitment")){
var droptarget:TimeDividerLines=TimeDividerLines(event.currentTarget);
DragManager.acceptDragDrop(droptarget);
DragManager.showFeedback(event.ctrlKey?DragManager.COPY:DragManager.MOVE);
return;
DragManager.showFeedback(DragManager.NONE);
private function dragDropHandler(event:DragEvent):void{
if(event.dragSource.hasFormat("Appoitment")){
var droppedObj:AppointmentDisplayBox=AppointmentDisplayBox(event.dragSource.dataForFormat("Ap poitment"));
//var droppedObj:TextInput=TextInput(event.dragSource.dataForFormat("Appoitment"));
var dropTarget:TimeDividerLines=TimeDividerLines(event.currentTarget);
droppedObj.x=dropTarget.mouseX;
droppedObj.y=dropTarget.mouseY;
dropTarget.addChild(droppedObj);
]]>
</mx:Script>
<mx:HBox width="100%" height="100%">
<DayViewControl:TimeDividerLines width="50%" height="100%">
<DayViewControl:AppointmentDisplayBox width="50" height="100" mouseDown="mouseDownHandler(event)"/>
</DayViewControl:TimeDividerLines>
<DayViewControl:TimeDividerLines width="50%" height="100%" dragEnter="dragEnterHandler(event)" dragDrop="dragDropHandler(event)"/>
</mx:HBox>
</mx:Application>First 3 .as are the component
source. in the last test.mxml file i have written the drag and drop functionality.
can any help me?? please -
Drag and Drop with multiple targets
I'm having a problem find a solution to my drag and drop problem. Here is what this flash piece is basically supposed to do:
9 dragable items on the stage
5 targets, numbers 1 - 5, where the items can be placed
5 of the 9 dragable items are the correct answer and the user needs to drag them to the correct target, and have to be in order from 1-5. (eg. let's say the instructions are:
Please place the, in the correct order, the 5 steps to getting ready in the morning
Drag items Targets
Brush teeth 1.
Change oil in car 2.
Wash face 3.
Put pants on 4.
Shower 5.
Get out of bed
Do tax's
So far I have it so if you drop the correct answer into its correct target it snaps to it and disable it's eventListeners. If you drop the drag item on the other targets they snap to it and disable it as well. They only problem is if the user accidentally drops the item anywheres else on the stage it locks it in place. Instead I want it to return to the orginal x and y position. Can anyone help?!?
Here is my code
DragDrop.as
package
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
public class DragDrop extends MovieClip
public var _targetPiece:*;
public function DragDrop()
this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
this.addEventListener(MouseEvent.MOUSE_UP, dropMovie);
this.buttonMode = true;
private function dragMovie(event:MouseEvent):void
this.startDrag();
this.filters = [new DropShadowFilter(0.5)];
this.parent.addChild(this);
private function dropMovie(event:MouseEvent):void
this.stopDrag();
this.filters = [];
public function disable():void
this.buttonMode = false;
this.removeEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
this.removeEventListener(MouseEvent.MOUSE_UP, dropMovie);
DragGame.as
package
import flash.display.MovieClip;
import flash.events.MouseEvent;
import DragDrop;
import BL;
import BR;
import BM;
import TL;
import TR;
import TM;
import BC;
import TC;
import BA;
public class DragGame extends MovieClip
private var bl:BL;
private var br:BR;
private var bm:BM;
private var tl:TL;
private var tr:TR;
private var tm:TM;
private var bc:BC;
private var tc:TC;
private var ba:BA;
private var _totalPieces:Number;
private var _currentPieces:Number;
private var _submit:Number;
private var _reveal:Number;
public function DragGame()
_totalPieces = 5;
_currentPieces = 0;
createPieces();
_submit = 6;
_reveal = 1;
private function createPieces():void
bl = new BL();
addChild(bl);
bl._targetPiece = blt_mc;
bl.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
piecePosition1(bl);
br = new BR();
addChild(br);
br._targetPiece = brt_mc;
br.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
piecePosition2(br);
bm = new BM();
addChild(bm);
bm._targetPiece = bmt_mc;
bm.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
piecePosition3(bm);
tl = new TL();
addChild(tl);
tl._targetPiece = tlt_mc;
tl.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
piecePosition4(tl);
tr = new TR();
addChild(tr);
tr._targetPiece = trt_mc;
tr.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
piecePosition5(tr);
tm = new TM();
addChild(tm);
tm._targetPiece = tmt_mc;
tm.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
piecePosition6(tm);
bc = new BC();
addChild(bc);
bc._targetPiece = trt_mc;
bc.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
piecePosition7(bc);
tc = new TC();
addChild(tc);
tc._targetPiece = trt_mc;
tc.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
piecePosition8(tc);
ba = new BA();
addChild(ba);
ba._targetPiece = trt_mc;
ba.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
piecePosition9(ba);
private function checkTarget(event:MouseEvent):void
if(event.currentTarget.hitTestObject(event.currentTarget._targetPiece))
event.currentTarget.x = event.currentTarget._targetPiece.x;
event.currentTarget.y = event.currentTarget._targetPiece.y;
event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
event.currentTarget.disable();
_currentPieces ++;
_submit --;
if(_currentPieces >= _totalPieces)
wrong_txt.visible = false;
answer_txt.visible = true;
if(_submit <= _reveal)
submit_mc.visible = true;
submit_mc.buttonMode = true;
else
event.currentTarget.x= event.currentTarget.dropTarget.parent.x;
event.currentTarget.y= event.currentTarget.dropTarget.parent.y;
event.currentTarget.disable();
if(_submit <= _reveal)
submit_mc.visible = true;
submit_mc.buttonMode = true;
private function piecePosition1(piece:*):void
piece.x = 50.2;
piece.y = 87.2;
piece._origX = 50.2;
piece._origY = 87.1;
private function piecePosition2(piece:*):void
piece.x = 50.2;
piece.y = 109.2;
piece._origX = 50.2;
piece._origY = 109.2;
private function piecePosition3(piece:*):void
piece.x = 50.2;
piece.y = 131.2;
piece._origX = 50.2;
piece._origY = 131.2;
private function piecePosition4(piece:*):void
piece.x = 50.2;
piece.y = 153.3;
piece._origX = 50.2;
piece._origY = 153.3;
private function piecePosition5(piece:*):void
piece.x = 50.2;
piece.y = 175.3;
piece._origX = 50.2;
piece._origY = 175.3;
private function piecePosition6(piece:*):void
piece.x = 50.2;
piece.y = 197.3;
piece._origX = 50.2;
piece._origY = 197.3;
private function piecePosition7(piece:*):void
piece.x = 50.2;
piece.y = 219.4;
piece._origX = 50.2;
piece._origY = 219.4;
private function piecePosition8(piece:*):void
piece.x = 50.2;
piece.y = 241.4;
piece._origX = 50.2;
piece._origY = 241.4;
private function piecePosition9(piece:*):void
piece.x = 50.2;
piece.y = 263.7;
piece._origX = 50.2;
piece._origY = 263.7;create an array of your droptargets (eg, droptargetA) and check if the object is dropped on a droptarget. you don't even need the if-branch of the following if-else unless you do something that depends on whether the correct droptarget is hit.
function checkTarget(event:MouseEvent):void
if(event.currentTarget.hitTestObject(event.currentTarget._targetPiece ))
event.currentTarget.x = event.currentTarget._targetPiece.x;
event.currentTarget.y = event.currentTarget._targetPiece.y;
event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
event.currentTarget.disable();
else
var x:Number=event.currentTarget.dropTarget._origX;
var y:Number=event.currentTarget.dropTarget._origY;
for(var i:uint=0;i<droptargetNum;i++){
if(event.currentTarget.hitTestObject(droptargetA[i] )){
x=droptargetA[i].x;
y=droptargetA[i].y;
break
event.currentTarget.x=x;
event.currentTarget.y=y; -
Help needed in drag and drop of Flex tree
Hi,
We have an application which allows drag and drop between
multiple
trees and lists.
Here are the steps I follow to refresh on drag and drop:
1. Dispatch a custom event which calls server.
2. On successful response from server I change the model
which is
data provider for the tree.
3. Then, set a flag which triggers 'invalidateDisplayList'
and 'invalidateList' for tree (and other listeners).
4. The tree refreshes fine. But as soon as I drag and drop
between
trees again, I get this error in Tree.as:
TypeError: Error #1010: A term is undefined and has no
properties.
at mx.controls::Tree/::updateDropData()
at mx.controls::Tree/calculateDropIndex()
at mx.controls.listClasses::ListBase/showDropFeedback()
at mx.controls::Tree/showDropFeedback()
The behaviour is weird, sometimes the browser hangs and stops
responding.
I am calling 'contentTree.showDropFeedback(event)' in my
dragOver
event listener which is triggering error.
My tree data provider is a custom class which has 'children'
array
collection attribute.
Any help on how to resolve this issue would be highly
appreciated.
Thanks in advance,
Sujathathe major restrictions in its implemented only in
jdk1.1.Why! -
Need help with drag and drop game, Urgent!
Hi I have created a drag and drop game, the drag and drop is
working alright however once the right word has been placed in the
box, and moves on to the next question the previous correct answer
stays where it was placed, how can i get it to snap back to its
original location? Also when the right word is draged in to the the
white box i want it to snap into place in that box so it fits in
there.
Also if you have any other thoughts and advice on how i can
improve on this please email me thanx
Can someone please help, my .fla file can be found here:
http://www.freshlemon.co.uk/timeline.fla
http://www.freshlemon.co.uk/timeline.fla.zip
thanxtellTarget is ancient
I forget what it even used to do??? hahaha
seriously, just put in the instance name and what you want it
to do:
tellTarget("movieclip"){
play();
is now just
movieclip.play(); -
Why is drag and drop not working in lion
Drag and drop has not worked correctly once since I started using lion.
Hi
I had the same problem in my case the remedy was simple
Preferences - Universal Access - Mouse and Trackpad tab - trackpad options
tick the drag and drop box
I dont know why this option had been turned off but ticking this box restored the drag and drop function
HTH -
Drag and drop correct answer window error#2032
Hi, when trying to create a drag and drop with multiple correct answer combinations I click on the correct answer option to open the correct answer window and the window that opens is empty except for a bar at the bottom saying Error #2032. I can't access the correct answer options because of this as the window is blank. Help please!
Hi there,
Are you trying to click on the 'Correct answer' button from Drag and Drop Panel? Can you please post a screenshot of the error window?
Thanks,
Nimmy Sukumaran. -
Drag and drop file list to MS PowerPoint
Hi there !
I've implemented a Transferable that supports drag and drop of multiple files from java application to natives. I took a DataFlavor.javaFileListFlavor and my getTransferData() method returns a Vector of File. My most important files are images in different formats.
This runs very well for most of the MS applications like Word, WordPad, Internet Explorer, File Explorer, Paint Shop Pro, .... These application import all my transferred files and show their image(s).
But I didn't reach for doing this with PowerPoint. On dropping to PowerPoint a message appears: "PowerPoint cannot open files of type <MyFile>."
If I drag and drop my files to the file explorer and then from there to PowerPoint it works as well as if I take the files my Transferable wrote to a temporary directory.
What's wrong ? What's the difference between PowerPoint and most other applications ? And What can I do to transfer my files to PowerPoint ?Look up javax.swing.TransferHandler, java.awt.datatransfer.DataFlavor, and DataFlavor.javaFileListFlavor.
-
Hi,
This was not what I meant.
The requirement is:
Drag and drop any one of specific list of components say x, y,z in the parsys
Only after the drag and drop of these components other components can be dragged to the parsys. So we can say that the parsys should allow only the specific components to be added first and only after that other components can be added.
Thanks ,
DiptiHi there
I'm guessing that you mean to ask if one is able to force a user to perform a drag-and-drop as part of a simulation?
Unless you program it in Flash or some other application it isn't avaiable. Check the link below for more.
Click here to view
Cheers... Rick
Helpful and Handy Links
Captivate Wish Form/Bug Reporting Form
Adobe Certified Captivate Training
SorcerStone Blog
Captivate eBooks -
Multiple drag-and-drop completely broken in Mail 4.2
I've noticed this since I first installed Snow Leopard, but it's now becoming too annoying to ignore.
If I try to select multiple emails from my MobileMe inbox and drag them all at once to a folder in the MobileMe account, it only drags a single email. Thus, moving 10 emails requires dragging and dropping 10 times.
This showed up as soon as I installed Snow Leopard.
Does anybody have a work around or other advice?
Is this a know issue?
Thanks.causes mine to crash.
'SnowCrash'?
Maybe you are looking for
-
Http tool not connecting with the PI
Hii,, I have done http to soap scenario... but when i want to test from http tool (HTML file which i got from sdn) its not connecting with PI i given the right information in Header portion and copied my payload to html tool. when i press send button
-
CM Repository manager is not appearing for other users
Hi Friends, I have configured CM repository manager with the user having super admin role. After configuring it am able to see the KM content folder in the Content Administration->KM Content only with the user from where i have configured it. But i
-
Is there a way to recover files from a folder that has accidentally been overwritten?
Need help real bad coz I stand to lose a lot of articles I have written and could make up my portfolio...
-
Question on Passivation / Activation example in Dev Guide
Adf 11g Hello I'm loading some values into the session UserData in my application module PrepareSession. As I understand things I need to passivate/activate this information. However the example in the Fusion Dev Guide on page 39-19 for the passivati
-
Error in sqlj stub: invalid argument
Could you please help me with this? When I try to launch sqlj it always answer in the same way:" Error in sqlj stup: ivalid argument" even if I specify arguments that should be recognized. I am using WinNT 4.0 Server: Classpath: .;..;c:\sqlj\lib\tran