-
Notifications
You must be signed in to change notification settings - Fork 236
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
Cloning issues arise with subclasses #252
Comments
Before the changes done in #253, a developer could subclass either of the four areas ( Currently, the base is Although we could provide 2 classes for each area (one as the base that extends So, the names of the four areas should remain the same, but they will act as a base-class: their model will need to be specified each time they are used. |
For those developers who still want to use just one of the four regular areas without any subclassing, |
Another question I've run into: should each text area have its own subclass of For example, without following this "each area class has its own model class" approach, the code would be: public class SubClassModel extends StyledTextAreaModel<
Collection<String>, Collection<String>
> {
// constructor
// other code for stuff
}
public class SubClassArea extends StyleClassedTextArea<SubClassModel>
> {
// constructor
// other code for stuff
} If this approach was followed, then RichTextFX would also include public class StyleClassedTextAreaModel extends StyledTextAreaModel<
Collection<String>, Collection<String>
> {
// Constructor
} and the above code is reduced to: public class SubClassModel extends StyleClassedTextAreaModel {
// constructor
// other methods
}
public class SubClassArea extends StyleClassedTextArea<SubClassModel> {
// constructor
// other methods that relate to SubClassModel
} I'm going to say yes, they should. |
After implementing the above code in #263, I've learned that this is the right approach to use. Since the Area classes are now base classes to be extended, there are some pieces of code in the Area classes that must now be in the Model class. By following this approach, I can insure that these pieces of code don't get lost both in subclasses of the model and when using |
|
Now that |
I'm assuming we'll follow the first approach. In other words,
For example.... public class SomeArea extends InlineCssTextArea {
/*
If StyledTextAreaModel is public but EditableStyledDocument
is not public, then this constructor could work
to clone a subclass.
*/
public SomeArea(SomeArea areaToClone) {
super(areaToClone.getModel().getContent());
}
/*
However, if EditableStyledDocument is not public, then
subclasses of SomeArea cannot clone themselves
because EditableStyledDocument cannot be used as a parameter
in a constructor
*/
public SomeArea(EditableStyledDocument<String, String> doc) {
super(doc);
}
public static class AnotherArea extends SomeArea {
// Will only work if EditableStyledDocument is public
public AnotherArea(EditableStyledDocument<String, String> doc) {
super(doc);
}
}
} |
I would make the |
Ok, that will work if we add the necessary API to expose a getter for public class StyledTextArea<PS, S> ... {
public EditableStyledDocument<PS, S> getContent() {
return model.getContent();
}
} |
👍 |
I am also quite skeptical about the usefulness of "cloning", especially if the user can pass an |
I think the only one that I can think of is when a user wants a second or third view. In such a case, one wouldn't immediately create that second or third view when the first is created. |
In such a case, I'm still wondering whether it is simpler to use the cloning methods or just get the |
Right, but that option to use different |
I'm fine with having some convenience methods provided if it is a common enough use case. But it's hopeless to try to cover all the use cases and users should not fear construct their |
When I first started using your library, I didn't think about using StyledTextArea because it wasn't demonstrated in your |
Good point. Or maybe after, since the flavors are still easier to start with, especially for people who are not too used to a lot of type parameters and lambdas. |
Good point. Perhaps a small note that |
This was fixed in #277 |
I've run into another issue revolving around cloning.
Currently, each
StyledTextArea
(the View) creates its ownStyledTextAreaModel
(the Model). I'm guessing that the model itself is not passed to the View in order to prevent multiple views sharing the same model. (Each model is tasked with storing the data for where the caret position and selection values should be. If two views share the same model, it defeats the whole point).However, this also creates another issue:
StyledTextAreaModel
cannot be subclassed. The following problems arise:StyledTextAreaModel
's constructor takes anEditableStyledDocument
as an argument, which is currently package-private, not public, subclasses can't have constructors that are used to clone those subclassed models since they can't fulfillsuper
's constructor requirement.StyledTextArea
constructs its ownStyledTextAreaModel
, even if one subclassedStyledTextAreaModel
, they would not be able to create aStyledTextArea
(a view) that uses such a model.So, it seems like
EditableStyledDocument
should be made public, and a StyledTextArea would be updated to below:With a subclass of
StyledTextAreaModel
like the following:...and a subclass of
StyledTextArea
like the following:To create an area, one would use the following code:
or use the following code:
I think this was the conclusion I reached when I was working on #243.
The text was updated successfully, but these errors were encountered: