source: java/main/src/main/java/com/framsticks/params/PropertiesAccess.java @ 101

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

HIGHLIGHTS:

  • improve tree side notes
  • improve GUI layout
  • add foldable list of occured events to EventControl?
  • improve automatic type conversion in proxy listeners
  • implement several Access functionalities as algorithms independent of Access type
  • introduce draft base classes for distributed experiments
  • automatically register dependant Java classes to FramsClass? registry
  • add testing prime experiment and configuration
  • simplify and improve task dispatching

CHANGELOG:
Improve task dispatching in RemoteTree?.

GUI no longer hangs on connection problems.

Make all dispatchers joinables.

Refactorize Thread dispatcher.

Remove Task and PeriodicTask?.

Use Java utilities in those situations.

Reworking tasks dispatching.

Fix bug in EventControl? listener dispatching.

Minor improvements.

Add testing configuration for ExternalProcess? in GUI.

More improvement to prime.

Support for USERREADONLY in GUI.

Add that flag to various params in Java classes.

Remove redundant register clauses from several FramsClassAnnotations?.

Automatically gather and register dependant classes.

Add configuration for prime.

Improve Simulator class.

Add prime.xml configuration.

Introduce draft Experiment and Simulator classes.

Add prime experiment tests.

Enclose typical map with listeners into SimpleUniqueList?.

Needfile works in GUI.

Improve needfile handling in Browser.

More improvement with NeedFile?.

Implementing needfile.

Update test.

Rename ChangeEvent? to TestChangeEvent?.

Automatic argument type search in RemoteTree? listeners.

MultiParamLoader? uses AccessProvider?. By default old implementation
enclosed in AccessStash? or Registry.

Minor changes.

Rename SourceInterface? to Source.

Also improve toString of File and ListSource?.

Remove unused SimpleSource? class.

Add clearing in HistoryControl?.

Show entries in table at EventControl?.

Improve EventControl?.

Add listeners registration to EventControl?.

Add foldable table to HistoryControl?.

Add control row to Procedure and Event controls.

Improve layout of controls.

Another minor change to gui layout.

Minor improvement in the SliderControl?.

Minor changes.

Move ReflectionAccess?.Backend to separate file.

It was to cluttered.

Cleanup in ReflectionAccess?.

Move setMin, setMax, setDef to AccessOperations?.

Extract loading operation into AccessOperations?.

Append Framsticks to name of UnsupportedOperationException?.

The java.lang.UnsupportedOperationException? was shadowing this class.

Rename params.Util to params.ParamsUtil?.

Several improvements.

Minor changes.

Implement revert functionality.

Improve local changes management.

Minor improvement.

Remove methods rendered superfluous after SideNoteKey? improvement.

Improve SideNoteKey?.

It is now generic type, so explicit type specification at
call site is no more needed.

Introduce SideNoteKey? interface.

Only Objects implementing that key may be used as side note keys.

Minor improvements.

Use strings instead of ValueControls? in several gui mappings.

File size: 3.4 KB
Line 
1package com.framsticks.params;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import com.framsticks.params.types.EventParam;
7import com.framsticks.params.types.ProcedureParam;
8
9
10/**
11 * The Class PropertiesAccess.
12 *
13 * @author Jarek Szymczak <name.surname@gmail.com> (please replace name and
14 *         surname with my personal data)
15 *
16 * @author Piotr Śniegowski
17 */
18public class PropertiesAccess extends SimpleAbstractAccess {
19
20        public Map<String, Object> properties;
21
22        @Override
23        public Map<String, Object> createAccessee() {
24                return PropertiesAccess.createPropertiesMap();
25        }
26
27        public static Map<String, Object> createPropertiesMap() {
28                return new HashMap<String, Object>();
29        }
30
31        public PropertiesAccess(FramsClass framsClass) {
32                super(framsClass);
33        }
34
35        @Override
36        public void clearValues() {
37                assert properties != null;
38                properties.clear();
39        }
40
41        @Override
42        public <T> T get(ValueParam param, Class<T> type) {
43                assert properties != null;
44                assert param != null;
45                Object object = properties.get(param.getId());
46                if (object != null) {
47                        try {
48                                return type.cast(object);
49                        } catch (ClassCastException e) {
50                                throw (ClassCastException) new ClassCastException("property " + param + " type is " + object.getClass().getName() + ", not " + type.getName()).initCause(e);
51                        }
52                }
53                try {
54                        return param.getDef(type);
55                } catch (ClassCastException e) {
56                        throw (ClassCastException) new ClassCastException("default value of property " + param + " is not of type " + type.getName()).initCause(e);
57                }
58
59        }
60
61        @Override
62        protected <T> void internalSet(ValueParam param, T value) {
63                properties.put(param.getId(), value);
64        }
65
66        /**
67         * Sets the new values to operate on. It does not check whether the values
68         * which are set through this method are correct. If set values are not
69         * correct exceptions might occurred while getting / setting the parameters
70         * values
71         *
72         * @param object
73         *            the properties with parameters values
74         */
75        @SuppressWarnings("unchecked")
76        @Override
77        public PropertiesAccess select(Object object) {
78                properties = ParamsUtil.selectObjectForAccess(this, object, Map.class);
79                return this;
80        }
81
82        /** covariant */
83        @Override
84        public Map<String, Object> getSelected() {
85                return properties;
86        }
87
88        @Override
89        public PropertiesAccess cloneAccess() {
90                return new PropertiesAccess(framsClass);
91        }
92
93        @Override
94        public void tryAutoAppend(Object object) {
95                throw new InvalidOperationException();
96        }
97
98        @Override
99        public Object call(String id, Object[] arguments) {
100                throw new InvalidOperationException().msg("properties access does not support calling methods").arg("id", id);
101        }
102
103        @Override
104        public Object call(ProcedureParam param, Object[] arguments) {
105                throw new InvalidOperationException().msg("properties access does not support calling methods").arg("param", param);
106        }
107
108        @Override
109        public void reg(EventParam param, EventListener<?> listener) {
110                throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this);
111        }
112
113        @Override
114        public void regRemove(EventParam param, EventListener<?> listener) {
115                throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this);
116        }
117
118        @Override
119        public String toString() {
120                StringBuilder b = new StringBuilder();
121                b.append(framsClass);
122                if (getSelected() != null) {
123                        b.append("(").append(getSelected().size()).append(")");
124                }
125                return b.toString();
126        }
127}
Note: See TracBrowser for help on using the repository browser.