- Timestamp:
- 06/22/13 21:51:33 (11 years ago)
- Location:
- java/main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main
-
Property
svn:ignore
set to
target
-
Property
svn:ignore
set to
-
java/main/src/main/java/com/framsticks/gui/ObjectPanel.java
r77 r84 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.gui.co mponents.Control;4 import com.framsticks.gui.co mponents.ValueControl;5 import com.framsticks.gui.co mponents.ValueControlListener;3 import com.framsticks.gui.controls.Control; 4 import com.framsticks.gui.controls.ValueControl; 5 import com.framsticks.gui.controls.ValueControlListener; 6 6 import com.framsticks.params.AccessInterface; 7 import com.framsticks.params.types.CompositeParam;8 7 import com.framsticks.params.Param; 9 import com.framsticks.util.Strings; 8 import com.framsticks.params.ValueParam; 9 10 10 import org.apache.log4j.Logger; 11 11 12 12 import javax.swing.*; 13 import java.awt.*;14 13 import java.util.Collection; 15 14 import java.util.HashMap; 16 15 import java.util.Map; 17 import java.util.List;16 import static com.framsticks.util.lang.Containers.filterInstanceof; 18 17 19 18 @SuppressWarnings("serial") 20 public class ObjectPanel extends com.framsticks.gui.Panel {19 public class ObjectPanel extends ModifiablePanel { 21 20 22 private static final Logger LOGGER= Logger.getLogger(ObjectPanel.class.getName());21 private static final Logger log = Logger.getLogger(ObjectPanel.class.getName()); 23 22 24 23 final protected Map<Param, Control> components = new HashMap<Param, Control>(); 25 final protected Map< Param, ValueControl> valueComponents = new HashMap<Param, ValueControl>();24 final protected Map<ValueParam, ValueControl> valueControls = new HashMap<ValueParam, ValueControl>(); 26 25 27 public static void fillWithComponents(JPanel panel, Collection<Param> params, Map<Param, Control> components) { 28 for (Param param : params) { 29 if (param.isUserHidden()) { 30 continue; 31 } 32 assert !(param instanceof CompositeParam); 33 Control control = Control.createSuitable(param); 34 if (control != null) { 35 LOGGER.debug("add component for " + param); 36 JPanel line = new JPanel(); 37 line.setLayout(new BoxLayout(line, BoxLayout.LINE_AXIS)); 38 line.setAlignmentX(LEFT_ALIGNMENT); 39 JLabel label = new JLabel(Strings.notEmpty(param.getName()) ? param.getName() : "? (" + param.getId() + ")"); 40 label.setToolTipText(label.getText()); 41 label.setHorizontalAlignment(JLabel.RIGHT); 42 Dimension labelSize = new Dimension(150, 30); 43 label.setMaximumSize(labelSize); 44 label.setMinimumSize(labelSize); 45 label.setPreferredSize(labelSize); 46 line.add(label); 47 line.add(Box.createRigidArea(new Dimension(8, 0))); 48 line.add(control); 49 line.revalidate(); 50 panel.add(line); 51 panel.add(Box.createRigidArea(new Dimension(0, 8))); 52 //component.setAlignmentX(LEFT_ALIGNMENT); 53 components.put(param, control); 54 continue; 55 } 56 LOGGER.error("component for param " + param + " of type " + param.getClass().getSimpleName() + " was not added"); 57 } 26 public ObjectPanel(Panel.Parameters parameters, Collection<Param> params) { 27 super(parameters); 58 28 59 }29 Gui.fillWithControls(contentPanel, params, components); 60 30 61 public ObjectPanel(EndpointAtFrame endpoint, String className, List<Param> params) { 62 super(endpoint, className); 63 64 fillWithComponents(contentPanel, params, components); 65 66 for (Map.Entry<Param, Control> e : components.entrySet()) { 67 Control control = e.getValue(); 68 Param param = e.getKey(); 69 if (control instanceof ValueControl) { 70 final ValueControl valueComponent = (ValueControl) control; 71 valueComponents.put(param, valueComponent); 72 valueComponent.setListener(new ValueControlListener() { 73 @Override 74 public boolean onChange(Object newValue) { 75 if (currentTreeNode == null) { 76 return true; 77 } 78 boolean result = currentTreeNode.changeValue(valueComponent, newValue); 79 refreshControlButtons(); 80 return result; 31 for (final ValueControl c : filterInstanceof(components.values(), ValueControl.class)) { 32 valueControls.put(c.getParam(), c); 33 c.setListener(new ValueControlListener() { 34 @Override 35 public boolean onChange(Object newValue) { 36 if (currentTreeNode == null) { 37 return true; 81 38 } 82 }); 83 } 39 boolean result = currentTreeNode.changeValue(c, newValue); 40 refreshControlButtons(); 41 return result; 42 } 43 }); 84 44 } 85 45 contentPanel.add(Box.createVerticalGlue()); … … 91 51 assert frame.isActive(); 92 52 assert currentTreeNode != null; 93 currentTreeNode. applyChanges();53 currentTreeNode.pushLocalChanges(); 94 54 } 95 55 96 56 protected void refreshControlButtons() { 97 57 assert frame.isActive(); 98 applyButton.setEnabled(currentTreeNode.changedValues != null); 58 applyButton.setEnabled(currentTreeNode.localChanges != null); 59 } 60 61 protected static void fillControlsWithValues(Map<ValueControl, Object> map) { 99 62 } 100 63 101 64 @Override 102 public void refreshComponents(AccessInterface access) {103 assert currentTreeNode.path.getInstance().isActive();104 assert currentTreeNode != null;105 LOGGER.debug("refreshing components");65 public void pullValuesFromLocalToUser(AccessInterface access) { 66 assert currentTreeNode != null; 67 assert currentTreeNode.path.getInstance().isActive(); 68 log.debug("refreshing components"); 106 69 107 final Map<ValueControl, Object> values = new HashMap<ValueControl, Object>(); 108 for (ValueControl vc : valueComponents.values()) { 109 Object value = access.get(vc.getParam().getId(), Object.class); 110 values.put(vc, value); 111 } 70 final Map<ValueControl, Object> values = new HashMap<ValueControl, Object>(); 71 for (Map.Entry<ValueParam, ValueControl> e : valueControls.entrySet()) { 72 values.put(e.getValue(), access.get(e.getKey().getId(), Object.class)); 73 } 112 74 113 frame.invokeLater(new Runnable() { 114 @Override 115 public void run() { 116 for (Map.Entry<ValueControl, Object> e : values.entrySet()) { 117 e.getKey().setValue(e.getValue()); 118 } 119 if (currentTreeNode.changedValues != null) { 120 for (Map.Entry<ValueControl, Object> e : currentTreeNode.changedValues.entrySet()) { 121 e.getKey().setValue(e.getValue()); 75 frame.invokeLater(new Runnable() { 76 @Override 77 public void run() { 78 if (currentTreeNode.localChanges != null) { 79 for (Map.Entry<ValueControl, Object> e : currentTreeNode.localChanges.entrySet()) { 80 values.put(e.getKey(), e.getValue()); 122 81 } 123 82 } 83 for (Map.Entry<ValueControl, Object> e : values.entrySet()) { 84 e.getKey().pushValueToUserInterface(e.getValue()); 85 } 124 86 refreshControlButtons(); 125 126 127 87 ObjectPanel.this.revalidate(); 88 } 89 }); 128 90 129 91 } 130 92 93 @Override 94 public String getTitle() { 95 return "Properties"; 96 } 131 97 132 98 133 /*public void updateValue() {134 //assert panel.getFrame().isActive();99 // public void updateValue() { 100 // //assert panel.getFrame().isActive(); 135 101 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 }*/102 // final Node n = panel.getCurrentNode(); 103 // panel.getBrowser().getManager().invokeLater(new Runnable() { 104 // @Override 105 // public void run() { 106 // Object v = n.getAccess().get(param, Object.class); 107 // if (v == null) { 108 // v = param.getDef(Object.class); 109 // } 110 // final Object fv = v; 111 // panel.getBrowser().invokeLater(new Runnable() { 112 // @Override 113 // public void run() { 114 // setValueImpl(fv); 115 // } 116 // }); 117 // } 118 // }); 119 // } 154 120 155 121 }
Note: See TracChangeset
for help on using the changeset viewer.