Download Jar. Uses 3874K of libraries. Click here for Pure Java version (13687L/99K).
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 | //db(); |
16 | for (S s : downloadedDiagramStructures()) |
17 | cnew(Drawing, name := "Downloaded", calStructure := s); |
18 | |
19 | substance(); |
20 | swing {
|
21 | fixCAL(); |
22 | canvas = cal.show(1000, 600); |
23 | /*addToWindowNorth(canvas, withMargin(jcenteredline( |
24 | jbutton("New circle", f newCircle)
|
25 | ); |
26 | addToWindow(canvas, withMargin(jcenteredline( |
27 | jbutton("New drawing", f newDrawing),
|
28 | jbutton("Save drawing", f saveDrawing),
|
29 | jbutton("Save drawing as...", f saveDrawingAs),
|
30 | jbutton("PUBLISH", f publish)));*/
|
31 | //addToWindow(canvas, withMargin(jcenteredlabel("Create connections by dragging between circles with right mouse button")));
|
32 | addDrawingsList(); |
33 | centerFrame(canvas); |
34 | hideConsole(); |
35 | } |
36 | } |
37 | |
38 | svoid newCircle {
|
39 | final JTextField text = jtextfield(); |
40 | showFormTitled("New Circle", "Text", text, r-thread { loading {
|
41 | S theText = getTextTrim(text); |
42 | double x = random(0.2, 0.8), y = random(0.2, 0.8); |
43 | if (autoVis) |
44 | cal.circle_autoVis(theText, x, y); |
45 | else |
46 | cal.circle(theText, x, y); |
47 | canvas.update(); |
48 | }}); |
49 | } |
50 | |
51 | static Drawing saveDrawing() {
|
52 | ret saveDrawing(drawing != null ? drawing.name : ""); |
53 | } |
54 | |
55 | static Drawing saveDrawing(S name) {
|
56 | if (empty(name)) {
|
57 | final JTextField tfName = jtextfield(makeUpName()); |
58 | showFormTitled("Name drawing",
|
59 | "Name", tfName, |
60 | r {
|
61 | saveDrawing(or2(getTextTrim(tfName), "Untitled")); |
62 | }); |
63 | null; |
64 | } |
65 | |
66 | cal.title = name; |
67 | S s = cal_structure(cal); |
68 | if (drawing == null) |
69 | drawing = cnew(Drawing); |
70 | cset(drawing, calStructure := s, +name); |
71 | setDrawing(drawing); |
72 | ret drawing; |
73 | } |
74 | |
75 | svoid newDrawing {
|
76 | setCAL(new CirclesAndLines); |
77 | setDrawing(null); |
78 | } |
79 | |
80 | sS drawingName(Drawing d) {
|
81 | ret d == null ? "" : "[" + d.id + "] " |
82 | + (nempty(d.name) ? quote(d.name) + " " : ""); |
83 | } |
84 | |
85 | static L makeDrawingsTable() {
|
86 | new L l; |
87 | for (final Drawing d : reversed(list(Drawing))) {
|
88 | CirclesAndLines cal = cal_unstructure(d.calStructure); |
89 | l.add(litorderedmap("Drawing" := drawingName(d),
|
90 | "Circles + Relations" := join("|",
|
91 | concatLists( |
92 | collect(cal.circles, 'text), |
93 | collectTreeSet(cal.lines, 'text))))); |
94 | } |
95 | ret l; |
96 | } |
97 | |
98 | static Drawing drawingFromTable(JTable table, int row) {
|
99 | ret getConcept(Drawing, parseFirstLong((S) getTableCell(table, row, 0))); |
100 | } |
101 | |
102 | svoid addDrawingsList {
|
103 | final JTable table = sexyTableWithoutDrag(); |
104 | O load = voidfunc(int row) { loadDrawing(drawingFromTable(table, row)) };
|
105 | onDoubleClick(table, load); |
106 | |
107 | tablePopupMenuItem(table, "Rename...", voidfunc(int row) {
|
108 | final Drawing d = drawingFromTable(table, row); |
109 | final JTextField tf = jtextfield(d.name); |
110 | showFormTitled("Rename Drawing",
|
111 | "Old name", jlabel(d.name), |
112 | "New name", tf, |
113 | r {
|
114 | cset(d, name := getTextTrim(tf)); |
115 | setDrawing(d); |
116 | }); |
117 | }); |
118 | |
119 | tablePopupMenuItem(table, "Show structure", voidfunc(int row) {
|
120 | final Drawing d = drawingFromTable(table, row); |
121 | showWrappedText("Structure of drawing", cal_simplifiedStructure(d.calStructure));
|
122 | }); |
123 | |
124 | tablePopupMenuItem(table, "Copy structure to clipboard", voidfunc(int row) {
|
125 | final Drawing d = drawingFromTable(table, row); |
126 | copyTextToClipboard(cal_simplifiedStructure(d.calStructure)); |
127 | }); |
128 | |
129 | tablePopupMenuItem(table, "Delete", voidfunc(int row) {
|
130 | final Drawing d = drawingFromTable(table, row); |
131 | removeConcept(d); |
132 | }); |
133 | |
134 | addToWindowSplitRight_aggressive(canvas, tableWithSearcher(table), 0.7f); |
135 | awtCalcOnConceptsChange(table, r { dataToTable(table, makeDrawingsTable()) });
|
136 | } |
137 | |
138 | svoid fixCAL() {
|
139 | cal.imageForUserMadeNodes = whiteImage(10, 10); |
140 | } |
141 | |
142 | svoid setCAL(CirclesAndLines cal) {
|
143 | main.cal = cal; |
144 | fixCAL(); |
145 | Canvas c = canvas; |
146 | canvas = cal.makeCanvas(); |
147 | awtReplaceComponent(c, canvas); |
148 | //new CirclesRelater(canvas, cal); |
149 | } |
150 | |
151 | svoid setDrawing(Drawing d) {
|
152 | drawing = d; |
153 | setFrameTitle(canvas, drawingName(d) + " - " + programName()); |
154 | } |
155 | |
156 | svoid loadDrawing(Drawing d) {
|
157 | setDrawing(d); |
158 | CirclesAndLines cal = cast unstructure(d.calStructure); |
159 | //cal_setAutoVis(cal); |
160 | setCAL(cal); |
161 | } |
162 | |
163 | svoid publish {
|
164 | final Drawing d = saveDrawing(); |
165 | if (d == null) ret; |
166 | thread { loading {
|
167 | S fullName = "Drawing " + d.globalID + " " + renderDate(now()) |
168 | + " - " + or2(d.name, "Untitled"); |
169 | S url = uploadToImageServer(canvas.getImage(), fullName); |
170 | infoBox("Image uploaded to server! " + url);
|
171 | S id = createSuperHighSnippet(structure(d), fullName, 56 /*SN_AI_DRAWING*/, null, null); |
172 | infoBox("Drawing uploaded. " + fsI(id));
|
173 | }} |
174 | } |
175 | |
176 | sS makeUpName() {
|
177 | Circle c = first(cal.circles); |
178 | ret c == null ? "" : c.text; |
179 | } |
180 | |
181 | svoid saveDrawingAs {
|
182 | drawing = cnew(Drawing); |
183 | saveDrawing(); |
184 | } |
185 | |
186 | svoid uploadAll {
|
187 | run(#1009985); |
188 | } |
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: | 866 / 1891 |
| Version history: | 2 change(s) |
| Referenced in: | [show references] |