package GUI.dialogs;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import model.CurrentDate;
import model.Date;
import model.exceptions.CurrentDateException;
/**
*
* @author Waldemar Smirnow
* @author Volha Baranouskaya
*/
public class SetCurrentDateDialog extends JDialog
{
private static final long serialVersionUID = 1247338857373301483L;
public boolean resetWarnings = false;
/** Creates new form SetCurrentDateDialog */
public SetCurrentDateDialog(java.awt.Frame parent, boolean modal)
{
super(parent, modal);
initComponents();
fillComboBoxes();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents()
{
okButton = new javax.swing.JButton();
titleLabel = new javax.swing.JLabel();
dayComboBox = new javax.swing.JComboBox();
monthComboBox = new javax.swing.JComboBox();
yearTextField = new javax.swing.JTextField();
resetWarningsCheckbox = new javax.swing.JCheckBox();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
okButtonActionPerformed(evt);
dispose();
}
});
titleLabel.setFont(new java.awt.Font("Arial", 0, 14));
titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
titleLabel.setText("Tagesdatum setzen:");
dayComboBox.setFont(new java.awt.Font("Tahoma", 0, 12));
monthComboBox.setFont(new java.awt.Font("Tahoma", 0, 12));
yearTextField.setFont(new java.awt.Font("Tahoma", 0, 12));
yearTextField.setText("2008");
yearTextField.setMaximumSize(new java.awt.Dimension(6, 21));
yearTextField.setMinimumSize(new java.awt.Dimension(4, 21));
resetWarningsCheckbox.setText("Mahnungen zurücksetzen");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(64, Short.MAX_VALUE)
.addComponent(dayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(monthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(yearTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(75, 75, 75))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(resetWarningsCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 170, Short.MAX_VALUE)
.addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(112, 112, 112)
.addComponent(titleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
.addGap(106, 106, 106))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(titleLabel)
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(yearTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(monthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(dayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(okButton)
.addComponent(resetWarningsCheckbox))
.addContainerGap())
);
this.setResizable(false);
this.setTitle("Tagesdatum festlegen");
// dialog mittig auf dem bildschirm setzen
DialogHelper.setToCenterScreen(this);
pack();
}// </editor-fold>
private void okButtonActionPerformed(java.awt.event.ActionEvent evt)
{
// hier wird das currentDate gesetzt
int day = dayComboBox.getSelectedIndex() + 1;
int month = monthComboBox.getSelectedIndex() + 1;
int year = Integer.parseInt(yearTextField.getText());
Date newCurrentDate = new Date(day, month, year);
try
{
CurrentDate.set(newCurrentDate);
this.setVisible(false);
this.resetWarnings = this.resetWarningsCheckbox.isSelected();
}
catch (CurrentDateException e)
{
JOptionPane.showMessageDialog(this, e.getMessage(),
"Fehler beim setzen des Tagesdatums",
JOptionPane.ERROR_MESSAGE);
}
}
private void fillComboBoxes()
{
for (int i = 1; i <= 31; i++)
{
dayComboBox.addItem(i);
}
String[] months = new String[]{"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August",
"September", "Oktober", "November", "Dezember"};
for(String month : months)
{
monthComboBox.addItem(month);
}
// default werte sind die des tatsächlichen datums
Date today = new Date();
dayComboBox.setSelectedIndex(today.getDate() - 1);
monthComboBox.setSelectedIndex(today.getMonth() - 1);
yearTextField.setText(Integer.toString(today.getYear()));
}
// Variables declaration - do not modify
private javax.swing.JComboBox dayComboBox;
private javax.swing.JComboBox monthComboBox;
private javax.swing.JButton okButton;
private javax.swing.JCheckBox resetWarningsCheckbox;
private javax.swing.JLabel titleLabel;
private javax.swing.JTextField yearTextField;
// End of variables declaration
}