source: java/main/src/main/java/com/framsticks/gui/MainFrame.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: 7.4 KB
Line 
1package com.framsticks.gui;
2
3import java.awt.event.ActionEvent;
4import java.awt.event.KeyEvent;
5import java.awt.event.WindowAdapter;
6import java.awt.event.WindowEvent;
7
8import javax.swing.AbstractAction;
9import javax.swing.JButton;
10import javax.swing.KeyStroke;
11import javax.swing.WindowConstants;
12
13import org.apache.log4j.Logger;
14
15import com.framsticks.util.swing.MenuConstructor;
16
17/**
18 * Application Main Frame.
19 */
20@SuppressWarnings("serial")
21public class MainFrame extends Frame {
22
23        private final static Logger log = Logger.getLogger(MainFrame.class.getName());
24
25        JButton start, stop, step;
26
27        /**
28         * Builds main frame.
29         */
30        public MainFrame(final Browser browser) {
31                super(browser);
32                setTitle("framsticks");
33                log.debug("creating main frame");
34
35        }
36
37
38        @Override
39        protected void initializeGui() {
40                super.initializeGui();
41
42                new MenuConstructor(fileMenu)
43                        .add(null, new AbstractAction("Console") {
44                                @Override
45                                public void actionPerformed(ActionEvent actionEvent) {
46                                        // showConsoleFrame();
47                                }
48                        })
49                        .add(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK), new AbstractAction("Goto") {
50                                @Override
51                                public void actionPerformed(ActionEvent actionEvent) {
52                                        browser.autoResolvePath("/simulator/genepools/groups/0", null);
53                                        // browser.autoResolvePath("/simulator/populations/groups/0", null;
54                                        // browser.autoResolvePath("/simulator/genepools/groups/0/genotypes", null);
55                                        // browser.autoResolvePath("/simulator/populations/groups", null);
56                                }
57                        })
58                        .add(null, new AbstractAction("Disconnect") {
59                                @Override
60                                public void actionPerformed(ActionEvent actionEvent) {
61                                        disconnect();
62                                }
63                        })
64                        .add(null, new AbstractAction("Quit") {
65                                @Override
66                                public void actionPerformed(ActionEvent actionEvent) {
67                                }
68                        })
69                        ;
70
71                setFrameProperties();
72        }
73
74        // private void onConnectionEstablished() {
75                // assert isActive();
76
77                // addNodeActionToTreePopupMenu("Open in console", new NodeAction() {
78                        // @Override
79                        // public void actionPerformed(TreeNode treeNode) {
80                                // assert isActive();
81                        // }
82                // });
83
84
85
86
87        //      // browser.addNodeActionToTreePopupMenu("Resolve recursively", new NodeAction() {
88        //      //      @Override
89        //      //      public void actionPerformed(TreeNode treeNode) {
90        //      //              final Child child = treeNode.getChild();
91        //      //              //server.invokeLater(new Runnable() {
92        //              //              @Override
93        //              //              public void run() {
94        //              //                      resolveRecursively(child);
95        //              //              }
96        //              //      });
97        //      // }
98        //      // });
99
100
101                // // addNodeActionToTreePopupMenu("Store in file", new NodeAction() {
102                // //     @Override
103                // //     public void actionPerformed(final TreeNode treeNode) {
104                // //         // final Node node = treeNode.getNode();
105                // //         // server.invokeLater(new Runnable() {
106                // //         //     @Override
107                // //         //     public void run() {
108                // //         //         try {
109                // //         //             log.info("storing");
110                // //         //             //File file = new File();
111                // //         //             StoreStream stream = new StoreStream(file, server.getManager());
112                // //         //             stream.store(node);
113                // //         //         } catch (FileNotFoundException e) {
114                // //         //             e.printStackTrace();
115                // //         //         }
116                // //         //     }
117                // //         // });
118                // //     }
119                // // });
120
121
122        //      // arguments.forEach("resolve", new UnaryFunctor<Boolean, String>() {
123        //      //      @Override
124        //      //      public Boolean call(final String s) {
125        //      //              server.getManager().resolvePath(s, new StateFunctor() {
126        //      //                      @Override
127        //      //                      public void call(Exception e) {
128        //      //                              if (e != null) {
129        //      //                                      log.error("failed to resolve: " + s);
130        //      //                                      return;
131        //      //                              }
132        //      //                              log.info("succeeded to resolve: " + s);
133        //      //                      }
134        //      //              });
135        //      //              return true;
136        //      //      }
137        //      // });
138
139
140        //      // arguments.forEach("console", new UnaryFunctor<Boolean, String>() {
141        //      //      @Override
142        //      //      public Boolean call(String s) {
143        //      //              showConsoleFrame().setCommandLine(s);
144        //      //              return true;
145        //      //      }
146        //      // });
147        // }
148
149
150        // /**
151        //  * Creates panel with start, step, stop buttons.
152        //  */
153        // @Override
154        // protected JPanel createLeftTopPanel() {
155        //      assert isActive();
156        //      Dimension buttonDimension = new Dimension(45, 45);
157
158        //      JPanel panel = new JPanel();
159
160        //      stop = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STOP));
161        //      stop.addActionListener(new ActionListener() {
162
163        //              public void actionPerformed(ActionEvent e) {
164        //                      setSimulationRunning(false);
165        //              }
166
167        //      });
168
169        //      stop.setPreferredSize(buttonDimension);
170        //      stop.setToolTipText("Simulation Stop");
171        //      stop.setEnabled(false);
172
173        //      step = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STEP));
174        //      /*
175        //      step.addActionListener(new ActionListener() {
176
177        //              public void actionPerformed(ActionEvent e) {
178        //                      connection.send(new CallQuery().setMethod("step").setPath("/simulator"));
179        //              }
180
181        //      });
182        //      */
183
184        //      step.setPreferredSize(buttonDimension);
185        //      step.setToolTipText("Simulation Step");
186
187        //      start = new JButton(ImageProvider.loadImage(ImageProvider.SIM_START));
188        //      start.addActionListener(new ActionListener() {
189
190        //              public void actionPerformed(ActionEvent e) {
191        //                      setSimulationRunning(true);
192        //              }
193
194        //      });
195
196        //      start.setPreferredSize(buttonDimension);
197        //      start.setToolTipText("Start Simulation");
198
199        //      JPanel buttonPanel = new JPanel();
200        //      buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
201        //      buttonPanel.add(Box.createHorizontalStrut(5));
202        //      buttonPanel.add(stop);
203        //      buttonPanel.add(Box.createHorizontalStrut(10));
204        //      buttonPanel.add(step);
205        //      buttonPanel.add(Box.createHorizontalStrut(10));
206        //      buttonPanel.add(start);
207        //      buttonPanel.add(Box.createHorizontalStrut(5));
208
209        //      buttonPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory
210        //                      .createRaisedBevelBorder(), "Simulation Control",
211        //                      TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION
212        //                      ));
213
214        //      panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
215        //      panel.add(Box.createHorizontalGlue());
216        //      panel.add(buttonPanel);
217        //      panel.add(Box.createHorizontalGlue());
218        //      return panel;
219        // }
220
221        /**
222         * Sets frame properties.
223         */
224        private void setFrameProperties() {
225                assert isActive();
226                getSwing().setMinimumSize(getSwing().getPreferredSize());
227                getSwing().setSize(getSwing().getPreferredSize());
228                getSwing().setMaximumSize(screenDimension);
229                getSwing().setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
230
231                getSwing().setIconImage(ImageProvider.loadImage(ImageProvider.LOGO)
232                                .getImage());
233
234
235                getSwing().addWindowListener(new WindowAdapter() {
236                        public void windowClosing(WindowEvent e) {
237                                assert isActive();
238                                /*
239                                if (connection != null) {
240                                        connection.close();
241                                }
242                                */
243                                onWindowClosing();
244                                getSwing().dispose();
245                        }
246                });
247        }
248
249        // public ConsoleFrame showConsoleFrame() {
250        //      assert isActive();
251        //      /*
252        //      ConsoleFrame consoleFrame = new ConsoleFrame(connection);
253        //      consoleFrame.show(MainFrame.this);
254        //      return consoleFrame;
255        //      */
256        //      return null;
257        // }
258
259        /**
260         * Closes connection with manager.
261         */
262        private void disconnect() {
263                assert isActive();
264                browser.clear();
265                onWindowClosing();
266                // statusBar.setText("You are disconnected");
267        }
268
269        /**
270         * Method used while window is closing.
271         */
272        private void onWindowClosing() {
273                assert isActive();
274
275        }
276
277        public void setRunningButtons(boolean running) {
278                assert isActive();
279                step.setEnabled(!running);
280                stop.setEnabled(running);
281                start.setEnabled(!running);
282        }
283
284}
285
Note: See TracBrowser for help on using the repository browser.