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)
}
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)
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
}
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();