source: java/main/src/main/java/com/framsticks/gui/Gui.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: 4.6 KB
Line 
1package com.framsticks.gui;
2
3import java.awt.Dimension;
4import java.util.Collection;
5import java.util.Map;
6
7import javax.swing.Box;
8import javax.swing.BoxLayout;
9import javax.swing.JLabel;
10import javax.swing.JPanel;
11
12import org.apache.log4j.Logger;
13
14import com.framsticks.gui.controls.CheckBoxControl;
15import com.framsticks.gui.controls.Control;
16import com.framsticks.gui.controls.ControlOwner;
17import com.framsticks.gui.controls.EnumControl;
18import com.framsticks.gui.controls.EventControl;
19import com.framsticks.gui.controls.ProcedureControl;
20import com.framsticks.gui.controls.SliderControl;
21import com.framsticks.gui.controls.TextAreaControl;
22import com.framsticks.gui.controls.TextFieldControl;
23import com.framsticks.params.CompositeParam;
24import com.framsticks.params.Param;
25import com.framsticks.params.PrimitiveParam;
26import com.framsticks.params.types.BinaryParam;
27import com.framsticks.params.types.BooleanParam;
28import com.framsticks.params.types.ColorParam;
29import com.framsticks.params.types.DecimalParam;
30import com.framsticks.params.types.EnumParam;
31import com.framsticks.params.types.EventParam;
32import com.framsticks.params.types.FloatParam;
33import com.framsticks.params.types.ProcedureParam;
34import com.framsticks.params.types.StringParam;
35import com.framsticks.params.types.UniversalParam;
36import com.framsticks.util.FramsticksException;
37import com.framsticks.util.lang.Strings;
38
39public final class Gui {
40
41        private static final Logger log = Logger.getLogger(Gui.class.getName());
42
43        private Gui() {
44        }
45
46        public static Control createComponentForText(PrimitiveParam<?> valueParam) {
47                if (valueParam.getMax(Object.class) != null) {
48                        return new TextFieldControl(valueParam);
49                }
50                return new TextAreaControl(valueParam);
51
52
53                // if (valueParam.getMin(Object.class) != null) {
54                //      return new TextAreaControl(valueParam);
55                // }
56                // return new TextFieldControl(valueParam);
57        }
58
59        public static Control createSuitable(Param param) {
60
61                if (param instanceof EnumParam) {
62                        return new EnumControl((EnumParam) param);
63                }
64                if (param instanceof BooleanParam) {
65                        return new CheckBoxControl((BooleanParam) param);
66                }
67                if (param instanceof DecimalParam) {
68                        DecimalParam decimalParam = (DecimalParam)param;
69                        if (decimalParam.getMin(Integer.class) != null && decimalParam.getMax(Integer.class) != null) {
70                                return new SliderControl(decimalParam);
71                        }
72                        return new TextFieldControl(decimalParam);
73                }
74                if (param instanceof FloatParam) {
75                        FloatParam floatParam = (FloatParam)param;
76                        if (floatParam.getMin(Double.class) != null && floatParam.getMax(Double.class) != null) {
77                                return new SliderControl(floatParam);
78                        }
79                        return new TextFieldControl(floatParam);
80                }
81                if (param instanceof StringParam) {
82                        return createComponentForText((StringParam) param);
83                }
84                if (param instanceof ProcedureParam) {
85                        return new ProcedureControl((ProcedureParam) param);
86                }
87                if (param instanceof BinaryParam) {
88                        return new TextFieldControl((BinaryParam) param);
89                }
90                if (param instanceof ColorParam) {
91                        return new TextFieldControl((ColorParam) param);
92                }
93                if (param instanceof UniversalParam) {
94                        return new TextAreaControl((UniversalParam) param);
95                }
96                if (param instanceof EventParam) {
97                        return new EventControl((EventParam) param);
98                }
99                return null;
100        }
101
102        public static <P extends Param, C extends Control> void fillWithControls(ControlOwner owner, Collection<P> params, Map<P, C> components, Class<C> controlType) {
103                JPanel panel = owner.getPanelForControls();
104                for (P param : params) {
105                        if (param.isUserHidden()) {
106                                continue;
107                        }
108                        assert !(param instanceof CompositeParam);
109                        Control c = Gui.createSuitable(param);
110
111                        if (!controlType.isInstance(c)) {
112                                throw new FramsticksException().msg("created control is not of required type").arg("control", c).arg("type", controlType);
113                        }
114
115                        C control = controlType.cast(c);
116
117                        control.setOwner(owner);
118
119                        log.debug("add component for " + param);
120                        JPanel line = new JPanel();
121                        line.setLayout(new BoxLayout(line, BoxLayout.LINE_AXIS));
122                        line.setAlignmentX(JPanel.LEFT_ALIGNMENT);
123                        JLabel label = new JLabel(Strings.notEmpty(param.getName()) ? param.getName() : (Strings.notEmpty(param.getId()) ? param.getId() : "?"));
124                        label.setToolTipText(control.getToolTipText());
125                        label.setHorizontalAlignment(JLabel.RIGHT);
126                        Dimension labelSize = new Dimension(150, 30);
127                        label.setMaximumSize(labelSize);
128                        label.setMinimumSize(labelSize);
129                        label.setPreferredSize(labelSize);
130                        line.add(label);
131                        line.add(Box.createRigidArea(new Dimension(8, 0)));
132                        line.add(control);
133                        line.revalidate();
134                        panel.add(line);
135                        panel.add(Box.createRigidArea(new Dimension(0, 8)));
136                        //component.setAlignmentX(LEFT_ALIGNMENT);
137                        components.put(param, control);
138                }
139
140        }
141}
Note: See TracBrowser for help on using the repository browser.