Creation des dialogs
This commit is contained in:
72
src/ovh/alexisdelhaie/curling/windows/AddHeader.java
Normal file
72
src/ovh/alexisdelhaie/curling/windows/AddHeader.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package ovh.alexisdelhaie.curling.windows;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class AddHeader extends JDialog {
|
||||
|
||||
public static String WINDOW_TITLE = "Ajouter une en-tête";
|
||||
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
private JTextField keyField;
|
||||
private JTextField valueField;
|
||||
|
||||
private String value;
|
||||
|
||||
public AddHeader() {
|
||||
this.value = "";
|
||||
setContentPane(contentPane);
|
||||
setModal(true);
|
||||
setTitle(WINDOW_TITLE);
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() when cross is clicked
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() on ESCAPE
|
||||
contentPane.registerKeyboardAction(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
}
|
||||
|
||||
private void onOK() {
|
||||
if(!keyField.getText().isBlank()) {
|
||||
value = keyField.getText();
|
||||
if(!valueField.getText().isBlank()) {
|
||||
value += String.format(": %s", valueField.getText());
|
||||
}
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
pack();
|
||||
setVisible(true);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user