package com.example.ligne.indoor; public class AddCommand implements Command { private Plan plan; private Ligne ligne; private Porte porte; private EltPlan elt; AddCommand(Plan p, Ligne l) { this.plan = p; this.ligne = l; } AddCommand(Ligne l, Porte p) { this.ligne = l; this.porte = p; } public AddCommand(Ligne ligneSelected, EltPlan elt) { this.ligne = ligneSelected; this.setElt(elt); } public void execute() { if ((ligne != null)) { if (porte != null) { this.ligne.add(this.porte); this.ligne.getPlan().invalidate(); } else { this.ligne.setPlan(this.plan); this.plan.add(this.ligne); plan.invalidate(); } } } @Override public void undo() { if (ligne != null) { if (porte != null) { this.ligne.remove(this.porte); this.ligne.getPlan().invalidate(); } else { this.plan.remove(this.ligne); plan.invalidate(); } } } public EltPlan getElt() { return elt; } public void setElt(EltPlan elt) { this.elt = elt; } public Plan getPlan() { return plan; } public void setPlan(Plan plan) { this.plan = plan; } public Ligne getLigne() { return ligne; } public void setLigne(Ligne ligne) { this.ligne = ligne; } public Porte getPorte() { return porte; } public void setPorte(Porte porte) { this.porte = porte; } }