Simple editor to create custom node network graphs aka ontologies
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Keys only get caught for changing a nodes title.
  3. * Previous title is remembered in savedTitle and restored when hitting Escape
  4. */
  5. String savedTitle;
  6. void keyPressed() {
  7. if (key == ESC) {
  8. key = 0;
  9. }
  10. if (i_selectedNode != -1) {
  11. if (keyCode == BACKSPACE) {
  12. if (nodes[i_selectedNode].title.length() > 0) {
  13. nodes[i_selectedNode].title = nodes[i_selectedNode].title.substring(0, nodes[i_selectedNode].title.length()-1);
  14. nodes[i_selectedNode].refreshSize();
  15. }
  16. } else if (keyCode == DELETE) {
  17. deleteSelectedNode();
  18. } else if (keyCode == ESC) {
  19. nodes[i_selectedNode].title = savedTitle;
  20. nodes[i_selectedNode].refreshSize();
  21. deselect();
  22. } else if (keyCode == RETURN || keyCode == ENTER) {
  23. deselect();
  24. } else if (keyCode != SHIFT && keyCode != RETURN && keyCode != ENTER && keyCode != CONTROL) {
  25. nodes[i_selectedNode].title = nodes[i_selectedNode].title + key;
  26. nodes[i_selectedNode].refreshSize();
  27. }
  28. }
  29. }
  30. void mousePressed() {
  31. if (mouseButton == LEFT) {
  32. /**
  33. * Either press a button...
  34. */
  35. boolean buttonClicked = false;
  36. for (int i = 0; i < buttons.length; i++) {
  37. if (buttons[i].hover()) {
  38. buttons[i].click();
  39. //Not able to break out of here without using a flag
  40. buttonClicked = true;
  41. }
  42. }
  43. if (!buttonClicked) {
  44. for (int i = 0; i < nodeCount; i++) {
  45. /**
  46. * ...or select / drag a node...
  47. */
  48. if (nodes[i].hover()) {
  49. i_selectedNode = i;
  50. savedTitle = nodes[i].title;
  51. nodes[i].drag = true;
  52. nodes[i].dragMouseStartPoint.x = mouseX;
  53. nodes[i].dragMouseStartPoint.y = mouseY;
  54. break;
  55. }
  56. /**
  57. * ...or pull a new link out of an inlet or outlet.
  58. */
  59. else if (nodes[i].hoverInlet()) {
  60. dragLink = true;
  61. dragOriginLet = -1;
  62. dragOriginId = i;
  63. } else if (nodes[i].hoverOutlet()) {
  64. dragLink = true;
  65. dragOriginLet = 1;
  66. dragOriginId = i;
  67. }
  68. //deselecting the shit out of this for reasons I don't remember, no care to improve right now
  69. deselect();
  70. }
  71. }
  72. }
  73. }
  74. /**
  75. * Create links
  76. */
  77. void mouseReleased() {
  78. for (int i = 0; i < nodeCount; i++) {
  79. nodes[i].drag = false;
  80. if (dragLink && dragOriginId != i) {
  81. if (nodes[i].hoverInlet() && dragOriginLet == 1) {
  82. Link(dragOriginId, i);
  83. }
  84. if (nodes[i].hoverOutlet() && dragOriginLet == -1) {
  85. Link(i, dragOriginId);
  86. }
  87. }
  88. }
  89. /**
  90. * Reset drag&drop states
  91. */
  92. dragLink = false;
  93. dragOriginLet = 0;
  94. dragOriginId = -1;
  95. }
  96. /**
  97. * Scaling is tied to textSize. Having the UI on a seperate PGraphics would be better, but it's good enough for now
  98. */
  99. int zoomDelta = 3;
  100. void mouseWheel(MouseEvent event) {
  101. float zoom = event.getAmount();
  102. if (zoom < 0) {
  103. textSize += zoomDelta;
  104. } else if (zoom > 0) {
  105. if (textSize - zoomDelta > 0) {
  106. textSize -= zoomDelta;
  107. }
  108. }
  109. padding = textSize/3*2;
  110. for (int i = 0; i < nodeCount; i++) {
  111. nodes[i].refreshSize();
  112. nodes[i].setVectors();
  113. }
  114. }