]> matita.cs.unibo.it Git - logicplayer.git/blobdiff - mainActivity/src/com/example/furt/myapplication/touchHPHandler.java
New version (to be tested).
[logicplayer.git] / mainActivity / src / com / example / furt / myapplication / touchHPHandler.java
index 44691ce165ca0740e5b043b3e10e60c87c083bce..0e62a534947d999d3465ac0a245cf16a21549944 100755 (executable)
@@ -1,10 +1,11 @@
 package com.example.furt.myapplication;
 
 import android.view.View;
+import android.widget.Toast;
 
 public class touchHPHandler implements View.OnClickListener
 {
-    Node L;
+    Node L; //nodo contenente il sottoalbero successivo all'eliminazione dell'ipotesi
     boolean discard;
     Hypothesis thisHP; //ipotesi che sto eliminando
     touchHPHandler(Node n,Hypothesis hp)
@@ -15,13 +16,14 @@ public class touchHPHandler implements View.OnClickListener
     }
     public void onClick(View view)
     {
-        if (DrawActivity.selectedNode==null) //non-existent selectedNode (should never happen)
+        if (DrawActivity.selectedNode==null) //selectedNode non esiste (non dovrebbe mai succedere)
             return;
-        if (DrawActivity.selectedNode.Children.size()!=0) //not a leaf: can't add children
+        if (DrawActivity.selectedNode.Children.size()!=0) //non è una foglia: non si possono applicare regole.
         {
+            Toast.makeText(DrawActivity.rootNode.view.getContext(),"Impossibile scaricare ipotesi su nodi intermedi",Toast.LENGTH_LONG).show();
             return;
         }
-        if (thisHP.HP.toString().equals(DrawActivity.selectedNode.F.toString())) //close current Node
+        if (thisHP.HP.toString().equals(DrawActivity.selectedNode.F.toString())) //sto scaricando una formula uguale al nodo corrente: lo chiudo aggiornando lo stato del nodo
         {
             if (thisHP.isDeleted) {
                 if (DrawActivity.selectedNode.status == Node.OPEN)
@@ -39,17 +41,21 @@ public class touchHPHandler implements View.OnClickListener
             DrawActivity.startDraw();
             return;
         }
-        if (L==null) //incompatible elimination
+        if (L==null) //eliminazione incompatibile con il nodo attuale
+        {
+            Toast.makeText(DrawActivity.rootNode.view.getContext(),"Impossibile scaricare questa ipotesi ora",Toast.LENGTH_LONG).show();
             return;
-        for (Node n:L.Children) {
+        }
+        for (Node n:L.Children) { //aggiungo al sottoalbero della regola da applicare tutte le ipotesi del selectedNode. In più aggiungo alle ipotesi introdotte da questa regola il fromNode corretto.
             for (Hypothesis hp:n.NodeHP)
                 hp.fromNode= DrawActivity.selectedNode; //le ipotesi dei nuovi figli provengono dal nodo in cui stanno per essere inserite
             n.addHPList(DrawActivity.selectedNode.NodeHP);
             DrawActivity.selectedNode.addChild(n);
         }
-        DrawActivity.selectedNode.hasFocus=false;
-        DrawActivity.selectedNode.Children.get(0).hasFocus=true;
-        if(discard) {
+        DrawActivity.selectedNode.hasFocus=false; //il nodo su cui ho applicato la regola non è più una foglia e non ha più focus
+        DrawActivity.selectedNode.ruleName = L.ruleName;
+        DrawActivity.selectedNode.Children.get(0).hasFocus=true; //il primo figlio dell'applicazione della regola ha di default il focus
+        if(discard) { //sto scaricando un'ipotesi: il primo figlio è automaticamente chiuso
             if (thisHP.isDeleted)
                 DrawActivity.selectedNode.Children.get(0).status = Node.CANCELED;
             else
@@ -57,8 +63,6 @@ public class touchHPHandler implements View.OnClickListener
         }
         else
             DrawActivity.selectedNode.Children.get(0).status= Node.OPEN;
-        DrawActivity.selectedNode.hasFocus = false;
-        DrawActivity.selectedNode.ruleName = L.ruleName;
         DrawActivity.nmoves++;
         DrawActivity.rootNode.Clean();
         DrawActivity.startDraw();