Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

70
LINES

< > BotCompany Repo | #1020691 // Calendar

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (18139L/130K).

!7

concept CalendarEntry {
  int year, month, day;
  S text;
}

module Calendar > DynSCP {
  int year = localYear(), month = localMonth();
  transient SimpleCRUD<CalendarEntry> crud;

  start {
    dbIndexing(CalendarEntry, 'year);
    onChange(r {
      if (month == 0) dm_q(r { setFields(month := 12, year := year-1) });
      if (month == 13) dm_q(r { setFields(month := 1, year := year+1) });
      revisualize2();
    });
    crud = new SimpleCRUD(CalendarEntry);
  }
  
  visualize {
    ret withMargin(jBottomTabs("Month",
      withBottomMargin(northAndCenter(rightAlignedLine(
        jlabel("Month:"),
        dm_fieldSpinner('month, 0, 13),
        jlabel("Year:"),
        jspinner_disableDigitGrouping(dm_fieldSpinner('year, 1970, 2030))),
        super.visualize())),
      "All Entries", withBottomMargin(crud.makePanel()));
  }
  
  visualize2 {
    print("visualize2");
    setModuleName("Calendar (" + month + "/" + year + ")");
    int days = daysInMonth(year, month);
    int weekDay = dayOfWeek_nr(calendarFromYMD(year, month, 1))-1;
    //print("Weekday " + year + "/" + month + "/" + 1 + ": " + weekDay);
    new LL<Component> rows;
    rows.add(map(intRangeList(7), func(int i) -> Component {
      jcenteredlabel(shortEnglishWeekdays().get(i)) }));
    rows.add(new L);
    MultiMap<Int, CalendarEntry> entries = multiMapIndexByField day(conceptsWhere(CalendarEntry, +year, +month));
    for (int i = 1; i <= days; i++) {
      if (l(last(rows)) > weekDay) rows.add(new L);
      while (weekDay > l(last(rows))) last(rows).add(jlabel());
      JLabel lbl = jcenteredlabel(str(i));
      L<CalendarEntry> dayEntries = entries.get(i);
      if (nempty(dayEntries)) {
        setOpaqueBackground(Color.GREEN, lbl);
        toolTip(lbl, lines_rtrim(collect text(dayEntries)));
      }
      last(rows).add(lbl);
      weekDay = (weekDay+1) % 7;
    }
    while (l(last(rows)) < 7) last(rows).add(jlabel());
    ret hvgrid(rows);
  }
  
  // API
  
  void addEntry(S ymd, S text) {
    if (uniq_sync_returnIfNew(CalendarEntry,
      year := ymd_year(ymd),
      month := ymd_month(ymd),
      day := ymd_day(ymd),
      +text) != null && month == ymd_month(ymd))
      revisualize2();
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020691
Snippet name: Calendar
Eternal ID of this version: #1020691/36
Text MD5: e7311d227f74f05fd0e59acb6820b730
Transpilation MD5: 35fb8adfd72e14e04a632236d662bb47
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-01 02:45:55
Source code size: 2279 bytes / 70 lines
Pitched / IR pitched: No / No
Views / Downloads: 333 / 1279
Version history: 35 change(s)
Referenced in: [show references]