/extensions/org/mt4jx/input/inputProcessors/componentProcessors/Group3DProcessorNew/FingerTapGrouping/FingerTapSelection.java

http://mt4j.googlecode.com/ · Java · 168 lines · 131 code · 37 blank · 0 comment · 5 complexity · fc108a6dd5fbd4f4e879d4468122a379 MD5 · raw file

  1. package org.mt4jx.input.inputProcessors.componentProcessors.Group3DProcessorNew.FingerTapGrouping;
  2. import java.util.ArrayList;
  3. import org.mt4j.components.MTCanvas;
  4. import org.mt4j.components.MTComponent;
  5. import org.mt4j.input.inputData.InputCursor;
  6. import org.mt4j.input.inputProcessors.componentProcessors.lassoProcessor.IdragClusterable;
  7. import org.mt4jx.input.inputProcessors.componentProcessors.Group3DProcessorNew.Cluster;
  8. import org.mt4jx.input.inputProcessors.componentProcessors.Group3DProcessorNew.ClusterDataManager;
  9. import org.mt4jx.input.inputProcessors.componentProcessors.Group3DProcessorNew.ISelection;
  10. public class FingerTapSelection implements ISelection {
  11. private ClusterDataManager clusterDataManager;
  12. private FingerTapSelectionManager selectionManager;
  13. private FingerTapState state = FingerTapState.NOELEMENTSELECTED;
  14. private InputCursor firstCursor;
  15. private MTComponent firstCursorComp;
  16. private ArrayList<InputCursor> currentlyPressedCursors = new ArrayList<InputCursor>();
  17. private ArrayList<MTComponent> selectedComps = new ArrayList<MTComponent>();
  18. private MTCanvas canvas;
  19. private Cluster currentlySelectedCluster;
  20. public FingerTapSelection(ClusterDataManager clusterDataManager,MTCanvas canvas,FingerTapSelectionManager selectionManager)
  21. {
  22. this.clusterDataManager = clusterDataManager;
  23. this.canvas = canvas;
  24. this.selectionManager = selectionManager;
  25. }
  26. public synchronized void addComponentToSelection(MTComponent comp)
  27. {
  28. if(!(selectedComps.contains(comp)))
  29. {
  30. selectedComps.add(comp);
  31. }
  32. }
  33. public boolean compIsInSelection(MTComponent comp)
  34. {
  35. return selectedComps.contains(comp);
  36. }
  37. public synchronized void removeCurrentlySelectedFromCanvas()
  38. {
  39. for(MTComponent comp : selectedComps)
  40. {
  41. this.canvas.removeChild(comp);
  42. }
  43. }
  44. public synchronized void removeComponentFromSelection(MTComponent comp)
  45. {
  46. if(selectedComps.contains(comp))
  47. {
  48. selectedComps.remove(comp);
  49. }
  50. }
  51. public void addComponentToCanvas(MTComponent comp)
  52. {
  53. canvas.addChild(comp);
  54. }
  55. public void removeComponentFromCanvas(MTComponent comp)
  56. {
  57. canvas.removeChild(comp);
  58. }
  59. public ArrayList<MTComponent> getSelectedComponents() {
  60. return selectedComps;
  61. }
  62. public synchronized void setSelectedComponents(ArrayList<MTComponent> selectedComps)
  63. {
  64. this.selectedComps = selectedComps;
  65. }
  66. public synchronized void setState(FingerTapState state) {
  67. this.state = state;
  68. this.state.stateEntry(this);
  69. }
  70. public FingerTapState getState() {
  71. return state;
  72. }
  73. public void setClusterDataManager(ClusterDataManager clusterDataManager) {
  74. this.clusterDataManager = clusterDataManager;
  75. }
  76. public ClusterDataManager getClusterDataManager() {
  77. return clusterDataManager;
  78. }
  79. public synchronized void setFirstCursor(InputCursor firstCursor) {
  80. this.firstCursor = firstCursor;
  81. }
  82. public InputCursor getFirstCursor() {
  83. return firstCursor;
  84. }
  85. public boolean isFirstCursor(InputCursor cursor)
  86. {
  87. if(firstCursor==cursor)
  88. {
  89. return true;
  90. }
  91. return false;
  92. }
  93. public synchronized void setCurrentlyPressedCursors(ArrayList<InputCursor> currentlyPressedCursors) {
  94. this.currentlyPressedCursors = currentlyPressedCursors;
  95. }
  96. public ArrayList<InputCursor> getCurrentlyPressedCursors() {
  97. return currentlyPressedCursors;
  98. }
  99. public void createCluster()
  100. {
  101. ArrayList<MTComponent> components = new ArrayList<MTComponent>();
  102. for(MTComponent comp : selectedComps)
  103. {
  104. MTComponent component = (MTComponent)comp;
  105. components.add(component);
  106. }
  107. clusterDataManager.createCluster(components, true);
  108. }
  109. public void setCurrentlySelectedCluster(Cluster currentlySelectedCluster) {
  110. this.currentlySelectedCluster = currentlySelectedCluster;
  111. }
  112. public Cluster getCurrentlySelectedCluster() {
  113. return currentlySelectedCluster;
  114. }
  115. public void setSelectionManager(FingerTapSelectionManager selectionManager) {
  116. this.selectionManager = selectionManager;
  117. }
  118. public FingerTapSelectionManager getSelectionManager() {
  119. return selectionManager;
  120. }
  121. public void setFirstCursorComp(MTComponent firstCursorComp) {
  122. this.firstCursorComp = firstCursorComp;
  123. }
  124. public MTComponent getFirstCursorComp() {
  125. return firstCursorComp;
  126. }
  127. public MTComponent getComponentForCursor(InputCursor cursor)
  128. {
  129. return (MTComponent)canvas.getComponentAt(cursor.getStartPosX(), cursor.getStartPosY());
  130. }
  131. }