Package mate00.parafia.ui

Source Code of mate00.parafia.ui.DatePicker

package mate00.parafia.ui;

import java.awt.Frame;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import mate00.parafia.net.ExpeditionDetails;
import org.jdesktop.application.Action;
import org.joda.time.DateTime;

/**
*
* @author mate00
*/
public class DatePicker extends javax.swing.JDialog implements SliderUpdateListener {

    private ExpeditionDetails mDetails;
   
    private ChangeListener slidersListener;
   
    public DatePicker(Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
   
    public DatePicker(Frame parent, ExpeditionDetails details) {
        this(parent, true);
        if(details == null) {
            mDetails = new ExpeditionDetails();
        }
       
        mDetails = details;
        lblReturn.setText("");
        slidersListener = new ExpeditionTimeSliderListener(sliderDays, sliderHours, this);
        setSliderListeners(slidersListener);
        if(details != null) {
            setSliderValues(details);
        }
    }
   
    @Action
    public void onOk() {
        mDetails.setDays(sliderDays.getValue());
        mDetails.setHours(sliderHours.getValue());
        dispose();
    }
   
    @Action
    public void onCancel() {
        dispose();
    }
   
   
    @Override
    public void updateWithDetails(ExpeditionDetails details) {
        DateTime back = DateTime.now().plusDays(details.getDays()).plusHours(details.getHours());
        lblReturn.setText(getLabelFromBackDate(back));
    }
   
    private void setSliderListeners(ChangeListener slidersListener) {
        sliderDays.addChangeListener(slidersListener);
        sliderHours.addChangeListener(slidersListener);
    }
   
    private String getLabelFromBackDate(DateTime back) {
        return back.getDayOfMonth() + "-" + back.getMonthOfYear() + "   " + back.getHourOfDay() + ":" + back.getMinuteOfHour();
    }
   
    private void setSliderValues(ExpeditionDetails details) {
        sliderDays.setValue(details.getDays());
        sliderHours.setValue(details.getHours());
    }
   

    /** 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sliderDays = new javax.swing.JSlider();
        sliderHours = new javax.swing.JSlider();
        btnOk = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        lblReturnTitle = new javax.swing.JLabel();
        lblReturn = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        sliderDays.setMaximum(30);
        sliderDays.setPaintLabels(true);
        sliderDays.setValue(0);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(mate00.parafia.ui.ParafiaApp.class).getContext().getResourceMap(DatePicker.class);
        sliderDays.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("sliderDays.border.title"))); // NOI18N
        sliderDays.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        sliderDays.setName("sliderDays"); // NOI18N

        sliderHours.setMaximum(23);
        sliderHours.setValue(0);
        sliderHours.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("sliderHours.border.title"))); // NOI18N
        sliderHours.setName("sliderHours"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(mate00.parafia.ui.ParafiaApp.class).getContext().getActionMap(DatePicker.class, this);
        btnOk.setAction(actionMap.get("onOk")); // NOI18N
        btnOk.setText(resourceMap.getString("btnOk.text")); // NOI18N
        btnOk.setName("btnOk"); // NOI18N

        btnCancel.setAction(actionMap.get("onCancel")); // NOI18N
        btnCancel.setText(resourceMap.getString("btnCancel.text")); // NOI18N
        btnCancel.setName("btnCancel"); // NOI18N

        lblReturnTitle.setText(resourceMap.getString("lblReturnTitle.text")); // NOI18N
        lblReturnTitle.setName("lblReturnTitle"); // NOI18N

        lblReturn.setText(resourceMap.getString("lblReturn.text")); // NOI18N
        lblReturn.setName("lblReturn"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(sliderDays, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnOk)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancel)
                        .addGap(141, 141, 141))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(sliderHours, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblReturnTitle)
                        .addGap(18, 18, 18)
                        .addComponent(lblReturn)
                        .addContainerGap(193, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(sliderDays, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sliderHours, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblReturnTitle)
                    .addComponent(lblReturn))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnOk)
                    .addComponent(btnCancel)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DatePicker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DatePicker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DatePicker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DatePicker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                DatePicker dialog = new DatePicker(new javax.swing.JFrame(), new ExpeditionDetails());
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnOk;
    private javax.swing.JLabel lblReturn;
    private javax.swing.JLabel lblReturnTitle;
    private javax.swing.JSlider sliderDays;
    private javax.swing.JSlider sliderHours;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of mate00.parafia.ui.DatePicker

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.