- Timestamp:
- 07/14/13 23:20:04 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/gui/ObjectPanel.java
r100 r101 5 5 import com.framsticks.gui.controls.ControlOwner; 6 6 import com.framsticks.gui.controls.ValueControl; 7 import com.framsticks.gui.controls.ValueControlListener;8 7 import com.framsticks.params.Access; 9 8 import com.framsticks.params.Param; 10 import com.framsticks.params.ValueParam;11 9 12 10 import org.apache.logging.log4j.Logger; … … 16 14 17 15 import java.util.Collection; 18 import java.util. IdentityHashMap;16 import java.util.HashMap; 19 17 import java.util.Map; 20 18 import static com.framsticks.util.lang.Containers.filterInstanceof; 21 19 22 20 import com.framsticks.util.FramsticksException; 21 22 import static com.framsticks.core.TreeOperations.*; 23 23 24 24 @SuppressWarnings("serial") … … 27 27 private static final Logger log = LogManager.getLogger(ObjectPanel.class); 28 28 29 final protected Map< Param, Control> components = new IdentityHashMap<Param, Control>();30 final protected Map< ValueParam, ValueControl> valueControls = new IdentityHashMap<ValueParam, ValueControl>();29 final protected Map<String, Control> controls = new HashMap<String, Control>(); 30 final protected Map<String, ValueControl> valueControls = new HashMap<String, ValueControl>(); 31 31 32 32 protected final JPanel contentPanel; … … 38 38 contentPanel = new JPanel(); 39 39 scrollPane = new JScrollPane(contentPanel); 40 contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS)); 40 41 41 setupContentComponent(scrollPane); 42 42 43 Gui.fillWithControls(this, params, components, Control.class);43 Gui.fillWithControls(this, contentPanel, params, controls, Control.class); 44 44 setName(framsClass.getId()); 45 45 46 for (final ValueControl c : filterInstanceof(co mponents.values(), ValueControl.class)) {47 valueControls.put(c.getParam() , c);46 for (final ValueControl c : filterInstanceof(controls.values(), ValueControl.class)) { 47 valueControls.put(c.getParam().getId(), c); 48 48 c.setUserEnabled(true); 49 c.setListener(new ValueControlListener() {50 @Override51 public boolean onChange(Object newValue) {52 if (currentPath == null) {53 return true;54 }55 boolean result = treeAtFrame.changeValue(currentPath.assureResolved().getTopObject(), c, newValue);56 refreshControlButtons();57 return result;58 }59 });60 49 } 61 50 … … 68 57 assert frame.isActive(); 69 58 assert currentPath != null; 70 treeAtFrame.pushLocalChanges(currentPath); 59 treeAtFrame.pushUserChangesToTree(currentPath); 60 refreshControlButtons(); 71 61 } 72 62 73 protected void refreshControlButtons() { 74 assert frame.isActive(); 75 applyButton.setEnabled(treeAtFrame.hasLocalChanges(currentPath.getTopObject())); 63 64 @Override 65 protected void revertChanges() { 66 assert currentPath != null; 67 removeSideNote(currentPath, treeAtFrame.getUserChangesKey()); 68 pullValuesFromLocalToUser(bindAccess(currentPath)); 76 69 } 77 70 … … 81 74 log.debug("refreshing components"); 82 75 83 final Map<ValueControl, Object> values = new IdentityHashMap<ValueControl, Object>(); 84 for (Map.Entry<ValueParam, ValueControl> e : valueControls.entrySet()) { 85 values.put(e.getValue(), access.get(e.getKey().getId(), Object.class)); 76 UserChanges userChanges = getSideNote(currentPath, treeAtFrame.getUserChangesKey()); 77 78 79 for (Map.Entry<String, ValueControl> e : valueControls.entrySet()) { 80 String id = e.getKey(); 81 Object value; 82 if (userChanges != null && userChanges.changes.containsKey(id)) { 83 value = userChanges.changes.get(id); 84 } else { 85 value = access.get(id, Object.class); 86 } 87 88 e.getValue().pushValueToUserInterface(value); 86 89 } 87 90 88 89 NodeAtFrame nodeAtFrame = treeAtFrame.getLocalInfo(currentPath.getTopObject()); 90 if (nodeAtFrame != null) { 91 for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) { 92 values.put(e.getKey(), e.getValue()); 93 } 91 for (Map.Entry<String, Control> e : controls.entrySet()) { 92 e.getValue().refreshState(); 94 93 } 95 94 96 for (Map.Entry<ValueControl, Object> e : values.entrySet()) {97 e.getKey().pushValueToUserInterface(e.getValue());98 }99 95 refreshControlButtons(); 100 ObjectPanel.this.revalidate(); 101 96 // ObjectPanel.this.revalidate(); 102 97 } 103 98 … … 105 100 public String getTitle() { 106 101 return "Properties"; 107 }108 109 @Override110 public JPanel getPanelForControls() {111 return contentPanel;112 102 } 113 103 … … 122 112 } 123 113 114 @Override 115 public boolean onValueChange(ValueControl control, Object newValue) { 116 if (currentPath == null) { 117 return true; 118 } 119 boolean result = treeAtFrame.changeValue(currentPath.assureResolved().getTopObject(), control, newValue); 120 refreshControlButtons(); 121 return result; 122 } 123 124 124 }
Note: See TracChangeset
for help on using the changeset viewer.