94 lines
3.3 KiB
Java
94 lines
3.3 KiB
Java
package fenetres;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Font;
|
|
import java.util.ArrayList;
|
|
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JCheckBox;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.SwingConstants;
|
|
|
|
import cXML.node;
|
|
|
|
|
|
public class CustomInputDialogSimplePointCaseCoche {
|
|
public static void showCustominputDialog(node nod, String nameMethod, String explication, ImageIcon icon) {
|
|
Integer initialValue = 0;
|
|
|
|
if (nod.getAttributs().get(nameMethod) != null) {
|
|
initialValue = Integer.parseInt(nod.getAttributs().get(nameMethod));
|
|
}
|
|
|
|
JLabel lblTitre = new JLabel("<html><h2>"+nameMethod+"<h2></html>");
|
|
lblTitre.setForeground(new Color(50,50,200));
|
|
|
|
JLabel lblExpliaction = new JLabel(explication);
|
|
lblExpliaction.setFont(new Font("Tahoma", Font.BOLD, 12));
|
|
lblExpliaction.setForeground(Color.blue);
|
|
|
|
JTextField textField = new JTextField(String.valueOf(initialValue), 4);
|
|
textField.setFont(new Font("Tahoma", Font.BOLD, 14));
|
|
textField.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
|
JCheckBox caseFrere = new JCheckBox("Placer la méthode sur tous les nodes frères.");
|
|
caseFrere.setFont(new Font("Tahoma", Font.BOLD, 12));
|
|
caseFrere.setSelected(false);
|
|
|
|
Object[] message = {
|
|
lblTitre,
|
|
lblExpliaction,
|
|
caseFrere,
|
|
"Quel est le nombre de points?", textField
|
|
};
|
|
|
|
String[] options = {"Ajouter", "Supprimer"};
|
|
|
|
int optionSelected = JOptionPane.showOptionDialog(
|
|
null,
|
|
message,
|
|
"Ajouter ou supprimer la méthode " + nameMethod,
|
|
JOptionPane.DEFAULT_OPTION,
|
|
JOptionPane.INFORMATION_MESSAGE,
|
|
icon,
|
|
options,
|
|
options[0]);
|
|
|
|
if (optionSelected == 0) { // Bouton "Ajouter" sélectionné
|
|
try {
|
|
Integer inputValue = Integer.parseInt(textField.getText());
|
|
if(!caseFrere.isSelected()) {
|
|
nod.getAttributs().put(nameMethod, String.valueOf(inputValue));
|
|
}else {
|
|
ajouteAToutesLesFeres(nod, inputValue,nameMethod);
|
|
}
|
|
|
|
} catch (NumberFormatException e) {
|
|
JOptionPane.showMessageDialog(null, "Veuillez saisir un entier valide.", "Erreur", JOptionPane.ERROR_MESSAGE);
|
|
}
|
|
} else if (optionSelected == 1) { // Bouton "Supprimer" sélectionné
|
|
if(!caseFrere.isSelected()) {
|
|
nod.supprimeAttribut(nameMethod);
|
|
}else {
|
|
ajouteAToutesLesFeres(nod,0,nameMethod);
|
|
}
|
|
|
|
} else { // Si la boîte de dialogue est annulée ou fermée
|
|
|
|
}
|
|
}
|
|
|
|
private static void ajouteAToutesLesFeres(node nod,Integer point,String nameMethod) {
|
|
ArrayList<node> nodFeres = nod.retourneTousLesFreres();
|
|
for(int i=0; i < nodFeres.size();i++) {
|
|
if(point>0) {
|
|
nodFeres.get(i).getAttributs().put(nameMethod, String.valueOf(point));
|
|
}else {
|
|
nodFeres.get(i).supprimeAttribut(nameMethod);
|
|
}
|
|
}
|
|
}
|
|
}
|