Browse Source

REPORT-14835 日期控件自定义

bugfix/10.0
XiaXiang 6 years ago
parent
commit
e83ea53ce1
  1. 4
      designer-base/src/main/java/com/fr/design/gui/date/SingleObjectComboBoxModel.java
  2. 16
      designer-base/src/main/java/com/fr/design/gui/date/UIDatePicker.java
  3. 79
      designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/ActionLabel.java

4
designer-base/src/main/java/com/fr/design/gui/date/SingleObjectComboBoxModel.java

@ -1,6 +1,7 @@
package com.fr.design.gui.date;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
@ -9,7 +10,7 @@ import java.util.Date;
public class SingleObjectComboBoxModel extends AbstractListModel implements ComboBoxModel {
private SimpleDateFormat dateFormat;
private String selectedDate = "";
private String selectedDate = StringUtils.EMPTY;
public SingleObjectComboBoxModel() {
}
@ -28,6 +29,7 @@ public class SingleObjectComboBoxModel extends AbstractListModel implements Comb
public void setSelectedItem(Object anItem) {
if (anItem == null) {
selectedDate = StringUtils.EMPTY;
return;
}
if (anItem instanceof Date) {

16
designer-base/src/main/java/com/fr/design/gui/date/UIDatePicker.java

@ -6,6 +6,7 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
@ -156,8 +157,12 @@ public class UIDatePicker extends UIComboBox implements Serializable {
/**
* 设置当前选择的日期
*/
public void setSelectedDate(Date date) throws ParseException {
this.setSelectedItem(dateFormat.format(date));
public void setSelectedDate(Date date) {
if (date == null) {
this.setSelectedItem(null);
} else {
this.setSelectedItem(dateFormat.format(date));
}
}
public void setSelectedItem(Object anObject) {
@ -215,8 +220,11 @@ public class UIDatePicker extends UIComboBox implements Serializable {
try {
String strDate = comboBox.getSelectedItem().toString();
synchronized (this) {
Date selectionDate = dateFormat.parse(strDate);
calendarPanel.setSelectedDate(selectionDate);
Date selectionDate = new Date();
if (StringUtils.isNotBlank(strDate)) {
selectionDate = dateFormat.parse(strDate);
}
calendarPanel.setSelectedDate(selectionDate);
calendarPanel.updateHMS();
}
} catch (Exception e) {

79
designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/ActionLabel.java

@ -0,0 +1,79 @@
package com.fr.design.mainframe.vcs.ui;
import com.fr.design.gui.ilable.UILabel;
import javax.swing.event.MouseInputAdapter;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
/**
* Action label
*/
public class ActionLabel extends UILabel {
private ActionListener actionListener;
private Color color;
private MouseInputAdapter mouseInputAdapter = new MouseInputAdapter() {
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent evt) {
Object source = evt.getSource();
if (source instanceof UILabel) {
//Action.
if (actionListener != null) {
ActionEvent actionEvent = new ActionEvent(source, 99, "");
actionListener.actionPerformed(actionEvent);
}
}
}
public void mouseEntered(MouseEvent evt) {
Object source = evt.getSource();
if (source instanceof UILabel) {
((UILabel) source).setCursor(new Cursor(Cursor.HAND_CURSOR));
}
}
public void mouseExited(MouseEvent evt) {
Object source = evt.getSource();
if (source instanceof UILabel) {
((UILabel) source).setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent evt) {
Object source = evt.getSource();
if (source instanceof UILabel) {
((UILabel) source).setCursor(new Cursor(Cursor.HAND_CURSOR));
}
}
};
public ActionLabel(String text, Color color) {
super(text);
this.color = color;
this.setForeground(color);
this.addMouseListener(mouseInputAdapter);
this.addMouseMotionListener(mouseInputAdapter);
}
public void addActionListener(ActionListener actionListener) {
this.actionListener = actionListener;
}
}
Loading…
Cancel
Save