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