Package io.codeworth.panelmatic.impl
Class AbstractPanelBuilder
- java.lang.Object
-
- io.codeworth.panelmatic.impl.AbstractPanelBuilder
-
- All Implemented Interfaces:
PanelBuilder
- Direct Known Subclasses:
GbPanelBuilder
public abstract class AbstractPanelBuilder extends Object implements PanelBuilder
This class provides a skeletal implementation of thePanelBuilderinterface, to minimize the effort required to implement it from scratch. Deals with:- Getting/setting the ComponentFactory
- Getting/setting the default component behaviors
- Getting/setting the component customizers (both the regulars and the single build ones)
- Lookup of strings in a
ResourceBundle. - Customizing the components
- Creating the effective behaviors for the added components (e.g. when
more behavior modifiers are passed to an
add(...)method
- Author:
- michaelbar-sinai
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.codeworth.panelmatic.PanelBuilder
PanelBuilder.HeaderLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractPanelBuilder()AbstractPanelBuilder(ComponentBehavior baseComponentBehavior)AbstractPanelBuilder(ComponentBehavior headerBehavior, ComponentBehavior labelBehavior, ComponentBehavior baseComponentBehavior)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description PanelBuilderadd(String title, JComponent comp, BehaviorModifier... modifiers)protected PanelBuilderadd(String labelText, JComponent labelComp, JComponent aComp, BehaviorModifier... modifiers)PanelBuilderadd(Icon icn, String title, JComponent comp, BehaviorModifier... modifiers)PanelBuilderadd(JComponent comp, BehaviorModifier... modifiers)PanelBuilderadd(JComponent labelComp, JComponent comp, BehaviorModifier... modifiers)PanelBuilderaddFlexibleSpace()Adds an empty space that stretches to take any extra space available.PanelBuilderaddHeader(PanelBuilder.HeaderLevel hx, String title, JComponent... comps)PanelBuilderaddHeader(PanelBuilder.HeaderLevel hx, Icon icn, String title, JComponent... comps)protected abstract voidaddHeaderImpl(JComponent aHeaderComp)Implementation of adding a header to the product.protected abstract voidaddImpl(JComponent aLabelComp, JComponent aComp, ComponentBehavior aBehavior)The actual addition of the component to the product is done here.PanelBuilderbegin(PanelMaticComponentCustomizer... custsForCurrentBuild)Prepares the builder to get a panel using internally-created container.PanelBuilderbegin(JComponent basePanel, PanelMaticComponentCustomizer... custsForCurrentBuild)Prepares the builder to get a panel using the suppliedJComponentas the top-level container.protected abstract voidbeginImpl(JComponent aBaseComp)Implementation of thebegin(org.panelmatic.PanelMaticComponentCustomizer[])method.protected JComponentcustomizeComponent(String labelText, JComponent c)Runs the component through the customizers chain.JComponentget(PanelPostProcessor... ppps)Finalizes the build, and returns the built panel.ComponentBehaviorgetBaseComponentBehavior()PanelBuilderComponentFactorygetComponentFactory()List<PanelMaticComponentCustomizer>getCustomizerChain()Allows access to the chain ofPanelMaticComponentCustomizers that customize components before adding them to the built panel.ComponentBehaviorgetHeaderBehavior()protected abstract JComponentgetImpl()Implementation of the #get(org.panelmatic.PanelPostProcessor[]) method.ComponentBehaviorgetLabelBehavior()ResourceBundlegetResourceBundle()protected StringgetResourceString(String key)Return a localized version of the string, if we have a resource bundle, or the passed key, if we don't.voidsetBaseComponentBehavior(ComponentBehavior baseComponentBehavior)voidsetBuilderPool(BuilderPool aPool)Sets the pool into which the builder will return when done.voidsetComponentFactory(PanelBuilderComponentFactory aComponentFactory)voidsetHeaderBehavior(ComponentBehavior aHeaderBehavior)voidsetLabelBehavior(ComponentBehavior aLabelBehavior)AbstractPanelBuildersetResourceBundle(ResourceBundle aResourceBundle)
-
-
-
Constructor Detail
-
AbstractPanelBuilder
public AbstractPanelBuilder(ComponentBehavior headerBehavior, ComponentBehavior labelBehavior, ComponentBehavior baseComponentBehavior)
- Parameters:
headerBehavior- The behavior of the headerslabelBehavior- The behavior of the labelsbaseComponentBehavior- the behavior of the added components.
-
AbstractPanelBuilder
public AbstractPanelBuilder(ComponentBehavior baseComponentBehavior)
-
AbstractPanelBuilder
public AbstractPanelBuilder()
-
-
Method Detail
-
begin
public PanelBuilder begin(PanelMaticComponentCustomizer... custsForCurrentBuild)
Description copied from interface:PanelBuilderPrepares the builder to get a panel using internally-created container. When possible, you should use this method, rather thanPanelBuilder.begin(javax.swing.JComponent, org.panelmatic.PanelMaticComponentCustomizer[]), as it is guaranteed to work.- Specified by:
beginin interfacePanelBuilder- Parameters:
custsForCurrentBuild- Component customizers that are prepended to the normal component customizers, for this get only (untilPanelBuilder.get(org.panelmatic.PanelPostProcessor[])is called).- Returns:
thisbuilder.
-
begin
public PanelBuilder begin(JComponent basePanel, PanelMaticComponentCustomizer... custsForCurrentBuild)
Description copied from interface:PanelBuilderPrepares the builder to get a panel using the suppliedJComponentas the top-level container. Use when laying-out existing panels. The builder would probably try to set properties on the component, make sure that panel can handle those changes (e.g setting of aLayoutManager.- Specified by:
beginin interfacePanelBuilder- Parameters:
basePanel- The component to be used as container.custsForCurrentBuild- Component customizers that are prepended to the normal component customizers, for this get only (untilPanelBuilder.get(org.panelmatic.PanelPostProcessor[])is called).- Returns:
thisbuilder.
-
addHeader
public PanelBuilder addHeader(PanelBuilder.HeaderLevel hx, String title, JComponent... comps)
- Specified by:
addHeaderin interfacePanelBuilder
-
addHeader
public PanelBuilder addHeader(PanelBuilder.HeaderLevel hx, Icon icn, String title, JComponent... comps)
- Specified by:
addHeaderin interfacePanelBuilder
-
add
public PanelBuilder add(String title, JComponent comp, BehaviorModifier... modifiers)
- Specified by:
addin interfacePanelBuilder
-
add
public PanelBuilder add(Icon icn, String title, JComponent comp, BehaviorModifier... modifiers)
- Specified by:
addin interfacePanelBuilder
-
add
public PanelBuilder add(JComponent comp, BehaviorModifier... modifiers)
- Specified by:
addin interfacePanelBuilder
-
add
public PanelBuilder add(JComponent labelComp, JComponent comp, BehaviorModifier... modifiers)
- Specified by:
addin interfacePanelBuilder
-
add
protected PanelBuilder add(String labelText, JComponent labelComp, JComponent aComp, BehaviorModifier... modifiers)
-
addFlexibleSpace
public PanelBuilder addFlexibleSpace()
Description copied from interface:PanelBuilderAdds an empty space that stretches to take any extra space available.- Specified by:
addFlexibleSpacein interfacePanelBuilder- Returns:
thisbuilder.
-
get
public JComponent get(PanelPostProcessor... ppps)
Description copied from interface:PanelBuilderFinalizes the build, and returns the built panel. The builder returns to its pool. After calling this method, the client code can no longer use the builder! To obtain a new builder, call on ofPanelMatic]'sbegin()methods- Specified by:
getin interfacePanelBuilder- Parameters:
ppps- optional post processors for the built panel.- Returns:
- the built component.
-
beginImpl
protected abstract void beginImpl(JComponent aBaseComp)
Implementation of thebegin(org.panelmatic.PanelMaticComponentCustomizer[])method.- Parameters:
aBaseComp- The starting component, may benull.
-
addHeaderImpl
protected abstract void addHeaderImpl(JComponent aHeaderComp)
Implementation of adding a header to the product.- Parameters:
aHeaderComp- The component to be used as a header.
-
addImpl
protected abstract void addImpl(JComponent aLabelComp, JComponent aComp, ComponentBehavior aBehavior)
The actual addition of the component to the product is done here.- Parameters:
aLabelComp- The component that will be used as a label. Can benull.aComp- The (customized) component that we add to the product.aBehavior- The (modified) behavior thataCompshould have.
-
getImpl
protected abstract JComponent getImpl()
Implementation of the #get(org.panelmatic.PanelPostProcessor[]) method. Return the product and clean the state.- Returns:
- The built panel.
-
customizeComponent
protected JComponent customizeComponent(String labelText, JComponent c)
Runs the component through the customizers chain.- Parameters:
labelText- The label the component would have. Might be useful for, e.g. setting a tool tip.c- the component to customize.- Returns:
- a customized component. Note that this component ] might not be the same passed (e.g when wrapped by a customizer in a JScrollPane).
-
getResourceString
protected String getResourceString(String key)
Return a localized version of the string, if we have a resource bundle, or the passed key, if we don't.- Parameters:
key- The key to lookup in the bundle (if we have one). Whennull, the method returnsnull.- Returns:
- If we have a resource bundle, the string whose key is passed. Otherwise,
key.
-
getBaseComponentBehavior
public ComponentBehavior getBaseComponentBehavior()
-
getCustomizerChain
public List<PanelMaticComponentCustomizer> getCustomizerChain()
Description copied from interface:PanelBuilderAllows access to the chain of
PanelMaticComponentCustomizers that customize components before adding them to the built panel.To add a customizer, use
builder.getCustomizerChain().add( cust );Note that since the builders are pooled, changes made to a builder obtained byPanelMatic.begin(...)might not effect other builders obtained the same way. To ensure all builders are changed, consider implementing aPanelBuilderFactoryand calling this method on thePanelBuilderFactory.build()method.- Specified by:
getCustomizerChainin interfacePanelBuilder- Returns:
- The chain of customizers.
-
getHeaderBehavior
public ComponentBehavior getHeaderBehavior()
-
getLabelBehavior
public ComponentBehavior getLabelBehavior()
-
setBaseComponentBehavior
public void setBaseComponentBehavior(ComponentBehavior baseComponentBehavior)
-
setBuilderPool
public void setBuilderPool(BuilderPool aPool)
Description copied from interface:PanelBuilderSets the pool into which the builder will return when done. Normally client code should not call this method.- Specified by:
setBuilderPoolin interfacePanelBuilder- Parameters:
aPool- the pool this builder should return to when done building.
-
getComponentFactory
public PanelBuilderComponentFactory getComponentFactory()
-
setComponentFactory
public void setComponentFactory(PanelBuilderComponentFactory aComponentFactory)
-
setHeaderBehavior
public void setHeaderBehavior(ComponentBehavior aHeaderBehavior)
-
setLabelBehavior
public void setLabelBehavior(ComponentBehavior aLabelBehavior)
-
getResourceBundle
public ResourceBundle getResourceBundle()
-
setResourceBundle
public AbstractPanelBuilder setResourceBundle(ResourceBundle aResourceBundle)
-
-