1 16 17 package com.buchuki.ensmer.object; 18 19 import com.buchuki.ensmer.EnsmerManager; 20 import com.buchuki.ensmer.SelectionManager; 21 import com.buchuki.ensmer.input.ObjectInputManager; 22 import com.buchuki.ensmer.input.event.semantic.*; 23 import java.awt.event.ItemEvent ; 24 import java.awt.event.ItemListener ; 25 import java.util.Collection ; 26 import javax.media.j3d.Appearance; 27 import javax.media.j3d.Material; 28 29 36 public abstract class SelectableFrontend implements Frontend, ItemListener , FocusListener { 37 38 42 public SelectableFrontend() { 43 EnsmerManager.instance().getSelectionManager().addItemListener(this); 44 EnsmerManager.instance().getUserManager().getInputManager(). 45 getObjectManager().addFocusListener(this); 46 } 47 48 54 public void itemStateChanged(ItemEvent event) { 55 if (!event.getItem().equals(getBackend().getId())) { 56 return; 57 } 58 updateSelection(); 59 } 60 61 public void focusChanged(FocusEvent event) { 62 if (!event.getFocusedObject().equals(getBackend().getId())) { 63 return; 64 } 65 updateSelection(); 66 } 67 68 72 protected void setAppearanceCollection(Collection <Appearance> collection) { 73 this.appearanceNodes = collection; 74 updateSelection(); 75 } 76 77 80 private void updateSelection() { 81 if (appearanceNodes == null || appearanceNodes.isEmpty()) { 82 return; 83 } 84 SelectionManager sel = EnsmerManager.instance().getSelectionManager(); 85 ObjectInputManager obj = EnsmerManager.instance().getUserManager().getInputManager().getObjectManager(); 86 if (getBackend().getId().equals(obj.getFocusedObject())) { 87 for (Appearance app : appearanceNodes) { 88 Material matt = app.getMaterial(); 89 if (matt != null) { 90 matt.setEmissiveColor(.4f, .4f, 1.0f); 91 } 92 } 93 } 94 else if (sel.isSelected(getBackend().getId())) { 95 for (Appearance app : appearanceNodes) { 96 Material matt = app.getMaterial(); 97 if (matt != null) { 98 matt.setEmissiveColor(.5f, .5f, .5f); 99 } 100 } 101 } 102 else { 103 for (Appearance app : appearanceNodes) { 104 Material matt = app.getMaterial(); 105 if (matt != null) { 106 matt.setEmissiveColor(0, 0, 0); 107 } 108 } 109 } 110 } 111 112 115 public void destroy() { 116 EnsmerManager.instance().getSelectionManager().removeItemListener(this); 117 EnsmerManager.instance().getUserManager().getInputManager(). 118 getObjectManager().removeFocusListener(this); 119 } 120 121 125 private Collection <Appearance> appearanceNodes; 126 } 127 | Popular Tags |