You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by lello <rb...@gmail.com> on 2010/10/06 21:40:35 UTC

Custom skin on a ListView

Hello,
I am new here and I am trying to use pivot for a new project. Basically I
need a ListView but I would like to have alternating colors for the items in
the list. Since setSkin() is protected subclassing 
ListView should be enough. However, the following code

public class MyListView extends ListView {

	public MyListView() {
		TerraListViewSkin lskin = new TerraListViewSkin();
		lskin.setAlternateItemBackgroundColor(Color.CYAN);
		setSkin(lskin);
	}

}

returns and error "Skin already installed".
What am I doing wrong?

Thanks,
Lello

-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Custom-skin-on-a-ListView-tp1644722p1644722.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Custom skin on a ListView

Posted by lello <rb...@gmail.com>.
Just a last question.
If I understand correctly, I should be able to set
"alternateTemBackgroundColor" using styles in a wtkx file.
However, 

<ListView wtkx:id="listView" selectMode="single"
styles="{alternateItemBackgroundColor: 12}" />

doesn't work.
Again, where is my mistake?...
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Custom-skin-on-a-ListView-tp1644722p1647035.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Custom skin on a ListView

Posted by Superstring Media <su...@gmail.com>.
Would I'm wondering if having alternate skins might be what my music score and staves could use to change appearance and notation types. I printed off the skin related code to look further into this and will read it today sometime. Maybe setting style aspects can do what I need to but I am yet unsure until I look into this more.

At any rate I will want to change the look of the score or staves at runtime dynamically.

Thom


On 2010-10-07, at 7:23 AM, Greg Brown wrote:

>> I tried your code and it works, I wonder now what is the purpose of
>> setSkin().
>> If I understand correctly it is called just once, when the class is
>> instantiated and
>> then it cannot be called anymore.
> 
> 
> The setSkin() method attaches a skin implementation to a component. The skin is often provided by a theme (similar to a PLAF in Swing), which is dynamically loaded (i.e. not known until application startup). So the constructors of most components include a call to installSkin(), which uses the theme to create an appropriate skin instance and calls setSkin() with it.
> 
> We actually used to support runtime replacement of skins, but dropped it a few releases back because there wasn't a strong enough use case to justify maintaining the feature.
> 
> G
> 
> 
> 
> 
> 


Re: Custom skin on a ListView

Posted by Greg Brown <gk...@mac.com>.
> I tried your code and it works, I wonder now what is the purpose of
> setSkin().
> If I understand correctly it is called just once, when the class is
> instantiated and
> then it cannot be called anymore.


The setSkin() method attaches a skin implementation to a component. The skin is often provided by a theme (similar to a PLAF in Swing), which is dynamically loaded (i.e. not known until application startup). So the constructors of most components include a call to installSkin(), which uses the theme to create an appropriate skin instance and calls setSkin() with it.

We actually used to support runtime replacement of skins, but dropped it a few releases back because there wasn't a strong enough use case to justify maintaining the feature.

G






Re: Custom skin on a ListView

Posted by lello <rb...@gmail.com>.
Thank you very much for you answer.
I tried your code and it works, I wonder now what is the purpose of
setSkin().
If I understand correctly it is called just once, when the class is
instantiated and
then it cannot be called anymore.

By the way: wonderful job. Pivot is really what I was missing in Java.



-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Custom-skin-on-a-ListView-tp1644722p1647021.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Custom skin on a ListView

Posted by Chris Bartlett <cb...@gmail.com>.
Lello,

Pivot uses Themes to associate Components with Skins.
Currently there is only one Theme bundled with Pivot, named 'Terra'.

When a Component such as ListView is instantiated, it will query the current
Theme to determine which skin to install (load).  This means that you
generally will only access styles (bean properties of skins) via the
Component#getStyles() method.

This returns a StyleDictionary which is essentially a Map of style names
(bean properties of the skin) and their values.

If you just want to set a style of a property with Java code, you would do
something like this.  You do not need to create a subclass of ListView or
it's skin implementation (TerraListViewSkin

// Create a ListView, get a reference from a loaded WTKX file etc.
ListView listView = ....;
// Change a style
listView.getStyles().put("alternateItemBackgroundColor", Color.CYAN);


For reference, here is some related source code.
http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
http://svn.apache.org/repos/asf/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java


If you do need to, it is possible to create your components and skins for
components, either from scratch or by extending the ones provided with
Pivot.

Regards,

Chris

On 7 October 2010 02:40, lello <rb...@gmail.com> wrote:

>
> Hello,
> I am new here and I am trying to use pivot for a new project. Basically I
> need a ListView but I would like to have alternating colors for the items
> in
> the list. Since setSkin() is protected subclassing
> ListView should be enough. However, the following code
>
> public class MyListView extends ListView {
>
>        public MyListView() {
>                TerraListViewSkin lskin = new TerraListViewSkin();
>                lskin.setAlternateItemBackgroundColor(Color.CYAN);
>                setSkin(lskin);
>        }
>
> }
>
> returns and error "Skin already installed".
> What am I doing wrong?
>
> Thanks,
> Lello
>
> --
> View this message in context:
> http://apache-pivot-users.399431.n3.nabble.com/Custom-skin-on-a-ListView-tp1644722p1644722.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>