1 16 17 package com.buchuki.ensmer.input.command; 18 19 import com.buchuki.ensmer.Area; 20 import com.buchuki.ensmer.AreaManager; 21 import com.buchuki.ensmer.EnsmerManager; 22 import com.buchuki.ensmer.SceneGraphUtils; 23 import com.buchuki.ensmer.SelectionManager; 24 import com.buchuki.ensmer.input.event.EnsmerInputEvent; 25 26 33 public class RemoveFromAreaCommand implements Command { 34 35 38 public RemoveFromAreaCommand(Long areaID) { 39 this.areaID = areaID; 40 } 41 42 47 public boolean execute(EnsmerInputEvent event) { 48 EnsmerManager ens = EnsmerManager.instance(); 49 AreaManager man = ens.getAreaManager(); 50 SelectionManager sel = ens.getSelectionManager(); 51 52 Area area = man.getArea(areaID); 53 if (man.getCurrentArea() != area) { 54 return false; 55 } 56 Area prev = man.getArea(man.getHistoricalAreaID(1)); 57 if (prev == null || prev.isReadOnly()) { 58 return false; 59 } 60 Object [] objs = sel.getSelectedObjects(); 61 for (Object obj : objs) { 62 Long id = (Long ) obj; 63 area.removeObject(id); 64 prev.addObject(id); 65 prev.setObjectPosition(id, SceneGraphUtils.randomPositionInFrontOfUser(prev)); 66 } 67 man.previousArea(); 68 for (Object obj : objs) { 69 sel.toggleSelection((Long ) obj); 70 } 71 return true; 72 } 73 74 78 private Long areaID; 79 } 80 | Popular Tags |