/*
* DialogNewHoliday.java
*
* Created on 29 Декабрь 2007 г., 18:26
*/
package clips.shedule.holidays;
import beans.shedule.holiday.SheduleHolidayDetails;
import cli_fmw.main.audit.AuditManager;
import cli_fmw.utils.Selector;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JFrame;
/**
*
* @author Axe Ilshat
*/
class DialogNewHoliday extends ModalDialog {
/** Creates new form DialogNewHoliday */
public DialogNewHoliday(JFrame parent) {
super(parent, "Праздничные дни", null);
initComponents();
buttonGroup.add(oneDayBtn);
buttonGroup.add(periodDayBtn);
for (int i = 0; i < 31; i++) {
day.addItem(new Integer(i+1));
dayBegin.addItem(new Integer(i+1));
dayEnd.addItem(new Integer(i+1));
}
for (int i = 0; i < 12; i++) {
month.addItem(new Integer(i+1));
monthBegin.addItem(new Integer(i+1));
monthEnd.addItem(new Integer(i+1));
}
checkInputValues();
Dimension scrSize=Toolkit.getDefaultToolkit().getScreenSize();
Rectangle dlgSize=this.getBounds();
this.setLocation((scrSize.width-dlgSize.width)/2,(scrSize.height-dlgSize.height)/2);
StateSaver.attachTo(this);
}
/** 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">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup = new javax.swing.ButtonGroup();
jPanel2 = new javax.swing.JPanel();
jLabel7 = new javax.swing.JLabel();
day = new javax.swing.JComboBox();
jLabel8 = new javax.swing.JLabel();
oneDayBtn = new javax.swing.JRadioButton();
month = new javax.swing.JComboBox();
periodDayBtn = new javax.swing.JRadioButton();
jLabel9 = new javax.swing.JLabel();
dayEnd = new javax.swing.JComboBox();
jLabel10 = new javax.swing.JLabel();
monthEnd = new javax.swing.JComboBox();
jLabel11 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
dayBegin = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
monthBegin = new javax.swing.JComboBox();
jLabel4 = new javax.swing.JLabel();
errorDescription = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
description = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
addBtn = new javax.swing.JButton();
cancelBtn = new javax.swing.JButton();
getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Даты"));
jLabel7.setText("День");
day.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dayActionPerformed(evt);
}
});
jLabel8.setText("Месяц");
oneDayBtn.setText("Праздничный день");
oneDayBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
oneDayBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oneDayBtnActionPerformed(evt);
}
});
month.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
monthActionPerformed(evt);
}
});
periodDayBtn.setText("Период праздничных дней");
periodDayBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
periodDayBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
periodDayBtnActionPerformed(evt);
}
});
jLabel9.setText("Продолжаются до");
dayEnd.setEnabled(false);
dayEnd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dayEndActionPerformed(evt);
}
});
jLabel10.setText("числа");
monthEnd.setEnabled(false);
monthEnd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
monthEndActionPerformed(evt);
}
});
jLabel11.setText("месяца");
jLabel2.setText("Начиная с");
dayBegin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dayBeginActionPerformed(evt);
}
});
jLabel3.setText("числа");
monthBegin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
monthBeginActionPerformed(evt);
}
});
jLabel4.setText("месяца");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(day, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel8))
.addComponent(oneDayBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(month, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(periodDayBtn)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(17, 17, 17)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(dayBegin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(monthBegin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel4))
.addGroup(jPanel2Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(dayEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(monthEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel11)))))
.addGap(47, 47, 47))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(errorDescription, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(oneDayBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(day, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8)
.addComponent(month, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(periodDayBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(dayBegin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(monthBegin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(dayEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10)
.addComponent(monthEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(errorDescription)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
getContentPane().add(jPanel2);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Краткое описание"));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(description, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(description, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
getContentPane().add(jPanel1);
addBtn.setText("Добавить");
addBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addBtnActionPerformed(evt);
}
});
jPanel3.add(addBtn);
cancelBtn.setText(" Отмена ");
cancelBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelBtnActionPerformed(evt);
}
});
jPanel3.add(cancelBtn);
getContentPane().add(jPanel3);
pack();
}// </editor-fold>//GEN-END:initComponents
private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBtnActionPerformed
this.setVisible(false);
setDlgResult(DLG_OK);
}//GEN-LAST:event_addBtnActionPerformed
private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
this.setVisible(false);
}//GEN-LAST:event_cancelBtnActionPerformed
private void periodDayBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_periodDayBtnActionPerformed
checkInputValues();
}//GEN-LAST:event_periodDayBtnActionPerformed
private void oneDayBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oneDayBtnActionPerformed
checkInputValues();
}//GEN-LAST:event_oneDayBtnActionPerformed
private void monthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monthActionPerformed
checkInputValues();
}//GEN-LAST:event_monthActionPerformed
private void dayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dayActionPerformed
checkInputValues();
}//GEN-LAST:event_dayActionPerformed
private void monthEndActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monthEndActionPerformed
checkInputValues();
}//GEN-LAST:event_monthEndActionPerformed
private void dayEndActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dayEndActionPerformed
checkInputValues();
}//GEN-LAST:event_dayEndActionPerformed
private void monthBeginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monthBeginActionPerformed
checkInputValues();
}//GEN-LAST:event_monthBeginActionPerformed
private void dayBeginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dayBeginActionPerformed
checkInputValues();
}//GEN-LAST:event_dayBeginActionPerformed
private void checkInputValues() {
day.setEnabled(oneDayBtn.isSelected());
month.setEnabled(oneDayBtn.isSelected());
dayBegin.setEnabled(periodDayBtn.isSelected());
monthBegin.setEnabled(periodDayBtn.isSelected());
dayEnd.setEnabled(periodDayBtn.isSelected());
monthEnd.setEnabled(periodDayBtn.isSelected());
boolean canBeAdded = true;
if(periodDayBtn.isSelected()) {
try {
GregorianCalendar gcb = (GregorianCalendar) GregorianCalendar.getInstance();
gcb.set(Calendar.DAY_OF_MONTH, (Integer)dayBegin.getSelectedItem()-1);
gcb.set(Calendar.MONTH, (Integer)monthBegin.getSelectedItem());
GregorianCalendar gce = (GregorianCalendar) GregorianCalendar.getInstance();
gce.set(Calendar.DAY_OF_MONTH, (Integer)dayEnd.getSelectedItem()-1);
gce.set(Calendar.MONTH, (Integer)monthEnd.getSelectedItem());
if(gce.get(Calendar.DAY_OF_YEAR) <= gcb.get(Calendar.DAY_OF_YEAR)) {
errorDescription.setText("Период задан неверно!");
canBeAdded = false;
} else if (gce.get(Calendar.DAY_OF_YEAR) > gcb.get(Calendar.DAY_OF_YEAR)+30) {
errorDescription.setText("Период превышает 30 дней!");
canBeAdded = false;
} else {
errorDescription.setText("");
}
} catch (Exception ex) {
canBeAdded = false;
}
} else {
errorDescription.setText("");
}
addBtn.setEnabled(canBeAdded);
day.setSize(day.getPreferredSize());
month.setSize(month.getPreferredSize());
dayBegin.setSize(dayBegin.getPreferredSize());
monthBegin.setSize(monthBegin.getPreferredSize());
dayEnd.setSize(dayEnd.getPreferredSize());
monthEnd.setSize(monthEnd.getPreferredSize());
this.setSize(getPreferredSize());
}
public Selector getDays() {
return new Days();
}
class Days implements Selector {
public int size() {
if(getDlgResult() == ModalDialog.DLG_CANCEL) {
return 0;
} else if(oneDayBtn.isSelected()) {
return 1;
} else if(periodDayBtn.isSelected()) {
try {
GregorianCalendar gcb = (GregorianCalendar) GregorianCalendar.getInstance();
gcb.set(Calendar.DAY_OF_MONTH, (Integer)dayBegin.getSelectedItem());
gcb.set(Calendar.MONTH, (Integer)monthBegin.getSelectedItem()-1);
GregorianCalendar gce = (GregorianCalendar) GregorianCalendar.getInstance();
gce.set(Calendar.DAY_OF_MONTH, (Integer)dayEnd.getSelectedItem());
gce.set(Calendar.MONTH, (Integer)monthEnd.getSelectedItem()-1);
if(gce.get(Calendar.DAY_OF_YEAR) > gcb.get(Calendar.DAY_OF_YEAR)) {
return gce.get(Calendar.DAY_OF_YEAR) - gcb.get(Calendar.DAY_OF_YEAR) +1;
}
} catch (Exception ex) {
//do nothing
}
}
return 0;
}
public Object get(int index) {
if(getDlgResult() == ModalDialog.DLG_CANCEL) {
return null;
} else if(oneDayBtn.isSelected()) {
SheduleHolidayDetails details = new SheduleHolidayDetails();
details.day = (Integer)day.getSelectedItem();
details.month = (Integer)month.getSelectedItem();
details.description = description.getText();
return details;
} else if(periodDayBtn.isSelected()) {
try {
GregorianCalendar gcb = (GregorianCalendar) GregorianCalendar.getInstance();
gcb.set(Calendar.DAY_OF_MONTH, (Integer)dayBegin.getSelectedItem());
gcb.set(Calendar.MONTH, (Integer)monthBegin.getSelectedItem()-1);
GregorianCalendar gce = (GregorianCalendar) GregorianCalendar.getInstance();
gce.set(Calendar.DAY_OF_MONTH, (Integer)dayEnd.getSelectedItem());
gce.set(Calendar.MONTH, (Integer)monthEnd.getSelectedItem()-1);
if(gce.get(Calendar.DAY_OF_YEAR) >= gcb.get(Calendar.DAY_OF_YEAR)
&& index <= gce.get(Calendar.DAY_OF_YEAR) - gcb.get(Calendar.DAY_OF_YEAR)) {
gcb.add(Calendar.DAY_OF_YEAR, index);
SheduleHolidayDetails details = new SheduleHolidayDetails();
details.day = gcb.get(Calendar.DAY_OF_MONTH);
details.month = gcb.get(Calendar.MONTH)+1;
details.description = description.getText();
return details;
}
} catch (Exception ex) {
//do nothing
}
}
return null;
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addBtn;
private javax.swing.ButtonGroup buttonGroup;
private javax.swing.JButton cancelBtn;
private javax.swing.JComboBox day;
private javax.swing.JComboBox dayBegin;
private javax.swing.JComboBox dayEnd;
private javax.swing.JTextField description;
private javax.swing.JLabel errorDescription;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JComboBox month;
private javax.swing.JComboBox monthBegin;
private javax.swing.JComboBox monthEnd;
private javax.swing.JRadioButton oneDayBtn;
private javax.swing.JRadioButton periodDayBtn;
// End of variables declaration//GEN-END:variables
}