Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Index is cut off when names are too long for PersonCard #323 #338

Merged
merged 1 commit into from
Mar 20, 2017

Conversation

MightyCupcakes
Copy link
Contributor

Resolves #323

Before:

image

After: (Index modified)

image

@mention-bot
Copy link

@MightyCupcakes, thanks for your PR! By analyzing the history of the files in this pull request, we identified @damithc, @pyokagan and @edmundmok to be potential reviewers.

@CanIHasReview-bot
Copy link

v1

@MightyCupcakes submitted v1 for review.

(📚 Archive)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/1/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

* Ensures that the index is shown on the UI regardless of the length of the {@code Person}
* name.
*/
private void setMinWidthForIdLabel() {
Copy link
Member

Choose a reason for hiding this comment

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

Feels like this method can be inlined? The name of the method and the header comment doesn't seem to match up anyway (the intent is not obvious in the name :P).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well there are several reasons this is a method. The original solution involves the calculation of the length of text in the ID label and adjusting accordingly. Then I found this elegant solution that does it in one line.

However, setting minimum width for the label is not that obvious. So the method name can be renamed to better fit the intentions if you want.

Copy link
Contributor

Choose a reason for hiding this comment

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

More importantly, I seem to recall the minWidth property can be set via the FXML file? We should try not to encode too much style-related information in the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

FXML file, or via the stylesheet.

@MightyCupcakes MightyCupcakes force-pushed the 323-persconcard-id-cut-off branch 4 times, most recently from 1a2814d to 7603875 Compare March 16, 2017 14:43
@CanIHasReview-bot
Copy link

v2

@MightyCupcakes submitted v2 for review.

(📚 Archive) (📈 Interdiff between v1 and v2)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/2/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@@ -30,7 +30,7 @@
<HBox spacing="5" alignment="CENTER_LEFT">
<children>
<HBox>
<Label fx:id="id" styleClass="cell_big_label"></Label>
<Label fx:id="id" styleClass="cell_big_label" minWidth="-Infinity"/>
Copy link
Member

Choose a reason for hiding this comment

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

Might want to put a comment in the .fxml file for CS2103 students, to explain to them the purpose of doing minWidth="-Infinity".

Copy link
Contributor Author

@MightyCupcakes MightyCupcakes Mar 17, 2017

Choose a reason for hiding this comment

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

No, I don't agree.

I don't think it is a good idea to have to comment on every attribute we add to fxml files.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the meaning of that attribute? 'Never truncate'? Is it a well documented JavaFx behavior students can find with a quick web search?

Copy link
Contributor Author

@MightyCupcakes MightyCupcakes Mar 17, 2017

Choose a reason for hiding this comment

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

The class Region defines a constant USE_PREF_WIDTH as Double.NEGATIVE_INFINITY

This is also one reason why I want to set this in the code instead in the FXML files because there are already meaningful constants names (along with javadocs!) already defined.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is a good idea to have to comment on every attribute we add to fxml files.

Agree. This case is a bit special though, because that attribute is not self explanatory nor common knowledge. Does this and this help to make the code more self-explanatory? i.e. somehow make the fxml code refer to the actual constant. Not sure if it is possible though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That might be the solution. Will explore this later.

Copy link
Contributor

@chao1995 chao1995 left a comment

Choose a reason for hiding this comment

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

No additional comment.

@MightyCupcakes MightyCupcakes force-pushed the 323-persconcard-id-cut-off branch 2 times, most recently from fd24267 to 913991d Compare March 17, 2017 06:54
@CanIHasReview-bot
Copy link

v3

@MightyCupcakes submitted v3 for review.

(📚 Archive) (📈 Interdiff between v2 and v3)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/3/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

<Label fx:id="id" styleClass="cell_big_label"></Label>
<Label fx:id="id" styleClass="cell_big_label">
<minWidth>
<Region fx:constant="USE_PREF_SIZE" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Kudos for figuring out the syntax for referring a constant from fxml. I guess we cannot say Region.USE_PREF_SIZE?
On a related note, I still feel this can benefit from an explanatory comment though. A reader, especially someone new to fxml, may not be able to understand what's going on here.
Also, any chance of adding a test case that fails if this attribute is removed? I guess we have to do that in PersonCard unit test which is WIP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A test case that fails?

I guess it will be possible if the tests can detect the presence of an ellipsis character shown on the screen? I am not sure if this is possible with FxRobot. Or maybe we can check the width allocated to the label on a card and make some educated guess about the value being truncated or not?

Copy link
Member

Choose a reason for hiding this comment

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

The JavaFx API's Label does not expose a public method to indicate that it has been truncated. Any checked to the actual displayed text requires the use of reflection because that is not accessible publicly (Source).

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. May be using label width as @MightyCupcakes has suggested?

Copy link
Member

@yamgent yamgent Mar 18, 2017

Choose a reason for hiding this comment

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

That can be explored. In fact, we might not need to guess the width if we create a separate label control, that automatically resizes, to determine the minimum required for a particular text.

@CanIHasReview-bot
Copy link

v4

@MightyCupcakes submitted v4 for review.

(📚 Archive) (📈 Interdiff between v3 and v4)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/4/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@MightyCupcakes
Copy link
Contributor Author

V4

Added comments. Although I am not so sure what is our stand on multi-line XML comments.

Copy link
Contributor

@damithc damithc left a comment

Choose a reason for hiding this comment

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

Just a minor suggestion.
We don't have a convention for multi-line comments on fxml yet. We should probably set indentation of markup files to 2 spaces instead, given their tendency for deep nesting, but that's not related to this PR.

<minWidth>
<!--
Ensures that the index is shown on the UI regardless of the length of the
Person's name
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensures the label text is never truncated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am looking into simplifying the FXML files.

The FXML files can be simplified and some parent elements are unneeded. Removing those will reduce the amount of nesting needed.

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

No other comments.

@CanIHasReview-bot
Copy link

v5

@MightyCupcakes submitted v5 for review.

(📚 Archive) (📈 Interdiff between v4 and v5)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/5/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

Copy link
Contributor

@damithc damithc left a comment

Choose a reason for hiding this comment

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

Commit message:

This is not desirable
as the PersonCard id is important for the user as they need it to use
and execute some commands (like the edit command)

Tried to shorten and to get rid of one of the two as in the sentence:

This is not desirable as users need to know the index of a person
to perform some commands (e.g. edit command)

Let's modify the id label's minimum width to use its preferred width.
This sets it so that it tracks its preferred width as its minimum width
and therefore it will always be wide enough to display the containing
PersonCard id.

It's not exactly correct to say 'modify the id label's minimum width', right?
Also, try to shorten the sentence (feels a bit verbose).

@yamgent
Copy link
Member

yamgent commented Mar 18, 2017

Minor nit: Also add a full stop to the second paragraph. :)

@CanIHasReview-bot
Copy link

v6

@MightyCupcakes submitted v6 for review.

(📚 Archive) (📈 Interdiff between v5 and v6)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/6/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

Copy link
Contributor

@chao1995 chao1995 left a comment

Choose a reason for hiding this comment

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

[v6 1/1]

As a consequence, a very long name would possibly cause the id label to
overflow, replacing the number with an ellipsis. This is not desirable as
users need to know the index of a person to perform some commands
(e.g. edit command).

As a consequence, a very long person name could cause the number in id
label to be replaced with an ellipsis. This is not desirable as users need to
know the id number of a person to use some commands. (e.g. edit).

Let's set the id label's minimum width to its preferred width.
This is so that the id label will always be wide enough to display the
containing PersonCard id.

Let's set the id label's minimum width to its preferred width so that the
id label will always be wide enough to display the id number, regardless
of the length of person names.

@yamgent
Copy link
Member

yamgent commented Mar 18, 2017

@chao1995:
label to be replaced with an ellipsis.

Or can say truncated.

@MightyCupcakes MightyCupcakes force-pushed the 323-persconcard-id-cut-off branch 2 times, most recently from 02c244c to defe7e8 Compare March 18, 2017 07:58
The id text label does not define its minimum width on the PersonCard
cell.

As a consequence, a very long person name could cause the number in the
label to be truncated. This is not desirable as users need to
know the id number of a person to use some commands (e.g. edit).

Let's set the id label's minimum width to its preferred width so that the
id label will always be wide enough to display the id number, regardless
of the length of the person's name.
@CanIHasReview-bot
Copy link

v7

@MightyCupcakes submitted v7 for review.

(📚 Archive) (📈 Interdiff between v6 and v7)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/7/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@damithc
Copy link
Contributor

damithc commented Mar 19, 2017

Going to merge soon.

@damithc damithc merged commit 4c4e1ed into se-edu:master Mar 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants