source: java/main/src/main/java/com/framsticks/gui/controls/ValueControl.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: 2.8 KB
Line 
1package com.framsticks.gui.controls;
2
3import org.apache.log4j.Logger;
4
5import com.framsticks.params.CastFailure;
6import com.framsticks.params.Flags;
7import com.framsticks.params.PrimitiveParam;
8import com.framsticks.params.ReassignResult;
9import com.framsticks.util.FramsticksException;
10import com.framsticks.util.swing.TooltipConstructor;
11
12/**
13 * @author Piotr Sniegowski
14 */
15@SuppressWarnings("serial")
16public abstract class ValueControl extends Control {
17        private static final Logger log =
18                Logger.getLogger(ValueControl.class);
19
20        /**
21         *
22         */
23        protected ValueControlListener listener;
24
25        public ValueControl(PrimitiveParam<?> primitiveParam) {
26                super(primitiveParam);
27
28                this.setToolTipText(new TooltipConstructor()
29                        .append("name", primitiveParam.getName())
30                        .append("id", primitiveParam.getId())
31                        .append("help", primitiveParam.getHelp())
32                        .append("def", primitiveParam.getDef(Object.class))
33                        .append("min", primitiveParam.getMin(Object.class))
34                        .append("max", primitiveParam.getMax(Object.class))
35                        .append("flags", Flags.write(primitiveParam.getFlags(), null))
36                        .append("group", primitiveParam.getGroup())
37                        .append("extra", primitiveParam.getExtra())
38                        .build())
39                        ;
40        }
41
42        @Override
43        public PrimitiveParam<?> getParam() {
44                return (PrimitiveParam<?>) param;
45        }
46
47        protected abstract void pushValueToUserInterfaceImpl(Object value);
48
49        /** I consider this an ugly solution, but I was unable to find proper
50         * action listeners for underlying swing controls, that would only fire
51         * on user change and on programmatic change.
52         */
53        protected boolean programmaticChange = false;
54
55        public void pushValueToUserInterface(Object value) {
56                programmaticChange = true;
57                pushValueToUserInterfaceImpl(value);
58                programmaticChange = false;
59        }
60
61        public abstract Object pullValueFromUserInterface();
62
63        public void setListener(ValueControlListener listener) {
64                this.listener = listener;
65        }
66
67        protected Object filterValueThroughConstraints(Object candidate) {
68                Object oldValue = pullValueFromUserInterface();
69                try {
70                        ReassignResult<?> res = getParam().reassign(candidate, oldValue);
71                        if (res.getFlags() != 0) {
72                                log.warn("filter of param " + param + " failed: " + Flags.write(res.getFlags(), "0"));
73                        }
74                        return res.getValue();
75                } catch (CastFailure e) {
76                        //TODO just throw here, but check where that function is being used
77                        handle(new FramsticksException().msg("invalid value in control").arg("param", param).arg("value", candidate).cause(e));
78                }
79                return oldValue;
80        }
81
82        /** This method is meant as a public interface to obtain current and correct value from control.
83         *
84         */
85        public final Object getCurrentValue() {
86                return filterValueThroughConstraints(pullValueFromUserInterface());
87        }
88
89        protected boolean notifyOfChange() {
90                if (!programmaticChange) {
91                        if (listener == null) {
92                                return true;
93                        }
94                        return listener.onChange(getCurrentValue());
95                }
96                return true;
97        }
98
99
100}
Note: See TracBrowser for help on using the repository browser.