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