source: java/main/src/main/java/com/framsticks/gui/ObjectPanel.java @ 105

Last change on this file since 105 was 105, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • import refactorization: move Tree, Path, etc.

from core to structure package

  • initial serialization implementation
  • improve PrimeExperiment? test
  • many organizational changes and convenience improvements

CHANGELOG:
Make registry in AbstractTree? final.

Move most classes from core to structure package.

Minor changes.

Switch names of Future and FutureHandler?.

Rename ExceptionResultHandler? to ExceptionHandler?.

Rename ExceptionHandler? to ExceptionDispatcherHandler?.

Fix bug in ParamCandidate? cache.

Add missing synchronization to the BufferedDispatcher?.

Develop @Serialized support.

Rework serialization further.

Add serialization/deserialization interface to ValueParam?.

Move getStorageType and isNumeric from Param down to params hierarchy.

Minor changes.

Improve param type induction.

Add TestSerializedClass? for testing new serialization.

Add info files gor GenePool? and Population.

Add standard.expt exemplary netfile.

Add type name field to PropertiesObject?.

Use PropertiesObject? for PropertiesAccess? instead of ordinary map.

Hide getFramsClass is several more places.

More unification accross FramsClass?, Access and Path.

Add ParamCollection?.

Simplify interface for getting params from FramsClass?, Access
or Path.

Make Access.call() interface variadic.

Add arguments(args) convenience wrapper around new Object[] {args}.

Upgrade to apache.commons.lang version 3.1

Minor improvement with Response constructors.

Develop proper result printing in ClientAtServer?.

Add experimentNetsave to PrimeExperiment?.

File size: 3.2 KB
Line 
1package com.framsticks.gui;
2
3import com.framsticks.gui.controls.Control;
4import com.framsticks.gui.controls.ControlOwner;
5import com.framsticks.gui.controls.ValueControl;
6import com.framsticks.params.Access;
7import com.framsticks.params.Param;
8
9import org.apache.logging.log4j.Logger;
10import org.apache.logging.log4j.LogManager;
11
12import javax.swing.*;
13
14import java.util.Collection;
15import java.util.HashMap;
16import java.util.Map;
17
18import static com.framsticks.structure.TreeOperations.*;
19import static com.framsticks.util.lang.Containers.filterInstanceof;
20
21import com.framsticks.structure.Path;
22import com.framsticks.util.FramsticksException;
23
24
25@SuppressWarnings("serial")
26public class ObjectPanel extends ModifiablePanel implements ControlOwner {
27
28        private static final Logger log = LogManager.getLogger(ObjectPanel.class);
29
30        final protected Map<String, Control> controls = new HashMap<String, Control>();
31        final protected Map<String, ValueControl> valueControls = new HashMap<String, ValueControl>();
32
33        protected final JPanel contentPanel;
34        protected final JScrollPane scrollPane;
35
36        public ObjectPanel(TreePanel.Parameters parameters, Collection<Param> params) {
37                super(parameters);
38
39                contentPanel = new JPanel();
40                scrollPane = new JScrollPane(contentPanel);
41
42                setupContentComponent(scrollPane);
43
44                Gui.fillWithControls(this, contentPanel, params, controls, Control.class);
45                setName(framsClass.getId());
46
47                for (final ValueControl c : filterInstanceof(controls.values(), ValueControl.class)) {
48                        valueControls.put(c.getParam().getId(), c);
49                        c.setUserEnabled(true);
50                }
51
52                contentPanel.add(Box.createVerticalGlue());
53                this.revalidate();
54        }
55
56        @Override
57        protected void applyChanges() {
58                assert frame.isActive();
59                assert currentPath != null;
60                treeAtFrame.pushUserChangesToTree(currentPath);
61                refreshControlButtons();
62        }
63
64
65        @Override
66        protected void revertChanges() {
67                assert currentPath != null;
68                removeSideNote(currentPath, treeAtFrame.getUserChangesKey());
69                pullValuesFromLocalToUser(bindAccess(currentPath));
70        }
71
72        @Override
73        public void pullValuesFromLocalToUser(Access access) {
74                assert currentPath != null;
75                log.debug("refreshing components");
76
77                UserChanges userChanges = getSideNote(currentPath, treeAtFrame.getUserChangesKey());
78
79
80                for (Map.Entry<String, ValueControl> e : valueControls.entrySet()) {
81                        String id = e.getKey();
82                        Object value;
83                        if (userChanges != null && userChanges.changes.containsKey(id)) {
84                                value = userChanges.changes.get(id);
85                        } else {
86                                value = access.get(id, Object.class);
87                        }
88
89                        e.getValue().pushValueToUserInterface(value);
90                }
91
92                for (Map.Entry<String, Control> e : controls.entrySet()) {
93                        e.getValue().refreshState();
94                }
95
96                refreshControlButtons();
97                // ObjectPanel.this.revalidate();
98        }
99
100        @Override
101        public String getTitle() {
102                return "Properties";
103        }
104
105        @Override
106        public void handle(FramsticksException exception) {
107                frame.handle(exception);
108        }
109
110        @Override
111        public Path getCurrentPath() {
112                return super.getCurrentPath();
113        }
114
115        @Override
116        public boolean onValueChange(ValueControl control, Object newValue) {
117                if (currentPath == null) {
118                        return true;
119                }
120                boolean result = treeAtFrame.changeValue(currentPath.assureResolved().getTopObject(), control, newValue);
121                refreshControlButtons();
122                return result;
123        }
124
125}
Note: See TracBrowser for help on using the repository browser.