1 16 17 package com.buchuki.ensmer.builtin; 18 19 import com.buchuki.ensmer.*; 20 import com.buchuki.ensmer.input.event.semantic.*; 21 import com.buchuki.ensmer.object.Backend; 22 import com.buchuki.ensmer.text.TextInput; 23 import com.sun.j3d.utils.geometry.Text2D; 24 import java.awt.Font ; 25 import java.awt.event.KeyEvent ; 26 import java.io.Serializable ; 27 import javax.media.j3d.*; 28 import javax.vecmath.Color3f; 29 30 39 public class Container extends Backend { 40 41 45 public Container() { 46 area = EnsmerManager.instance().getAreaManager().newArea(); 47 setupCommands(); 48 } 49 50 56 public Container(Serializable data) { 57 AreaManager man = EnsmerManager.instance().getAreaManager(); 58 area = man.getArea((Long ) data); 59 setupCommands(); 60 } 61 62 67 @Override 68 public Serializable getSerializable() { 69 return area.getAreaID(); 70 } 71 72 75 public void setId(Long id) { 76 super.setId(id); 77 if (getConfigProperty("name") == null) { 78 setConfigProperty("name", ""); 79 } 80 } 81 82 88 public Area getArea() { 89 return area; 90 } 91 92 96 public void addSelectedObjects() { 97 Area current = EnsmerManager.instance().getAreaManager().getCurrentArea(); 98 for (Object obj : EnsmerManager.instance().getSelectionManager().getSelectedObjects()) { 99 Long id = (Long ) obj; 100 if (id != getId()) { 101 current.removeObject(id); 102 area.addObject(id); 103 area.setObjectPosition(id, SceneGraphUtils.randomPositionInFrontOfUser(area)); 104 } 105 } 106 fireChangeEvent(); 107 } 108 109 113 public void removeSelectedObjects() { 114 AreaManager man = EnsmerManager.instance().getAreaManager(); 115 SelectionManager sel = EnsmerManager.instance().getSelectionManager(); 116 if (man.getCurrentArea() != area) { 117 return; 118 } 119 Area prev = man.getArea(man.getHistoricalAreaID(1)); 120 if (prev == null || prev.isReadOnly()) { 121 return; 122 } 123 Object [] objs = sel.getSelectedObjects(); 124 for (Object obj : objs) { 125 Long id = (Long ) obj; 126 area.removeObject(id); 127 prev.addObject(id); 128 prev.setObjectPosition(id, SceneGraphUtils.randomPositionInFrontOfUser(prev)); 129 } 130 man.previousArea(); 131 for (Object obj : objs) { 132 sel.toggleSelection((Long ) obj); 133 } 134 } 135 136 140 public void lookInside() { 141 EnsmerManager.instance().getUserManager().getInputManager().systemMode(); 142 EnsmerManager.instance().getAreaManager().setCurrentArea(area.getAreaID()); 143 } 144 145 153 @Override 154 public static BranchGroup getRepresentation() { 155 Text2D text = new Text2D("Container", new Color3f(0f, .6f, .4f), "Times", 16, Font.BOLD); 156 Appearance app = text.getAppearance(); 157 PolygonAttributes poly = new PolygonAttributes(); 158 poly.setCullFace(poly.CULL_NONE); 159 app.setPolygonAttributes(poly); 160 BranchGroup ret = new BranchGroup(); 161 ret.addChild(text); 162 return ret; 163 } 164 165 168 private Area area; 169 170 175 private void setupCommands() { 176 177 EnsmerManager.instance().getAreaManager().addObjectListener( 178 new ObjectListener() { 179 public void objectStateChanged(ObjectEvent event) { 180 if (event.getObject() != getId()) { 181 return; 182 } 183 if (event.getAction() == ObjectEvent.EventType.OBJECT_DESTROYED) { 184 AreaManager man = EnsmerManager.instance().getAreaManager(); 185 man.removeArea(area.getAreaID()); 186 man.removeObjectListener(this); 187 } 188 } 189 }); 190 } 191 } 192 | Popular Tags |