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

188
LINES

< > BotCompany Repo | #1015803 // Cubes Frame [v4, with module persistence, OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (12680L/89K).

1  
!7
2  
3  
sS background = #1009931;
4  
static JDesktopPane desktop;
5  
static JTextField tfInput;
6  
//static L<Module> modules;
7  
static ReliableSingleThread rst = new(f updateModules);
8  
9  
p-noconsole {
10  
  autoRestart(5);
11  
  db();
12  
13  
  desktop = jTiledBackgroundDesktopPane(background);
14  
  autoFixDesktopPane(desktop);
15  
  cleanExitOnFrameClose(showMaximizedFrame(desktop));
16  
    
17  
  final JInternalFrame f = showCenteredInternalFrame(desktop, "Hello", 700, 150, setFontSize(20, tfInput = jcenteredtextfield("Find me some stuff")));
18  
  packInternalFrameVertically(f);
19  
  centerInternalFrame(f);
20  
  swing {
21  
 f.setLocation(f.getX(), 40);
22  
 }
23  
24  
  cset(uniq(ModuleClasses), on := true, visible := true);
25  
  for (Module m : onModules())
26  
    startModule(m);
27  
28  
  addConceptIndex(simpleConceptIndex(rTrigger(rst)));
29  
}
30  
31  
svoid updateModules {
32  
  for (Module m : onModules())
33  
    pcall { m.update(); }
34  
}
35  
36  
svoid cleanMeUp {
37  
  print('cleanMeUp);
38  
  for (Module m) if (m.vis != null) pcall {
39  
    print(m);
40  
    m.unvisualize();
41  
  }
42  
  print("done cleanMeUp");
43  
}
44  
45  
static L<Module> onModules() {
46  
  ret conceptsWhere(Module, on := true);
47  
}
48  
49  
sbool hasModuleWithFields(Class c, O... params) {
50  
  ret hasConcept(Module, c, concatArrays(new O[] {on := true}, params));
51  
}
52  
53  
svoid startModule(Module m) {
54  
  //addIfNotThere(modules, m);
55  
  lock m.lock;
56  
  if (m.started) ret;
57  
  m.started = true;
58  
  m.start();
59  
  if (m.visible) showModule(m);
60  
}
61  
62  
svoid showModule(final Module m) {
63  
  startModule(m);
64  
  lock m.lock;
65  
  cset(m, visible := true);
66  
  pcall-messagebox {
67  
    if (m.vis == null)
68  
      m.vis = m.visualize();
69  
  }
70  
  if (m.vis != null) swing {
71  
    Rect r = m.frameRect;
72  
    if (r == null) randomRect(desktop.getWidth(), desktop.getHeight(), 10, 150, 100);
73  
    if (r == null) r = Rect(10, 10, 200, 100);
74  
    print("Showing frame at " + r);
75  
    S frameTitle = humanizeFormLabel(shortClassName(m));
76  
    onInternalFrameClosing(showInternalFrame(desktop, frameTitle, r.x, r.y, r.w, r.h, m.vis), r {
77  
      cset(m, visible := false);
78  
      m.unvisualize();
79  
    });
80  
  }
81  
}
82  
83  
concept Module {
84  
  transient Component vis;
85  
  transient bool started;
86  
  transient Lock lock = lock();
87  
  
88  
  bool on = true, visible;
89  
  Rect frameRect;
90  
  
91  
  JComponent visualize() { ret jCenteredMultiLineLabel(sfu(this)); }
92  
  void unvisualize() { unvisualize1(); unvisualize2(); }
93  
  void start() {}
94  
  void unvisualize1() {
95  
    print("unvisualize1");
96  
    JInternalFrame f = getInternalFrame(vis);
97  
    if (f != null)
98  
      cset(this, frameRect := toRect(getBounds(f)));
99  
    vis = null;
100  
    print("done unvisualize1");
101  
  }
102  
  void unvisualize2() {}
103  
  void update() {}
104  
105  
  void delete() {  
106  
    unvisualize();
107  
    cleanUp(this);
108  
    super.delete();
109  
  }
110  
}
111  
112  
sclass InterestingStringModule extends Module {
113  
  S theString;
114  
}
115  
116  
sclass InputToInterestingString extends Module {
117  
  transient java.util.Timer timer;
118  
  
119  
  void start {
120  
    timer = doEvery(1000, r {
121  
      S s = getTextTrim(tfInput);
122  
      if (!hasModuleWithFields(InterestingStringModule, theString := s))
123  
        startModule(nu(InterestingStringModule, theString := s));
124  
    });
125  
  }
126  
127  
  void cleanMeUp() { cancelTimer(timer); }
128  
}
129  
130  
sclass ModuleCount extends Module {
131  
  transient JLabel label;
132  
133  
  void update {
134  
    if (label != null)
135  
      setText(label, lstr(onModules()));
136  
  }
137  
138  
  JComponent visualize() {
139  
    label = setFontSize(30, jcenteredlabel(lstr(onModules())));
140  
    ret label;
141  
  }
142  
  
143  
  void unvisualize2() { label = null; }  
144  
}
145  
146  
sclass ModuleList extends Module {
147  
  transient JList list;
148  
149  
  void update() {
150  
    if (list != null)
151  
      fillListWithStrings(list, calc());
152  
  }
153  
154  
  JComponent visualize() {
155  
    list = jlist(calc());
156  
    listPopupMenuItem(list, "Delete", voidfunc(fS s) {
157  
      thread-messagebox {
158  
        Module m = getConcept(Module, parseFirstLong(s));
159  
        removeConcept(m);
160  
      }
161  
    });
162  
    ret list;
163  
  }
164  
165  
  L<S> calc() {
166  
    ret map(func(Module m) -> S { renderConcept(m) /* contains id as first int */ }, onModules());
167  
  }
168  
  
169  
  void unvisualize2() { list = null; }  
170  
}
171  
172  
sclass ModuleClasses extends Module {
173  
  transient L<Class<? extends Module>> classes;
174  
175  
  void start() {
176  
    classes = myNonAbstractClassesImplementing(Module);
177  
  }
178  
179  
  JComponent visualize() {
180  
    JList list = jlist(map shortClassName(classes));
181  
    listPopupMenuItem(list, "Instantiate", voidfunc(fS s) {
182  
      thread-messagebox {
183  
        showModule((Module) nu(classForName("main$" + s)));
184  
      }
185  
    });
186  
    ret list;
187  
  }
188  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015803
Snippet name: Cubes Frame [v4, with module persistence, OK]
Eternal ID of this version: #1015803/33
Text MD5: b892446d27e85bd981e9e246e39190eb
Transpilation MD5: 8d91fb60b05ca51a19bf68c450eb4488
Author: stefan
Category:
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-27 23:53:46
Source code size: 4565 bytes / 188 lines
Pitched / IR pitched: No / No
Views / Downloads: 440 / 1812
Version history: 32 change(s)
Referenced in: [show references]