Java源码示例:org.jdesktop.swingx.JXDatePicker
示例1
public static DatePickerEditCommiter setupDatePicker(final JXDatePicker picker, final Date initialDate, final DateValidator dv, final ValueValidator<Date> parseValidator, final ActionListener listener) {
if (dv == null) {
picker.addActionListener(listener);
} else {
picker.addActionListener(e -> {
Date date = ((JXDatePicker) e.getSource()).getDate();
if (date != null) {
Pair<Boolean, String> validation = dv.apply(date);
if (!validation.first()) {
throw new ValidationException(validation.second());
}
}
});
}
final JFormattedTextField editor = picker.getEditor();
UIUtil.attachValidator(editor, parseValidator, null);
if (initialDate != null) {
picker.setDate(initialDate);
}
return new DatePickerEditCommiter(picker, editor, dv, parseValidator);
}
示例2
private void validateDateChooser(JXDatePicker button) {
Date startDate = startDateButton.getDate();
Date endDate = stopDateButton.getDate();
if (startDate == null || endDate == null) {
return;
}
if (startDate.after(endDate)) {
if (button.equals(startDateButton)) {
startDateButton.setDate(endDate);
LOG.info("Start date after end date: Set start date to end date.");
} else if (button.equals(stopDateButton)) {
stopDateButton.setDate(startDate);
LOG.info("Start date after end date: Set end date to start date.");
}
}
}
示例3
private JPanel createLinkPanel() {
linkPanel = new JPanel();
linkPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
todayLink = new JLabel();
todayLink.setForeground(new Color(16, 66, 104));
todayLink.setCursor(new Cursor(Cursor.HAND_CURSOR));
linkPanel.add(todayLink);
todayLink.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
Action delegate = getActionMap().get(e.getClickCount() != 2 ? JXDatePicker.HOME_NAVIGATE_KEY : JXDatePicker.HOME_COMMIT_KEY);
if (delegate != null && delegate.isEnabled())
delegate.actionPerformed(null);
}
}
});
return linkPanel;
}
示例4
private Date getPickDateDlg() {
JPanel panel = new JPanel();
JXDatePicker picker = new JXDatePicker();
picker.setDate(Calendar.getInstance().getTime());
picker.setFormats(new SimpleDateFormat("dd.MM.yyyy")); //$NON-NLS-1$
panel.add(picker);
int result = JOptionPane.showConfirmDialog(frame, panel, Messages.getString("ExportActionListener.1"), //$NON-NLS-1$
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
return picker.getDate();
} else {
return null;
}
}
示例5
@Override
protected boolean isFocused( Component c ) {
if( c instanceof JXDatePicker )
return FlatUIUtils.isPermanentFocusOwner( ((JXDatePicker)c).getEditor() );
return super.isFocused( c );
}
示例6
/**
* 使用JXDatePicker创建日期选择器
* @param date
* @return
*/
public JXDatePicker getJXDatePicker (Date date){
final JXDatePicker datepick = new JXDatePicker();
// 设置 date日期
datepick.setDate(date);
//设置日期格式
String DefaultFormat = "yyyy-MM-dd";
datepick.setFormats(new SimpleDateFormat(DefaultFormat));
//设置字体
Font font = new Font("Times New Roman", Font.BOLD, 14);
datepick.setFont(font);
//用setBounds()直接设置大小与位置
datepick.setBounds(this.x, this.y, this.width, this.height);
return datepick;
}
示例7
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
ActionMap pickerMap = datePicker.getActionMap();
pickerMap.remove(JXDatePicker.CANCEL_KEY);
InputMap pickerInputMap = datePicker.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
pickerInputMap.remove(KeyStroke.getKeyStroke("ESCAPE"));
}
示例8
public static void setupDatePicker(
final JXDatePicker picker, final Date initialDate, final DateValidator dv, final ActionListener listener) {
Supplier<List<DateFormat>> formatSupplier = new Supplier<List<DateFormat>>() {
@Override
public List<DateFormat> get() {
return ImmutableList.<DateFormat>of(
GanttLanguage.getInstance().getLongDateFormat(),
GanttLanguage.getInstance().getShortDateFormat());
}
};
ValueValidator<Date> parseValidator = createStringDateValidator(dv, formatSupplier);
DatePickerEditCommiter commiter = setupDatePicker(picker, initialDate, dv, parseValidator, listener);
commiter.attachOnFocusLost(listener);
}
示例9
private DatePickerEditCommiter(JXDatePicker datePicker, JFormattedTextField textEditor,
DateValidator dateValidator, ValueValidator<Date> parseValidator) {
myTextEditor = Preconditions.checkNotNull(textEditor);
myDatePicker = Preconditions.checkNotNull(datePicker);
myInitialDate = myDatePicker.getDate();
myDateValidator = dateValidator;
myParseValidator = parseValidator;
}
示例10
private static Calendar getDate(final JXDatePicker dateField) {
final Date date = dateField.getDate();
if (date == null)
return null;
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar;
}
示例11
private JXDatePicker createDateComboBox() {
TimeZone utcZone = TimeZone.getTimeZone("UTC");
Calendar utc = Calendar.getInstance(utcZone);
Date date = utc.getTime();
JXDatePicker datePicker = new JXDatePicker(date);
datePicker.setTimeZone(utcZone);
datePicker.setFormats(dateFormat);
return datePicker;
}
示例12
public static void changeLocale(Locale locale) {
resBundle = PropertyResourceBundle.getBundle("i18n/next-ui", locale);
Locale.setDefault(locale);
// any third-party components with internationalization must change
// locale
JXDatePicker.setDefaultLocale(locale);
}
示例13
public JXDatePicker getJXDatePicker(){
return getJXDatePicker(new Date());
}
示例14
public JXDatePicker getDatePicker() {
return datePicker;
}
示例15
public void initGUI() {
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{126, 0, 0};
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0};
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
setLayout(gridBagLayout);
txtDescription = new JTextField(10);
add(txtDescription, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 0));
add(new JLabel("Description :"), UITools.createGridBagConstraints(GridBagConstraints.WEST, null, 0, 0));
add(new JLabel("Edition :"), UITools.createGridBagConstraints(GridBagConstraints.WEST, null, 0, 1));
add(new JLabel("Transaction : "), UITools.createGridBagConstraints(GridBagConstraints.WEST, null, 0, 2));
add(new JLabel("Item Type :"), UITools.createGridBagConstraints(GridBagConstraints.WEST, null, 0, 3));
add(new JLabel("Price : "), UITools.createGridBagConstraints(GridBagConstraints.WEST, null, 0, 4));
add(new JLabel("Source :"), UITools.createGridBagConstraints(GridBagConstraints.WEST, null, 0, 5));
add(new JLabel("ID Transaction :"), UITools.createGridBagConstraints(GridBagConstraints.WEST, null, 0, 6));
add(new JLabel("Date :"), UITools.createGridBagConstraints(GridBagConstraints.WEST, null, 0, 7));
cboEditions = UITools.createComboboxEditions();
add(cboEditions, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 1));
cboTransactionType = UITools.createCombobox(OrderEntry.TYPE_TRANSACTION.values());
add(cboTransactionType, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 2));
cboTypeItem = UITools.createCombobox(OrderEntry.TYPE_ITEM.values());
add(cboTypeItem, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 3));
JPanel panelPrice = new JPanel();
((FlowLayout)panelPrice.getLayout()).setAlignment(FlowLayout.LEFT);
txtPrice = new JTextField(5);
txtShipPrice = new JTextField(5);
cboCurrency = UITools.createCombobox(new ArrayList<>(Currency.getAvailableCurrencies()));
panelPrice.add(cboCurrency);
panelPrice.add(txtPrice);
panelPrice.add(new JLabel("Shippement :"));
panelPrice.add(txtShipPrice);
add(panelPrice, UITools.createGridBagConstraints(GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL, 1, 4));
txtSource = new JTextField(10);
add(txtSource, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 5));
txtidTransaction = new JTextField(10);
add(txtidTransaction, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 6));
txtDateTransaction = new JXDatePicker(MTGControler.getInstance().getLocale());
add(txtDateTransaction, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 7));
}
示例16
public static JXDatePicker createDatePicker(DateFormat... dateFormats) {
final JXDatePicker result = new JXDatePicker();
result.setLocale(GanttLanguage.getInstance().getDateFormatLocale());
result.setFormats(dateFormats);
return result;
}
示例17
private void setSelectedTaskProperties() {
myUnpluggedClone = selectedTasks[0].unpluggedClone();
nameField1.setText(originalName);
setName(selectedTasks[0].toString());
percentCompleteSlider.setValue(new Integer(originalCompletionPercentage));
priorityComboBox.setSelectedIndex(originalPriority.ordinal());
myTaskScheduleDates.setUnpluggedClone(myUnpluggedClone);
DateValidator validator = UIUtil.DateValidator.Default.aroundProjectStart(myProject.getTaskManager().getProjectStart());
ActionListener listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setThird(CalendarFactory.createGanttCalendar(((JXDatePicker) e.getSource()).getDate()));
}
};
UIUtil.setupDatePicker(myEarliestBeginDatePicker, originalEarliestBeginDate == null ? null : originalEarliestBeginDate.getTime(), validator, listener);
myThird = originalEarliestBeginDate;
myEarliestBeginEnabled.setSelected(originalEarliestBeginEnabled == 1);
myOnEarliestBeginToggle.actionPerformed(null);
if (mileStoneCheckBox1 != null) {
mileStoneCheckBox1.setSelected(originalIsMilestone);
} else if (projectTaskCheckBox1 != null) {
projectTaskCheckBox1.setSelected(originalIsProjectTask);
}
myTaskScheduleDates.setupFields(isMilestone(), isSupertask());
tfWebLink.setText(originalWebLink);
if (selectedTasks[0].shapeDefined()) {
for (int j = 0; j < ShapeConstants.PATTERN_LIST.length; j++) {
if (originalShape.equals(ShapeConstants.PATTERN_LIST[j])) {
shapeComboBox.setSelectedIndex(j);
break;
}
}
}
noteAreaNotes.setText(originalNotes);
myTaskColorOption.setValue(selectedTasks[0].getColor());
myShowInTimeline.setSelected(myUIfacade.getCurrentTaskView().getTimelineTasks().contains(selectedTasks[0]));
}
示例18
public TimeRangeFilter(final JCheckBox filterCheckBox) {
this.filterCheckBox = filterCheckBox;
final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
Date date = utc.getTime();
startDateButton = new JXDatePicker(date);
startDateButton.setFormats(dateFormat);
stopDateButton = new JXDatePicker(date);
stopDateButton.setFormats(dateFormat);
final int width = 150;
final Dimension ps = startDateButton.getPreferredSize();
final Dimension comboBoxDimension = new Dimension(width, ps.height);
setJComponentSize(comboBoxDimension, startDateButton);
setJComponentSize(comboBoxDimension, stopDateButton);
datePatternComboBox = new JComboBox<>();
setJComponentSize(comboBoxDimension, datePatternComboBox);
datePatternComboBox.setEditable(true);
fileNamePatternComboBox = new JComboBox<>();
setJComponentSize(comboBoxDimension, fileNamePatternComboBox);
fileNamePatternComboBox.setEditable(true);
initPatterns();
final UIUpdater uiUpdater = new UIUpdater();
filterCheckBox.addActionListener(e -> {
updateUIState();
if (timeStampExtractor != null) {
fireFilterChangedEvent();
}
});
startDateButton.addPropertyChangeListener(DateTimePicker.COMMIT_KEY, evt -> updateUIState());
startDateButton.addPropertyChangeListener(DateTimePicker.COMMIT_KEY, evt -> validateDateChooser(startDateButton));
stopDateButton.addPropertyChangeListener(DateTimePicker.COMMIT_KEY, evt -> updateUIState());
stopDateButton.addPropertyChangeListener(DateTimePicker.COMMIT_KEY, evt -> validateDateChooser(stopDateButton));
datePatternComboBox.addActionListener(uiUpdater);
fileNamePatternComboBox.addActionListener(uiUpdater);
listeners = new ArrayList<>();
labels = new ArrayList<>();
applyButton = new JButton("Apply");
applyButton.addActionListener(e -> {
if (StringUtils.isNotNullAndNotEmpty(datePatternComboBox.getEditor().getItem().toString())
&& StringUtils.isNotNullAndNotEmpty(fileNamePatternComboBox.getEditor().getItem().toString())) {
timeStampExtractor = new TimeStampExtractor(datePatternComboBox.getSelectedItem().toString(),
fileNamePatternComboBox.getSelectedItem().toString());
} else {
timeStampExtractor = null;
}
startDate = startDateButton.getDate();
endDate = stopDateButton.getDate();
updateUIState();
applyButton.setEnabled(false);
fireFilterChangedEvent();
});
}
示例19
public Object getParameterValue(QueryParameter qp) throws RuntimeParameterException {
String paramName = qp.getName();
String runtimeParamName = qp.getRuntimeName();
if ((runtimeParamName == null) || runtimeParamName.trim().equals("")) {
runtimeParamName = paramName;
}
JComponent component = getComponent(qp);
String type = qp.getValueClassName();
Object value = null;
if (!qp.isIgnore()) {
if (component instanceof JTextField) {
value = ((JTextField) component).getText();
if (value.equals("")) {
if (qp.isMandatory()) {
throw new RuntimeParameterException(I18NSupport.getString("runtime.parameters.notentered", runtimeParamName));
} else {
value = null;
}
}
} else if (component instanceof JComboBox) {
JComboBox combo = (JComboBox) component;
if (combo.getSelectedIndex() == 0) {
if (qp.isMandatory()) {
throw new RuntimeParameterException(I18NSupport.getString("runtime.parameters.notselected", runtimeParamName));
} else {
value = null;
}
} else {
value = combo.getSelectedItem();
}
} else if (component instanceof ListSelectionPanel) {
value = ((ListSelectionPanel) component).getDestinationElements().toArray();
if (((Object[]) value).length == 0) {
if (qp.isMandatory()) {
throw new RuntimeParameterException(I18NSupport.getString("runtime.parameters.notselected", runtimeParamName));
} else {
value = new Object[]{ParameterUtil.NULL};
}
}
} else if (component instanceof ListAddPanel) {
value = ((ListAddPanel) component).getElements().toArray();
if (((Object[]) value).length == 0) {
if (qp.isMandatory()) {
throw new RuntimeParameterException(I18NSupport.getString("runtime.parameters.notselected", runtimeParamName));
} else {
value = new Object[]{ParameterUtil.NULL};
}
}
} else if (component instanceof JDateTimePicker) {
value = ((JDateTimePicker) component).getDate();
if (value == null) {
if (qp.isMandatory()) {
throw new RuntimeParameterException(I18NSupport.getString("runtime.parameters.notentered", runtimeParamName));
}
}
} else if (component instanceof JXDatePicker) {
value = ((JXDatePicker) component).getDate();
if (value == null) {
if (qp.isMandatory()) {
throw new RuntimeParameterException(I18NSupport.getString("runtime.parameters.notentered", runtimeParamName));
}
}
} else if (component instanceof JCheckBox) {
value = ((JCheckBox) component).isSelected();
}
if (value != null) {
if (value.getClass().getName().equals("java.lang.String")) {
try {
value = ParameterUtil.getParameterValueFromString(qp.getValueClassName(),(String)value );
} catch (Exception e) {
LOG.error(e.getMessage(), e);
// the exception is thrown outside the for statement so that
// all parameter values are saved
throw new RuntimeParameterException("Invalid parameter value " + value +
" for parameter " + runtimeParamName + " of type " + type + " .");
}
}
}
}
return value;
}
示例20
public JXDatePicker getDatePicker() {
return datePicker;
}
示例21
/**
* @return a {@link JXDatePicker} component with the default locale, images
* and date formats.
*/
public static JXDatePicker createDatePicker() {
return createDatePicker(GanttLanguage.getInstance().getLongDateFormat(), GanttLanguage.getInstance().getShortDateFormat());
}