67 lines
2.3 KiB
Java
67 lines
2.3 KiB
Java
package fenetres;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Font;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.SwingConstants;
|
|
|
|
import cXML.node;
|
|
|
|
|
|
public class CustomInputDialogSimplePoint {
|
|
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);
|
|
|
|
Object[] message = {
|
|
lblTitre,
|
|
lblExpliaction,
|
|
"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());
|
|
nod.getAttributs().put(nameMethod, String.valueOf(inputValue));
|
|
} catch (NumberFormatException e) {
|
|
JOptionPane.showMessageDialog(null, "Veuillez saisir un entier valide.", "Erreur", JOptionPane.ERROR_MESSAGE);
|
|
}
|
|
} else if (optionSelected == 1) { // Bouton "Supprimer" sélectionné
|
|
nod.supprimeAttribut(nameMethod);
|
|
} else { // Si la boîte de dialogue est annulée ou fermée
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|