Se aplico el estilo de codigo de google :3
https://github.com/google/styleguide
This commit is contained in:
@@ -1,33 +1,34 @@
|
||||
package danielcortes.xyz.views.dialogs;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class InformeGeneratedConfirmation {
|
||||
private Path path;
|
||||
|
||||
public InformeGeneratedConfirmation(Path path){
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public void execute(){
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"El informes se a generado" + "\n" + "¿Desea abrirlo?",
|
||||
"Confirmacion",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
|
||||
if (result == 0) {
|
||||
try {
|
||||
Desktop.getDesktop().open(this.path.toFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
private Path path;
|
||||
|
||||
public InformeGeneratedConfirmation(Path path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"El informes se a generado" + "\n" + "¿Desea abrirlo?",
|
||||
"Confirmacion",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
|
||||
if (result == 0) {
|
||||
try {
|
||||
Desktop.getDesktop().open(this.path.toFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,160 +29,201 @@ 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.Insets;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SpinnerModel;
|
||||
|
||||
public class MonthSelectDialog extends JDialog {
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
private JComboBox<String> monthCombo;
|
||||
private JSpinner yearSpinner;
|
||||
|
||||
private ArrayList<String> months;
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
private JComboBox<String> monthCombo;
|
||||
private JSpinner yearSpinner;
|
||||
|
||||
private boolean acepted;
|
||||
private ArrayList<String> months;
|
||||
|
||||
public MonthSelectDialog() {
|
||||
$$$setupUI$$$();
|
||||
setup();
|
||||
private boolean acepted;
|
||||
|
||||
public MonthSelectDialog() {
|
||||
$$$setupUI$$$();
|
||||
setup();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
this.setContentPane(contentPane);
|
||||
this.setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
this.getRootPane().setDefaultButton(buttonOK);
|
||||
|
||||
this.buttonOK.addActionListener(e -> onOK());
|
||||
|
||||
this.buttonCancel.addActionListener(e -> onCancel());
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public YearMonth execute() {
|
||||
setVisible(true);
|
||||
if (this.isAcepted()) {
|
||||
return this.getMonth();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void onOK() {
|
||||
this.acepted = true;
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
this.acepted = false;
|
||||
dispose();
|
||||
}
|
||||
|
||||
private boolean isAcepted() {
|
||||
return this.acepted;
|
||||
}
|
||||
|
||||
private YearMonth getMonth() {
|
||||
int year = Integer.valueOf((String) yearSpinner.getValue());
|
||||
int month = this.months.indexOf(this.monthCombo.getSelectedItem()) + 1;
|
||||
|
||||
return YearMonth.of(year, month);
|
||||
}
|
||||
|
||||
|
||||
private void createUIComponents() {
|
||||
createYearSpinner();
|
||||
createMonthCombo();
|
||||
}
|
||||
|
||||
private void createYearSpinner() {
|
||||
SpinnerModel model = new YearSpinnerModel();
|
||||
this.yearSpinner = new JSpinner();
|
||||
this.yearSpinner.setModel(model);
|
||||
((JSpinner.DefaultEditor) this.yearSpinner.getEditor()).getTextField().setEditable(true);
|
||||
}
|
||||
|
||||
private void createMonthCombo() {
|
||||
months = new ArrayList<>();
|
||||
months.add("Enero");
|
||||
months.add("Febrero");
|
||||
months.add("Marzo");
|
||||
months.add("Abril");
|
||||
months.add("Mayo");
|
||||
months.add("Junio");
|
||||
months.add("Julio");
|
||||
months.add("Agosto");
|
||||
months.add("Septiembre");
|
||||
months.add("Octubre");
|
||||
months.add("Noviembre");
|
||||
months.add("Diciembre");
|
||||
|
||||
monthCombo = new JComboBox<>();
|
||||
for (String month : months) {
|
||||
monthCombo.addItem(month);
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
this.setContentPane(contentPane);
|
||||
this.setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
this.getRootPane().setDefaultButton(buttonOK);
|
||||
int currentMonth = LocalDate.now().getMonth().getValue() - 1;
|
||||
monthCombo.setSelectedIndex(currentMonth);
|
||||
}
|
||||
|
||||
this.buttonOK.addActionListener(e -> onOK());
|
||||
/**
|
||||
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
|
||||
* call it in your code!
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$setupUI$$$() {
|
||||
createUIComponents();
|
||||
contentPane = new JPanel();
|
||||
contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
|
||||
final JPanel panel1 = new JPanel();
|
||||
panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
|
||||
contentPane.add(panel1,
|
||||
new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null,
|
||||
null, null, 0, false));
|
||||
final Spacer spacer1 = new Spacer();
|
||||
panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER,
|
||||
GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null,
|
||||
0, false));
|
||||
final JPanel panel2 = new JPanel();
|
||||
panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false));
|
||||
panel1.add(panel2,
|
||||
new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null,
|
||||
null, 0, false));
|
||||
buttonOK = new JButton();
|
||||
buttonOK.setText("OK");
|
||||
panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER,
|
||||
GridConstraints.FILL_HORIZONTAL,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
buttonCancel = new JButton();
|
||||
buttonCancel.setText("Cancelar");
|
||||
panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER,
|
||||
GridConstraints.FILL_HORIZONTAL,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JPanel panel3 = new JPanel();
|
||||
panel3.setLayout(new GridLayoutManager(3, 2, new Insets(0, 0, 0, 0), -1, -1));
|
||||
contentPane.add(panel3,
|
||||
new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null,
|
||||
null, 0, false));
|
||||
final JLabel label1 = new JLabel();
|
||||
label1.setText("Mes");
|
||||
panel3.add(label1,
|
||||
new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
|
||||
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
|
||||
false));
|
||||
panel3.add(monthCombo, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST,
|
||||
GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JLabel label2 = new JLabel();
|
||||
label2.setText("Año");
|
||||
panel3.add(label2,
|
||||
new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
|
||||
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
|
||||
false));
|
||||
panel3.add(yearSpinner, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST,
|
||||
GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW,
|
||||
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JLabel label3 = new JLabel();
|
||||
label3.setText("Seleccione Mes y Año");
|
||||
panel3.add(label3,
|
||||
new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
|
||||
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
|
||||
false));
|
||||
}
|
||||
|
||||
this.buttonCancel.addActionListener(e -> onCancel());
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public YearMonth execute() {
|
||||
setVisible(true);
|
||||
if (this.isAcepted()) {
|
||||
return this.getMonth();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void onOK() {
|
||||
this.acepted = true;
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
this.acepted = false;
|
||||
dispose();
|
||||
}
|
||||
|
||||
private boolean isAcepted() {
|
||||
return this.acepted;
|
||||
}
|
||||
|
||||
private YearMonth getMonth() {
|
||||
int year = Integer.valueOf((String) yearSpinner.getValue());
|
||||
int month = this.months.indexOf(this.monthCombo.getSelectedItem()) + 1;
|
||||
|
||||
return YearMonth.of(year, month);
|
||||
}
|
||||
|
||||
|
||||
private void createUIComponents() {
|
||||
createYearSpinner();
|
||||
createMonthCombo();
|
||||
}
|
||||
|
||||
private void createYearSpinner() {
|
||||
SpinnerModel model = new YearSpinnerModel();
|
||||
this.yearSpinner = new JSpinner();
|
||||
this.yearSpinner.setModel(model);
|
||||
((JSpinner.DefaultEditor) this.yearSpinner.getEditor()).getTextField().setEditable(true);
|
||||
}
|
||||
|
||||
private void createMonthCombo() {
|
||||
months = new ArrayList<>();
|
||||
months.add("Enero");
|
||||
months.add("Febrero");
|
||||
months.add("Marzo");
|
||||
months.add("Abril");
|
||||
months.add("Mayo");
|
||||
months.add("Junio");
|
||||
months.add("Julio");
|
||||
months.add("Agosto");
|
||||
months.add("Septiembre");
|
||||
months.add("Octubre");
|
||||
months.add("Noviembre");
|
||||
months.add("Diciembre");
|
||||
|
||||
monthCombo = new JComboBox<>();
|
||||
for (String month : months) {
|
||||
monthCombo.addItem(month);
|
||||
}
|
||||
|
||||
int currentMonth = LocalDate.now().getMonth().getValue() - 1;
|
||||
monthCombo.setSelectedIndex(currentMonth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method generated by IntelliJ IDEA GUI Designer
|
||||
* >>> IMPORTANT!! <<<
|
||||
* DO NOT edit this method OR call it in your code!
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$setupUI$$$() {
|
||||
createUIComponents();
|
||||
contentPane = new JPanel();
|
||||
contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
|
||||
final JPanel panel1 = new JPanel();
|
||||
panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
|
||||
contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false));
|
||||
final Spacer spacer1 = new Spacer();
|
||||
panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
|
||||
final JPanel panel2 = new JPanel();
|
||||
panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false));
|
||||
panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
|
||||
buttonOK = new JButton();
|
||||
buttonOK.setText("OK");
|
||||
panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
buttonCancel = new JButton();
|
||||
buttonCancel.setText("Cancelar");
|
||||
panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JPanel panel3 = new JPanel();
|
||||
panel3.setLayout(new GridLayoutManager(3, 2, new Insets(0, 0, 0, 0), -1, -1));
|
||||
contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
|
||||
final JLabel label1 = new JLabel();
|
||||
label1.setText("Mes");
|
||||
panel3.add(label1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
panel3.add(monthCombo, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JLabel label2 = new JLabel();
|
||||
label2.setText("Año");
|
||||
panel3.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
panel3.add(yearSpinner, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JLabel label3 = new JLabel();
|
||||
label3.setText("Seleccione Mes y Año");
|
||||
panel3.add(label3, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
public JComponent $$$getRootComponent$$$() {
|
||||
return contentPane;
|
||||
}
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
public JComponent $$$getRootComponent$$$() {
|
||||
return contentPane;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,116 +30,145 @@ import danielcortes.xyz.data.DAOManager;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoToStringWrapper;
|
||||
import danielcortes.xyz.views.listeners.WindowClosingListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.KeyEvent;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
public class TipoEgresoSelectDialog extends JDialog {
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
private JComboBox<TipoEgresoToStringWrapper> tipoEgresoCombo;
|
||||
|
||||
private boolean acepted;
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
private JComboBox<TipoEgresoToStringWrapper> tipoEgresoCombo;
|
||||
|
||||
public TipoEgresoSelectDialog() {
|
||||
$$$setupUI$$$();
|
||||
this.setup();
|
||||
private boolean acepted;
|
||||
|
||||
public TipoEgresoSelectDialog() {
|
||||
$$$setupUI$$$();
|
||||
this.setup();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
this.setContentPane(contentPane);
|
||||
this.setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
this.getRootPane().setDefaultButton(buttonOK);
|
||||
|
||||
this.buttonOK.addActionListener(e -> onOK());
|
||||
this.buttonCancel.addActionListener(e -> onCancel());
|
||||
|
||||
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);
|
||||
this.pack();
|
||||
}
|
||||
|
||||
public TipoEgreso execute() {
|
||||
this.setVisible(true);
|
||||
|
||||
if (this.isAcepted()) {
|
||||
return this.getTipoEgreso();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
this.setContentPane(contentPane);
|
||||
this.setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
this.getRootPane().setDefaultButton(buttonOK);
|
||||
private void onOK() {
|
||||
this.acepted = true;
|
||||
dispose();
|
||||
}
|
||||
|
||||
this.buttonOK.addActionListener(e -> onOK());
|
||||
this.buttonCancel.addActionListener(e -> onCancel());
|
||||
private void onCancel() {
|
||||
this.acepted = false;
|
||||
dispose();
|
||||
}
|
||||
|
||||
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);
|
||||
public boolean isAcepted() {
|
||||
return this.acepted;
|
||||
}
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
this.pack();
|
||||
public TipoEgreso getTipoEgreso() {
|
||||
return (TipoEgreso) tipoEgresoCombo.getSelectedItem();
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
createTipoEgresoCombo();
|
||||
}
|
||||
|
||||
private void createTipoEgresoCombo() {
|
||||
tipoEgresoCombo = new JComboBox<>();
|
||||
for (TipoEgreso tipoEgreso : DAOManager.getTipoEgresoDAO().findAll()) {
|
||||
tipoEgresoCombo.addItem(new TipoEgresoToStringWrapper(tipoEgreso));
|
||||
}
|
||||
}
|
||||
|
||||
public TipoEgreso execute() {
|
||||
this.setVisible(true);
|
||||
/**
|
||||
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
|
||||
* call it in your code!
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$setupUI$$$() {
|
||||
createUIComponents();
|
||||
contentPane = new JPanel();
|
||||
contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
|
||||
final JPanel panel1 = new JPanel();
|
||||
panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||
contentPane.add(panel1,
|
||||
new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null,
|
||||
null, null, 0, false));
|
||||
final JPanel panel2 = new JPanel();
|
||||
panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false));
|
||||
panel1.add(panel2,
|
||||
new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null,
|
||||
null, 0, false));
|
||||
buttonOK = new JButton();
|
||||
buttonOK.setText("OK");
|
||||
panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER,
|
||||
GridConstraints.FILL_HORIZONTAL,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
buttonCancel = new JButton();
|
||||
buttonCancel.setText("Cancel");
|
||||
panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER,
|
||||
GridConstraints.FILL_HORIZONTAL,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JPanel panel3 = new JPanel();
|
||||
panel3.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||
contentPane.add(panel3,
|
||||
new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null,
|
||||
null, 0, false));
|
||||
panel3.add(tipoEgresoCombo, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST,
|
||||
GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW,
|
||||
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JLabel label1 = new JLabel();
|
||||
label1.setText("Seleccione el Tipo de Egreso:");
|
||||
panel3.add(label1,
|
||||
new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
|
||||
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
|
||||
false));
|
||||
}
|
||||
|
||||
if (this.isAcepted()) {
|
||||
return this.getTipoEgreso();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void onOK() {
|
||||
this.acepted = true;
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
this.acepted = false;
|
||||
dispose();
|
||||
}
|
||||
|
||||
public boolean isAcepted() {
|
||||
return this.acepted;
|
||||
}
|
||||
|
||||
public TipoEgreso getTipoEgreso() {
|
||||
return (TipoEgreso) tipoEgresoCombo.getSelectedItem();
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
createTipoEgresoCombo();
|
||||
}
|
||||
|
||||
private void createTipoEgresoCombo() {
|
||||
tipoEgresoCombo = new JComboBox<>();
|
||||
for (TipoEgreso tipoEgreso : DAOManager.getTipoEgresoDAO().findAll()) {
|
||||
tipoEgresoCombo.addItem(new TipoEgresoToStringWrapper(tipoEgreso));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method generated by IntelliJ IDEA GUI Designer
|
||||
* >>> IMPORTANT!! <<<
|
||||
* DO NOT edit this method OR call it in your code!
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$setupUI$$$() {
|
||||
createUIComponents();
|
||||
contentPane = new JPanel();
|
||||
contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
|
||||
final JPanel panel1 = new JPanel();
|
||||
panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||
contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false));
|
||||
final JPanel panel2 = new JPanel();
|
||||
panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false));
|
||||
panel1.add(panel2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
|
||||
buttonOK = new JButton();
|
||||
buttonOK.setText("OK");
|
||||
panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
buttonCancel = new JButton();
|
||||
buttonCancel.setText("Cancel");
|
||||
panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JPanel panel3 = new JPanel();
|
||||
panel3.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||
contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
|
||||
panel3.add(tipoEgresoCombo, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final JLabel label1 = new JLabel();
|
||||
label1.setText("Seleccione el Tipo de Egreso:");
|
||||
panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
public JComponent $$$getRootComponent$$$() {
|
||||
return contentPane;
|
||||
}
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
public JComponent $$$getRootComponent$$$() {
|
||||
return contentPane;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,79 +1,85 @@
|
||||
package danielcortes.xyz.views.dialogs;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
|
||||
public class XLSFileChooser {
|
||||
private JFileChooser chooser;
|
||||
|
||||
public XLSFileChooser(String suggestedName){
|
||||
this.chooser = new JFileChooser();
|
||||
this.chooser.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
this.chooser.setSelectedFile(new File(suggestedName + ".xls"));
|
||||
this.chooser.setFileFilter(new FileNameExtensionFilter("Excel 2007", "xls"));
|
||||
private JFileChooser chooser;
|
||||
|
||||
public XLSFileChooser(String suggestedName) {
|
||||
this.chooser = new JFileChooser();
|
||||
this.chooser.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
this.chooser.setSelectedFile(new File(suggestedName + ".xls"));
|
||||
this.chooser.setFileFilter(new FileNameExtensionFilter("Excel 2007", "xls"));
|
||||
}
|
||||
|
||||
public Path execute() {
|
||||
boolean accepted = this.chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION;
|
||||
if (accepted) {
|
||||
Path path = processFilePath(this.chooser.getSelectedFile().getPath());
|
||||
return path;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Path processFilePath(String pathString) {
|
||||
Path path;
|
||||
|
||||
if (!pathString.endsWith(".xls")) {
|
||||
pathString = pathString + ".xls";
|
||||
}
|
||||
|
||||
public Path execute(){
|
||||
boolean accepted = this.chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION;
|
||||
if(accepted){
|
||||
Path path = processFilePath(this.chooser.getSelectedFile().getPath());
|
||||
return path;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
path = Paths.get(pathString);
|
||||
} catch (InvalidPathException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"El nombre de archivo entregado es invalido",
|
||||
"Error!",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
private Path processFilePath(String pathString) {
|
||||
Path path;
|
||||
try {
|
||||
Files.createFile(path);
|
||||
} catch (FileAlreadyExistsException e) {
|
||||
int response = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"El archivo ya existe" + "\n" + "¿Desea sobreescribirlo?",
|
||||
"Confirmacion",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE
|
||||
);
|
||||
|
||||
if (!pathString.endsWith(".xls")) {
|
||||
pathString = pathString + ".xls";
|
||||
}
|
||||
if (response != 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
path = Paths.get(pathString);
|
||||
} catch (InvalidPathException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"No a sido posible crear el archivo",
|
||||
"Error!",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"El nombre de archivo entregado es invalido",
|
||||
"Error!",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Files.createFile(path);
|
||||
} catch (FileAlreadyExistsException e) {
|
||||
int response = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"El archivo ya existe" + "\n" + "¿Desea sobreescribirlo?",
|
||||
"Confirmacion",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE
|
||||
);
|
||||
|
||||
if (response != 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"No a sido posible crear el archivo",
|
||||
"Error!",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return path;
|
||||
return null;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user