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

Search for JPanel in optionPane that contains the buttons #220

Merged
merged 2 commits into from
Sep 21, 2023

Conversation

daniel-theia
Copy link
Contributor

Related issue: #218

@daniel-theia
Copy link
Contributor Author

@andrasfuchs Can I trouble you for a review of this please? It affects command line usage in Ubuntu (maybe others) in v1.8.0: #218

It appears at some point Java changed the layout of the option pane dialogue. Rather than assume we know where the buttons are, this performs a quick search for them. This approach should also be backwards compatible encase somebody uses outdated libraries.

Not sure how much you want to engineer safety into this, we could:

  • recursively search the dialogue for buttons
  • check the strings of the buttons to ensure they are not flipped
  • have a default behaviour encase the buttons are not found

Regarding the exception handling message, it would be great if it also gave a file name and line number for where the exception was triggered.

@andrasfuchs
Copy link
Collaborator

Hey @daniel-theia, thank you for the PR, it sounds great, and I appreciate your help!

I'm on holiday at the moment, and I need to focus on other things too as soon as I'm back, but I plan to block a day or two for freerouting in the near future. When this happens your PR will be one of the first things to check.

Thanks again, I'll keep you updated here.

@daniel-theia daniel-theia mentioned this pull request Aug 30, 2023
10 tasks
@maksz42
Copy link
Contributor

maksz42 commented Sep 10, 2023

@daniel-theia Hi, I haven't come across the issue but looks like the commit e1fd77a in my PR #224 might have fixed the problem. Instead of searching for the button I supplied the dialog with my own. Can you check if that works?

@daniel-theia
Copy link
Contributor Author

@daniel-theia Hi, I haven't come across the issue but looks like the commit e1fd77a in my PR #224 might have fixed the problem. Instead of searching for the button I supplied the dialog with my own. Can you check if that works?

@maksz42 Haven't currently got time to check, but looking through the code it does appear to address the casting issue from the wrong index.

@andrasfuchs
Copy link
Collaborator

@daniel-theia I didn't find the part where you check if the buttons are flipped. Their text might mislead that check because freerouting applies the local language by default. I also added a check for the case where we don't find an optionPanel to prevent an exception.

Otherwise it looks good, thank you, I'll merge it now.

@andrasfuchs andrasfuchs merged commit ea5cc72 into freerouting:master Sep 21, 2023
3 checks passed
@daniel-theia
Copy link
Contributor Author

@andrasfuchs : I didn't find the part where you check if the buttons are flipped. Their text might mislead that check because freerouting applies the local language by default.

We find the buttons: https://github.com/daniel-theia/freerouting/blob/748b390772e197534f94d453233d2cc077b779f3/src/main/java/app/freerouting/gui/MainApplication.java#L371

And then we set the text to the locale, meaning we control their text meaning. As long as the locales are all stored together (which they should be), there is no possibility for them being flipped.

Let me check this merge, I see a difference between the start and cancel button setup and want to make sure that was pushed correctly.

Copy link
Contributor Author

@daniel-theia daniel-theia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully some useful comments on the changes.

Comment on lines +410 to +411
JButton cancelButton;
if ((optionPanel != null) && (cancelButtonIndex >= 0)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancelButton is declared in name only outside of the if-statement, whereas startButton is fully declared. I know that startButton is not used in a timer, but for readability it makes sense to have both of these buttons similar so that in the future they are coded in the same way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good insight!

Comment on lines 374 to 377
if(c instanceof JPanel && ((JPanel)c).getComponents()[0] instanceof JButton){
if(c instanceof JPanel && ((JPanel)c).getComponents()[0] instanceof JButton && ((JPanel)c).getComponents()[1] instanceof JButton){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should make sure that there is more than one component packed into the JPanel first, something like:

if(
  c instanceof JPanel &&
  ((JPanel)c).getComponents().length >= 2 && // Ensure that there is at least two components
  ((JPanel)c).getComponents()[0] instanceof JButton &&
  ((JPanel)c).getComponents()[1] instanceof JButton
){

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree 👍

@andrasfuchs
Copy link
Collaborator

I've made these modifications.

Thank you!

@daniel-theia
Copy link
Contributor Author

@andrasfuchs No problem, thank you.

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

Successfully merging this pull request may close these issues.

None yet

3 participants