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

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

HIGHLIGHTS:

  • upgrade to Java 7
    • use try-multi-catch clauses
    • use try-with-resources were appropriate
  • configure FindBugs? (use mvn site and then navigate in browser to the report)
    • remove most bugs found
  • parametrize Dispatching environment (Dispatcher, RunAt?) to enforce more control on the place of closures actual call

CHANGELOG:
Rework FavouritesXMLFactory.

FindBugs?. Thread start.

FindBugs?. Minor change.

FindBugs?. Iterate over entrySet.

FindBugs?. Various.

FindBug?.

FindBug?. Encoding.

FindBug?. Final fields.

FindBug?.

Remove synchronization bug in ClientConnection?.

Experiments with findbugs.

Finish parametrization.

Make RunAt? an abstract class.

More changes in parametrization.

More changes in parametrizing dispatching.

Several changes to parametrize tasks.

Rename Runnable to RunAt?.

Add specific framsticks Runnable.

Add JSR305 (annotations).

Add findbugs reporting.

More improvements to ParamBuilder? wording.

Make FramsClass? accept also ParamBuilder?.

Change wording of ParamBuilder?.

Change wording of Request creation.

Use Java 7 exception catch syntax.

Add ScopeEnd? class.

Upgrade to Java 7.

File size: 3.4 KB
Line 
1package com.framsticks.gui;
2
3import com.framsticks.gui.controls.Control;
4import com.framsticks.gui.controls.ValueControl;
5import com.framsticks.gui.controls.ValueControlListener;
6import com.framsticks.params.AccessInterface;
7import com.framsticks.params.Param;
8import com.framsticks.params.ValueParam;
9
10import org.apache.log4j.Logger;
11
12import javax.swing.*;
13import java.util.Collection;
14import java.util.HashMap;
15import java.util.Map;
16import static com.framsticks.util.lang.Containers.filterInstanceof;
17import com.framsticks.util.dispatching.RunAt;
18
19@SuppressWarnings("serial")
20public class ObjectPanel extends ModifiablePanel {
21
22        private static final Logger log = Logger.getLogger(ObjectPanel.class.getName());
23
24        final protected Map<Param, Control> components = new HashMap<Param, Control>();
25        final protected Map<ValueParam, ValueControl> valueControls = new HashMap<ValueParam, ValueControl>();
26
27        public ObjectPanel(Panel.Parameters parameters, Collection<Param> params) {
28                super(parameters);
29
30                Gui.fillWithControls(contentPanel, params, components);
31
32                for (final ValueControl c : filterInstanceof(components.values(), ValueControl.class)) {
33                        valueControls.put(c.getParam(), c);
34                        c.setListener(new ValueControlListener() {
35                                @Override
36                                public boolean onChange(Object newValue) {
37                                        if (currentTreeNode == null) {
38                                                return true;
39                                        }
40                                        boolean result = currentTreeNode.changeValue(c, newValue);
41                                        refreshControlButtons();
42                                        return result;
43                                }
44                        });
45                }
46                contentPanel.add(Box.createVerticalGlue());
47                this.revalidate();
48        }
49
50        @Override
51        protected void applyChanges() {
52                assert frame.isActive();
53                assert currentTreeNode != null;
54                currentTreeNode.pushLocalChanges();
55        }
56
57        protected void refreshControlButtons() {
58                assert frame.isActive();
59                applyButton.setEnabled(currentTreeNode.localChanges != null);
60        }
61
62        protected static void fillControlsWithValues(Map<ValueControl, Object> map) {
63        }
64
65        @Override
66        public void pullValuesFromLocalToUser(AccessInterface access) {
67                assert currentTreeNode != null;
68                assert currentTreeNode.path.getInstance().isActive();
69                log.debug("refreshing components");
70
71                final Map<ValueControl, Object> values = new HashMap<ValueControl, Object>();
72                for (Map.Entry<ValueParam, ValueControl> e : valueControls.entrySet()) {
73                        values.put(e.getValue(), access.get(e.getKey().getId(), Object.class));
74                }
75
76                frame.invokeLater(new RunAt<Frame>() {
77                        @Override
78                        public void run() {
79                                if (currentTreeNode.localChanges != null) {
80                                        for (Map.Entry<ValueControl, Object> e : currentTreeNode.localChanges.entrySet()) {
81                                                values.put(e.getKey(), e.getValue());
82                                        }
83                                }
84                                for (Map.Entry<ValueControl, Object> e : values.entrySet()) {
85                                        e.getKey().pushValueToUserInterface(e.getValue());
86                                }
87                                refreshControlButtons();
88                                ObjectPanel.this.revalidate();
89                        }
90                });
91
92        }
93
94        @Override
95        public String getTitle() {
96                return "Properties";
97        }
98
99
100        // public void updateValue() {
101        //      //assert panel.getFrame().isActive();
102
103        //      final Node n = panel.getCurrentNode();
104        //      panel.getBrowser().getManager().invokeLater(new Runnable() {
105        //              @Override
106        //              public void run() {
107        //                      Object v = n.getAccess().get(param, Object.class);
108        //                      if (v == null) {
109        //                              v = param.getDef(Object.class);
110        //                      }
111        //                      final Object fv = v;
112        //                      panel.getBrowser().invokeLater(new Runnable() {
113        //                              @Override
114        //                              public void run() {
115        //                                      setValueImpl(fv);
116        //                              }
117        //                      });
118        //              }
119        //      });
120        // }
121
122}
Note: See TracBrowser for help on using the repository browser.