-
Notifications
You must be signed in to change notification settings - Fork 1
/
MapInsight_V1_2.groovy
2167 lines (1875 loc) · 104 KB
/
MapInsight_V1_2.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
scriptVersion='MapInsight v1.1'
helptext1="""
$scriptVersion
28th July 2017
1. WALKING AROUND NODES
This script creates a free standing resizable window that allows you to 'walk' around
the nodes in a map.
When the script is run the currently selected node in the map is displayed along with its related nodes
ie. parent, children, connections in and out.
The user can double click any of the related nodes and it will be selected and become the currently selected node
Hovering over any related nodes shows its note and detail text if present.
To see the Note and details of the currently selected node use the View Menu and select Node Details
To see recent nodes visited see the History menu item
"""
helptext2="""
2. FINDING ASSOCIATED NODES
The script shows a sortable list of any possible related nodes (candidate nodes) by using 'proper'
words
(a) from the selected node's core text
(b) optionally from the node's note text
(c) optionally from the node's detail text
(d) and/or words entered by the user (separated by commas) or you can
specify a search phrase which is any string inside double quotes
(e) or a regular expression which is any string inside forward slashes
eg /M.*h/ would find the text March, Macbeth. Moth
For example if the selected node had the word 'London'
then any other nodes in map with the word 'London' in them would show as a possible connections.
(Proper word means a word is not a noise or stop word such as and, or, if etc.
This script has English stop words - can alter by changing 'stopWords' table in script)
If a candidate node is selected it will turn blue.
Once selected you can view the node in the map without selecting it (locate button) or
select the node (Go To button) and Map Insight will 'walk' to that node.
If a candidate node is right clicked then you can choose to add a connector between the main node and
the selected candidate node. The connector is created with the middle label being the word that links
the main and candidate node (eg 'london' in the example above).
If you wish to automatically create a connector for ALL the candidates then
press the "Connect All" button. You can reverse this by clicking the "Undo Connect ALL" button.
"""
helptext3="""
3. MANAGING CONNECTORS
Shows all the connectors in a sortable list and allows you to remove them or change the label if required.
This is useful when a map has so many connectors that they are difficult to see in the map
First select the base node to see the connectors belonging to it and its sub nodes.
Selecting the root node will view all connectors in the map.
Choose 'Connectors Manager' in the View menu
All connectors will be shown with the source node, target node and middle label. (To avoid label confusion
I decided to just use middle labels).
Clicking on a connector will highlight the connector in BLUE in the list and BLUE in the map.
You can remove the connector by clicking the 'Remove Connector' button
You can change the connectors middle label by clicking the 'Edit Label'
4. VIEWING CONNECTORS
The sub menu in the View menu lets you view specific connectors
'Show Current Node Connectors' will display only connectors to and from the current node in the map. All other
connectors will be hidden
'Show Connectors for a label' will display only connectors with a specific label in the map. All other
connectors will be hidden
'Hide all Connectors' will hide all connectors in the map (useful in crowded maps)
'Unhide all Connectors' will show all connectors in the map
"""
versionhistory="""
Version History
v1.0 First Version
v1.1 Added following new features thanks to forum members feedback
1. 'Refresh current view' in the Actions menu. Updates the current node details which is handy when underlying map has changed
2. New button 'Save As Map' on 'Possible Connections' window will save the source node and all suggested nodes together
with the connectors into a new map
3. Connector Candidates Options windows now caters for regular expressions
4. View, Connectors has new menu item 'Show Current Node Connectors' which will display only the connectors for the
current node and hide all other connectors. 'Unhide All Connectors' will restore view of all connectors
5. View, Connectors has new menu item 'Show Connectors for a label' which will display only the connectors with a
middle label that contains the label text and hide all other connectors. 'Unhide All Connectors' will restore view of all connectors
6. Allows multiline labels when adding connectors
7. Bug fixes (as per https://sourceforge.net/p/freeplane/discussion/758437/thread/a49efba6/)
"""
installation="""
Installation
1. Open the User Directory in Freeplane (Tools/Open User directory)
2. Open the scripts folder
3. Save this script as 'Map Insight v0.1.groovy' in the scripts folder
4. Restart Freeplane
To Use Script
1. Select an existing node
2. In Freeplane 'Tools' menu select 'Scripts'
3. Choose the script 'Map_Insight_V1_0'
"""
import javax.swing.*
import java.awt.*
import groovy.swing.SwingBuilder
import javax.swing.table.*
import java.awt.event.*
import java.text.SimpleDateFormat
import java.util.concurrent.TimeUnit
//*********************************************
// Global Variables
//*********************************************
newNode=null // refers to the node that Map Insight is focussed on
// (central white node in the Map Insight window
def recenthistoryDisplayed=false // stops recent history being displayed twice
def selectedCandidateNode=null // refers to a node that may be a connector candidate
def selectedConnectortablerow=null // refers to a connector table row that is currently selected in the Connectors window
def selectedconnectorobject=null // refers to the connector object that is currently selected in the Connectors window
def currentconnectorobjects=[] // buffr used to store all connectors for cut and paste
//*********************************************
// Global Functions
//*********************************************
// These global function closures are added to the main groovy script object (Object.metaClass)
// so they can be used globally through the script
Object.metaClass.msg = {text -> msg(text)}
Object.metaClass.statusBarMsg = {msg -> statusBarMsg(msg)}
Object.metaClass.getNodeFromMapSelection = {-> getNodeFromMapSelection()}
Object.metaClass.getNodeByID = {nodeID -> getNodeByID(nodeID)}
Object.metaClass.findNodeByID = {nodeID -> findNodeByID(nodeID)}
Object.metaClass.selectNodeByID = {nodeID -> selectNodeByID(nodeID)}
Object.metaClass.formatForSwingDisplay = {nodetype,text,note,details -> formatForSwingDisplay(nodetype,text,note,details)}
Object.metaClass.removeHtmlTags = {text -> removeHtmlTags(text)}
Object.metaClass.removeHtmlTags = {-> setAllConnectorsToDefaultColor()}
Object.metaClass.showConnectorsForCurrentNode = {-> showConnectorsForCurrentNode()}
Object.metaClass.hideAllConnectors = {-> hideAllConnectors()}
Object.metaClass.unhideAllConnectors = {-> unhideAllConnectors()}
Object.metaClass.formatNodeTextForCell = {nodetext ->formatNodeTextForCell(nodetext)}
Object.metaClass.removeAllConnectors = {->removeAllConnectors()}
//-----------------------
// == GLOBAL FUNCTION: == display text as Freeplane information message
def msg(text) {
ui.informationMessage(text)
}
//-----------------------
// == GLOBAL FUNCTION: == display text on status bar
def statusBarMsg(msg) {
c.statusInfo=msg
}
//-----------------------
// == GLOBAL FUNCTION: == get node object for currently selected node
def getNodeFromMapSelection() {
def theNode=null
c.selected.each{
theNode=it
}
return theNode
}
//-----------------------
// == GLOBAL FUNCTION: == get node object for specific node ID
def getNodeByID(nodeID) {
def theNode=null
c.find{it.nodeID==nodeID}.each{
theNode=it
}
return theNode
}
//-----------------------
// == GLOBAL FUNCTION: == find node object for specific node ID
def findNodeByID(nodeID) {
def theNode=null
c.find{it.nodeID==nodeID}.each{
theNode=it
}
return theNode
}
//-----------------------
// == GLOBAL FUNCTION: == select node on Map by node ID and center the map on the node
def selectNodeByID(nodeID) {
c.find{it.nodeID==nodeID}.each{
c.select(it)
c.centerOnNode(it)
updateRecentNodesVisited(it.text)
}
}
//-----------------------
// == GLOBAL FUNCTION: == select node object with specific title and center the map on the node
def selectNodeByTitle(nodeTitle) {
c.find{it.text==nodeTitle}.each{
c.select(it)
c.centerOnNode(it)
updateRecentNodesVisited(it.text)
}
}
//-----------------------
// == GLOBAL FUNCTION: == copy a node and all its properties to a new node
def copyProperties(dest, source) {
dest.text = source.text
dest.attributes = source.attributes.map
dest.link.text = source.link.text
if (source.note != null)
dest.note = source.note
dest.details = source.detailsText
}
// initialise recent nodes visited array
recentNodesVisited=[]
//-----------------------
// == GLOBAL FUNCTION: == update recent nodes visited array
def updateRecentNodesVisited(newNodeTitle) {
if (!recentNodesVisited.contains(newNodeTitle)) {
if (recentNodesVisited.size()>15) recentNodesVisited.pop()
recentNodesVisited.add(0,newNodeTitle)
}
}
//-----------------------
// == GLOBAL FUNCTION: == prepare node core, note and detail texts for display in Swing UI elements
def formatForSwingDisplay(nodetype,text,note,details) {
// In order to display node, note and detail text
// in swing ui elements remove extraneous html tags
// and format with 'clean' HTML to keep Swing UI
// elements happy
text=nodetype
wrapafterchars=80
wrapcharacter='\n'
String msgtext='<HTML><head></head><body style=\"width: 250px;\">'
if (text==null) text='empty'
text=text
.replace('</html>','')
.replace('</HTML>','')
.replace('<html>','')
.replace('<HTML>','')
.replace('</head>','')
.replace('</HEAD>','')
.replace('<head>','')
.replace('<HEAD>','')
.replace('</body>','')
.replace('</BODY>','')
.replace('<body>','')
.replace(' ',' ')
text=wordwrap(text,wrapafterchars,wrapcharacter).trim()
msgtext+="<B><font color=\"blue\">Title:</font></B><HR><B>$text</B><BR>"
if (note==null) note='empty'
note=note
.replace('</html>','')
.replace('</HTML>','')
.replace('<html>','')
.replace('<HTML>','')
.replace('</head>','')
.replace('</HEAD>','')
.replace('<head>','')
.replace('<HEAD>','')
.replace('</body>','')
.replace('</BODY>','')
.replace('<body>','')
.replace(' ',' ')
note=wordwrap(note,wrapafterchars,wrapcharacter).trim()
msgtext+="<B><font color=\"blue\">Note:</font></B><HR>$note<BR><BR>"
if (details==null) details='empty'
details=details
.replace('</html>','')
.replace('</HTML>','')
.replace('<html>','')
.replace('<HTML>','')
.replace('</head>','')
.replace('</HEAD>','')
.replace('<head>','')
.replace('<HEAD>','')
.replace('</body>','')
.replace('</ BODY>','')
.replace('<body>','')
.replace(' ',' ')
details=wordwrap(details,wrapafterchars,wrapcharacter).trim()
msgtext+="<B><font color=\"blue\">Details:</font></B><HR>$details<BR>"
msgtext+="""</body></HTML>"""
return msgtext.replace('\n\n','<BR>').replace('\n','<BR>')
}
//-----------------------
// == GLOBAL FUNCTION: == word wrap text
def wordwrap(text, width=80, prefix='') {
def out = ''
def remaining = text.replaceAll("\n", " ")
while (remaining) {
def next = prefix + remaining
def found = next.lastIndexOf(' ', width)
if (found == -1) remaining = ''
else {
remaining = next.substring(found + 1)
next = next[0..found]
}
out += next + '\n'
}
return out
}
//-----------------------
// == GLOBAL FUNCTION: == strip HTML tags from text
def removeHtmlTags(text) {
if (text!=null) {
def strippedText = text.replaceAll('\n\\s*', '\n') // remove extra spaces after line breaks
strippedText = strippedText.replaceAll('<.*?>', '') // remove anythiing in between < and >
strippedText = strippedText.replaceAll('^\\s*', '') // remove whitespace
strippedText = strippedText.replaceAll('\n\n\n', '\n') // replace multiple line feed with single line feed
return strippedText
} else return ""
}
//-----------------------
// == GLOBAL FUNCTION: == format text for display in table cell
def formatNodeTextForCell(nodetext) {
maxCharsInCell=100
nodetext=removeHtmlTags(nodetext).take(maxCharsInCell)
.replace(' ','')
return nodetext
}
//-----------------------
// == GLOBAL FUNCTION: == clean up a word for comparisons
def cleanupWord(word) {
cleanword=word.toLowerCase()
.replace('.','') // remove full stops
.replace(',','') // remove commas
.replace('!','') // remove exclamation marks
.replace("'s",'') // remove plurals
.trim() // remove leading and trailing blanks
if (cleanword.endsWith('s')) { // remove plural from words ending in s and NOT ss
if (!cleanword.endsWith('ss')) {
cleanword=cleanword.substring(0,cleanword.length()-1)
}
if (cleanword.endsWith('&')) {
cleanword=cleanword.substring(0,cleanword.length()-1)
}
}
return cleanword
}
//-----------------------
// == GLOBAL FUNCTION: == set all connectors in the current node and subnodes to default color (GRAY)
def setAllConnectorsToDefaultColor() {
// set all connectors to GRAY
node.map.root.findAll().each {
it.connectorsOut.each {
it.setColor(Color.GRAY)
}
}
}
//-----------------------
// == GLOBAL FUNCTION: == remove All connectors in the current node and subnodes to default color (GRAY)
def removeAllConnectors() {
// set all connectors to GRAY
node.map.root.findAll().each {
it.connectorsIn.each {
node.removeConnector(it)
}
it.connectorsOut.each {
node.removeConnector(it)
}
}
}
//-----------------------
// == GLOBAL FUNCTION: == hide all connectors by setting color to WHITE
def hideAllConnectors() {
// set all connectors to WHITE
node.map.root.findAll().each {
it.connectorsOut.each {
it.setColor(Color.WHITE)
}
}
}
// == GLOBAL FUNCTION: == unhide all connectors by setting color to default
def unhideAllConnectors() {
setAllConnectorsToDefaultColor()
}
// == GLOBAL FUNCTION: == unhide all connectors by setting color to default
def showConnectorsForCurrentNode() {
// TODO Only show connectors in map for current node
hideAllConnectors()
// set current node connectors to GRAY
newNode.connectorsOut.each {
it.setColor(Color.GRAY)
}
newNode.connectorsIn.each {
it.setColor(Color.GRAY)
}
}
//-----------------------
// == GLOBAL FUNCTION: == set all connectors in the current node and subnodes to default color (GRAY)
def showAllConnectorsWithLabel(label) {
def searchtype="contains"
def searcharg=label
if (label.startsWith('/') && label.endsWith('/')) {
searchtype="regex"
searcharg=label.substring(1,label.length()-1)
}
// set all connectors to GRAY
hideAllConnectors()
node.map.root.findAll().each {
it.connectorsIn.each {
if (searchtype=="contains") {
if (it.middleLabel.toLowerCase().contains(searcharg.toLowerCase())) {
it.setColor(Color.RED)
}
}
if (searchtype=="regex") {
if (it.middleLabel=~searcharg) {
it.setColor(Color.BLUE)
}
}
}
it.connectorsOut.each {
if (searchtype=="contains") {
if (it.middleLabel.toLowerCase().contains(searcharg.toLowerCase())) {
it.setColor(Color.RED)
}
}
if (searchtype=="regex") {
if (it.middleLabel=~searcharg) {
it.setColor(Color.BLUE)
}
}
}
}
}
//-----------------------
// == GLOBAL FUNCTION: == populate the working array with
// (1) the parent node details
// (2) children node details
// (3) connections in/out details
def loadNodeData(node) {
// load node data
//
// get parent node details
def nodeparenttext = 'root'
def nodeparentnotetext = ''
def nodeparentdetailstext = ''
def nodeparentID = null
if (node.parent != null) {
nodeparenttext = node.parent.text
nodeparentnotetext = node.parent.noteText
nodeparentdetailstext = node.parent.detailsText
nodeparentID = node.parent.nodeID
}
// clear working array
nodes_data = []
// add parent node info of selected node to working array
nodes_data.add([id: nodeparentID, type: 'parent', nodetext: nodeparenttext, label: 'parent', notetext: nodeparentnotetext, details: nodeparentdetailstext])
// add child node(s) info of selected node to working array
if (node.children) {
node.children.each {
nodes_data.add([id: it.nodeID, type: 'child', nodetext: it.text, label: 'child', notetext: it.noteText, details: it.detailsText])
}
}
// add info for any connections (source nodes) into this selected node into the working array
if (node.connectorsIn) {
node.connectorsIn.each {
if (node != it.source) {
def middleLabel = "<-"
if (it.middleLabel != null) {
middleLabel = it.middleLabel
}
sourceNode = getNodeByID(it.delegate.source.id)
nodes_data.add([id: it.source.nodeID, type: 'conn-IN', nodetext: it.source.text, label: middleLabel, notetext: sourceNode.noteText, details: sourceNode.detailsText])
}
}
}
// add info for any connections out (target nodes) from this selected node into the working array
if (node.connectorsOut) {
node.connectorsOut.each {
if (node != it.target) {
def middleLabel = "->"
if (it.middleLabel != null) {
middleLabel = it.middleLabel
}
targetNode = getNodeByID(it.delegate.targetID)
targetnoteText = targetNode.noteText.toString()
nodes_data.add([id: it.target.nodeID, type: 'conn-OUT', nodetext: it.target.text, label: middleLabel, notetext: targetnoteText, details: targetNode.detailsText])
}
}
}
updateRecentNodesVisited(node.text)
newNode=node
}
//-----------------------
// == GLOBAL FUNCTION: == checks if the nodeID is not present in the working arrays which are visible in the ui Tables
def nodeIDNotInCurrentTables(nodeID) {
def result=true
if (connection_candidates_nodes_data.find { it.id==nodeID }) result=false
return result
}
//-----------------------
// == GLOBAL FUNCTION: == Update the user interface (UI) tables from the working array for the selected node
def updateUI (newNode) {
selected_node_button.text=formatNodeTextForCell(newNode.text)
selected_node_button.setToolTipText(formatSelectedNodeButtonToolTipText(newNode))
frame.title="$scriptVersion"
connectorsInTable.model = swing.tableModel(list: nodes_data.findAll{it.type=="conn-IN"}) {
propertyColumn(header: 'Type', propertyName: 'type', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Node', propertyName: 'nodetext', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Note', propertyName: 'notetext', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Details', propertyName: 'details', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Label', propertyName: 'label', editable: false, cellRenderer: new MainTableCellRenderer())
}
parentTable.model = swing.tableModel(list: nodes_data.findAll{it.type=="parent"}) {
propertyColumn(header: 'Type', propertyName: 'type', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Node', propertyName: 'nodetext', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Note', propertyName: 'notetext', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Details', propertyName: 'details', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Label', propertyName: 'label', editable: false, cellRenderer: new MainTableCellRenderer())
}
childrenTable.model = swing.tableModel(list: nodes_data.findAll{it.type=="child"}) {
propertyColumn(header: 'Type', propertyName: 'type', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Node', propertyName: 'nodetext', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Note', propertyName: 'notetext', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Details', propertyName: 'details', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Label', propertyName: 'label', editable: false, cellRenderer: new MainTableCellRenderer())
}
connectorsOutTable.model = swing.tableModel(list: nodes_data.findAll{it.type=="conn-OUT"}) {
propertyColumn(header: 'Type', propertyName: 'type', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Node', propertyName: 'nodetext', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Note', propertyName: 'notetext', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Details', propertyName: 'details', editable: false, cellRenderer: new MainTableCellRenderer())
propertyColumn(header: 'Label', propertyName: 'label', editable: false, cellRenderer: new MainTableCellRenderer())
}
setColumnsForDisplay()
setConnectorLabelsForDisplay()
frame.pack()
frame.show()
}
// ===============================================================
// ====================== UI Functions ===========================
// ===============================================================
// this class overrides the standard table cell renderer in the tables
// populated from the working arrays
// Each table cell contains a nodes core text. A tooltip displays
// the nodes note and detail text
class MainTableCellRenderer extends JLabel implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int rowIndex, int vColIndex) {
//*********************************************
// set the text for the cell
//*********************************************
//def displaytext=formatNodeTextForCell(value.toString())
setText(value.toString())
// set the cell to text and connector label (if row is showing a connector OUT)
if (table.model.getValueAt(rowIndex,0)=='conn-OUT') {
setText('(' + table.model.getValueAt(rowIndex, 4) + ') '+removeHtmlTags(value.toString()))
}
// set the cell to text and connector label (if row is showing a connector IN)
if (table.model.getValueAt(rowIndex,0)=='conn-IN') {
setText(removeHtmlTags(value.toString() + ' (' + table.model.getValueAt(rowIndex, 4)) + ')')
}
// center the text in the cell
setHorizontalAlignment(SwingConstants.CENTER)
// color the cell based on whether the referred node is
// a parent of the selected node
// a child of the selected node
// a connection into or out of the selected node
if (table.model.getValueAt(rowIndex,0)=='parent') setForeground(new Color(0,102,0))
if (table.model.getValueAt(rowIndex,0)=='child') setForeground(Color.BLUE)
if (table.model.getValueAt(rowIndex,0)=='conn-IN') setForeground(Color.RED)
if (table.model.getValueAt(rowIndex,0)=='conn-OUT') setForeground(new Color(153,0,0))
if (vColIndex==0) {
setForeground(Color.WHITE)
}
//*****************************************************
// Set up tooltip for cell which shows the note and
// detail texts related to the node the cell refers to
//*****************************************************
// show connector labels for connectors in and out in the tooltip
String nodetype=removeHtmlTags(value.toString())+'<HR>'+table.model.getValueAt(rowIndex,0)+'<HR>'
if (table.model.getValueAt(rowIndex,0)=='conn-IN' || table.model.getValueAt(rowIndex,0)=='conn-OUT') {
nodetype=removeHtmlTags(value.toString())+'<HR>'+table.model.getValueAt(rowIndex,0)+' ('+table.model.getValueAt(rowIndex,4)+')'+'<HR>'
}
// show the node's note text
String notetext=table.model.getValueAt(rowIndex,2)
if (notetext==null) notetext="empty"
// show the node's details text
String detailstext=table.model.getValueAt(rowIndex,3)
if (detailstext==null) detailstext="empty"
// format the tooltip for display
def tooltiptext= "<html><br>" + formatForSwingDisplay(nodetype,value,notetext,detailstext)
// attach tooltip to the cell
setToolTipText((String) tooltiptext)
return this
}
}
//-----------------------
// == UI FUNCTION: == display the details for a node selected in a UI table
def displayNewNode(tab,nodes_data) {
def nodedata=nodes_data[tab.getSelectedRow(),tab.getSelectedColumn()][0]
def theNode=getNodeByID(nodedata["id"])
selectNodeByID(nodedata["id"])
loadNodeData(theNode)
updateUI(theNode)
}
//-----------------------
// == UI FUNCTION: == display the details for the source and target notes for a node candidate
def displayConnection(tab,nodes_data,candidatenodeID) {
def nodedata=nodes_data[tab.getSelectedRow(),tab.getSelectedColumn()][0]
def a=1
// def theNode=getNodeByID(nodedata["id"])
// selectNodeByID(nodedata["id"])
// loadNodeData(theNode)
// updateUI(theNode)
}
//-----------------------
// == UI FUNCTION: == Set the display widths for the UI
def setColumnsForDisplay() {
// set width of parent table which forces panel to the minWidth value
minWidth=300
parentTable.getColumn('nodetext').setMinWidth(minWidth)
HideTableColumns(parentTable,['type','notetext','details','label'])
HideTableColumns(childrenTable,['type','notetext','details','label'])
HideTableColumns(connectorsInTable,['type','notetext','details','label'])
HideTableColumns(connectorsOutTable,['type','notetext','details','label'])
}
//-----------------------
// == UI FUNCTION: == Hide one or more table columns
def HideTableColumns(table,columns) {
columns.each {
try {
table.getColumn(it).setWidth(0)
table.getColumn(it).setMinWidth(0)
table.getColumn(it).setMaxWidth(0)
} catch(all) {
// ignore if column not found
}
}
}
//-----------------------
// == UI FUNCTION: == Set the connection labels based on whether connections or children are present for the selected node
def setConnectorLabelsForDisplay() {
if (nodes_data.find{it.type=="conn-IN"}) {
conn_in_label.setVisible(true)
} else {
conn_in_label.setVisible(false)
}
if (nodes_data.find{it.type=="conn-OUT"}) {
conn_out_label.setVisible(true)
} else {
conn_out_label.setVisible(false)
}
if (nodes_data.find{it.type=="child"}) {
children_label.setVisible(true)
} else {
children_label.setVisible(false)
}
}
//-----------------------
// == UI FUNCTION: == Set the connection labels based on whether connections or children are present for the selected node
def setButtonsForDisplay() {
selected_node_button.setToolTipText(formatSelectedNodeButtonToolTipText(newNode))
}
//-----------------------
// == UI FUNCTION: == format tooltip for the selected node button
def formatSelectedNodeButtonToolTipText(selectednode) {
return "<html><b>Selected Node</b><br><br>" +
formatForSwingDisplay(selectednode.text + '<br>',
selectednode.text,
selectednode.noteText,
selectednode.detailsText).replace('<html>', '')
}
//*********************************************
//*********************************************
//*********************************************
// MAIN LOGIC ENTRY POINT
//*********************************************
//*********************************************
//*********************************************
// load the data from the currently selected node
loadNodeData(node)
Color tablebg = new Color(224,224,224)
// ===============================================================
// ============== THE USER INTERFACE DEFINITION ================
// ===============================================================
// BASIC LAYOUT FOR DISPLAYING SELECTED NODE
// -------------------------
// | Menus |
// -------------------------
// | |
// | PARENT NODE |
// | v |
// | CONNECTED |
// | NODES |
// | IN |
// | v |
// | ------------ |
// | | SELECTED | |
// | | NODE | |
// | ------------ |
// | v |
// | CONNECTED |
// | NODES |
// | OUT |
// | v |
// | CHILD NODES |
// | |
// -------------------------
// create a groovy SwingBuilder
swing = new SwingBuilder()
// define the main ui window(frame)
frame = swing.frame(title: "$scriptVersion", defaultCloseOperation: JFrame.DISPOSE_ON_CLOSE, alwaysOnTop: true,minimumSize: new Dimension(400,25)) {
// main panel
mypanel = panel (background: tablebg) {
gridLayout()
vbox {
// Menu panel
panel(background: tablebg) {
gridLayout()
mainmenu=menuBar(minimumSize: new Dimension(400,25),maximumSize: new Dimension(400,25)) {
menu(text:'Actions') {
menuItem() {
action(
name:"open selected map node", closure:{
newNode = getNodeFromMapSelection()
loadNodeData(newNode)
updateUI(newNode)
})
}
separator()
menuItem() {
action(
name:"Go to Root Node", closure:{
newNode=newNode.map.root
loadNodeData(newNode.map.root)
updateUI(newNode.map.root)
})
}
menuItem() {
action(
name:"Refresh current view", closure:{
loadNodeData(newNode)
updateUI(newNode)
})
}
separator()
}
menu(text:'View') {
menuItem() {
action(name:"Node Details",
closure:{
if (newNode!=null) {
def notetext='empty'
if (newNode.noteText!=null) {
notetext=newNode.noteText
}
def detailstext='empty'
if (newNode.detailsText!=null) {
detailstext=newNode.detailsText
}
msgtext=formatForSwingDisplay(newNode.text,newNode.text,notetext,detailstext)
msg=label(msgtext)
def pane = swing.optionPane(message: msg)
def dialog = pane.createDialog(frame, 'Note')
dialog.show()
}
})
}
separator()
menu(text:'Connectors') {
menuItem() {
action(name:"Connector Candidates",
closure:{
connectoroptions()
})
}
separator()
menuItem() {
action(name: "Connectors Manager",
closure: {
connectorManagerUI()
})
}
separator()
menuItem() {
action(name: "Show Current Node Connectors",
closure: {
if (newNode!=null) {
showConnectorsForCurrentNode()
}
})
}
separator()
menuItem() {
action(name: "Show Connectors for a label",
closure: {
def pane = swing.optionPane()
def label = pane.showInputDialog(null,"Enter full or partial label text\n OR a regular expression eg /M.*h/","Connector Label Search",JOptionPane.QUESTION_MESSAGE)
showAllConnectorsWithLabel(label)
})
}
separator()
menuItem() {
action(name: "Hide All Connectors",
closure: {
hideAllConnectors()
})
}
separator()
menuItem() {
action(name: "UnHide All Connectors",
closure: {
unhideAllConnectors()
})
}
separator()
}
}
menu(text:'History') {
menuItem() {
action(name:'Recent Nodes Visited',
closure:{
if (recenthistoryDisplayed==true || recentNodesVisited.size==0) {
return
}
recenthistoryDisplayed=true
swing.setVariable('Recent Nodes Visited',[:])
def vars = swing.variables
dial = swing.dialog(title:'Recent Nodes Visited',
id:'recentDialog',
minimumSize: [300,50],
modal:true,
location: [mypanel.getAt('width')+5,0],
// locationRelativeTo: ui.frame,
owner:ui.frame,
defaultCloseOperation:JFrame.DO_NOTHING_ON_CLOSE,
// Using DO_NOTHING_ON_CLOSE so the Close button has full control
// and it can ensure only one instance of the dialog appears
pack:true,
show:true) {
panel() {
boxLayout(axis: BoxLayout.Y_AXIS)
recentspanel=panel(alignmentX: 0f) {
flowLayout(alignment: FlowLayout.LEFT)
recentlist=list(id: 'type', items: recentNodesVisited)
}
panel(alignmentX: 0f) {
flowLayout(alignment: FlowLayout.RIGHT)
button(action: action(name: 'Locate', defaultButton: true,
closure: {
// locate the node selected in the table and go to it in the map
// but do not load it into Map Insights array
vars.ok=true
c.find{
it.text == vars.type.selectedValue
}.each {
selectNodeByTitle(it.text)
}
// recentDialog.dispose()
}))
button(action: action(name: 'Go To', defaultButton: true,
closure: {
// locate the node selected in the table and go to it in the map
// and load it into Map Insights array as the main node for Map Insight
vars.ok=true
c.find{
it.text == vars.type.selectedValue
}.each {
selectNodeByTitle(it.text)
newNode=c.selected
loadNodeData(newNode)
updateUI(newNode)
}
recentDialog.dispose()
recenthistoryDisplayed=false
}))
button(action: action(name: 'Close', closure: {
recenthistoryDisplayed=false
recentDialog.dispose()
}))
}
}
}
}
)
}
}
menu(text:'Help') {
menuItem() {
action(name:'About', closure:{
def pane = swing.optionPane(message: "<html>$scriptVersion<p><small>Author: Allan Davies><br><i>ADXSoft</i><br><br><br>https://github.com/adxsoft/MapInsight</small></html>")
def dialog = pane.createDialog(frame, scriptVersion)
dialog.show()
})}
menuItem() {
action(name:'Installation', closure:{
def pane = swing.optionPane(message: installation)
def dialog = pane.createDialog(frame, "Installing in Freeplane")
dialog.show()
})}
menuItem() {
action(name:'Using Map Insight', closure:{
def pane = swing.optionPane(message: helptext1)
def dialog = pane.createDialog(frame, "using Map Insight")
dialog.show()
})}
menuItem() {