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

188
LINES

< > BotCompany Repo | #1010501 // Browse Downloaded Diagrams [dev.]

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

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

!7

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

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

p {
  //db();
  for (S s : downloadedDiagramStructures())
    cnew(Drawing, name := "Downloaded", calStructure := s);
    
  substance();
  swing {
    fixCAL();
    canvas = cal.show(1000, 600);
    /*addToWindowNorth(canvas, withMargin(jcenteredline(
      jbutton("New circle", f newCircle)
    );
    addToWindow(canvas, withMargin(jcenteredline(
      jbutton("New drawing", f newDrawing),
      jbutton("Save drawing", f saveDrawing),
      jbutton("Save drawing as...", f saveDrawingAs),
      jbutton("PUBLISH", 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(makeUpName());
    showFormTitled("Name drawing",
      "Name", tfName,
      r { 
        saveDrawing(or2(getTextTrim(tfName), "Untitled"));
      });
    null;
  }
  
  cal.title = name;
  S s = cal_structure(cal);
  if (drawing == null)
    drawing = cnew(Drawing);
  cset(drawing, calStructure := s, +name);
  setDrawing(drawing);
  ret drawing;
}

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

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

static L makeDrawingsTable() {
  new L l;
  for (final Drawing d : reversed(list(Drawing))) {
    CirclesAndLines cal = cal_unstructure(d.calStructure);
    l.add(litorderedmap("Drawing" := drawingName(d),
      "Circles + Relations" := join("|",
        concatLists(
          collect(cal.circles, 'text),
          collectTreeSet(cal.lines, 'text)))));
  }
  ret l;
}

static Drawing drawingFromTable(JTable table, int row) {
  ret getConcept(Drawing, parseFirstLong((S) getTableCell(table, row, 0)));
}

svoid addDrawingsList {
  final JTable table = sexyTableWithoutDrag();
  O load = voidfunc(int row) { loadDrawing(drawingFromTable(table, row)) };
  onDoubleClick(table, load);
  
  tablePopupMenuItem(table, "Rename...", voidfunc(int row) {
    final Drawing d = drawingFromTable(table, row);
    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);
      });
  });
  
  tablePopupMenuItem(table, "Show structure", voidfunc(int row) {
    final Drawing d = drawingFromTable(table, row);
    showWrappedText("Structure of drawing", cal_simplifiedStructure(d.calStructure));
  });
  
  tablePopupMenuItem(table, "Copy structure to clipboard", voidfunc(int row) {
    final Drawing d = drawingFromTable(table, row);
    copyTextToClipboard(cal_simplifiedStructure(d.calStructure));
  });
  
  tablePopupMenuItem(table, "Delete", voidfunc(int row) {
    final Drawing d = drawingFromTable(table, row);
    removeConcept(d);
  });
  
  addToWindowSplitRight_aggressive(canvas, tableWithSearcher(table), 0.7f);
  awtCalcOnConceptsChange(table, r { dataToTable(table, makeDrawingsTable()) });
}

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));
  }}
}

sS makeUpName() {
  Circle c = first(cal.circles);
  ret c == null ? "" : c.text;
}

svoid saveDrawingAs {
  drawing = cnew(Drawing);
  saveDrawing();
}

svoid uploadAll {
  run(#1009985);
}

Author comment

Began life as a copy of #1009961

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: #1010501
Snippet name: Browse Downloaded Diagrams [dev.]
Eternal ID of this version: #1010501/3
Text MD5: 877b8b75ca0b2f3aba48668f27bc442d
Transpilation MD5: 5f1f62ecd2b04750a10a5cdf9cfe6e62
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-18 20:29:02
Source code size: 5110 bytes / 188 lines
Pitched / IR pitched: No / No
Views / Downloads: 551 / 1112
Version history: 2 change(s)
Referenced in: