WIP170317
parent
2e9d8584fb
commit
ee5bd6ea1f
|
@ -14,6 +14,9 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JCheckBox;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class JTimeSpanEditor extends JComponent implements FocusListener {
|
||||
private JSpinner spDays;
|
||||
|
@ -26,32 +29,45 @@ public class JTimeSpanEditor extends JComponent implements FocusListener {
|
|||
|
||||
private List<FocusListener> focusListeners;
|
||||
private List<Component> components;
|
||||
private JCheckBox cbNull;
|
||||
|
||||
public JTimeSpanEditor() {
|
||||
this.focusListeners = new LinkedList<FocusListener>();
|
||||
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0};
|
||||
gridBagLayout.columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0};
|
||||
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
spDays = new JSpinner();
|
||||
spDays.addFocusListener(this);
|
||||
spDays.getEditor().addFocusListener(this);
|
||||
|
||||
cbNull = new JCheckBox("");
|
||||
cbNull.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
enableControls(cbNull.isSelected());
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_cbNull = new GridBagConstraints();
|
||||
gbc_cbNull.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_cbNull.gridx = 0;
|
||||
gbc_cbNull.gridy = 0;
|
||||
add(cbNull, gbc_cbNull);
|
||||
spDays.setModel(new SpinnerNumberModel(0, 0, 366, 1));
|
||||
GridBagConstraints gbc_spDays = new GridBagConstraints();
|
||||
gbc_spDays.fill = GridBagConstraints.BOTH;
|
||||
gbc_spDays.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_spDays.gridx = 0;
|
||||
gbc_spDays.gridx = 1;
|
||||
gbc_spDays.gridy = 0;
|
||||
add(spDays, gbc_spDays);
|
||||
|
||||
lblD = new JLabel("d");
|
||||
GridBagConstraints gbc_lblD = new GridBagConstraints();
|
||||
gbc_lblD.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblD.gridx = 1;
|
||||
gbc_lblD.gridx = 2;
|
||||
gbc_lblD.gridy = 0;
|
||||
add(lblD, gbc_lblD);
|
||||
|
||||
|
@ -63,14 +79,14 @@ public class JTimeSpanEditor extends JComponent implements FocusListener {
|
|||
GridBagConstraints gbc_spHours = new GridBagConstraints();
|
||||
gbc_spHours.fill = GridBagConstraints.BOTH;
|
||||
gbc_spHours.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_spHours.gridx = 2;
|
||||
gbc_spHours.gridx = 3;
|
||||
gbc_spHours.gridy = 0;
|
||||
add(spHours, gbc_spHours);
|
||||
|
||||
lblNewLabel = new JLabel(":");
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblNewLabel.gridx = 3;
|
||||
gbc_lblNewLabel.gridx = 4;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
|
@ -81,14 +97,14 @@ public class JTimeSpanEditor extends JComponent implements FocusListener {
|
|||
GridBagConstraints gbc_spMinutes = new GridBagConstraints();
|
||||
gbc_spMinutes.fill = GridBagConstraints.BOTH;
|
||||
gbc_spMinutes.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_spMinutes.gridx = 4;
|
||||
gbc_spMinutes.gridx = 5;
|
||||
gbc_spMinutes.gridy = 0;
|
||||
add(spMinutes, gbc_spMinutes);
|
||||
|
||||
label = new JLabel(":");
|
||||
GridBagConstraints gbc_label = new GridBagConstraints();
|
||||
gbc_label.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_label.gridx = 5;
|
||||
gbc_label.gridx = 6;
|
||||
gbc_label.gridy = 0;
|
||||
add(label, gbc_label);
|
||||
|
||||
|
@ -98,7 +114,7 @@ public class JTimeSpanEditor extends JComponent implements FocusListener {
|
|||
spSeconds.setModel(new SpinnerNumberModel(0, 0, 59, 1));
|
||||
GridBagConstraints gbc_spSeconds = new GridBagConstraints();
|
||||
gbc_spSeconds.fill = GridBagConstraints.BOTH;
|
||||
gbc_spSeconds.gridx = 6;
|
||||
gbc_spSeconds.gridx = 7;
|
||||
gbc_spSeconds.gridy = 0;
|
||||
add(spSeconds, gbc_spSeconds);
|
||||
|
||||
|
@ -148,20 +164,21 @@ public class JTimeSpanEditor extends JComponent implements FocusListener {
|
|||
;
|
||||
}
|
||||
|
||||
private void enableControls(Boolean enable){
|
||||
spSeconds.setEnabled(enable);
|
||||
spMinutes.setEnabled(enable);
|
||||
spHours.setEnabled(enable);
|
||||
spDays.setEnabled(enable);
|
||||
}
|
||||
|
||||
public void setValue(Integer seconds){
|
||||
Integer mod = seconds;
|
||||
|
||||
if (mod == null){
|
||||
spSeconds.setEnabled(false);
|
||||
spMinutes.setEnabled(false);
|
||||
spHours.setEnabled(false);
|
||||
spDays.setEnabled(false);
|
||||
cbNull.setSelected(false);
|
||||
} else {
|
||||
spSeconds.setEnabled(true);
|
||||
spMinutes.setEnabled(true);
|
||||
spHours.setEnabled(true);
|
||||
spDays.setEnabled(true);
|
||||
|
||||
cbNull.setSelected(true);
|
||||
|
||||
if (spDays.isVisible())
|
||||
spDays.setValue(mod / 86400);
|
||||
|
||||
|
@ -174,6 +191,22 @@ public class JTimeSpanEditor extends JComponent implements FocusListener {
|
|||
}
|
||||
}
|
||||
|
||||
public String getValueAsString(){
|
||||
return getValueAsString(getValue());
|
||||
}
|
||||
|
||||
public String getValueAsString(int timeSpan){
|
||||
int hours,minutes,seconds;
|
||||
|
||||
hours = timeSpan / 3600;
|
||||
timeSpan %= 3600;
|
||||
minutes = timeSpan / 60;
|
||||
timeSpan %= 60;
|
||||
seconds = timeSpan;
|
||||
|
||||
return String.format("%d:%02d:%02d", hours,minutes,seconds);
|
||||
}
|
||||
|
||||
public boolean isDaysEnabled(){
|
||||
return spDays.isVisible();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue