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

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

HIGHLIGHTS:

  • simplification of entities management model
  • cleanup around params (improve hierarchy)
  • migrate from JUnit to TestNG
  • introduce FEST to automatically test GUI
  • improve slider control
  • loosen synchronization between gui tree and backend representation
  • and many other bug fixes

NOTICE:

  • a great many of lines is changed only because of substituting spaces with tabs

CHANGELOG (oldest changes at the bottom):

Some cleaning after fix found.

Fix bug with tree.

More changes with TreeNodes?.

Finally fix issue with tree.

Improve gui tree management.

Decouple update of values from fetch request in gui.

Minor changes.

Minor changes.

Minor change.

Change Path construction wording.

More fixes to SliderControl?.

Fix SliderControl?.

Fix SliderControl?.

Minor improvement.

Several changes.

Make NumberParam? a generic class.

Add robot to the gui test.

Setup common testing logging configuration.

Remove Parameters class.

Remove entityOwner from Parameters.

Move name out from Parameters class.

Move configuration to after the construction.

Simplify observers and endpoints.

Remove superfluous configureEntity overrides.

Add dependency on fest-swing-testng.

Use FEST for final print test.

Use FEST for more concise and readable assertions.

Divide test of F0Parser into multiple methods.

Migrate to TestNG

Minor change.

Change convention from LOGGER to log.

Fix reporting of errors during controls filling.

Bound maximal height of SliderControl?.

Minor improvements.

Improve tooltips for controls.

Also use Delimeted in more places.

Move static control utilities to Gui.

Rename package gui.components to controls.

Some cleaning in controls.

Improve Param classes placing.

Move ValueParam?, PrimitiveParam? and CompositeParam? one package up.

Improve ParamBuilder?.

Move getDef to ValueParam? and PrimitiveParam?.

Move getMax and getDef to ValueParam?.

Move getMin to ValueParam?.

Upgrade to laters apache commons versions.

Use filterInstanceof extensively.

Add instanceof filters.

Make ValueParam? in many places of Param.

Place assertions about ValueParam?.

Add ValueParam?

Rename ValueParam? to PrimitiveParam?

Minor changes.

Several improvements to params types.

Add NumberParam?.

Add TextControl? component.

Add .swp files to .gitignore

Greatly improved slider component.

Some improvements.

Make Param.reassign return also a state.

Add IterableIterator?.

Several changes.

  • Move util classes to better packages.
  • Remove warnings from eclim.

Several improvements.

Fix bug with BooleanParam?.

Some experiments with visualization.

Another fix to panel management.

Improve panel management.

Some refactorization around panels.

Add root class for panel.

File size: 4.2 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.EnumControl;
17import com.framsticks.gui.controls.EventControl;
18import com.framsticks.gui.controls.ProcedureControl;
19import com.framsticks.gui.controls.SliderControl;
20import com.framsticks.gui.controls.TextAreaControl;
21import com.framsticks.gui.controls.TextFieldControl;
22import com.framsticks.params.CompositeParam;
23import com.framsticks.params.Param;
24import com.framsticks.params.PrimitiveParam;
25import com.framsticks.params.types.BinaryParam;
26import com.framsticks.params.types.BooleanParam;
27import com.framsticks.params.types.ColorParam;
28import com.framsticks.params.types.DecimalParam;
29import com.framsticks.params.types.EnumParam;
30import com.framsticks.params.types.EventParam;
31import com.framsticks.params.types.FloatParam;
32import com.framsticks.params.types.ProcedureParam;
33import com.framsticks.params.types.StringParam;
34import com.framsticks.params.types.UniversalParam;
35import com.framsticks.util.lang.Strings;
36
37public final class Gui {
38
39        private static final Logger log = Logger.getLogger(Gui.class.getName());
40
41        private Gui() {
42        }
43
44        public static Control createComponentForText(PrimitiveParam valueParam) {
45                if (valueParam.getMin(Object.class) != null) {
46                        return new TextAreaControl(valueParam);
47                }
48                return new TextFieldControl(valueParam);
49        }
50
51        public static Control createSuitable(Param param) {
52
53                if (param instanceof EnumParam) {
54                        return new EnumControl((EnumParam) param);
55                }
56                if (param instanceof BooleanParam) {
57                        return new CheckBoxControl((BooleanParam) param);
58                }
59                if (param instanceof DecimalParam) {
60                        DecimalParam decimalParam = (DecimalParam)param;
61                        if (decimalParam.getMin(Integer.class) != null && decimalParam.getMax(Integer.class) != null) {
62                                return new SliderControl(decimalParam);
63                        }
64                        return createComponentForText(decimalParam);
65                }
66                if (param instanceof FloatParam) {
67                        FloatParam floatParam = (FloatParam)param;
68                        if (floatParam.getMin(Double.class) != null && floatParam.getMax(Double.class) != null) {
69                                return new SliderControl(floatParam);
70                        }
71                        return createComponentForText(floatParam);
72                }
73                if (param instanceof StringParam) {
74                        return createComponentForText((StringParam)param);
75                }
76                if (param instanceof ProcedureParam) {
77                        return new ProcedureControl((ProcedureParam)param);
78                }
79                if (param instanceof BinaryParam) {
80                        return createComponentForText((BinaryParam)param);
81                }
82                if (param instanceof ColorParam) {
83                        return createComponentForText((ColorParam) param);
84                }
85                if (param instanceof UniversalParam) {
86                        return new TextAreaControl((UniversalParam)param);
87                }
88                if (param instanceof EventParam) {
89                        return new EventControl((EventParam)param);
90                }
91                return null;
92        }
93
94        public static void fillWithControls(JPanel panel, Collection<Param> params, Map<Param, Control> components) {
95                for (Param param : params) {
96                        if (param.isUserHidden()) {
97                                continue;
98                        }
99                        assert !(param instanceof CompositeParam);
100                        Control control = Gui.createSuitable(param);
101                        if (control == null) {
102                                log.error("component for param " + param + " of type " + param.getClass().getSimpleName() + " was not added");
103                                continue;
104                        }
105                        log.debug("add component for " + param);
106                        JPanel line = new JPanel();
107                        line.setLayout(new BoxLayout(line, BoxLayout.LINE_AXIS));
108                        line.setAlignmentX(JPanel.LEFT_ALIGNMENT);
109                        JLabel label = new JLabel(Strings.notEmpty(param.getName()) ? param.getName() : "? (" + param.getId() + ")");
110                        label.setToolTipText(control.getToolTipText());
111                        label.setHorizontalAlignment(JLabel.RIGHT);
112                        Dimension labelSize = new Dimension(150, 30);
113                        label.setMaximumSize(labelSize);
114                        label.setMinimumSize(labelSize);
115                        label.setPreferredSize(labelSize);
116                        line.add(label);
117                        line.add(Box.createRigidArea(new Dimension(8, 0)));
118                        line.add(control);
119                        line.revalidate();
120                        panel.add(line);
121                        panel.add(Box.createRigidArea(new Dimension(0, 8)));
122                        //component.setAlignmentX(LEFT_ALIGNMENT);
123                        components.put(param, control);
124                }
125
126        }
127}
Note: See TracBrowser for help on using the repository browser.