java-org.hwo.ui/src/org/hwo/ui/JCalendar.java

94 lines
2.1 KiB
Java

package org.hwo.ui;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.awt.Dimension;
public class JCalendar extends JPanel {
private JTextField tfDate;
private Date date;
private JButton btnLookup;
private boolean nullable;
public JCalendar() {
setMaximumSize(new Dimension(32767, 30));
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{100, 134, 0};
gridBagLayout.rowHeights = new int[]{29, 0};
gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
setLayout(gridBagLayout);
tfDate = new JTextField();
GridBagConstraints gbc_tfDate = new GridBagConstraints();
gbc_tfDate.fill = GridBagConstraints.BOTH;
gbc_tfDate.insets = new Insets(0, 0, 0, 5);
gbc_tfDate.gridx = 0;
gbc_tfDate.gridy = 0;
add(tfDate, gbc_tfDate);
tfDate.setColumns(10);
btnLookup = new JButton("X");
btnLookup.setMaximumSize(new Dimension(25, 29));
btnLookup.setPreferredSize(new Dimension(25, 29));
btnLookup.setMinimumSize(new Dimension(25, 29));
GridBagConstraints gbc_btnLookup = new GridBagConstraints();
gbc_btnLookup.fill = GridBagConstraints.BOTH;
gbc_btnLookup.gridx = 1;
gbc_btnLookup.gridy = 0;
add(btnLookup, gbc_btnLookup);
}
private void updateView()
{
tfDate.setEnabled(false);
if (date != null)
{
btnLookup.setEnabled(false);
tfDate.setText( SimpleDateFormat.getInstance().format(date));
} else
{
btnLookup.setEnabled(false);
tfDate.setText("");
}
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
updateView();
}
public void setValue(Object value)
{
setDate((Date)value);
}
public Object getValue()
{
return this.getDate();
}
public boolean isNullable() {
return nullable;
}
public void setNullable(boolean nullable) {
this.nullable = nullable;
}
}