Skip to main content

2 calendar component problems, please help!

4 replies [Last post]
lwuitnewb
Offline
Joined: 2010-05-10

Hi Everyone. I've got a dialog with 2 buttons (accept and cancel) and a calendar object on it. I've got 2 issues

Problem 1) It's very unresponsive. I've looked through the calendar code and found that it's calling if (!getComponentForm().isSingleFocusMode()) every time you click on a date. And since every time you click the form kills the underlying vector it has to remake the vector which contains all the components on the form every single time. This is very time consuming since the calendar has over 30 buttons it. I handled this by overriding clearFocusVectors() in my dialog to not null out those vectors. This defiantly speeds things up. Probably not the best way of doing things so if you have advice on that I'd love to hear it.

Problem 2) It won't always draw the border around the selected date. Sometimes it'll get into something weird where it draws the previously selected date. So for example if I click on the 5th. Then click on the 6th. The 5th will get a border after I click on the 6th. then I click 7th.. now 6th is highlighted. The vast majority of the time the current date (which highlights by default on start up) just stops being highlighted and no date is highlighted again.

Has anyone seen either of these issues? I'm running an android emulator not that I think that's has anything to do with it.

Thanks in advance for your replies.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lwuitnewb
Offline
Joined: 2010-05-10

fireActionEvent();
if (!getComponentForm().isSingleFocusMode()) {
setHandlesInput(false);
}
return;
}
}
}

The problem is that last if statement. isSingleFocusMode() basically tells the form to go through and reform those vectors. So every click kills the vector and then rebuilds it. Now since the calendar is comprised of like 60-70 components this makes the click functionality very slow right on that call every time. To deal with this I I override clearFocusVectors() to do nothing so those vectors don't get nulled out which means isSingleFocusMode() doesn't have to rebuild them. This speeds it up significantly although it may have unforeseen consequences. As such I was wondering if anyone had a better solutions. So that was problem 1.

Problem 2 is that when you click on a day of the week it doesn't change focus. So there should be a little square around the current date. When I click the calendar should remove the square from the current date and put it around the one I clicked on. What happens is completely different and somewhat random. The current day will be deselected (desired) but the clicked date won't be selected. Then if I click again. The previously clicked day will be selected and the newly clicked day won't be. I click again. same thing.. the last day is highlighted not the currently clicked day. Then it'll stop working all together. It doesn't even always follow that pattern. Sometimes it deselects the initial day and just does nothing. I was hoping someone had seen this behavior before and come up with a solutions.
Thanks again.

lwuitnewb
Offline
Joined: 2010-05-10

So has anybody else ever seen these problems?

Chen Fishbein

Hi,
The issue is not clear to me, please send a short sample code and/or a
screenshot.

Regards,
Chen

On 6/22/2010 10:01 PM, lwuit-users@mobileandembedded.org wrote:
> Hi Everyone. I've got a dialog with 2 buttons (accept and cancel) and a calendar object on it. I've got 2 issues
>
> Problem 1) It's very unresponsive. I've looked through the calendar code and found that it's calling if (!getComponentForm().isSingleFocusMode()) every time you click on a date. And since every time you click the form kills the underlying vector it has to remake the vector which contains all the components on the form every single time. This is very time consuming since the calendar has over 30 buttons it. I handled this by overriding clearFocusVectors() in my dialog to not null out those vectors. This defiantly speeds things up. Probably not the best way of doing things so if you have advice on that I'd love to hear it.
>
> Problem 2) It won't always draw the border around the selected date. Sometimes it'll get into something weird where it draws the previously selected date. So for example if I click on the 5th. Then click on the 6th. The 5th will get a border after I click on the 6th. then I click 7th.. now 6th is highlighted. The vast majority of the time the current date (which highlights by default on start up) just stops being highlighted and no date is highlighted again.
>
> Has anyone seen either of these issues? I'm running an android emulator not that I think that's has anything to do with it.
>
> Thanks in advance for your replies.
> [Message sent by forum member 'lwuitnewb']
>
> http://forums.java.net/jive/thread.jspa?messageID=475397
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

lwuitnewb
Offline
Joined: 2010-05-10

BoxLayout mainLayout = new BoxLayout(BoxLayout.Y_AXIS);

Style style = getDialogStyle();
style.setBorder(Border.createEtchedLowered());
style.setMargin(0,0);
style.setPadding(0, 0, 0, 0);

this.setLayout(mainLayout);
returnDate = new Date(date);

/*8888 BUTTON SETUP 8888888*/
acceptButton = new Button("Accept");
cancelButton = new Button("Cancel");
acceptButton.addActionListener(this);
cancelButton.addActionListener(this);
acceptButton.setAlignment(Label.CENTER);
cancelButton.setAlignment(Label.CENTER);

Container horizontalButtonHolder = new Container();

Layout la = new GridLayout(1, 2);
horizontalButtonHolder.setLayout(la);
horizontalButtonHolder.addComponent(acceptButton);
horizontalButtonHolder.addComponent(cancelButton);

if (date == Long.MIN_VALUE){
date = System.currentTimeMillis();
calendarComponent = new Calendar(date);
this.addComponent(calendarComponent);
}

this.addComponent(horizontalButtonHolder);

So this is how I create the dialog. Nothing really fancy. I don't know if a screen shot will help you at all since it won't show what the problem is. I'll try to explain better.
Problem 1) Whenever you click on the calendar it calls this in the form
void clearFocusVectors() {
focusDownSequence = null;
focusRightSequence = null;
}

these are vectors of components. It then proceeds to call actionPerformed in calendar (Below)

public void actionPerformed(ActionEvent evt) {
Object src = evt.getSource();
if(src instanceof ComboBox){
setMonth(Integer.parseInt((String)year.getSelectedItem()),
month.getSelectedIndex());
componentChanged();
return;
}
for (int iter = 0; iter < buttons.length; iter++) {
if (src == buttons[iter]) {

selected.setUnselectedStyle(new Style(buttons[iter].getUnselectedStyle()));
buttons[iter].setUnselectedStyle(new Style(selectedStyle));

selectedDay = dates[iter];
selected = buttons[iter];
fireActionEvent();
if (!getComponentForm().isSingleFocusMode()) {
setHandlesInput(false);
}
return;
}
}
}

The problem is that last if statement. isSingleFocusMode() basically tells the form to go through and reform those vectors. So every click kills the vector and then rebuilds it. Now since the calendar is comprised of like 60-70 components this makes the click functionality very slow right on that call every time. To deal with this I I override clearFocusVectors() to do nothing so those vectors don't get nulled out which means isSingleFocusMode() doesn't have to rebuild them. This speeds it up significantly although it may have unforeseen consequences. As such I was wondering if anyone had a better solutions. So that was problem 1.

Problem 2 is that when you click on a day of the week it doesn't change focus. So there should be a little square around the current date. When I click the calendar should remove the square from the current date and put it around the one I clicked on. What happens is completely different and somewhat random. The current day will be deselected (desired) but the clicked date won't be selected. Then if I click again. The previously clicked day will be selected and the newly clicked day won't be. I click again. same thing.. the last day is highlighted not the currently clicked day. Then it'll stop working all together. It doesn't even always follow that pattern. Sometimes it deselects the initial day and just does nothing. I was hoping someone had seen this behavior before and come up with a solutions.
Thanks again.