Ignore:
Timestamp:
06/22/13 21:51:33 (11 years ago)
Author:
psniegowski
Message:

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.

Location:
java/main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • java/main

    • Property svn:ignore set to
      target
  • java/main/src/main/java/com/framsticks/gui/ObjectPanel.java

    r77 r84  
    11package com.framsticks.gui;
    22
    3 import com.framsticks.gui.components.Control;
    4 import com.framsticks.gui.components.ValueControl;
    5 import com.framsticks.gui.components.ValueControlListener;
     3import com.framsticks.gui.controls.Control;
     4import com.framsticks.gui.controls.ValueControl;
     5import com.framsticks.gui.controls.ValueControlListener;
    66import com.framsticks.params.AccessInterface;
    7 import com.framsticks.params.types.CompositeParam;
    87import com.framsticks.params.Param;
    9 import com.framsticks.util.Strings;
     8import com.framsticks.params.ValueParam;
     9
    1010import org.apache.log4j.Logger;
    1111
    1212import javax.swing.*;
    13 import java.awt.*;
    1413import java.util.Collection;
    1514import java.util.HashMap;
    1615import java.util.Map;
    17 import java.util.List;
     16import static com.framsticks.util.lang.Containers.filterInstanceof;
    1817
    1918@SuppressWarnings("serial")
    20 public class ObjectPanel extends com.framsticks.gui.Panel {
     19public class ObjectPanel extends ModifiablePanel {
    2120
    22         private static final Logger LOGGER = Logger.getLogger(ObjectPanel.class.getName());
     21        private static final Logger log = Logger.getLogger(ObjectPanel.class.getName());
    2322
    2423        final protected Map<Param, Control> components = new HashMap<Param, Control>();
    25         final protected Map<Param, ValueControl> valueComponents = new HashMap<Param, ValueControl>();
     24        final protected Map<ValueParam, ValueControl> valueControls = new HashMap<ValueParam, ValueControl>();
    2625
    27         public static void fillWithComponents(JPanel panel, Collection<Param> params, Map<Param, Control> components) {
    28                 for (Param param : params) {
    29                         if (param.isUserHidden()) {
    30                                 continue;
    31                         }
    32                         assert !(param instanceof CompositeParam);
    33                         Control control = Control.createSuitable(param);
    34                         if (control != null) {
    35                                 LOGGER.debug("add component for " + param);
    36                                 JPanel line = new JPanel();
    37                                 line.setLayout(new BoxLayout(line, BoxLayout.LINE_AXIS));
    38                                 line.setAlignmentX(LEFT_ALIGNMENT);
    39                                 JLabel label = new JLabel(Strings.notEmpty(param.getName()) ? param.getName() : "? (" + param.getId() + ")");
    40                                 label.setToolTipText(label.getText());
    41                                 label.setHorizontalAlignment(JLabel.RIGHT);
    42                                 Dimension labelSize = new Dimension(150, 30);
    43                                 label.setMaximumSize(labelSize);
    44                                 label.setMinimumSize(labelSize);
    45                                 label.setPreferredSize(labelSize);
    46                                 line.add(label);
    47                                 line.add(Box.createRigidArea(new Dimension(8, 0)));
    48                                 line.add(control);
    49                                 line.revalidate();
    50                                 panel.add(line);
    51                                 panel.add(Box.createRigidArea(new Dimension(0, 8)));
    52                                 //component.setAlignmentX(LEFT_ALIGNMENT);
    53                                 components.put(param, control);
    54                                 continue;
    55                         }
    56                         LOGGER.error("component for param " + param + " of type " + param.getClass().getSimpleName() + " was not added");
    57                 }
     26        public ObjectPanel(Panel.Parameters parameters, Collection<Param> params) {
     27                super(parameters);
    5828
    59         }
     29                Gui.fillWithControls(contentPanel, params, components);
    6030
    61         public ObjectPanel(EndpointAtFrame endpoint, String className, List<Param> params) {
    62                 super(endpoint, className);
    63 
    64                 fillWithComponents(contentPanel, params, components);
    65 
    66                 for (Map.Entry<Param, Control> e : components.entrySet()) {
    67                         Control control = e.getValue();
    68                         Param param = e.getKey();
    69                         if (control instanceof ValueControl) {
    70                                 final ValueControl valueComponent = (ValueControl) control;
    71                                 valueComponents.put(param, valueComponent);
    72                                 valueComponent.setListener(new ValueControlListener() {
    73                                         @Override
    74                                         public boolean onChange(Object newValue) {
    75                                                 if (currentTreeNode == null) {
    76                                                         return true;
    77                                                 }
    78                                                 boolean result = currentTreeNode.changeValue(valueComponent, newValue);
    79                                                 refreshControlButtons();
    80                                                 return result;
     31                for (final ValueControl c : filterInstanceof(components.values(), ValueControl.class)) {
     32                        valueControls.put(c.getParam(), c);
     33                        c.setListener(new ValueControlListener() {
     34                                @Override
     35                                public boolean onChange(Object newValue) {
     36                                        if (currentTreeNode == null) {
     37                                                return true;
    8138                                        }
    82                                 });
    83                         }
     39                                        boolean result = currentTreeNode.changeValue(c, newValue);
     40                                        refreshControlButtons();
     41                                        return result;
     42                                }
     43                        });
    8444                }
    8545                contentPanel.add(Box.createVerticalGlue());
     
    9151                assert frame.isActive();
    9252                assert currentTreeNode != null;
    93                 currentTreeNode.applyChanges();
     53                currentTreeNode.pushLocalChanges();
    9454        }
    9555
    9656        protected void refreshControlButtons() {
    9757                assert frame.isActive();
    98                 applyButton.setEnabled(currentTreeNode.changedValues != null);
     58                applyButton.setEnabled(currentTreeNode.localChanges != null);
     59        }
     60
     61        protected static void fillControlsWithValues(Map<ValueControl, Object> map) {
    9962        }
    10063
    10164        @Override
    102         public void refreshComponents(AccessInterface access) {
    103         assert currentTreeNode.path.getInstance().isActive();
    104         assert currentTreeNode != null;
    105         LOGGER.debug("refreshing components");
     65        public void pullValuesFromLocalToUser(AccessInterface access) {
     66                assert currentTreeNode != null;
     67                assert currentTreeNode.path.getInstance().isActive();
     68                log.debug("refreshing components");
    10669
    107         final Map<ValueControl, Object> values = new HashMap<ValueControl, Object>();
    108         for (ValueControl vc : valueComponents.values()) {
    109             Object value = access.get(vc.getParam().getId(), Object.class);
    110             values.put(vc, value);
    111         }
     70                final Map<ValueControl, Object> values = new HashMap<ValueControl, Object>();
     71                for (Map.Entry<ValueParam, ValueControl> e : valueControls.entrySet()) {
     72                        values.put(e.getValue(), access.get(e.getKey().getId(), Object.class));
     73                }
    11274
    113         frame.invokeLater(new Runnable() {
    114             @Override
    115             public void run() {
    116                 for (Map.Entry<ValueControl, Object> e : values.entrySet()) {
    117                     e.getKey().setValue(e.getValue());
    118                 }
    119                                 if (currentTreeNode.changedValues != null) {
    120                                         for (Map.Entry<ValueControl, Object> e : currentTreeNode.changedValues.entrySet()) {
    121                                                 e.getKey().setValue(e.getValue());
     75                frame.invokeLater(new Runnable() {
     76                        @Override
     77                        public void run() {
     78                                if (currentTreeNode.localChanges != null) {
     79                                        for (Map.Entry<ValueControl, Object> e : currentTreeNode.localChanges.entrySet()) {
     80                                                values.put(e.getKey(), e.getValue());
    12281                                        }
    12382                                }
     83                                for (Map.Entry<ValueControl, Object> e : values.entrySet()) {
     84                                        e.getKey().pushValueToUserInterface(e.getValue());
     85                                }
    12486                                refreshControlButtons();
    125                 ObjectPanel.this.revalidate();
    126             }
    127         });
     87                                ObjectPanel.this.revalidate();
     88                        }
     89                });
    12890
    12991        }
    13092
     93        @Override
     94        public String getTitle() {
     95                return "Properties";
     96        }
    13197
    13298
    133 /*      public void updateValue() {
    134                 //assert panel.getFrame().isActive();
     99        // public void updateValue() {
     100        //      //assert panel.getFrame().isActive();
    135101
    136         final Node n = panel.getCurrentNode();
    137         panel.getBrowser().getManager().invokeLater(new Runnable() {
    138             @Override
    139             public void run() {
    140                 Object v = n.getAccess().get(param, Object.class);
    141                 if (v == null) {
    142                     v = param.getDef(Object.class);
    143                 }
    144                 final Object fv = v;
    145                 panel.getBrowser().invokeLater(new Runnable() {
    146                     @Override
    147                     public void run() {
    148                         setValueImpl(fv);
    149                     }
    150                 });
    151             }
    152         });
    153         }*/
     102        //      final Node n = panel.getCurrentNode();
     103        //      panel.getBrowser().getManager().invokeLater(new Runnable() {
     104        //              @Override
     105        //              public void run() {
     106        //                      Object v = n.getAccess().get(param, Object.class);
     107        //                      if (v == null) {
     108        //                              v = param.getDef(Object.class);
     109        //                      }
     110        //                      final Object fv = v;
     111        //                      panel.getBrowser().invokeLater(new Runnable() {
     112        //                              @Override
     113        //                              public void run() {
     114        //                                      setValueImpl(fv);
     115        //                              }
     116        //                      });
     117        //              }
     118        //      });
     119        // }
    154120
    155121}
Note: See TracChangeset for help on using the changeset viewer.