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

237
LINES

< > BotCompany Repo | #1009961 // Circles Editor v3 [OK]

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

Download Jar. Uses 4597K of libraries. Click here for Pure Java version (25268L/141K).

1  
!7
2  
3  
set flag WebWithRelationsMap.
4  
set flag AllPublic.
5  
6  
concept Drawing {
7  
  S globalID = aGlobalID();
8  
  S name;
9  
  S calStructure;
10  
}
11  
12  
static new CirclesAndLines cal;
13  
static Canvas canvas;
14  
static Drawing drawing;
15  
static JLabel lblGlobalID;
16  
sbool autoVis;
17  
18  
p {
19  
  autoRestart();
20  
  useDBOf(#1007609);
21  
  db();
22  
  fixGlobalIDs();
23  
  substance();
24  
  swing {
25  
    fixCAL();
26  
    canvas = cal.show(1000, 600);
27  
    makeMenu();
28  
    addToWindowNorth(canvas, withMargin(jcenteredline(
29  
      jbutton("New drawing", f newDrawing),
30  
      lblGlobalID = jlabel(),
31  
      jbutton("New circle", f newCircle)
32  
    )));
33  
    addToWindow(canvas, withMargin(jcenteredline(
34  
      jbutton("Save drawing", f saveDrawing),
35  
      jbutton("Save drawing as...", f saveDrawingAs),
36  
      jbutton("PUBLISH", f publish)));
37  
    //addToWindow(canvas, withMargin(jcenteredlabel("Create connections by dragging between circles with right mouse button")));
38  
    addDrawingsList();
39  
    centerFrame(canvas);
40  
    hideConsole();
41  
  }
42  
  bot("Circles Editor.");
43  
  sleepIfMain();
44  
}
45  
46  
svoid newCircle {
47  
  final JTextField text = jtextfield();
48  
  showFormTitled("New Circle", "Text", text, r-thread { loading {
49  
    S theText = getTextTrim(text);
50  
    newCircle(theText);
51  
  }});
52  
}
53  
54  
svoid newCircle(S theText) {
55  
  double x = random(0.2, 0.8), y = random(0.2, 0.8);
56  
  if (autoVis)
57  
    cal.circle_autoVis(theText, x, y);
58  
  else
59  
    cal.circle(theText, x, y);
60  
  canvas.update();
61  
}
62  
63  
static Drawing saveDrawing() {
64  
  ret saveDrawing(drawing != null ? drawing.name : "");
65  
}
66  
  
67  
static Drawing saveDrawing(S name) {
68  
  if (empty(name)) {
69  
    final JTextField tfName = jtextfield(makeUpName());
70  
    showFormTitled("Name drawing",
71  
      "Name", tfName,
72  
      r { 
73  
        saveDrawing(or2(getTextTrim(tfName), "Untitled"));
74  
      });
75  
    null;
76  
  }
77  
  
78  
  cal.title = name;
79  
  if (drawing == null)
80  
    drawing = cnew(Drawing);
81  
  cal.globalID = drawing.globalID;
82  
  S s = cal_structure(cal);
83  
  cset(drawing, calStructure := s, +name);
84  
  setDrawing(drawing);
85  
  ret drawing;
86  
}
87  
88  
svoid newDrawing {
89  
  setCAL(new CirclesAndLines);
90  
  setDrawing(null);
91  
  newCircle();
92  
}
93  
94  
svoid makeMenu {
95  
  /*if (hasSSHPassword("root", "tinybrain.de"))
96  
    addMenu(canvas, "Menu",
97  
      "Upload all drawings to tinybrain.de (only for Stefan ^^)", f uploadAll);*/
98  
  addMenu(canvas, "Menu",
99  
    "Upload all drawings!", f uploadAll2);
100  
}
101  
102  
sS drawingName(Drawing d) {
103  
  ret d == null ? "" : "[" + d.id + "] "
104  
    + (nempty(d.name) ? quote(d.name) + " " : "");
105  
}
106  
107  
static L makeDrawingsTable() {
108  
  new L l;
109  
  for (final Drawing d : reversed(list(Drawing))) {
110  
    CirclesAndLines cal = cal_unstructure(d.calStructure);
111  
    l.add(litorderedmap("Drawing" := drawingName(d),
112  
      "Circles + Relations" := join("|",
113  
        concatLists(
114  
          collect(cal.circles, 'text),
115  
          collectTreeSet(cal.lines, 'text)))));
116  
  }
117  
  ret l;
118  
}
119  
120  
static Drawing drawingFromTable(JTable table, int row) {
121  
  ret getConcept(Drawing, parseFirstLong((S) getTableCell(table, row, 0)));
122  
}
123  
124  
svoid addDrawingsList {
125  
  final JTable table = sexyTableWithoutDrag();
126  
  O load = voidfunc(int row) { loadDrawing(drawingFromTable(table, row)) };
127  
  onDoubleClick(table, load);
128  
  
129  
  tablePopupMenu(table, voidfunc(JPopupMenu menu, final int row) {
130  
    final Drawing d = drawingFromTable(table, row);
131  
    addMenuItem(menu, "ID: " + d.globalID, r { copyTextToClipboard(d.globalID) });
132  
  });
133  
  
134  
  tablePopupMenuItem(table, "Rename...", voidfunc(int row) {
135  
    final Drawing d = drawingFromTable(table, row);
136  
    final JTextField tf = jtextfield(d.name);
137  
    showFormTitled("Rename Drawing",
138  
      "Old name", jlabel(d.name),
139  
      "New name", tf,
140  
      r {
141  
        cset(d, name := getTextTrim(tf));
142  
        setDrawing(d);
143  
      });
144  
  });
145  
  
146  
  tablePopupMenuItem(table, "Show structure", voidfunc(int row) {
147  
    final Drawing d = drawingFromTable(table, row);
148  
    showWrappedText("Structure of drawing", cal_simplifiedStructure(d.calStructure));
149  
  });
150  
  
151  
  tablePopupMenuItem(table, "Copy structure to clipboard", voidfunc(int row) {
152  
    final Drawing d = drawingFromTable(table, row);
153  
    copyTextToClipboard(cal_simplifiedStructure(d.calStructure));
154  
  });
155  
  
156  
  tablePopupMenuItem(table, "Delete", voidfunc(int row) {
157  
    final Drawing d = drawingFromTable(table, row);
158  
    removeConcept(d);
159  
  });
160  
  
161  
  addToWindowSplitRight_aggressive(canvas, tableWithSearcher(table), 0.7f);
162  
  awtCalcOnConceptsChange(table, r { dataToTable(table, makeDrawingsTable()) });
163  
}
164  
165  
svoid fixCAL() {
166  
  cal.imageForUserMadeNodes = whiteImage(10, 10);
167  
}
168  
169  
svoid setCAL(CirclesAndLines cal) {
170  
  main.cal = cal;
171  
  fixCAL();
172  
  Canvas c = canvas;
173  
  canvas = cal.makeCanvas();
174  
  awtReplaceComponent(c, canvas);
175  
  //new CirclesRelater(canvas, cal);
176  
}
177  
178  
svoid setDrawing(Drawing d) {
179  
  drawing = d;
180  
  setText(lblGlobalID, drawing != null ? "Drawing ID: " + drawing.globalID : "");
181  
  setFrameTitle(canvas, trim(drawingName(d)) + " - " + programName());
182  
}
183  
184  
svoid loadDrawing(Drawing d) {
185  
  setDrawing(d);
186  
  CirclesAndLines cal = cast unstructure(d.calStructure);
187  
  //cal_setAutoVis(cal);
188  
  setCAL(cal);
189  
}
190  
191  
svoid publish {
192  
  final Drawing d = saveDrawing();
193  
  if (d == null) ret;
194  
  thread { loading {
195  
    S fullName = "Drawing " + d.globalID + " " + renderDate(now())
196  
      + " - " + or2(d.name, "Untitled");
197  
    S url = uploadToImageServer(canvas.getImage(), fullName);
198  
    infoBox("Image uploaded to server! " + url);
199  
    S id = createSuperHighSnippet(structure(d), fullName, 56 /*SN_AI_DRAWING*/, null, null);
200  
    infoBox("Drawing uploaded. " + fsI(id));
201  
  }}
202  
}
203  
204  
sS makeUpName() {
205  
  Circle c = first(cal.circles);
206  
  ret c == null ? "" : c.text;
207  
}
208  
209  
svoid saveDrawingAs {
210  
  drawing = cnew(Drawing);
211  
  saveDrawing();
212  
}
213  
214  
svoid uploadAll { fixGlobalIDs(); run(#1009985); }
215  
svoid uploadAll2 { runInNewThread_awt(#1010485); }
216  
217  
answer {
218  
  if "new diagram with node *" {
219  
    swing {
220  
      activateFrame(canvas);
221  
      newDrawing();
222  
      if (nempty($1)) newCircle($1);
223  
    }
224  
    ret "OK";
225  
  }
226  
}
227  
228  
svoid fixGlobalIDs {
229  
  for (Drawing d) pcall {
230  
    if (!d.calStructure.contains(d.globalID)) {
231  
      print("Fixing global ID: " + d.globalID);
232  
      CirclesAndLines cal = cal_unstructure(d.calStructure);
233  
      cal.globalID = d.globalID;
234  
      cset(d, calStructure := cal_structure(cal));
235  
    }
236  
  }
237  
}

Author comment

Began life as a copy of #1009958

download  show line numbers  debug dex  old transpilations   

Travelled to 23 computer(s): aoiabmzegqzx, aqvamacmveew, bhatertpkbcr, bvmoasoxxqgd, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, imzmzdywqqli, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pwiztjibzslt, pyentgdyhuwx, pzhvpgtvlbxg, triorysbatvj, tslmcundralx, tvejysmllsmz, vouqrxazstgt, vpdwwinrgdga, xeobevbjagfg, xrpafgyirdlv

No comments. add comment

Snippet ID: #1009961
Snippet name: Circles Editor v3 [OK]
Eternal ID of this version: #1009961/52
Text MD5: d6e107dcbf3e10d9f34c5976556f1122
Transpilation MD5: baf8af9c64b3e9e4b612fd3ea931b1f4
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-25 02:45:27
Source code size: 6442 bytes / 237 lines
Pitched / IR pitched: No / No
Views / Downloads: 746 / 74303
Version history: 51 change(s)
Referenced in: [show references]