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/params/ParamBuilder.java

    r77 r84  
    22
    33import com.framsticks.params.types.*;
     4import com.framsticks.util.lang.Numbers;
     5
    46import org.apache.log4j.Logger;
    57
     
    911/**
    1012 * The class ParamBuilder helps building Param objects.
    11  * 
     13 *
    1214 * @author Mateusz Jarus <name.surname@gmail.com> (please replace name and
    1315 *         surname with my personal data)
     
    1719
    1820public class ParamBuilder {
    19         private final static Logger LOGGER = Logger.getLogger(ParamBuilder.class.getName());
     21        private final static Logger log = Logger.getLogger(ParamBuilder.class.getName());
    2022
    2123        private static final String ID_FIELD = "id";
     
    4850
    4951        /** The getType of parameter. */
    50         @SuppressWarnings("rawtypes")
    51         private Class paramType;
     52        private Class<? extends Param> paramType;
    5253
    5354        private Param param;
     55        private PrimitiveParam primitiveParam;
    5456
    5557        /**
    5658         * Build Param based on provided data.
    57          * 
     59         *
    5860         * @return Param object
    5961         * @throws Exception
     
    6163         */
    6264        public Param build()  {
    63         assert param != null;
     65                assert param != null;
    6466                param.id = id;
    6567                param.name = name;
     
    6870                param.flags = flags;
    6971                param.internalId = internalId;
    70 
    7172                return param;
    7273        }
     
    7778        }
    7879
     80        protected <T extends Param> ParamBuilder internalSetType(Class<? extends Param> type, T param) {
     81                this.paramType = type;
     82                this.param = param;
     83                if (param instanceof PrimitiveParam) {
     84                        primitiveParam = (PrimitiveParam) param;
     85                }
     86                return this;
     87        }
     88
    7989        public <T extends Param> ParamBuilder setType(Class<T> type) {
    80                 this.paramType = type;
    8190                try {
    82                         this.param = (Param)paramType.newInstance();
     91                        return internalSetType(type, type.newInstance());
    8392                } catch (InstantiationException e) {
    8493                        e.printStackTrace();
     
    8998        }
    9099
    91         public <T extends Param> ParamBuilder setType(T type) {
    92                 this.paramType = type.getClass();
    93                 this.param = type;
    94                 return this;
     100        public <T extends Param> ParamBuilder setType(T param) {
     101                return internalSetType(param.getClass(), param);
    95102        }
    96103
     
    116123        }
    117124
     125        protected <T extends Number> void parseMinMaxDefNumber(Class<T> type, String second, String third) {
     126                if (primitiveParam == null) {
     127                        log.warn("param is not a primitive param");
     128                        return;
     129                }
     130                if (second != null) {
     131                        this.primitiveParam.min = Numbers.parse(second, type);
     132                        if (this.primitiveParam.min == null) {
     133                                log.warn("value of min attribute was invalid");
     134                        }
     135                }
     136                if (third != null) {
     137                        this.primitiveParam.max = Numbers.parse(third, type);
     138                        if (this.primitiveParam.max == null) {
     139                                log.warn("value of min attribute was invalid");
     140                        }
     141                }
     142        }
     143
    118144        public ParamBuilder setType(String type) {
    119145
    120                 LOGGER.trace("parsing type: " + type);
     146                log.trace("parsing type: " + type);
    121147
    122148                String[] typeSplitted = type.split(" ");
     
    136162                                        procedureParam.parseSignature(signature);
    137163                                } catch (Exception e) {
    138                                         LOGGER.error("invalid procedure signature '" + signature + "': " + e);
     164                                        log.error("invalid procedure signature '" + signature + "': " + e);
    139165                                }
    140166                                setType(procedureParam);
     
    148174                                } else {
    149175                                        if (first.length() >= 2) {
    150                                                 switch (first.charAt(1)) {
     176                                switch (first.charAt(1)) {
    151177                                                        case 'b': {
    152178                                                                setType(BinaryParam.class);
     
    159185                                                }
    160186                                        }
    161                     if ("0".equals(second) && "1".equals(third)) {
    162                         setType(BooleanParam.class);
    163                     }
     187                                        if ("0".equals(second) && "1".equals(third)) {
     188                                                setType(BooleanParam.class);
     189                                        }
    164190                                        if (param == null) {
    165191                                                setType(DecimalParam.class);
     
    167193                                }
    168194                                if (this.param instanceof DecimalParam) {
    169                                         try {
    170                                                 if (second != null) {
    171                                                         this.param.min = Integer.parseInt(second);
    172                                                 }
    173 
    174                                                 if (third != null) {
    175                                                         this.param.max = Integer.parseInt(third);
    176                                                 }
    177                                         } catch (NumberFormatException e) {
    178                                                 LOGGER.warn("value of min or max attribute should be an Integer");
    179                                         }
     195                                        parseMinMaxDefNumber(Integer.class, second, third);
    180196                                }
    181197                                break;
     
    183199                        case 'f': {
    184200                                setType(FloatParam.class);
    185                                 try {
    186                                         if (second != null) {
    187                                                 this.param.min = Double.parseDouble(second);
    188                                         }
    189 
    190                                         if (third != null) {
    191                                                 this.param.max = Double.parseDouble(third);
    192                                         }
    193                                 } catch (NumberFormatException ex) {
    194                                         LOGGER.warn("Value of min or max attribute should be Double");
    195                                 }
     201                                parseMinMaxDefNumber(Double.class, second, third);
    196202                                break;
    197203                        }
     
    202208                        case 's': {
    203209                                setType(StringParam.class);
    204                                 this.param.min = second;
    205                                 this.param.max = third;
     210                                setMin(second);
     211                                setMax(third);
    206212                                break;
    207213                        }
     
    211217                        }
    212218                        case 'l': {
    213 
    214219                                setType(third != null ? new UniqueListParam(second, third) : new ArrayListParam(second));
    215220                                break;
     
    225230        }
    226231
     232        /**
     233         * @return the paramType
     234         */
     235        public Class<? extends Param> getParamType() {
     236                return paramType;
     237        }
     238
    227239        public <T> ParamBuilder setMin(T min) {
    228                 this.param.min = min;
     240                if (primitiveParam != null) {
     241                        this.primitiveParam.min = min;
     242                }
    229243                return this;
    230244        }
    231245
    232246        public <T> ParamBuilder setMax(T max) {
    233                 this.param.max = max;
     247                if (primitiveParam != null) {
     248                        this.primitiveParam.max = max;
     249                }
    234250                return this;
    235251        }
    236252
    237253        public <T> ParamBuilder setDef(T def) {
    238                 this.param.def = def;
    239                 return this;
     254                if (def != null && primitiveParam != null) {
     255                        this.primitiveParam.def = def;
     256                }
     257                return this;
     258        }
     259
     260        public Class<?> getStorageType() {
     261                assert param != null;
     262                return param.getStorageType();
    240263        }
    241264
     
    244267
    245268                if (paramEntryValues.length == 0) {
    246                         LOGGER.warn("field empty or wrong format (" + line
     269                        log.warn("field empty or wrong format (" + line
    247270                                        + ") - omitting");
    248271                        return null;
     
    263286                        /** everything is ok, parameters have just finished*/
    264287                } catch (NumberFormatException ex) {
    265                         LOGGER.warn("wrong format of entry: " + line
     288                        log.warn("wrong format of entry: " + line
    266289                                        + ", omitting");
    267290                        return null;
Note: See TracChangeset for help on using the changeset viewer.