PageRenderTime 123ms CodeModel.GetById 40ms app.highlight 16ms RepoModel.GetById 64ms app.codeStats 1ms

/src/mpv5/ui/dialogs/MiniCalendarDialog.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 189 lines | 140 code | 27 blank | 22 comment | 6 complexity | 36c26f61005c960322706f9d9364a130 MD5 | raw file
  1/*
  2 * To change this template, choose Tools | Templates
  3 * and open the template in the editor.
  4 */
  5
  6/*
  7 * MiniCalendar1.java
  8 *
  9 * Created on 24.08.2009, 12:34:57
 10 */
 11package mpv5.ui.dialogs;
 12
 13import com.michaelbaranov.microba.calendar.CalendarPane;
 14import java.awt.BorderLayout;
 15import java.beans.PropertyVetoException;
 16import java.text.DateFormat;
 17import java.util.Date;
 18import java.util.logging.Level;
 19import java.util.logging.Logger;
 20import javax.swing.JComponent;
 21import javax.swing.JSpinner;
 22import javax.swing.JTextField;
 23import mpv5.ui.frames.MPView;
 24import mpv5.utils.date.DateConverter;
 25
 26/**
 27 *
 28 * @author anti
 29 */
 30public class MiniCalendarDialog extends javax.swing.JDialog {
 31
 32    private CalendarPane xc;
 33    private final JComponent t;
 34
 35    /** Creates new form MiniCalendar1 */
 36    public MiniCalendarDialog(JComponent t, boolean modal) {
 37        super(mpv5.YabsViewProxy.instance().getIdentifierFrame(), modal);
 38        initComponents();
 39
 40
 41        xc = new com.michaelbaranov.microba.calendar.CalendarPane();
 42        xc.setShowTodayButton(true);
 43        try {
 44            xc.setDate(new Date());
 45        } catch (PropertyVetoException ex) {
 46        }
 47        xc.addActionListener(new java.awt.event.ActionListener() {
 48
 49            @Override
 50            public void actionPerformed(java.awt.event.ActionEvent evt) {
 51                jButton1ActionPerformed(evt);
 52            }
 53        });
 54
 55        this.t = t;
 56        this.jPanel1.add(xc, BorderLayout.CENTER);
 57    }
 58
 59    /** This method is called from within the constructor to
 60     * initialize the form.
 61     * WARNING: Do NOT modify this code. The content of this method is
 62     * always regenerated by the Form Editor.
 63     */
 64    @SuppressWarnings("unchecked")
 65    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 66    private void initComponents() {
 67
 68        jPanel2 = new javax.swing.JPanel();
 69        jButton1 = new javax.swing.JButton();
 70        jPanel1 = new javax.swing.JPanel();
 71
 72        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 73        setAlwaysOnTop(true);
 74        setName("Form"); // NOI18N
 75        setUndecorated(true);
 76
 77        jPanel2.setBackground(new java.awt.Color(227, 219, 202));
 78        jPanel2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
 79        jPanel2.setName("jPanel2"); // NOI18N
 80
 81        jButton1.setText("Ok");
 82        jButton1.setName("jButton1"); // NOI18N
 83        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
 84            public void mouseClicked(java.awt.event.MouseEvent evt) {
 85                jButton1MouseClicked(evt);
 86            }
 87        });
 88        jButton1.addActionListener(new java.awt.event.ActionListener() {
 89            public void actionPerformed(java.awt.event.ActionEvent evt) {
 90                jButton1ActionPerformed(evt);
 91            }
 92        });
 93        jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
 94            public void keyPressed(java.awt.event.KeyEvent evt) {
 95                jButton1KeyPressed(evt);
 96            }
 97        });
 98
 99        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
100        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
101        jPanel1.setName("jPanel1"); // NOI18N
102        jPanel1.addKeyListener(new java.awt.event.KeyAdapter() {
103            public void keyPressed(java.awt.event.KeyEvent evt) {
104                jPanel1KeyPressed(evt);
105            }
106        });
107        jPanel1.setLayout(new java.awt.BorderLayout());
108
109        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
110        jPanel2.setLayout(jPanel2Layout);
111        jPanel2Layout.setHorizontalGroup(
112            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
113            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
114                .addContainerGap()
115                .addComponent(jButton1))
116            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
117        );
118        jPanel2Layout.setVerticalGroup(
119            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
120            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
121                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
122                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
123                .addComponent(jButton1))
124        );
125
126        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
127        getContentPane().setLayout(layout);
128        layout.setHorizontalGroup(
129            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
130            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
131        );
132        layout.setVerticalGroup(
133            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
135        );
136
137        pack();
138    }// </editor-fold>//GEN-END:initComponents
139
140    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
141        go();
142}//GEN-LAST:event_jButton1MouseClicked
143
144    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
145        go();
146}//GEN-LAST:event_jButton1ActionPerformed
147
148    private void jButton1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyPressed
149        go();
150}//GEN-LAST:event_jButton1KeyPressed
151
152    private void jPanel1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel1KeyPressed
153        this.dispose();
154}//GEN-LAST:event_jPanel1KeyPressed
155 public Date getDate() {
156        return xc.getDate();
157    }
158
159    public void setDate(Date date) {
160        try {
161            xc.setDate(date);
162            go();
163        } catch (PropertyVetoException ex) {
164            mpv5.logging.Log.Debug(ex);//Logger.getLogger(MiniCalendar.class.getName()).log(Level.SEVERE, null, ex);
165        }
166
167    }
168
169    private void go() {
170        DateFormat format = DateConverter.DEF_DATE_FORMAT;
171        if (xc.getDate() != null) {
172
173            if (t instanceof JTextField) {
174                ((JTextField) t).setText(format.format(xc.getDate()));
175            } else if (t instanceof JSpinner) {
176                ((JSpinner) t).setValue(xc.getDate());
177            }
178            this.setVisible(false);
179        } else {
180            this.setVisible(false);
181        }
182    }
183  
184    // Variables declaration - do not modify//GEN-BEGIN:variables
185    private javax.swing.JButton jButton1;
186    private javax.swing.JPanel jPanel1;
187    private javax.swing.JPanel jPanel2;
188    // End of variables declaration//GEN-END:variables
189}