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

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

HIGHLIGHTS:

  • add proper exception passing between communication sides:

if exception occur during handling client request, it is
automatically passed as comment to error response.

it may be used to snoop communication between peers

  • fix algorithm choosing text controls in GUI
  • allow GUI testing in virtual frame buffer (xvfb)

FEST had some problem with xvfb but workaround was found

supports tab-completion based on requests history

CHANGELOG:
Further improve handling of exceptions in GUI.

Add StatusBar? implementing ExceptionResultHandler?.

Make completion processing asynchronous.

Minor changes.

Improve completion in console.

Improve history in InteractiveConsole?.

First working version of DirectConsole?.

Minor changes.

Make Connection.address non final.

It is more suitable to use in configuration.

Improvement of consoles.

Improve PopupMenu? and closing of FrameJoinable?.

Fix BrowserTest?.

Found bug with FEST running under xvfb.

JButtonFixture.click() is not working under xvfb.
GuiTest? has wrapper which uses JButton.doClick() directly.

Store CompositeParam? param in TreeNode?.

Simplify ClientSideManagedConnection? connecting.

There is now connectedFunctor needed, ApplicationRequests? can be
send right after creation. They are buffered until the version
and features are negotiated.

Narow down interface of ClientSideManagedConnection?.

Allow that connection specialization send only
ApplicationRequests?.

Improve policy of text control choosing.

Change name of Genotype in BrowserTest?.

Make BrowserTest? change name of Genotype.

Minor change.

First working draft of TrackConsole?.

Simplify Consoles.

More improvements with gui joinables.

Unify initialization on gui joinables.

More rework of Frame based entities.

Refactorize structure of JFrames based entities.

Extract GuiTest? from BrowserBaseTest?.

Reorganize Console classes structure.

Add Collection view to JoinableCollection?.

Configure timeout in testing.

Minor changes.

Rework connections hierarchy.

Add Mode to the get operation.

Make get and set in Tree take PrimitiveParam?.

Unify naming of operations.

Make RunAt? use the given ExceptionHandler?.

It wraps the virtual runAt() method call with
try-catch passing exception to handler.

Force RunAt? to include ExceptionHandler?.

Improve ClientAtServer?.

Minor change.

Another sweep with FindBugs?.

Rename Instance to Tree.

Minor changes.

Minor changes.

Further clarify semantics of Futures.

Add FutureHandler?.

FutureHandler? is refinement of Future, that proxifies
exception handling to ExceptionResultHandler? given
at construction time.

Remove StateFunctor? (use Future<Void> instead).

Make Connection use Future<Void>.

Unparametrize *ResponseFuture?.

Remove StateCallback? not needed anymore.

Distinguish between sides of ResponseFuture?.

Base ResponseCallback? on Future (now ResponseFuture?).

Make asynchronous store taking Future for flags.

Implement storeValue in ObjectInstance?.

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.getPanel();
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.