private boolean performCardDrop(Card[] cards) {
int location = getCurrentLocation();
Card targetCard = null;
CardGroup targetGroup = null;
// MOVE/COPY card on card
if( getCurrentTarget() instanceof Card ) {
targetCard = (Card)getCurrentTarget();
targetGroup = (CardGroup)targetCard.getParent();
// MOVE/COPY card on group
} else if( getCurrentTarget() instanceof CardGroup ) {
targetGroup = (CardGroup)getCurrentTarget();
if( location == LOCATION_BEFORE) {
Deck deck = (Deck)targetGroup.getParent();
CardGroup prior = deck.getPrior(targetGroup);
if( prior != null) {
targetGroup = prior;
location = LOCATION_AFTER;
}
} else {
location = LOCATION_BEFORE;
}
} else
return false;
for (Card card : cards) {
List<Card> toInsert = new ArrayList<Card>(4);
CardGroup sourceGroup = (CardGroup)card.getParent();
if(getCurrentOperation() == DND.DROP_COPY) {
// check for existing identical cards
List<Card> targetList = targetGroup.lookup(card);
if(!targetList.isEmpty()) {
targetCard = targetList.get(0);
location = LOCATION_AFTER;
}
// need to remove one copy from sourceGroup
// use dragged card
if( sourceGroup != null )
sourceGroup.remove( card );
toInsert.add( card );
} else if(getCurrentOperation() == DND.DROP_MOVE) {
// need to remove all copies from sourceGroup
// add to dragged cards
if( sourceGroup != null ) {
toInsert.addAll( sourceGroup.lookup( card ) );
sourceGroup.removeAll( toInsert );
}
}
if( location == LOCATION_BEFORE ) {
targetGroup.addAllBefore( toInsert, targetCard );