PageRenderTime 22ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

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