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

!7

sS background = #1009931;
static JDesktopPane desktop;
static JTextField tfInput;
static L onModuleListChange = synchroList();
static L<Module> modules;

p-noconsole {
  autoRestart(5);

  modules = listWithMultiNotify(onModuleListChange);
  
  desktop = jTiledBackgroundDesktopPane(background);
  autoFixDesktopPane(desktop);
  cleanExitOnFrameClose(showMaximizedFrame(desktop));
    
  final JInternalFrame f = showCenteredInternalFrame(desktop, "Hello", 700, 150, setFontSize(20, tfInput = jcenteredtextfield("Find me some stuff")));
  packInternalFrameVertically(f);
  centerInternalFrame(f);
  swing {
 f.setLocation(f.getX(), 40);
 }

  showModule(new ModuleClasses);
  showModule(new ModuleCount);
  startModule(new InputToInterestingString);
}

sbool hasModuleWithFields(Class c, O... params) {
  ret hasWhere(modules, c, params);
}

svoid startModule(Module m) {
  addIfNotThere(modules, m);
  lock m.lock;
  if (m.started) ret;
  m.started = true;
  m.start();
}

svoid showModule(final Module m) {
  startModule(m);
  lock m.lock;
  if (m.vis == null)
    m.vis = m.visualize();
  swing {
    Rect r = m.frameRect;
    if (r == null) randomRect(desktop.getWidth(), desktop.getHeight(), 10, 150, 100);
    if (r == null) r = Rect(10, 10, 200, 100);
    print("Showing frame at " + r);
    S frameTitle = humanizeFormLabel(shortClassName(m));
    showInternalFrame(desktop, frameTitle, r.x, r.y, r.w, r.h, m.vis);
  }
}

sclass Module {
  transient Component vis;
  transient bool started;
  transient Lock lock = lock();
  
  Rect frameRect;
  
  JComponent visualize() { ret jCenteredMultiLineLabel(sfu(this)); }
  void unvisualize() {}
  void start() {}
  void cleanMeUp() {
    JInternalFrame f = getInternalFrame(vis);
    if (f != null)
      frameRect = toRect(getBounds(f));
  }
}

sclass InterestingStringModule extends Module {
  S theString;
}

sclass InputToInterestingString extends Module {
  transient java.util.Timer timer;
  
  void start {
    timer = doEvery(1000, r {
      S s = getTextTrim(tfInput);
      if (!hasModuleWithFields(InterestingStringModule, theString := s))
        startModule(nu(InterestingStringModule, theString := s));
    });
  }

  void cleanMeUp() { cancelTimer(timer); }
}

sclass ModuleCount extends Module {
  JLabel label;

  void start() {
    onModuleListChange.add(r {
      if (label != null)
        setText(label, lstr(modules));
    });
  }

  JComponent visualize() {
    label = setFontSize(30, jcenteredlabel(lstr(modules)));
    ret label;
  }
  
  void unvisualize() { label = null; }  
}

sclass ModuleClasses extends Module {
  L<Class<? extends Module>> classes;

  void start() {
    classes = myNonAbstractClassesImplementing(Module);
  }

  JComponent visualize() {
    JList list = jlist(map shortClassName(classes));
    listPopupMenuItem(list, "Instantiate", voidfunc(fS s) {
      thread {
        pcall-messagebox {
          showModule((Module) nu(classForName("main$" + s)));
        }
      }
    });
    ret list;
  }
}

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: 516 / 1115
Version history: 20 change(s)
Referenced in: