Domain-Specific Modeling
by Risto Pohjonen and Steven Kelly

Listing One
// All this code is generated directly from the model.
// Since no manual coding or editing is needed, it is
// not intended to be particularly human-readable

public class SimpleTime extends AbstractWatchApplication {

  // define unique numbers for each Action (a...) and DisplayFn (d...)
  static final int a22_1405   = +1; //+1+1
  static final int a22_2926   = +1+1; //+1
  static final int d22_977    = +1+1+1; //

  public SimpleTime(Master master) {
    super(master);

    // Transitions and their triggering buttons and actions
    // Arguments: From State, Button, Action, To State
    addTransition ("Start [Watch]", "", 0, "Show");
    addTransition ("Show", "Mode", 0, "EditHours");
    addTransition ("EditHours", "Set", a22_2926, "EditHours");
    addTransition ("EditHours", "Mode", 0, "EditMinutes");
    addTransition ("EditMinutes", "Set", a22_1405, "EditMinutes");
    addTransition ("EditMinutes", "Mode", 0, "Show");

    // What to display in each state
    // Arguments: State, blinking unit, central unit, DisplayFn
    addStateDisplay("Show", -1, METime.MINUTE, d22_977);
    addStateDisplay("EditHours", METime.HOUR_OF_DAY, METime.MINUTE, d22_977);
    addStateDisplay("EditMinutes", METime.MINUTE, METime.MINUTE, d22_977);
  };

  // Actions (return null) and DisplayFns (return time)
  public Object perform(int methodId)
  {
    switch (methodId) {
      case a22_2926:
        getclockOffset().roll(METime.HOUR_OF_DAY, true, displayTime());
        return null;
      case a22_1405:
        getclockOffset().roll(METime.MINUTE, true, displayTime());
        return null;
      case d22_977:
        return getclockTime();
    }
    return null;
  }
}







5


