/src/mpv5/ui/dialogs/MiniCalendarDialog.java
Java | 189 lines | 140 code | 27 blank | 22 comment | 6 complexity | 36c26f61005c960322706f9d9364a130 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * MiniCalendar1.java
- *
- * Created on 24.08.2009, 12:34:57
- */
- package mpv5.ui.dialogs;
- import com.michaelbaranov.microba.calendar.CalendarPane;
- import java.awt.BorderLayout;
- import java.beans.PropertyVetoException;
- import java.text.DateFormat;
- import java.util.Date;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JComponent;
- import javax.swing.JSpinner;
- import javax.swing.JTextField;
- import mpv5.ui.frames.MPView;
- import mpv5.utils.date.DateConverter;
- /**
- *
- * @author anti
- */
- public class MiniCalendarDialog extends javax.swing.JDialog {
- private CalendarPane xc;
- private final JComponent t;
- /** Creates new form MiniCalendar1 */
- public MiniCalendarDialog(JComponent t, boolean modal) {
- super(mpv5.YabsViewProxy.instance().getIdentifierFrame(), modal);
- initComponents();
- xc = new com.michaelbaranov.microba.calendar.CalendarPane();
- xc.setShowTodayButton(true);
- try {
- xc.setDate(new Date());
- } catch (PropertyVetoException ex) {
- }
- xc.addActionListener(new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- this.t = t;
- this.jPanel1.add(xc, BorderLayout.CENTER);
- }
- /** 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() {
- jPanel2 = new javax.swing.JPanel();
- jButton1 = new javax.swing.JButton();
- jPanel1 = new javax.swing.JPanel();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setAlwaysOnTop(true);
- setName("Form"); // NOI18N
- setUndecorated(true);
- jPanel2.setBackground(new java.awt.Color(227, 219, 202));
- jPanel2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
- jPanel2.setName("jPanel2"); // NOI18N
- jButton1.setText("Ok");
- jButton1.setName("jButton1"); // NOI18N
- jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jButton1MouseClicked(evt);
- }
- });
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyPressed(java.awt.event.KeyEvent evt) {
- jButton1KeyPressed(evt);
- }
- });
- jPanel1.setBackground(new java.awt.Color(255, 255, 255));
- jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- jPanel1.setName("jPanel1"); // NOI18N
- jPanel1.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyPressed(java.awt.event.KeyEvent evt) {
- jPanel1KeyPressed(evt);
- }
- });
- jPanel1.setLayout(new java.awt.BorderLayout());
- javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
- jPanel2.setLayout(jPanel2Layout);
- jPanel2Layout.setHorizontalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jButton1))
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
- );
- jPanel2Layout.setVerticalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton1))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
- go();
- }//GEN-LAST:event_jButton1MouseClicked
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- go();
- }//GEN-LAST:event_jButton1ActionPerformed
- private void jButton1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyPressed
- go();
- }//GEN-LAST:event_jButton1KeyPressed
- private void jPanel1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel1KeyPressed
- this.dispose();
- }//GEN-LAST:event_jPanel1KeyPressed
- public Date getDate() {
- return xc.getDate();
- }
- public void setDate(Date date) {
- try {
- xc.setDate(date);
- go();
- } catch (PropertyVetoException ex) {
- mpv5.logging.Log.Debug(ex);//Logger.getLogger(MiniCalendar.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void go() {
- DateFormat format = DateConverter.DEF_DATE_FORMAT;
- if (xc.getDate() != null) {
- if (t instanceof JTextField) {
- ((JTextField) t).setText(format.format(xc.getDate()));
- } else if (t instanceof JSpinner) {
- ((JSpinner) t).setValue(xc.getDate());
- }
- this.setVisible(false);
- } else {
- this.setVisible(false);
- }
- }
-
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- // End of variables declaration//GEN-END:variables
- }