pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From influence160 <tiliouine.oth...@gmail.com>
Subject Re: Custom component extending existing one
Date Mon, 21 Jan 2013 19:45:16 GMT
repost 

i am creating a custom TableView that extends org.apache.pivot.wtk.TableView
i have a problem to set the skin property of my class, i get this message
"java.lang.IllegalStateException: Skin is already installed."
my component class is OtTableView and my component skin class is
TerraOtTableViewSkin and here is some codes

the constructors of my class

    public OtTableView() {
		this(new ArrayList());
	}

	public OtTableView(List<?> tableData) {
                super(tableData);
		*setSkin(new TerraOtTableViewSkin());*
	}


the constructors of org.apache.pivot.wtk.TableView

   public TableView() {
        this(new ArrayList());
    }

    public TableView(List<?> tableData) {
        setTableData(tableData);
       * installSkin(TableView.class);*
    }

the method installSkin of org.apache.pivot.wtk.Component

    protected void installSkin(Class<? extends Component> componentClass) {
        // Walk up component hierarchy from this type; if we find a match
        // and the super class equals the given component class, install
        // the skin. Otherwise, ignore - it will be installed later by a
        // subclass of the component class.
        Class<?> type = getClass();

        Theme theme = Theme.getTheme();
        Class<? extends org.apache.pivot.wtk.Skin> skinClass =
            theme.getSkinClass((Class<? extends Component>)type);

*        while (skinClass == null
            && type != componentClass
            && type != Component.class) {
            type = type.getSuperclass();

            if (type != Component.class) {
                skinClass = theme.getSkinClass((Class<? extends
Component>)type);
            }
        }*

        if (type == Component.class) {
            throw new IllegalArgumentException(componentClass.getName()
                + " is not an ancestor of " + getClass().getName());
        }

        if (skinClass == null) {
            throw new IllegalArgumentException("No skin mapping for "
                + componentClass.getName() + " found.");
        }

        *if (type == componentClass)* {
            try {
                setSkin(skinClass.newInstance());
            } catch(InstantiationException exception) {
                throw new IllegalArgumentException(exception);
            } catch(IllegalAccessException exception) {
                throw new IllegalArgumentException(exception);
            }
        }
    }

the method installSkin of org.apache.pivot.wtk.Component

    protected void setSkin(Skin skin) {
        if (skin == null) {
            throw new IllegalArgumentException("skin is null.");
        }

*        if (this.skin != null) {
            throw new IllegalStateException("Skin is already installed.");
        }*

        this.skin = skin;
        styles = new BeanAdapter(skin);
        skin.install(this);

        // Apply any defined type styles
        LinkedList<Class&lt;?>> styleTypes = new LinkedList<Class&lt;?>>();

        Class<?> type = getClass();
        while (type != Object.class) {
            styleTypes.insert(type, 0);
            type = type.getSuperclass();
        }

        for (Class<?> styleType : styleTypes) {
            Map<String, ?> stylesLocal = typedStyles.get((Class<? extends
Component>)styleType);

            if (stylesLocal != null) {
                setStyles(stylesLocal);
            }
        }

        invalidate();
        repaint();
    }


the problem come because the constructor of TableView set his skin to my
component 
is there a way to set a new skin to my component without getting this
exception ,
is there a way to add my skin to  the terra theme and mapping it to my
component ?
if i can do this then i can change setSkin(new TerraOtTableViewSkin()); to
installSkin(OtTableView .class);




--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Custom-component-extending-existing-one-tp4022378p4022382.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Mime
View raw message