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

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

HIGHLIGTS:

  • complete events implementation
  • add CLI in Java Framsticks server
  • add automatic registration for events in GUI
  • improve objects fetching (object are never overwritten with new instances)
  • properly react for ListChange? events
  • add ListPanel? with table view
    • columns to be shown may be statically specified in configuration
    • currently modyfying data through tables is not available
  • improve maven configuration
    • configuration file may be specified without touching pom.xml

CHANGELOG:
Extract constants from Flags into ParamFlags? and SetStateFlags?.

Extract flags I/O to FlagsUtils? class.

Configured maven to exec given resource configuration.

For example:
mvn exec:exec -Dframsticks.config=/configs/managed-console.xml

Cleanup pom.xml

Rename ObjectTree? to LocalTree? (also make LocalTree? and RemoteTree? final).

Minor change.

Add maximum number of columns in ListPanelProvider?.

Improve ColumnsConfig? interpretation.

Automatically fill FramsClass?.name if trying to construct empty.

Improve identitifer case mangling in XmlLoader?.

Introduce configurable ColumnsConfig?.

Draft working version of ListPanel?.

Table is being shown (although empty).

More improvements to table building.

Move some functionality from Frame to TreeModel?.

Move tree classes in gui to separate package.

Remove old table related classes.

Add draft implementation of TableModel?.

Redirect ParamBuilder?.forAccess to AccessInterface?.

Optimize ParamBuilder?.forAccess()

Do not clear list when loading.

Do not load fetched values directly.

Implement different AccessInterface? copying policy.

Optimize fetching values routine.

Remove Mode enum (work out get semantics).

Some improvements to ListChange? handling.

Improve UniqueListAccess?.

Add reaction for ListChanges? in the TreeNode?.

EventListeners? are being added in the TreeNode?.

Listeners for ListParams? are now very naive (they download
whole list).

Automatially register on events in GUI.

Events are working in RemoteTree? and Server.

Move listeners to the ClientSideManagedConnection?.

Remove old classes responsible for event subscriptions.

Improve event reading.

Improve events handling at server side.

Add register attribute in FramsClassAnnotation?
to automatically also register other classes.

Registering events works.

Setup for remote listeners registration.

More improvements.

Minor changes.

Add rootTree to the ClientAtServer?.

Moving CLI to the ClientAtServer?.

Fix bug: use Void.TYPE instead of Void.class

More development around CLI.

  • Improve Path resolving.

Add synthetic root to ObjectTree?.

It is needed to allow sybling for the original root
that would containg CLI.

Some work with registering events in RemoteTree?.

Draft implementation of listener registering in RemoteTree?.

Support events registration in the ObjectTree?.

Add events support to ReflectionAccess?.

EventParam? is recognized by ParamCandidate?.

Prepare interface for Events across project.

Add EventListener? and API for listeners in Tree.

File size: 3.5 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.gui.controls.ValueControlListener;
7import com.framsticks.params.AccessInterface;
8import com.framsticks.params.Param;
9import com.framsticks.params.ValueParam;
10
11import org.apache.log4j.Logger;
12
13import javax.swing.*;
14import javax.swing.tree.TreePath;
15
16import java.util.Collection;
17import java.util.IdentityHashMap;
18import java.util.Map;
19import static com.framsticks.util.lang.Containers.filterInstanceof;
20
21import com.framsticks.util.FramsticksException;
22
23@SuppressWarnings("serial")
24public class ObjectPanel extends ModifiablePanel implements ControlOwner {
25
26        private static final Logger log = Logger.getLogger(ObjectPanel.class);
27
28        final protected Map<Param, Control> components = new IdentityHashMap<Param, Control>();
29        final protected Map<ValueParam, ValueControl> valueControls = new IdentityHashMap<ValueParam, ValueControl>();
30
31        protected final JPanel contentPanel;
32        protected final JScrollPane scrollPane;
33
34        public ObjectPanel(Panel.Parameters parameters, Collection<Param> params) {
35                super(parameters);
36
37                contentPanel = new JPanel();
38                scrollPane = new JScrollPane(contentPanel);
39                contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS));
40                setupContentComponent(scrollPane);
41
42                Gui.fillWithControls(this, params, components, Control.class);
43                setName(framsClass.getId());
44
45                for (final ValueControl c : filterInstanceof(components.values(), ValueControl.class)) {
46                        valueControls.put(c.getParam(), c);
47                        c.setUserEnabled(true);
48                        c.setListener(new ValueControlListener() {
49                                @Override
50                                public boolean onChange(Object newValue) {
51                                        if (currentTreePath == null) {
52                                                return true;
53                                        }
54                                        boolean result = treeAtFrame.changeValue(currentTreePath, c, newValue);
55                                        refreshControlButtons();
56                                        return result;
57                                }
58                        });
59                }
60
61                contentPanel.add(Box.createVerticalGlue());
62                this.revalidate();
63        }
64
65        @Override
66        protected void applyChanges() {
67                assert frame.isActive();
68                assert currentTreePath != null;
69                treeAtFrame.pushLocalChanges(currentTreePath);
70        }
71
72        protected void refreshControlButtons() {
73                assert frame.isActive();
74                applyButton.setEnabled(treeAtFrame.hasLocalChanges(currentTreePath));
75        }
76
77        protected static void fillControlsWithValues(Map<ValueControl, Object> map) {
78        }
79
80        @Override
81        public void pullValuesFromLocalToUser(AccessInterface access) {
82                assert currentTreePath != null;
83                log.debug("refreshing components");
84
85                final Map<ValueControl, Object> values = new IdentityHashMap<ValueControl, Object>();
86                for (Map.Entry<ValueParam, ValueControl> e : valueControls.entrySet()) {
87                        values.put(e.getValue(), access.get(e.getKey().getId(), Object.class));
88                }
89
90
91                NodeAtFrame nodeAtFrame = treeAtFrame.getLocalInfo(currentTreePath);
92                if (nodeAtFrame != null) {
93                        for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) {
94                                values.put(e.getKey(), e.getValue());
95                        }
96                }
97
98                for (Map.Entry<ValueControl, Object> e : values.entrySet()) {
99                        e.getKey().pushValueToUserInterface(e.getValue());
100                }
101                refreshControlButtons();
102                ObjectPanel.this.revalidate();
103
104        }
105
106        @Override
107        public String getTitle() {
108                return "Properties";
109        }
110
111        @Override
112        public JPanel getPanelForControls() {
113                return contentPanel;
114        }
115
116        @Override
117        public void handle(FramsticksException exception) {
118                frame.handle(exception);
119        }
120
121        @Override
122        public TreePath getCurrentTreePath() {
123                return super.getCurrentTreePath();
124        }
125
126
127}
Note: See TracBrowser for help on using the repository browser.