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

1  
!7
2  
3  
concept Drawing {
4  
  S globalID = aGlobalID();
5  
  S name;
6  
  S calStructure;
7  
}
8  
9  
static new CirclesAndLines cal;
10  
static Canvas canvas;
11  
static Drawing drawing;
12  
sbool autoVis;
13  
14  
p {
15  
  useDBOf(#1007609);
16  
  db();
17  
  substance();
18  
  swing {
19  
    fixCAL();
20  
    canvas = cal.show(1000, 600);
21  
    updateDrawingsMenu();
22  
    addToWindow(canvas, withMargin(jcenteredline(
23  
      jbutton("New drawing", f newDrawing),
24  
      jbutton("New circle...", f newCircle),
25  
      jbutton("Save drawing", f saveDrawing),
26  
      jbutton("PUBLISH drawing to server", f publish)));
27  
    //addToWindow(canvas, withMargin(jcenteredlabel("Create connections by dragging between circles with right mouse button")));
28  
    addDrawingsList();
29  
    centerFrame(canvas);
30  
    //hideConsole();
31  
  }
32  
}
33  
34  
svoid newCircle {
35  
  final JTextField text = jtextfield();
36  
  showFormTitled("New Circle", "Text", text, r-thread { loading {
37  
    S theText = getTextTrim(text);
38  
    double x = random(0.2, 0.8), y = random(0.2, 0.8);
39  
    if (autoVis)
40  
      cal.circle_autoVis(theText, x, y);
41  
    else
42  
      cal.circle(theText, x, y);
43  
    canvas.update();
44  
  }});
45  
}
46  
47  
static Drawing saveDrawing() {
48  
  ret saveDrawing(drawing != null ? drawing.name : "");
49  
}
50  
  
51  
static Drawing saveDrawing(S name) {
52  
  if (empty(name)) {
53  
    final JTextField tfName = jtextfield(name);
54  
    showFormTitled("Name drawing",
55  
      "Name", tfName,
56  
      r { 
57  
        saveDrawing(or2(getTextTrim(tfName), "Untitled"));
58  
      });
59  
    null;
60  
  }
61  
  
62  
  S s = structure(cal);
63  
  if (drawing == null)
64  
    drawing = cnew(Drawing);
65  
  setDrawing(drawing);
66  
  cset(drawing, calStructure := s, +name);
67  
  updateDrawingsMenu();
68  
  ret drawing;
69  
}
70  
71  
svoid newDrawing {
72  
  setCAL(new CirclesAndLines);
73  
  setDrawing(null);
74  
}
75  
76  
svoid updateDrawingsMenu {
77  
  L params = ll("New drawing", f newDrawing);
78  
  for (final Drawing d : reversed(list(Drawing)))
79  
    addAll(params, "Load " + (nempty(d.name) ? quote(d.name) : str(d.id)) + " (made " + renderDate(d.created) + ")", r { loadDrawing(d) });
80  
  addMenu(canvas, "Drawings", toObjectArray(params));
81  
}
82  
83  
sS drawingName(Drawing d) {
84  
  ret d == null ? "" : "[" + d.id + "] "
85  
    + (nempty(d.name) ? quote(d.name) + " " : "");
86  
}
87  
88  
static L<S> makeDrawingsList() {
89  
  new L<S> l;
90  
  for (final Drawing d : reversed(list(Drawing)))
91  
    l.add(drawingName(d)
92  
      /*+ " (" + renderDate(d.created) + ")"*/);
93  
  ret l;
94  
}
95  
96  
static Drawing drawingFromList(S s) {
97  
  ret getConcept(Drawing, parseFirstLong(s));
98  
}
99  
100  
svoid addDrawingsList {
101  
  final JList list = jlist();
102  
  O load = voidfunc(S s) { loadDrawing(drawingFromList(s)) };
103  
  onDoubleClick(list, load);
104  
  
105  
  listPopupMenuItem(list, "Rename...", voidfunc(S s) {
106  
    final Drawing d = drawingFromList(s);
107  
    final JTextField tf = jtextfield(d.name);
108  
    showFormTitled("Rename Drawing",
109  
      "Old name", jlabel(d.name),
110  
      "New name", tf,
111  
      r {
112  
        cset(d, name := getTextTrim(tf));
113  
        setDrawing(d);
114  
      });
115  
  });
116  
  
117  
  listPopupMenuItem(list, "Show structure", voidfunc(S s) {
118  
    final Drawing d = drawingFromList(s);
119  
    showWrappedText("Structure of drawing", d.calStructure);
120  
  });
121  
  
122  
  addToWindowSplitRight_aggressive(canvas, list, 0.7f);
123  
  awtCalcOnConceptsChange(list, r { fillListWithStrings(list, makeDrawingsList()) });
124  
}
125  
126  
svoid fixCAL() {
127  
  cal.imageForUserMadeNodes = whiteImage(10, 10);
128  
}
129  
130  
svoid setCAL(CirclesAndLines cal) {
131  
  main.cal = cal;
132  
  fixCAL();
133  
  Canvas c = canvas;
134  
  canvas = cal.makeCanvas();
135  
  awtReplaceComponent(c, canvas);
136  
  //new CirclesRelater(canvas, cal);
137  
}
138  
139  
svoid setDrawing(Drawing d) {
140  
  drawing = d;
141  
  setFrameTitle(canvas, drawingName(d) + " - " + programName());
142  
}
143  
144  
svoid loadDrawing(Drawing d) {
145  
  setDrawing(d);
146  
  CirclesAndLines cal = cast unstructure(d.calStructure);
147  
  //cal_setAutoVis(cal);
148  
  setCAL(cal);
149  
}
150  
151  
svoid publish {
152  
  final Drawing d = saveDrawing();
153  
  if (d == null) ret;
154  
  thread { loading {
155  
    S fullName = "Drawing " + d.globalID + " " + renderDate(now())
156  
      + " - " + or2(d.name, "Untitled");
157  
    S url = uploadToImageServer(canvas.getImage(), fullName);
158  
    infoBox("Image uploaded to server! " + url);
159  
    S id = createSuperHighSnippet(structure(d), fullName, 56 /*SN_AI_DRAWING*/, null, null);
160  
    infoBox("Drawing uploaded. " + fsI(id));
161  
  }}
162  
}

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: 602 / 1380
Version history: 25 change(s)
Referenced in: [show references]