It seems to me the component looks nicer if it tracks the mouse movements and is easy to support.
CalendarGridPanel constructor:
- // addMouseListener(this);
+ addMouseListener(new MouseAdapter() {
+ public void mouseEntered(MouseEvent e) {
+ requestFocusInWindow();
+ }
+ });
public void mouseEntered(MouseEvent e) {
+ Component c = e.getComponent();
+ if (c instanceof DateLabel) {
+ try {
+ int day = Integer.parseInt(((DateLabel) c).getText());
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(focusDate);
+ cal.set(Calendar.DAY_OF_MONTH, day);
+ focusDate = cal.getTime();
+ reflectData();
+ } catch (NumberFormatException ex) {}
+ }
}
The mouseEntered above does the job, but probably there's a simpler version that reads the focusDate directly from DateLabel. Unfortunately, this didn't work for me and I ran out of time do to further exploration. The basic idea would be something like:
// !!!The following impl. does not work because DateLabel.getDate() always returns null !!!
public void mouseEntered(MouseEvent e) {
Component c = e.getComponent();
if (c instanceof DateLabel) {
requestFocusInWindow();
Date d = ((DateLabel) c).getDate();
if (d != null) {
focusDate = d;
reflectData();
}
}
}
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
expanding on the idea... one could add a flag (boolean) to DatePicker for enabling/disabling the mouse tracking feature, and it would propagate all the way to CalendarGridPanel (property change events, peer.get..., etc.)
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
one little fix to the working mouseEntered: it also needs a call to requestFocusInWindow(); right after "if (c instanceof DateLabel) {"
https://github.com/tdbear/microba/issues/6