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).

1  
!7
2  
3  
concept CalendarEntry {
4  
  int year, month, day;
5  
  S text;
6  
}
7  
8  
module Calendar > DynSCP {
9  
  int year = localYear(), month = localMonth();
10  
  transient SimpleCRUD<CalendarEntry> crud;
11  
12  
  start {
13  
    dbIndexing(CalendarEntry, 'year);
14  
    onChange(r {
15  
      if (month == 0) dm_q(r { setFields(month := 12, year := year-1) });
16  
      if (month == 13) dm_q(r { setFields(month := 1, year := year+1) });
17  
      revisualize2();
18  
    });
19  
    crud = new SimpleCRUD(CalendarEntry);
20  
  }
21  
  
22  
  visualize {
23  
    ret withMargin(jBottomTabs("Month",
24  
      withBottomMargin(northAndCenter(rightAlignedLine(
25  
        jlabel("Month:"),
26  
        dm_fieldSpinner('month, 0, 13),
27  
        jlabel("Year:"),
28  
        jspinner_disableDigitGrouping(dm_fieldSpinner('year, 1970, 2030))),
29  
        super.visualize())),
30  
      "All Entries", withBottomMargin(crud.makePanel()));
31  
  }
32  
  
33  
  visualize2 {
34  
    print("visualize2");
35  
    setModuleName("Calendar (" + month + "/" + year + ")");
36  
    int days = daysInMonth(year, month);
37  
    int weekDay = dayOfWeek_nr(calendarFromYMD(year, month, 1))-1;
38  
    //print("Weekday " + year + "/" + month + "/" + 1 + ": " + weekDay);
39  
    new LL<Component> rows;
40  
    rows.add(map(intRangeList(7), func(int i) -> Component {
41  
      jcenteredlabel(shortEnglishWeekdays().get(i)) }));
42  
    rows.add(new L);
43  
    MultiMap<Int, CalendarEntry> entries = multiMapIndexByField day(conceptsWhere(CalendarEntry, +year, +month));
44  
    for (int i = 1; i <= days; i++) {
45  
      if (l(last(rows)) > weekDay) rows.add(new L);
46  
      while (weekDay > l(last(rows))) last(rows).add(jlabel());
47  
      JLabel lbl = jcenteredlabel(str(i));
48  
      L<CalendarEntry> dayEntries = entries.get(i);
49  
      if (nempty(dayEntries)) {
50  
        setOpaqueBackground(Color.GREEN, lbl);
51  
        toolTip(lbl, lines_rtrim(collect text(dayEntries)));
52  
      }
53  
      last(rows).add(lbl);
54  
      weekDay = (weekDay+1) % 7;
55  
    }
56  
    while (l(last(rows)) < 7) last(rows).add(jlabel());
57  
    ret hvgrid(rows);
58  
  }
59  
  
60  
  // API
61  
  
62  
  void addEntry(S ymd, S text) {
63  
    if (uniq_sync_returnIfNew(CalendarEntry,
64  
      year := ymd_year(ymd),
65  
      month := ymd_month(ymd),
66  
      day := ymd_day(ymd),
67  
      +text) != null && month == ymd_month(ymd))
68  
      revisualize2();
69  
  }
70  
}

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: 337 / 1284
Version history: 35 change(s)
Referenced in: [show references]