source: java/main/src/main/java/com/framsticks/params/FramsClass.java @ 98

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

HIGHLIGHTS:

CHANGELOG:
Get data also on tree expansion.

Use nice framstick icon for empty nodes.

Update panel after reload if it is current.

Add shallow reload procedure.

Cut Gui prefix from several tree classes.

Bring back counter of GuiTreeNode?.

Use IdentityHashMap? were it is more appriopriate.

Remove TreeListener?.

Do not use TreeListener? in GUI.

Minor change.

Done migration to GuiTreeModel?.

BrowserTest? in that version always crashes frams.linux.

Move rendering implementation into GuiAbstractNode?.

Use hand-crafted list in GuiTreeNode?.

Generally, it would be a great place for WeakIdentityHashMap?
(but there is none in Java Collection Framework).

Remove superfluous logging.

Fix bug in GuiTreeNode?.

Use IdentityHashMap? instead of HashMap?.

Improve structure update.

Filter out invalid uids in UniqueListAccess?.

Improve TreeCellRenderer?.

Add filtering in TrackConsole?.

Improve TreeModel?.

More changes.

More improvements.

More changes.

Remove TreeNode?.

Support MetaNode? in the GuiTreeModel?.

Implement more in GuiTreeModel?.

Add CompositeParam? interface to FramsClass? and AccessInterface?.

Allow access by number to UniqueList?.

Add UidComparator?.

Use TreeMap? as a default accessee in unique list.

It keeps order of keys.

Introduce classes to use with new TreeModel?.

Another step.

Migrate from TreeNode? to Node in many places.

Remove some uses of TreeNode? as DefaultMutableTreeNode?.

Remove Path from TreeNode? interface.

Remove Path from TreeNode?.

Add Path recration from node feature.

Reworking TreeCellRenderer?.

Minor change of TreeOperations? interface.

Remove last methods from TreeNode?.

Another minor step.

Do not store reference to TreeAtFrame? in TreeNode?.

Add proxy exceptionHandler to StatusBar?.

Move panels management to TreeAtFrame?.

Store localChanges in the NodeAtFrame?.

More cleanup.

Move name computing to TreeCellRenderer?.

Move tooltip and icon computations to TreeCellRenderer?.

More dispatches removed.

Remove most dispatching from TreeNode?.

TreeNode? does not actually redispatch tasks.

Make Tree embedded in Browser use SwingDispatcher?.

Make lazy binding of Tree with Dispatcher.

Minor changes.

Organizational change in AbstractTree?.

Make AbstractTree? compose from Thread instead of inherit from it.

Make SwingDispatcher? and AtOnceDispatcher? Joinable compatible.

Add ListPanelProvider?.

Improve Controls readonly and enabled handling.

Properly pass ExceptionHandlers? in more places.

Make Tree.get accept ValueParam?.

  • This is to allow access number of list elements.

Remove not needed get redirection in ClientAtServer?.

Rename tryResolve to tryGet.

Unify tryResolveAndGet into tryResolve.

Remove resolveTop from Tree interface.

Make Tree.get accept Future<Path>.

Use get to implement resolveTop also in ObjectTree?.

Unify resolveTop and get in RemoteTree?.

Another minor step.

More minor changes in tree operations.

Minor organizational changes.

In RemoteTree? first fetch info for root.

Reworking resolving.

Minor changes.

Make ListAccess? return proxy iterators (instead of creating temporary collection).

Let AccessInterface? return Iterable<Param>.

Improve resolving.

More improvements.

First working completion in ManagedConsole?.

Rename resolve to resolveTop.

This reflects the actuall functionality.

Change semantic of tryResolve and tryResolveAndGet.

File size: 4.9 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.params.annotations.FramsClassAnnotation;
4import com.framsticks.params.annotations.ParamAnnotation;
5import com.framsticks.util.FramsticksException;
6import com.framsticks.util.lang.Containers;
7// import com.framsticks.util.FramsticksException;
8
9import java.util.*;
10
11import javax.annotation.Nonnull;
12import javax.annotation.concurrent.Immutable;
13
14import org.apache.log4j.Logger;
15
16/**
17 * The class FramsClass represents the class / schema of connected parameters
18 * (such as parameters within the class). It differs from C++ version by storing
19 * information about the class that parameters belong to.
20 *
21 * Based loosely on c++ class Param located in cpp/gdk/param.*
22 *
23 * @author Jarek Szymczak <name.surname@gmail.com>, Mateusz Jarus (please
24 *         replace name and surname with my personal data)
25 *
26 * @author Piotr Sniegowski
27 */
28@Immutable
29@FramsClassAnnotation(id = "class", name = "class")
30public class FramsClass {
31
32        private final static Logger log = Logger.getLogger(FramsClass.class);
33
34        protected final String id;
35
36        protected final String name;
37
38        protected final String description;
39
40        protected final List<Group> groups;
41
42        /** The param list (for accessing parameters by offset in O(1) time. */
43        protected final List<Param> paramList;
44
45        protected final List<CompositeParam> compositeParamList = new ArrayList<>();
46
47        /**
48         * The param entry map <parameterId, param> (for fast accessing of parameters
49         * by their name)
50         */
51        protected Map<String, Param> paramEntryMap = new HashMap<>();
52
53
54        @ParamAnnotation(id = "props", name = "props")
55        public List<Param> getParamEntries() {
56                return Collections.unmodifiableList(paramList);
57        }
58
59        public FramsClass(FramsClassBuilder builder) {
60
61                this.id = builder.getId();
62                this.name = builder.getName();
63                this.description = builder.getDescription();
64                this.groups = Containers.build(builder.groupBuilders);
65                this.paramList = builder.params;
66
67                for (Param param : paramList) {
68                        paramEntryMap.put(param.getId(), param);
69                        if (param instanceof CompositeParam) {
70                                compositeParamList.add((CompositeParam) param);
71                        }
72                }
73
74                log.trace("created framsclass " + this);
75
76        }
77
78        @ParamAnnotation(id = "desc")
79        public String getDescription() {
80                return description;
81        }
82
83        public int getGroupCount() {
84                return groups.size();
85        }
86
87        public Group getGroup(int groupNumber) {
88                return Containers.getFromList(groups, groupNumber, "group", this);
89        }
90
91        // /**
92        //  * Gets the group member.
93        //  *
94        //  * @param gi
95        //  *            the offset of group
96        //  * @param pi
97        //  *            the offset of member within a group
98        //  * @return the pi-th member of group gi
99        //  */
100        // public Param getGroupMember(int gi, int pi) {
101        //      if (gi < 0 || pi < 0 || gi >= groups.size()) {
102        //              return null;
103        //      }
104        //      Group group = groups.get(gi);
105        //      return (group != null ? group.getProperty(pi) : null);
106        // }
107
108        // /**
109        //  * Gets the group name.
110        //  *
111        //  * @param gi
112        //  *            the offset of group
113        //  * @return the group name
114        //  */
115        // public String getGroupName(int gi) {
116        //      if (gi < 0 || gi >= groups.size())
117        //              return null;
118        //      return groups.get(gi).name;
119        // }
120
121        @ParamAnnotation
122        public String getId() {
123                return id;
124        }
125
126        @ParamAnnotation
127        public String getName() {
128                return name;
129        }
130
131        public String getNiceName() {
132                return name != null ? name : id;
133        }
134
135        public @Nonnull <T extends Param> T castedParam(@Nonnull final Param param, @Nonnull final Class<T> type, Object name) {
136                if (param == null) {
137                        // return null;
138                        throw new FramsticksException().msg("param is missing").arg("name", name).arg("in", this);
139                }
140                if (!type.isInstance(param)) {
141                        // return null;
142                        throw new FramsticksException().msg("wrong type of param").arg("actual", param.getClass()).arg("requested", type).arg("in", this);
143                }
144                return type.cast(param);
145        }
146
147        /**
148         * Gets the param entry.
149         *
150         * @param i
151         *            the offset of parameter
152         * @return the param entry
153         */
154        public @Nonnull <T extends Param> T getParamEntry(final int i, @Nonnull final Class<T> type) {
155                return castedParam(getParam(i), type, i);
156        }
157
158        /**
159         * Gets the param entry.
160         *
161         * @param id
162         *            the getId of parameter
163         * @return the param entry
164         */
165        public @Nonnull <T extends Param> T getParamEntry(@Nonnull final String id, @Nonnull final Class<T> type) {
166                return castedParam(getParam(id), type, id);
167        }
168
169        public Param getParam(int i) {
170                if (i < 0 || i >= paramList.size()) {
171                        return null;
172                }
173                return paramList.get(i);
174        }
175
176        public Param getParam(String id) {
177                if (!paramEntryMap.containsKey(id)) {
178                        return null;
179                }
180                return paramEntryMap.get(id);
181        }
182
183        public int getParamCount() {
184                return paramList.size();
185        }
186
187        public final int getCompositeParamCount() {
188                return compositeParamList.size();
189        }
190
191        public final CompositeParam getCompositeParam(int i) {
192                return compositeParamList.get(i);
193        }
194
195        @Override
196        public String toString() {
197                return id + "(" + name + ")";
198        }
199
200        public static FramsClassBuilder build() {
201                return new FramsClassBuilder();
202        }
203
204}
Note: See TracBrowser for help on using the repository browser.