All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alee.extended.label.StyledLabelText Maven / Gradle / Ivy

There is a newer version: 1.2.14
Show newest version
/*
 * This file is part of WebLookAndFeel library.
 *
 * WebLookAndFeel library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WebLookAndFeel library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WebLookAndFeel library.  If not, see .
 */

package com.alee.extended.label;

import com.alee.api.clone.behavior.OmitOnClone;
import com.alee.api.merge.behavior.OmitOnMerge;
import com.alee.painter.decoration.IDecoration;
import com.alee.painter.decoration.content.ContentPropertyListener;
import com.thoughtworks.xstream.annotations.XStreamAlias;

import java.util.List;

/**
 * Styled label text content implementation.
 *
 * @param  component type
 * @param  decoration type
 * @param  content type
 * @author Alexandr Zernov
 * @see How to use WebStyledLabel
 */
@XStreamAlias ( "StyledLabelText" )
public class StyledLabelText, I extends StyledLabelText>
        extends AbstractStyledTextContent
{
    /**
     * Component property change listener.
     */
    @OmitOnClone
    @OmitOnMerge
    protected transient ContentPropertyListener listener;

    @Override
    public void activate ( final C c, final D d )
    {
        // Performing default actions
        super.activate ( c, d );

        // Adding style ranges change listener
        listener = new ContentPropertyListener ( c, d )
        {
            @Override
            public void propertyChange ( final C c, final D d, final String property, final Object oldValue, final Object newValue )
            {
                buildTextRanges ( c, d );
                c.repaint ();
            }
        };
        c.addPropertyChangeListener ( WebStyledLabel.STYLE_RANGES_PROPERTY, listener );
    }

    @Override
    public void deactivate ( final C c, final D d )
    {
        // Removing style ranges change listener
        c.removePropertyChangeListener ( WebStyledLabel.STYLE_RANGES_PROPERTY, listener );
        listener = null;

        // Performing default actions
        super.deactivate ( c, d );
    }

    @Override
    protected List getStyleRanges ( final C c, final D d )
    {
        return c.getStyleRanges ();
    }

    @Override
    protected TextWrap getWrapType ( final C c, final D d )
    {
        return c.getWrap ();
    }

    @Override
    protected int getMaximumRows ( final C c, final D d )
    {
        return c.getMaximumRows ();
    }

    @Override
    protected String getText ( final C c, final D d )
    {
        return c.getText ();
    }

    @Override
    protected int getMnemonicIndex ( final C c, final D d )
    {
        return c.getDisplayedMnemonicIndex ();
    }

    @Override
    protected int getHorizontalAlignment ( final C c, final D d )
    {
        return halign != null ? halign : c.getHorizontalTextAlignment ();
    }

    @Override
    protected int getVerticalAlignment ( final C c, final D d )
    {
        return valign != null ? valign : c.getVerticalTextAlignment ();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy