Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CalendarGridPanel, mouse tracking #6

Open
tdbear opened this issue Mar 18, 2014 · 1 comment
Open

CalendarGridPanel, mouse tracking #6

tdbear opened this issue Mar 18, 2014 · 1 comment

Comments

@tdbear
Copy link
Owner

tdbear commented Mar 18, 2014

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();
}
}
}
@tdbear
Copy link
Owner Author

tdbear commented Mar 18, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant