com.alee.painter.decoration.AbstractSectionDecorationPainter Maven / Gradle / Ivy
/*
* 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.painter.decoration;
import com.alee.painter.Painter;
import com.alee.painter.PainterException;
import com.alee.painter.SectionPainter;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.lang.ref.WeakReference;
import java.util.List;
/**
* Abstract decoration painter that can be used by any section painter.
*
* @param component type
* @param component UI type
* @param decoration type
* @author Mikle Garin
*/
public abstract class AbstractSectionDecorationPainter>
extends AbstractDecorationPainter implements SectionPainter
{
/**
* Origin {@link Painter}.
* It is mainly used to provide origin decoration state duplication behavior.
* It is kept within {@link WeakReference} to avoid memory leaks as section painters might be easily replaced.
*/
protected transient WeakReference> origin;
@Override
public void install ( final C c, final U ui, final Painter origin )
{
this.origin = new WeakReference> ( origin );
super.install ( c, ui );
}
@Override
public void uninstall ( final C c, final U ui, final Painter origin )
{
super.uninstall ( c, ui );
this.origin = null;
}
@Override
public Painter getOrigin ()
{
if ( origin == null )
{
throw new PainterException ( "Origin Painter was not specified for painter: " + this );
}
final Painter originPainter = origin.get ();
if ( originPainter == null )
{
throw new PainterException ( "Origin Painter was destroyed before its SectionPainter: " + this );
}
return originPainter;
}
/**
* We do not want {@link SectionPainter} to perform any default tracking as it is already done within {@link #origin}.
* Maybe in some rare cases in the future this will be enabled but so far there are none.
*
* @return {@code false}
*/
@Override
protected boolean usesFocusedView ()
{
return false;
}
/**
* We do not want {@link SectionPainter} to perform any default tracking as it is already done within {@link #origin}.
* Maybe in some rare cases in the future this will be enabled but so far there are none.
*
* @return {@code false}
*/
@Override
protected boolean usesInFocusedParentView ()
{
return false;
}
/**
* We do not want {@link SectionPainter} to perform any default tracking as it is already done within {@link #origin}.
* Maybe in some rare cases in the future this will be enabled but so far there are none.
*
* @return {@code false}
*/
@Override
protected boolean usesHoverView ()
{
return false;
}
/**
* We do not want {@link SectionPainter} to perform any default tracking as it is already done within {@link #origin}.
* Maybe in some rare cases in the future this will be enabled but so far there are none.
*
* @return {@code false}
*/
@Override
protected boolean usesHierarchyBasedView ()
{
return false;
}
/**
* Returns decoration states from {@link #origin} {@link Painter} if possible.
* That is quite useful to retain all origin component states from its {@link Painter} and further expand on them for the section.
*
* @return current component section decoration states
*/
@Override
public List getDecorationStates ()
{
final List states;
final Painter origin = getOrigin ();
if ( origin != null && origin instanceof IDecorationPainter )
{
// Retrieving origin decoration states
final IDecorationPainter painter = ( IDecorationPainter ) origin;
states = painter.getDecorationStates ();
}
else
{
// Retrieving default decoration states
states = super.getDecorationStates ();
}
return states;
}
/**
* Plain background is rarely needed in section painters.
* It was designed mostly for base component painters that might want to fill background by default.
*
* @param c component to paint background for
* @return always {@code false}
*/
@Override
protected boolean isPlainBackgroundRequired ( final C c )
{
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy