/src/mpv5/ui/dialogs/MiniCalendarFrame.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/ · Java · 210 lines · 165 code · 28 blank · 17 comment · 6 complexity · 17721bcc9495043be0caf90dbcc74ad7 MD5 · raw file

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