You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Superstring Media <su...@gmail.com> on 2010/09/28 10:04:00 UTC
Data, Components and Skins
The MVC pattern in Pivot is well implemented and it is getting me thinking about options for a musical score. My view of a score is that it is comprised of its data, a model object graph and a graphic representation of the data in the graph. There may be a way to align these aspects with the MVC pattern that Pivot uses?
Presently, the model object graph has just enough objects arranged in a tree to allow any type of score to be formed. The objects carry a lot of data that is put there by editing tools and musical analysers. Possibly the graph could be an extended Component? There are many ways to represent pure music data so having alternate skins (and styles) might be a way to do that as well?
I have resolved my requirements already but there may be a benefit to refactoring to the MVC pattern Pivot uses?
Thom
Re: Data, Components and Skins
Posted by Greg Brown <gk...@mac.com>.
> The data model for a score contains one or more StaffComponents which in turn each reference a StaffComponentModel object that wraps a [collection] which contains Chord objects which also have a [collection] which contains Note objects. Having the ability to declare the object graph for a whole score or just a staff in BXML is important and it also looks like what type of Pivot collection to use in place of the generic placeholder [collection] used by the StaffComponentModel and Chord objects is important for binding.
You'll most likely want to use a "read-only sequence". The WTKX Primer section of the tutorial talks about this - I'm currently in the process of updating it to cover BXML, but many of the concepts still apply in the earlier version.
> What I am thinking of is having a StaffComponent, StaffComponentModel (also known as a Part in music) and StaffComponentSkin. There is only one type of StaffComponent that is created for each score staff desired. A StaffComponent will then reference one of the StaffComponentModel instances that are stored in a separate map outside of the score. A StaffComponent will also have a StaffComponentSkin which will be able to layout and paint the music data in the StaffComponentModel referenced by a StaffComponent in any possible way.
Makes sense.
> The StaffComponentSkin should be able to dynamically load JSON resource files to provide user/style properties (to load into it dictionaries) which will be recipes for different notation types (there are many types of proposed notations besides the standard notation we all know). Is it possible to use the same resource file mechanism that localization does for this?
Yes, you could certainly do that. But it might be more consistent with Pivot design to define "styles" in your skin class that allow the caller to customize its appearance/behavior. Styles are simply bean properties defined by your skin class. They can be accessed by the Component's style dictionary and set either programmatically in code or declaratively in BXML (using either JSON or XML).
> is it possible to dynamically load/store notation resource files for a StaffComponentSkin so the LNF for a staff can be changed at any time and be completely pluggable (as in PLNF)?
Pivot doesn't support runtime replacement of the entire L&F like Swing does. However, you can dynamically change styles at runtime, which may be sufficient. If you find that providing multiple skins makes development easier, you could simply re-instantiate the component using a specific skin and re-attach it to your model. This would allow you to swap out the L&F for an individual component, at least.
> There are also Renderer objects and Decorator objects to consider as extensions to the StaffComponentSkin. With the StaffComponentSkin responsible for the layout and painting of the data in the staff's StaffComponentModel how would Renderer and Decorator objects be best utilized?
Components represent the "controller" in Pivot's MVC implementation, and skins represent the "view". A skin defines the overall L&F of a component, but it doesn't define how the component's content is painted. That's where renderers come in. However, based on my understanding of your app's requirements, I'm not sure you would need to support a renderer (not all skins do).
Decorators are used to augment a component's default paint behavior. They allow a caller to hook into the paint process before and after a component is painted. Skins often take advantage of them, but they don't necessarily have to. In other words, there's no need to use a decorator if you can implement the behavior you need within the skin's paint() method.
G
Re: Data, Components and Skins
Posted by Superstring Media <su...@gmail.com>.
The data model for a score contains one or more StaffComponents which in turn each reference a StaffComponentModel object that wraps a [collection] which contains Chord objects which also have a [collection] which contains Note objects. Having the ability to declare the object graph for a whole score or just a staff in BXML is important and it also looks like what type of Pivot collection to use in place of the generic placeholder [collection] used by the StaffComponentModel and Chord objects is important for binding.
What I am thinking of is having a StaffComponent, StaffComponentModel (also known as a Part in music) and StaffComponentSkin. There is only one type of StaffComponent that is created for each score staff desired. A StaffComponent will then reference one of the StaffComponentModel instances that are stored in a separate map outside of the score. A StaffComponent will also have a StaffComponentSkin which will be able to layout and paint the music data in the StaffComponentModel referenced by a StaffComponent in any possible way.
The StaffComponentSkin should be able to dynamically load JSON resource files to provide user/style properties (to load into it dictionaries) which will be recipes for different notation types (there are many types of proposed notations besides the standard notation we all know). Is it possible to use the same resource file mechanism that localization does for this? Each notation that would be described by a resource file is very similar in concept. Only, instead of languages like english or french we have different languages/notations for the UI that the staff's skin provides. Also, is it possible to dynamically load/store notation resource files for a StaffComponentSkin so the LNF for a staff can be changed at any time and be completely pluggable (as in PLNF)?
There are also Renderer objects and Decorator objects to consider as extensions to the StaffComponentSkin. With the StaffComponentSkin responsible for the layout and painting of the data in the staff's StaffComponentModel how would Renderer and Decorator objects be best utilized? The paint method will paint many types of symbols and I'm not yet sure if an ImageView is warranted for each symbol. However, Renderer and Decorator objects could be attached to a StaffComponentSkin if not to ImageView's for symbols.
Most of what I need to do is map Pivot objects and patterns back to my existing design. Pivot is a fresh breath of air and the first framework that I feel has the capacity to make it possible.
Thom
On 2010-09-28, at 6:52 AM, Greg Brown wrote:
>> The MVC pattern in Pivot is well implemented and it is getting me thinking about options for a musical score. My view of a score is that it is comprised of its data, a model object graph and a graphic representation of the data in the graph. There may be a way to align these aspects with the MVC pattern that Pivot uses?
>
> This is exactly what I was talking about in my previous message. :-)
>
>> Presently, the model object graph has just enough objects arranged in a tree to allow any type of score to be formed. The objects carry a lot of data that is put there by editing tools and musical analysers. Possibly the graph could be an extended Component? There are many ways to represent pure music data so having alternate skins (and styles) might be a way to do that as well?
>
> Data models in Pivot are often implemented as collections, Java Beans, or a combination thereof. The Sequence interface is used to represent an ordered collection of values, and Dictionary is used to represent an indexed collection. Classes that implement these interfaces generally fire events to notify listeners about changes. Some classes fire events directly (such as ArrayList) while others fire them indirectly via an outer class instance (such as TabPane.TabSequence). Which approach to use is entirely up to you.
>
> Again, I'm not an expert, but I imagine that a "score" could loosely be modeled as a collection of "notes". So, you might be able to do something like:
>
> public interface Note {
> ...
> }
>
> public class Score implements Sequence<Note> {
> ...
>
> public ListenerList<ScoreListener> getScoreListeners() {
> // return scoreListenerList;
> }
> }
>
> public interface ScoreListener {
> // Define score events such as noteInserted(), notesRemoved(), etc.
> }
>
> If your model isn't too complex, you might actually be able to use an ArrayList rather than creating your own Sequence. ArrayList implements the List interface, which already defines a set of sequence-oriented events (in ListListener).
>
> Anyways, hopefully this is enough to get you started. There are lots of examples of Sequence implementations throughout the code, too (as well as Dictionary).
>
>> I have resolved my requirements already but there may be a benefit to refactoring to the MVC pattern Pivot uses?
>
> There is - if you use Pivot's collection interfaces (specifically Sequence and Dictionary or a class/interface that extends them), you can use BXML to declarative construct instances of your model.
>
> G
>
Re: Data, Components and Skins
Posted by Greg Brown <gk...@mac.com>.
> The MVC pattern in Pivot is well implemented and it is getting me thinking about options for a musical score. My view of a score is that it is comprised of its data, a model object graph and a graphic representation of the data in the graph. There may be a way to align these aspects with the MVC pattern that Pivot uses?
This is exactly what I was talking about in my previous message. :-)
> Presently, the model object graph has just enough objects arranged in a tree to allow any type of score to be formed. The objects carry a lot of data that is put there by editing tools and musical analysers. Possibly the graph could be an extended Component? There are many ways to represent pure music data so having alternate skins (and styles) might be a way to do that as well?
Data models in Pivot are often implemented as collections, Java Beans, or a combination thereof. The Sequence interface is used to represent an ordered collection of values, and Dictionary is used to represent an indexed collection. Classes that implement these interfaces generally fire events to notify listeners about changes. Some classes fire events directly (such as ArrayList) while others fire them indirectly via an outer class instance (such as TabPane.TabSequence). Which approach to use is entirely up to you.
Again, I'm not an expert, but I imagine that a "score" could loosely be modeled as a collection of "notes". So, you might be able to do something like:
public interface Note {
...
}
public class Score implements Sequence<Note> {
...
public ListenerList<ScoreListener> getScoreListeners() {
// return scoreListenerList;
}
}
public interface ScoreListener {
// Define score events such as noteInserted(), notesRemoved(), etc.
}
If your model isn't too complex, you might actually be able to use an ArrayList rather than creating your own Sequence. ArrayList implements the List interface, which already defines a set of sequence-oriented events (in ListListener).
Anyways, hopefully this is enough to get you started. There are lots of examples of Sequence implementations throughout the code, too (as well as Dictionary).
> I have resolved my requirements already but there may be a benefit to refactoring to the MVC pattern Pivot uses?
There is - if you use Pivot's collection interfaces (specifically Sequence and Dictionary or a class/interface that extends them), you can use BXML to declarative construct instances of your model.
G