source: java/main/src/main/java/com/framsticks/gui/controls/ProcedureControl.java @ 105

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

HIGHLIGHTS:

  • import refactorization: move Tree, Path, etc.

from core to structure package

  • initial serialization implementation
  • improve PrimeExperiment? test
  • many organizational changes and convenience improvements

CHANGELOG:
Make registry in AbstractTree? final.

Move most classes from core to structure package.

Minor changes.

Switch names of Future and FutureHandler?.

Rename ExceptionResultHandler? to ExceptionHandler?.

Rename ExceptionHandler? to ExceptionDispatcherHandler?.

Fix bug in ParamCandidate? cache.

Add missing synchronization to the BufferedDispatcher?.

Develop @Serialized support.

Rework serialization further.

Add serialization/deserialization interface to ValueParam?.

Move getStorageType and isNumeric from Param down to params hierarchy.

Minor changes.

Improve param type induction.

Add TestSerializedClass? for testing new serialization.

Add info files gor GenePool? and Population.

Add standard.expt exemplary netfile.

Add type name field to PropertiesObject?.

Use PropertiesObject? for PropertiesAccess? instead of ordinary map.

Hide getFramsClass is several more places.

More unification accross FramsClass?, Access and Path.

Add ParamCollection?.

Simplify interface for getting params from FramsClass?, Access
or Path.

Make Access.call() interface variadic.

Add arguments(args) convenience wrapper around new Object[] {args}.

Upgrade to apache.commons.lang version 3.1

Minor improvement with Response constructors.

Develop proper result printing in ClientAtServer?.

Add experimentNetsave to PrimeExperiment?.

File size: 2.8 KB
Line 
1package com.framsticks.gui.controls;
2
3import com.framsticks.gui.Frame;
4import com.framsticks.gui.Gui;
5import com.framsticks.params.Param;
6import com.framsticks.params.types.ProcedureParam;
7import com.framsticks.structure.Path;
8import com.framsticks.util.dispatching.Future;
9
10import javax.swing.*;
11
12import org.apache.logging.log4j.Logger;
13import org.apache.logging.log4j.LogManager;
14
15import java.awt.event.ActionEvent;
16import java.awt.event.ActionListener;
17import java.util.HashMap;
18import java.util.LinkedList;
19import java.util.List;
20import java.util.Map;
21
22@SuppressWarnings("serial")
23public class ProcedureControl extends HistoryControl implements ControlOwner {
24
25        private static final Logger log = LogManager.getLogger(ProcedureControl.class);
26
27        protected final JPanel argumentsPanel;
28
29        final protected Map<String, ValueControl> components = new HashMap<>();
30
31        public ProcedureControl(ProcedureParam procedureParam) {
32                super(procedureParam);
33
34
35                mainButton.setText("Call");
36                mainButton.setName("call");
37
38
39                argumentsPanel = new JPanel();
40                argumentsPanel.setName("arguments");
41
42                Gui.fillWithControls(this, argumentsPanel, procedureParam.getArgumentsType(), components, ValueControl.class);
43
44                if (components.size() != procedureParam.getArgumentsType().size()) {
45                        mainButton.setEnabled(false);
46                }
47
48                mainButton.addActionListener(new ActionListener() {
49                        @Override
50                        public void actionPerformed(ActionEvent e) {
51
52                                final Path path = getCurrentPath();
53
54                                final List<Object> arguments = new LinkedList<Object>();
55                                for (Param arg : getParam().getArgumentsType()) {
56                                        Object value = components.get(arg.getId()).getCurrentValue();
57                                        arguments.add(value);
58                                        log.debug("argument {}: {}", arg, value);
59                                }
60                                callProcedure(path, getParam(), arguments.toArray(), getFrame());
61
62                        }
63                });
64
65                updateFoldState();
66                Gui.setupTitledControl(this, argumentsPanel, controlRow, resultsScrollPane);
67
68        }
69
70
71        public static void callProcedure(final Path path, final ProcedureParam param, Object[] arguments, Frame frame) {
72
73                assert path.getTree().isActive();
74
75                path.getTree().call(path, param, arguments, Object.class, new Future<Object>(frame) {
76
77                        @Override
78                        public void result(Object result) {
79
80                        }
81                });
82        }
83
84        @Override
85        public ProcedureParam getParam() {
86                return (ProcedureParam) param;
87        }
88
89        @Override
90        protected void updateEnabled(boolean enabled) {
91                mainButton.setEnabled(enabled);
92                for (ValueControl vc : components.values()) {
93                        vc.setUserEnabled(enabled);
94                }
95        }
96
97        @Override
98        public Frame getFrame() {
99                return owner.getFrame();
100        }
101
102        @Override
103        public Path getCurrentPath() {
104                return owner.getCurrentPath();
105        }
106
107        @Override
108        public boolean onValueChange(ValueControl control, Object newValue) {
109                return true;
110        }
111
112        @Override
113        protected void refreshTable() {
114
115        }
116
117        @Override
118        protected void clearTable() {
119
120        }
121
122}
Note: See TracBrowser for help on using the repository browser.