Metodos que creaban dialogos a clases

Se separaron estos metodos para mayor claridad en el codigo y mas facil
reutilizacion de los dialogos ya que ahora me vi en el caso de que me
encontraba utilizando estos metodos  en 2 vistas separadas y me vi
copiando los metodos de una a otra, pero eso no es bonito! asi que las
separe en clases con un solo metodo publico llamado execute el cual
devuelve el objeto que se espera recibir o un null en caso de que el
usuario cancele el dialogo o ocurra algun error.
This commit is contained in:
Daniel Cortes
2019-02-27 02:48:54 -03:00
parent f5b44f32fe
commit 57d6d62b10
12 changed files with 668 additions and 194 deletions

View File

@@ -28,12 +28,11 @@ import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import danielcortes.xyz.views.components.YearSpinnerModel;
import danielcortes.xyz.views.listeners.WindowClosingListener;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.time.LocalDate;
import java.util.ArrayList;
@@ -48,29 +47,35 @@ public class MonthSelectDialog extends JDialog {
private boolean acepted;
public MonthSelectDialog(JComponent parent) {
public MonthSelectDialog() {
$$$setupUI$$$();
setContentPane(contentPane);
setModalityType(ModalityType.APPLICATION_MODAL);
getRootPane().setDefaultButton(buttonOK);
setup();
}
private void setup() {
this.setContentPane(contentPane);
this.setModalityType(ModalityType.APPLICATION_MODAL);
this.getRootPane().setDefaultButton(buttonOK);
buttonOK.addActionListener(e -> onOK());
this.buttonOK.addActionListener(e -> onOK());
buttonCancel.addActionListener(e -> onCancel());
this.buttonCancel.addActionListener(e -> onCancel());
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.addWindowListener((WindowClosingListener) e -> onCancel());
this.contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
this.setLocationRelativeTo(null);
pack();
setLocationRelativeTo(parent);
}
public LocalDate execute() {
setVisible(true);
if (this.isAcepted()) {
return this.getMonth();
} else {
return null;
}
}
private void onOK() {
@@ -83,11 +88,11 @@ public class MonthSelectDialog extends JDialog {
dispose();
}
public boolean isAcepted() {
private boolean isAcepted() {
return this.acepted;
}
public LocalDate getMonth() {
private LocalDate getMonth() {
int year = Integer.valueOf((String) yearSpinner.getValue());
int month = this.months.indexOf(this.monthCombo.getSelectedItem()) + 1;