Download Jar. Uses 4489K of libraries. Click here for Pure Java version (12617L/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 S name; |
12 | |
13 | p {
|
14 | db(); |
15 | substance(); |
16 | swing {
|
17 | canvas = cal.show(800, 600); |
18 | setCAL(cal); |
19 | updateDrawingsMenu(); |
20 | addToWindow(canvas, withMargin(jcenteredline( |
21 | jbutton("New Circle...", f newCircle),
|
22 | jbutton("Save drawing", f saveDrawing),
|
23 | jbutton("PUBLISH drawing to server", f publish)));
|
24 | addToWindow(canvas, withMargin(jcenteredlabel("Create connections by dragging between circles with right mouse button")));
|
25 | addDrawingsList(); |
26 | centerFrame(canvas); |
27 | hideConsole(); |
28 | } |
29 | } |
30 | |
31 | svoid newCircle {
|
32 | final JTextField text = jtextfield(); |
33 | showFormTitled("New Circle", "Text", text, r-thread { loading {
|
34 | cal.circle_autoVis(getTextTrim(text), random(0.2, 0.8), random(0.2, 0.8)); |
35 | canvas.update(); |
36 | }}); |
37 | } |
38 | |
39 | static Drawing saveDrawing() {
|
40 | if (empty(name)) {
|
41 | final JTextField tfName = jtextfield(); |
42 | showFormTitled("Name drawing",
|
43 | "Name", tfName, |
44 | r {
|
45 | name = getTextTrim(tfName); |
46 | saveDrawing(); |
47 | }); |
48 | null; |
49 | } |
50 | |
51 | S s = cal_structure(cal); |
52 | Drawing d = cnew(Drawing, calStructure := s, +name); |
53 | //infoBox("Drawing saved. ID: " + d.id + ", " + lUtf8(quote(s)) + " bytes");
|
54 | updateDrawingsMenu(); |
55 | ret d; |
56 | } |
57 | |
58 | svoid newDrawing {
|
59 | setCAL(new CirclesAndLines); |
60 | name = ""; |
61 | } |
62 | |
63 | svoid updateDrawingsMenu {
|
64 | L params = ll("New drawing", r { newDrawing() });
|
65 | for (final Drawing d : reversed(list(Drawing))) |
66 | addAll(params, "Load " + (nempty(d.name) ? quote(d.name) : str(d.id)) + " (made " + renderDate(d.created) + ")", r { loadDrawing(d) });
|
67 | addMenu(canvas, "Drawings", toObjectArray(params)); |
68 | } |
69 | |
70 | static L<S> makeDrawingsList() {
|
71 | new L<S> l; |
72 | for (final Drawing d : reversed(list(Drawing))) |
73 | l.add( |
74 | "[" + d.id + "] " |
75 | + (nempty(d.name) ? quote(d.name) + " " : "") |
76 | /*+ " (" + renderDate(d.created) + ")"*/);
|
77 | ret l; |
78 | } |
79 | |
80 | svoid addDrawingsList {
|
81 | final JList list = jlist(); |
82 | onDoubleClick(list, voidfunc(S s) { loadDrawing(getConcept(Drawing, parseFirstLong(s))) });
|
83 | addToWindowSplitRight_aggressive(canvas, list, 0.7f); |
84 | awtCalcOnConceptsChange(list, r { fillListWithStrings(list, makeDrawingsList()) });
|
85 | } |
86 | |
87 | svoid setCAL(CirclesAndLines cal) {
|
88 | main.cal = cal; |
89 | Canvas c = canvas; |
90 | canvas = cal.makeCanvas(); |
91 | awtReplaceComponent(c, canvas); |
92 | new CirclesRelater(canvas, cal); |
93 | } |
94 | |
95 | svoid loadDrawing(Drawing d) {
|
96 | CirclesAndLines cal = cast unstructure(d.calStructure); |
97 | cal_setAutoVis(cal); |
98 | setCAL(cal); |
99 | } |
100 | |
101 | svoid publish {
|
102 | fS globalID = aGlobalID(); |
103 | final JTextField tfName = jtextfield(name); |
104 | showFormTitled("Publish drawing to server?",
|
105 | "Global ID" := globalID, |
106 | "Name" := tfName, |
107 | r-thread { loading {
|
108 | name = getTextTrim(tfName); |
109 | Drawing d = saveDrawing(); |
110 | cset(d, +globalID, +name); |
111 | S fullName = "Drawing " + globalID + " " + renderDate(now()) |
112 | + " - " + or2(name, "Untitled"); |
113 | S url = uploadToImageServer(canvas.getImage(), fullName); |
114 | infoBox("Image uploaded to server! " + url);
|
115 | S id = createSuperHighSnippet(structure(d), fullName, 56 /*SN_AI_DRAWING*/, null, null); |
116 | infoBox("Drawing uploaded. " + fsI(id));
|
117 | }}); |
118 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): cfunsshuasjs, meaugxdlecrj, mqqgnosmbjvj, onxytkatvevr, tvejysmllsmz, wtqryiryparv, xinetxnxrdbb
No comments. add comment
| Snippet ID: | #1007609 |
| Snippet name: | Circles Editor [WORKS basically] |
| Eternal ID of this version: | #1007609/48 |
| Text MD5: | b0f00d1a7c300483c2c55343eacd85cd |
| Transpilation MD5: | 6d36db36b729bc9e120c084df94aa86b |
| 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-28 14:39:43 |
| Source code size: | 3389 bytes / 118 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1059 / 4063 |
| Version history: | 47 change(s) |
| Referenced in: | [show references] |