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

162
LINES

< > BotCompany Repo | #1009958 // Circles Editor v2 [OK]

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

Download Jar. Uses 4489K of libraries. Click here for Pure Java version (12605L/91K).

!7

concept Drawing {
  S globalID = aGlobalID();
  S name;
  S calStructure;
}

static new CirclesAndLines cal;
static Canvas canvas;
static Drawing drawing;
sbool autoVis;

p {
  useDBOf(#1007609);
  db();
  substance();
  swing {
    fixCAL();
    canvas = cal.show(1000, 600);
    updateDrawingsMenu();
    addToWindow(canvas, withMargin(jcenteredline(
      jbutton("New drawing", f newDrawing),
      jbutton("New circle...", f newCircle),
      jbutton("Save drawing", f saveDrawing),
      jbutton("PUBLISH drawing to server", f publish)));
    //addToWindow(canvas, withMargin(jcenteredlabel("Create connections by dragging between circles with right mouse button")));
    addDrawingsList();
    centerFrame(canvas);
    //hideConsole();
  }
}

svoid newCircle {
  final JTextField text = jtextfield();
  showFormTitled("New Circle", "Text", text, r-thread { loading {
    S theText = getTextTrim(text);
    double x = random(0.2, 0.8), y = random(0.2, 0.8);
    if (autoVis)
      cal.circle_autoVis(theText, x, y);
    else
      cal.circle(theText, x, y);
    canvas.update();
  }});
}

static Drawing saveDrawing() {
  ret saveDrawing(drawing != null ? drawing.name : "");
}
  
static Drawing saveDrawing(S name) {
  if (empty(name)) {
    final JTextField tfName = jtextfield(name);
    showFormTitled("Name drawing",
      "Name", tfName,
      r { 
        saveDrawing(or2(getTextTrim(tfName), "Untitled"));
      });
    null;
  }
  
  S s = structure(cal);
  if (drawing == null)
    drawing = cnew(Drawing);
  setDrawing(drawing);
  cset(drawing, calStructure := s, +name);
  updateDrawingsMenu();
  ret drawing;
}

svoid newDrawing {
  setCAL(new CirclesAndLines);
  setDrawing(null);
}

svoid updateDrawingsMenu {
  L params = ll("New drawing", f newDrawing);
  for (final Drawing d : reversed(list(Drawing)))
    addAll(params, "Load " + (nempty(d.name) ? quote(d.name) : str(d.id)) + " (made " + renderDate(d.created) + ")", r { loadDrawing(d) });
  addMenu(canvas, "Drawings", toObjectArray(params));
}

sS drawingName(Drawing d) {
  ret d == null ? "" : "[" + d.id + "] "
    + (nempty(d.name) ? quote(d.name) + " " : "");
}

static L<S> makeDrawingsList() {
  new L<S> l;
  for (final Drawing d : reversed(list(Drawing)))
    l.add(drawingName(d)
      /*+ " (" + renderDate(d.created) + ")"*/);
  ret l;
}

static Drawing drawingFromList(S s) {
  ret getConcept(Drawing, parseFirstLong(s));
}

svoid addDrawingsList {
  final JList list = jlist();
  O load = voidfunc(S s) { loadDrawing(drawingFromList(s)) };
  onDoubleClick(list, load);
  
  listPopupMenuItem(list, "Rename...", voidfunc(S s) {
    final Drawing d = drawingFromList(s);
    final JTextField tf = jtextfield(d.name);
    showFormTitled("Rename Drawing",
      "Old name", jlabel(d.name),
      "New name", tf,
      r {
        cset(d, name := getTextTrim(tf));
        setDrawing(d);
      });
  });
  
  listPopupMenuItem(list, "Show structure", voidfunc(S s) {
    final Drawing d = drawingFromList(s);
    showWrappedText("Structure of drawing", d.calStructure);
  });
  
  addToWindowSplitRight_aggressive(canvas, list, 0.7f);
  awtCalcOnConceptsChange(list, r { fillListWithStrings(list, makeDrawingsList()) });
}

svoid fixCAL() {
  cal.imageForUserMadeNodes = whiteImage(10, 10);
}

svoid setCAL(CirclesAndLines cal) {
  main.cal = cal;
  fixCAL();
  Canvas c = canvas;
  canvas = cal.makeCanvas();
  awtReplaceComponent(c, canvas);
  //new CirclesRelater(canvas, cal);
}

svoid setDrawing(Drawing d) {
  drawing = d;
  setFrameTitle(canvas, drawingName(d) + " - " + programName());
}

svoid loadDrawing(Drawing d) {
  setDrawing(d);
  CirclesAndLines cal = cast unstructure(d.calStructure);
  //cal_setAutoVis(cal);
  setCAL(cal);
}

svoid publish {
  final Drawing d = saveDrawing();
  if (d == null) ret;
  thread { loading {
    S fullName = "Drawing " + d.globalID + " " + renderDate(now())
      + " - " + or2(d.name, "Untitled");
    S url = uploadToImageServer(canvas.getImage(), fullName);
    infoBox("Image uploaded to server! " + url);
    S id = createSuperHighSnippet(structure(d), fullName, 56 /*SN_AI_DRAWING*/, null, null);
    infoBox("Drawing uploaded. " + fsI(id));
  }}
}

Author comment

Began life as a copy of #1007609

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): cfunsshuasjs, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1009958
Snippet name: Circles Editor v2 [OK]
Eternal ID of this version: #1009958/26
Text MD5: 66eb744fd1ed84b56668b629d4314385
Transpilation MD5: dd6790bf2e3829d49aeab17ea162efe7
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): Yes
Created/modified: 2017-08-27 22:30:18
Source code size: 4356 bytes / 162 lines
Pitched / IR pitched: No / No
Views / Downloads: 599 / 1375
Version history: 25 change(s)
Referenced in: [show references]