1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import javax.swing.BorderFactory;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TimePanel extends JPanel {
/** Layout constraints of the panel */
private final GridBagConstraints gbc;
public TimePanel()
{
// Initialization of the GBC
this.gbc = new GridBagConstraints();
this.gbc.gridwidth = 1;
this.gbc.gridheight = 1;
this.gbc.weightx = 0;
this.gbc.weighty = 0;
this.gbc.anchor = GridBagConstraints.CENTER;
this.gbc.insets = new Insets(5, 5, 5, 5);
this.gbc.fill = GridBagConstraints.NONE;
//this.gbc.anchor = GridBagConstraints.NORTHWEST;
this.setLayout(new GridBagLayout());
this.setBorder(BorderFactory.createLineBorder(Color.black));
this.setBackground(CharteGraphique.PANEL_BACKGROUND);
txtFieldHeureDebut = new JFormattedTextField(DateFormat.getTimeInstance());
Calendar hour = Calendar.getInstance(Locale.FRANCE);
hour.set(Calendar.HOUR, 0);
hour.set(Calendar.MINUTE, 0);
hour.set(Calendar.SECOND, 0);
txtFieldHeureDebut.setValue(hour.getTime());
txtFieldHeureFin = new JFormattedTextField(DateFormat.getTimeInstance());
txtFieldHeureFin.setValue(hour.getTime());
txtFieldDateDebut = new JFormattedTextField(DateFormat.getDateInstance());
Calendar startDate = Calendar.getInstance(Locale.FRANCE);
startDate.add(Calendar.DAY_OF_MONTH, -1);
txtFieldDateDebut.setValue(startDate.getTime());
txtFieldDateFin = new JFormattedTextField(DateFormat.getDateInstance());
Calendar endDate = Calendar.getInstance(Locale.FRANCE);
endDate.add(Calendar.DAY_OF_MONTH, +1);
txtFieldDateFin.setValue(endDate.getTime());
initComponents();
}
public Date getStartDate()
{
Calendar startDate = Calendar.getInstance();
startDate.setTime((Date)txtFieldDateDebut.getValue());
Calendar startTime = Calendar.getInstance();
startTime.setTime((Date)txtFieldHeureDebut.getValue());
startDate.set(Calendar.HOUR_OF_DAY, startTime.get(Calendar.HOUR_OF_DAY));
startDate.set(Calendar.MINUTE, startTime.get(Calendar.MINUTE));
return startDate.getTime();
}
public Date getEndDate()
{
Calendar startDate = Calendar.getInstance();
startDate.setTime((Date)txtFieldDateFin.getValue());
Calendar startTime = Calendar.getInstance();
startTime.setTime((Date)txtFieldHeureFin.getValue());
startDate.set(Calendar.HOUR_OF_DAY, startTime.get(Calendar.HOUR_OF_DAY));
startDate.set(Calendar.MINUTE, startTime.get(Calendar.MINUTE));
return startDate.getTime();
}
public double tpsTotal()
{
Date start = TimePanel.getStartDate();
Date end = TimePanel.getEndDate();
return (end.getTime() - start.getTime()) / (60*1000);
}
protected void initComponents()
{
this.gbc.gridx = 0;
this.gbc.gridy = 0;
this.gbc.fill = GridBagConstraints.HORIZONTAL;
JPanel panel = new JPanel();
panel.setBackground(CharteGraphique.TIME_LABEL_BACKGROUND);
JLabel label = new JLabel("H Début :");
label.setForeground(Color.WHITE);
panel.add(label);
add(panel, gbc);
this.gbc.gridx = 1;
this.gbc.gridy = 0;
this.gbc.fill = GridBagConstraints.NONE;
add(txtFieldHeureDebut, gbc);
this.gbc.gridx = 0;
this.gbc.gridy = 1;
this.gbc.fill = GridBagConstraints.HORIZONTAL;
panel = new JPanel();
panel.setBackground(CharteGraphique.TIME_LABEL_BACKGROUND);
label = new JLabel("H Fin :");
label.setForeground(Color.WHITE);
panel.add(label);
add(panel, gbc);
this.gbc.gridx = 1;
this.gbc.gridy = 1;
this.gbc.fill = GridBagConstraints.NONE;
add(txtFieldHeureFin, gbc);
this.gbc.gridx = 2;
this.gbc.gridy = 0;
panel = new JPanel();
panel.setBackground(CharteGraphique.TIME_LABEL_BACKGROUND);
label = new JLabel("Date Début :");
label.setForeground(Color.WHITE);
panel.add(label);
add(panel, gbc);
this.gbc.gridx = 3;
this.gbc.gridy = 0;
add(txtFieldDateDebut, gbc);
this.gbc.gridx = 2;
this.gbc.gridy = 1;
panel = new JPanel();
panel.setBackground(CharteGraphique.TIME_LABEL_BACKGROUND);
label = new JLabel("Date Fin :");
label.setForeground(Color.WHITE);
panel.add(label);
add(panel, gbc);
this.gbc.gridx = 3;
this.gbc.gridy = 1;
add(txtFieldDateFin, gbc);
}
private JFormattedTextField txtFieldHeureDebut;
private JFormattedTextField txtFieldHeureFin;
private JFormattedTextField txtFieldDateDebut;
private JFormattedTextField txtFieldDateFin;
/**
*
*/
} |
Partager