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

128
LINES

< > BotCompany Repo | #1015798 // Cubes Frame [v3]

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

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

1  
!7
2  
3  
sS background = #1009931;
4  
static JDesktopPane desktop;
5  
static JTextField tfInput;
6  
static L onModuleListChange = synchroList();
7  
static L<Module> modules;
8  
9  
p-noconsole {
10  
  autoRestart(5);
11  
12  
  modules = listWithMultiNotify(onModuleListChange);
13  
  
14  
  desktop = jTiledBackgroundDesktopPane(background);
15  
  autoFixDesktopPane(desktop);
16  
  cleanExitOnFrameClose(showMaximizedFrame(desktop));
17  
    
18  
  final JInternalFrame f = showCenteredInternalFrame(desktop, "Hello", 700, 150, setFontSize(20, tfInput = jcenteredtextfield("Find me some stuff")));
19  
  packInternalFrameVertically(f);
20  
  centerInternalFrame(f);
21  
  swing {
22  
 f.setLocation(f.getX(), 40);
23  
 }
24  
25  
  showModule(new ModuleClasses);
26  
  showModule(new ModuleCount);
27  
  startModule(new InputToInterestingString);
28  
}
29  
30  
sbool hasModuleWithFields(Class c, O... params) {
31  
  ret hasWhere(modules, c, params);
32  
}
33  
34  
svoid startModule(Module m) {
35  
  addIfNotThere(modules, m);
36  
  lock m.lock;
37  
  if (m.started) ret;
38  
  m.started = true;
39  
  m.start();
40  
}
41  
42  
svoid showModule(final Module m) {
43  
  startModule(m);
44  
  lock m.lock;
45  
  if (m.vis == null)
46  
    m.vis = m.visualize();
47  
  swing {
48  
    Rect r = m.frameRect;
49  
    if (r == null) randomRect(desktop.getWidth(), desktop.getHeight(), 10, 150, 100);
50  
    if (r == null) r = Rect(10, 10, 200, 100);
51  
    print("Showing frame at " + r);
52  
    S frameTitle = humanizeFormLabel(shortClassName(m));
53  
    showInternalFrame(desktop, frameTitle, r.x, r.y, r.w, r.h, m.vis);
54  
  }
55  
}
56  
57  
sclass Module {
58  
  transient Component vis;
59  
  transient bool started;
60  
  transient Lock lock = lock();
61  
  
62  
  Rect frameRect;
63  
  
64  
  JComponent visualize() { ret jCenteredMultiLineLabel(sfu(this)); }
65  
  void unvisualize() {}
66  
  void start() {}
67  
  void cleanMeUp() {
68  
    JInternalFrame f = getInternalFrame(vis);
69  
    if (f != null)
70  
      frameRect = toRect(getBounds(f));
71  
  }
72  
}
73  
74  
sclass InterestingStringModule extends Module {
75  
  S theString;
76  
}
77  
78  
sclass InputToInterestingString extends Module {
79  
  transient java.util.Timer timer;
80  
  
81  
  void start {
82  
    timer = doEvery(1000, r {
83  
      S s = getTextTrim(tfInput);
84  
      if (!hasModuleWithFields(InterestingStringModule, theString := s))
85  
        startModule(nu(InterestingStringModule, theString := s));
86  
    });
87  
  }
88  
89  
  void cleanMeUp() { cancelTimer(timer); }
90  
}
91  
92  
sclass ModuleCount extends Module {
93  
  JLabel label;
94  
95  
  void start() {
96  
    onModuleListChange.add(r {
97  
      if (label != null)
98  
        setText(label, lstr(modules));
99  
    });
100  
  }
101  
102  
  JComponent visualize() {
103  
    label = setFontSize(30, jcenteredlabel(lstr(modules)));
104  
    ret label;
105  
  }
106  
  
107  
  void unvisualize() { label = null; }  
108  
}
109  
110  
sclass ModuleClasses extends Module {
111  
  L<Class<? extends Module>> classes;
112  
113  
  void start() {
114  
    classes = myNonAbstractClassesImplementing(Module);
115  
  }
116  
117  
  JComponent visualize() {
118  
    JList list = jlist(map shortClassName(classes));
119  
    listPopupMenuItem(list, "Instantiate", voidfunc(fS s) {
120  
      thread {
121  
        pcall-messagebox {
122  
          showModule((Module) nu(classForName("main$" + s)));
123  
        }
124  
      }
125  
    });
126  
    ret list;
127  
  }
128  
}

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: #1015798
Snippet name: Cubes Frame [v3]
Eternal ID of this version: #1015798/21
Text MD5: f926ee27f3934fbe5044c1cb68d850ab
Transpilation MD5: cfd83c8ee65ed9896931f00f8c4ebc11
Author: stefan
Category:
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-27 22:30:42
Source code size: 3137 bytes / 128 lines
Pitched / IR pitched: No / No
Views / Downloads: 381 / 824
Version history: 20 change(s)
Referenced in: [show references]