source: java/main/src/main/java/com/framsticks/gui/Gui.java @ 90

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

HIGHLIGHTS:

CHANGELOG:
Make ProcedureParam? hold only ValueParams?.

Use id instead of names when naming gui components internally.

Basic procedure calling in GUI.

The actual procedure call is currently only backed
by the ObjectInstance?.

Add UnimplementedException?.

Improve naming of various gui elements.

Allow easy navigating in FEST Swing testing.

Add optional explicit order attribute to FramsClassAnnotation?.

That's because java reflection does return declared members
in any specific order. That ordering is needed only for
classes that have no representation in framsticks and need
a deterministic ordering of params.

Add ControlOwner? interface.

Add test for procedure calling in Browser.

First version of ParamAnnotation? for procedures.

Development of ProcedureParam?.

Add draft version of ProcedureParam? implementation in ReflectionAccess?.

Allow viewing FramsClasses? in gui Browser.

Extract ResourceBuilder? from ModelBuilder?.

Remove internalId from Param.

It was currently completely not utilised. Whether it is still needed
after introduction of ParamAnnotation? is arguable.

Add remaining param attributes to ParamAnnotation?.

Change AutoBuilder? semantics.

AutoBuilder? returns list of objects that are to be appended
with methods @AutoAppendAnnotation?.

This allows to omit explicit addition of ModelPackage? to instance
if the instance uses ModelBuilder? (registration of ModelPackage? comes
from schema).

Fix params ordering problem in auto created FramsClasses?.

Improve ObjectInstance?.

Several fixes to ModelBuilder?.

Improve test for ObjectInstance? in Browser.

Make initialization of robot static.

With robot recreated for second browser test, the test hanged
deep in AWT.

Add base convenience base test for Browser tests.

More tests to ObjectInstance?.

Rename Dispatcher.invokeLater() to dispatch().

Add assertDispatch.

It allows assertions in other threads, than TestNGInvoker.
Assertions are gathered after each method invocation and rethrown.

Use timeOut annotation attribute for tests involving some waiting.

Remove firstTask method (merge with joinableStart).

Clean up leftovers.

Remove unused FavouritesXMLFactory (the reading part is already
completely done with generic XmlLoader?, and writing part will be done
based on the same approach if needed).
Move UserFavourite? to the com.framsticks.gui.configuration package.

Remove GenotypeBrowser? as to specific.

This functionality will be available in ObjectInstance?.

Add interface ParamsPackage?.

Package containing registration of Java classes meant to use with
ReflectionAccess? may be in Instance using configuration.

Minor changes.

Make Group immutable.

Add AutoBuilder? interface extending Builder - only those would
be used to automatically build from XML.

Fix groups in FramsClass?.

Minor naming cleanup in Registry.

Add ModelComponent? interface.

All class creating the Model are implementing that interface.

Extract Model.build into ModelBuilder?.

ModelBuilder? will be compatible with other builders
and allow using it from configuration.

Fix NeuroConnection?.

Add synchronous get operation for dispatchers.

Rename JoinableMonitor? to Monitor.

Add ObjectInstance?.

This class is mainly for demonstration
and testing purposes.

Improve FramsServer? runner.

  • improve ExternalProcess? runner,
  • runner can kill the server but also react properly, when the server exists on it's own,
  • set default path to search for framsticks server installation,
  • add LoggingOutputListener?.
File size: 4.5 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.getMin(Object.class) != null) {
48                        return new TextAreaControl(valueParam);
49                }
50                return new TextFieldControl(valueParam);
51        }
52
53        public static Control createSuitable(Param param) {
54
55                if (param instanceof EnumParam) {
56                        return new EnumControl((EnumParam) param);
57                }
58                if (param instanceof BooleanParam) {
59                        return new CheckBoxControl((BooleanParam) param);
60                }
61                if (param instanceof DecimalParam) {
62                        DecimalParam decimalParam = (DecimalParam)param;
63                        if (decimalParam.getMin(Integer.class) != null && decimalParam.getMax(Integer.class) != null) {
64                                return new SliderControl(decimalParam);
65                        }
66                        return createComponentForText(decimalParam);
67                }
68                if (param instanceof FloatParam) {
69                        FloatParam floatParam = (FloatParam)param;
70                        if (floatParam.getMin(Double.class) != null && floatParam.getMax(Double.class) != null) {
71                                return new SliderControl(floatParam);
72                        }
73                        return createComponentForText(floatParam);
74                }
75                if (param instanceof StringParam) {
76                        return createComponentForText((StringParam)param);
77                }
78                if (param instanceof ProcedureParam) {
79                        return new ProcedureControl((ProcedureParam)param);
80                }
81                if (param instanceof BinaryParam) {
82                        return createComponentForText((BinaryParam)param);
83                }
84                if (param instanceof ColorParam) {
85                        return createComponentForText((ColorParam) param);
86                }
87                if (param instanceof UniversalParam) {
88                        return new TextAreaControl((UniversalParam)param);
89                }
90                if (param instanceof EventParam) {
91                        return new EventControl((EventParam)param);
92                }
93                return null;
94        }
95
96        public static <P extends Param, C extends Control> void fillWithControls(ControlOwner owner, Collection<P> params, Map<P, C> components, Class<C> controlType) {
97                JPanel panel = owner.getPanel();
98                for (P param : params) {
99                        if (param.isUserHidden()) {
100                                continue;
101                        }
102                        assert !(param instanceof CompositeParam);
103                        Control c = Gui.createSuitable(param);
104
105                        if (!controlType.isInstance(c)) {
106                                throw new FramsticksException().msg("created control is not of required type").arg("control", c).arg("type", controlType);
107                        }
108
109                        C control = controlType.cast(c);
110
111                        control.setOwner(owner);
112
113                        log.debug("add component for " + param);
114                        JPanel line = new JPanel();
115                        line.setLayout(new BoxLayout(line, BoxLayout.LINE_AXIS));
116                        line.setAlignmentX(JPanel.LEFT_ALIGNMENT);
117                        JLabel label = new JLabel(Strings.notEmpty(param.getName()) ? param.getName() : (Strings.notEmpty(param.getId()) ? param.getId() : "?"));
118                        label.setToolTipText(control.getToolTipText());
119                        label.setHorizontalAlignment(JLabel.RIGHT);
120                        Dimension labelSize = new Dimension(150, 30);
121                        label.setMaximumSize(labelSize);
122                        label.setMinimumSize(labelSize);
123                        label.setPreferredSize(labelSize);
124                        line.add(label);
125                        line.add(Box.createRigidArea(new Dimension(8, 0)));
126                        line.add(control);
127                        line.revalidate();
128                        panel.add(line);
129                        panel.add(Box.createRigidArea(new Dimension(0, 8)));
130                        //component.setAlignmentX(LEFT_ALIGNMENT);
131                        components.put(param, control);
132                }
133
134        }
135}
Note: See TracBrowser for help on using the repository browser.