Package com.jgoodies.forms.builder
Class ListViewBuilder
- java.lang.Object
-
- com.jgoodies.forms.builder.ListViewBuilder
-
public final class ListViewBuilder extends java.lang.Object
Builds list/table views from a set of mandatory and optional components: label, filter/search, list (table), list buttons, list extras, details view (or preview).Examples:
return new ListViewBuilder() .label("&Contacts:") .listView(contactsTable) .listBar(newButton, editButton, deleteButton) .build(); return new ListViewBuilder() .border(Borders.DLU14) .labelView(contactsLabel) .filterView(contactsSearchField) .listView(contactsTable) .listBar(newButton, editButton, deleteButton, null, printButton) .detailsView(contactDetailsView) .build();
For more examples see the JGoodies Showcase application.- Since:
- 1.6
- Version:
- $Revision: 1.2 $
-
-
Field Summary
Fields Modifier and Type Field Description private javax.swing.border.Border
border
private javax.swing.JComponent
detailsView
private ComponentFactory
factory
private javax.swing.JComponent
filterView
private java.lang.String
filterViewColSpec
private java.awt.FocusTraversalPolicy
focusTraversalPolicy
private boolean
honorsVisibility
private javax.swing.JComponent
labelView
private javax.swing.JComponent
listBarView
private javax.swing.JComponent
listExtrasView
private javax.swing.JComponent
listView
private java.lang.String
listViewRowSpec
private java.lang.String
namePrefix
private javax.swing.JComponent
panel
Holds the panel that has been lazily built in#buildPanel
.
-
Constructor Summary
Constructors Constructor Description ListViewBuilder()
Constructs a ListViewBuilder using the AbstractBuilder's default component factory.ListViewBuilder(ComponentFactory factory)
Constructs a ListViewBuilder using the given component factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ListViewBuilder
border(javax.swing.border.Border border)
Sets an optional border that surrounds the list view including the label and details.javax.swing.JComponent
build()
Lazily builds and returns the list view panel.private javax.swing.JComponent
buildDecoratedDetailsView()
private javax.swing.JComponent
buildDecoratedHeaderView()
private javax.swing.JComponent
buildDecoratedListBarAndExtras()
private javax.swing.JComponent
buildPanel()
ListViewBuilder
detailsView(javax.swing.JComponent detailsView)
Sets an optional details view that is located under the list view.ListViewBuilder
filterView(javax.swing.JComponent filterView)
Sets an optional view that will be placed in the upper right corner of the built list view panel.ListViewBuilder
filterViewColSpec(java.lang.String colSpec)
Changes the FormLayout column specification used to lay out the filter view.ListViewBuilder
focusTraversal(java.awt.FocusTraversalPolicy policy)
Sets the panel's focus traversal policy and sets the panel as focus traversal policy provider.ListViewBuilder
headerLabel(java.lang.String markedText)
Creates a header label for the given marked text and sets it as label view.ListViewBuilder
honorVisibility(boolean b)
Specifies whether invisible components shall be taken into account by this builder for computing the layout size and setting component bounds.private void
invalidatePanel()
ListViewBuilder
label(java.lang.String markedText)
Creates a plain label for the given marked text and sets it as label view.ListViewBuilder
labelView(javax.swing.JComponent labelView)
Sets the mandatory label view.ListViewBuilder
listBar(javax.swing.JComponent... buttons)
Builds a button bar using the given buttons and sets it as list bar.ListViewBuilder
listBarView(javax.swing.JComponent listBarView)
Sets an optional list bar - often a button bar - that will be located in the lower left corner of the list view.ListViewBuilder
listExtrasView(javax.swing.JComponent listExtrasView)
Sets an optional view that is located in the lower right corner of the list view, aligned with the list bar.ListViewBuilder
listView(javax.swing.JComponent listView)
Sets the given component as the the mandatory list view.ListViewBuilder
listViewRowSpec(java.lang.String rowSpec)
Changes the FormLayout row specification used to lay out the list view.ListViewBuilder
namePrefix(java.lang.String namePrefix)
Sets the prefix that is prepended to component name of components that have no name set or that are are implicitly created by this builder, e.g.private void
setName(javax.swing.JComponent component, java.lang.String suffix)
-
-
-
Field Detail
-
factory
private final ComponentFactory factory
-
labelView
private javax.swing.JComponent labelView
-
filterView
private javax.swing.JComponent filterView
-
listView
private javax.swing.JComponent listView
-
listBarView
private javax.swing.JComponent listBarView
-
listExtrasView
private javax.swing.JComponent listExtrasView
-
detailsView
private javax.swing.JComponent detailsView
-
border
private javax.swing.border.Border border
-
honorsVisibility
private boolean honorsVisibility
-
focusTraversalPolicy
private java.awt.FocusTraversalPolicy focusTraversalPolicy
-
namePrefix
private java.lang.String namePrefix
-
filterViewColSpec
private java.lang.String filterViewColSpec
-
listViewRowSpec
private java.lang.String listViewRowSpec
-
panel
private javax.swing.JComponent panel
Holds the panel that has been lazily built in#buildPanel
.
-
-
Constructor Detail
-
ListViewBuilder
public ListViewBuilder()
Constructs a ListViewBuilder using the AbstractBuilder's default component factory. The factory is required bylabel(String)
andheaderLabel(String)
.
-
ListViewBuilder
public ListViewBuilder(ComponentFactory factory)
Constructs a ListViewBuilder using the given component factory. The factory is required bylabel(String)
andheaderLabel(String)
.- Parameters:
factory
- the component factory used to create labels and headers
-
-
Method Detail
-
border
public ListViewBuilder border(javax.swing.border.Border border)
Sets an optional border that surrounds the list view including the label and details.- Parameters:
border
- the border to set
-
focusTraversal
public ListViewBuilder focusTraversal(java.awt.FocusTraversalPolicy policy)
Sets the panel's focus traversal policy and sets the panel as focus traversal policy provider. Hence, this call is equivalent to:builder.getPanel().setFocusTraversalPolicy(policy); builder.getPanel().setFocusTraversalPolicyProvider(true);
- Parameters:
policy
- the focus traversal policy that will manage keyboard traversal of the children in this builder's panel- Since:
- 1.7.2
- See Also:
Container.setFocusTraversalPolicy(FocusTraversalPolicy)
,Container.setFocusTraversalPolicyProvider(boolean)
-
honorVisibility
public ListViewBuilder honorVisibility(boolean b)
Specifies whether invisible components shall be taken into account by this builder for computing the layout size and setting component bounds. If set totrue
invisible components will be ignored by the layout. If set tofalse
components will be taken into account regardless of their visibility. Visible components are always used for sizing and positioning.The default value for this setting is
true
. It is useful to set the value tofalse
(in other words to ignore the visibility) if you switch the component visibility dynamically and want the container to retain the size and component positions.- Parameters:
b
-true
to honor the visibility, i.e. to exclude invisible components from the sizing and positioning,false
to ignore the visibility, in other words to layout visible and invisible components- Since:
- 1.7.1
-
namePrefix
public ListViewBuilder namePrefix(java.lang.String namePrefix)
Sets the prefix that is prepended to component name of components that have no name set or that are are implicitly created by this builder, e.g. the (header) label. The default name prefix is "ListView".- Parameters:
namePrefix
- the prefix to be used- Since:
- 1.7.1
-
labelView
public ListViewBuilder labelView(javax.swing.JComponent labelView)
Sets the mandatory label view. Useful to set a bound label that updates its text when the list content changes, for example to provide the number of list elements.- Parameters:
labelView
- the component that shall label the list view, often a bound label
-
label
public ListViewBuilder label(java.lang.String markedText)
Creates a plain label for the given marked text and sets it as label view. Equivalent to:labelView(aComponentFactory.createLabel(markedText));
- Parameters:
markedText
- the label's text, may contain a mnemonic marker
-
headerLabel
public ListViewBuilder headerLabel(java.lang.String markedText)
Creates a header label for the given marked text and sets it as label view. Equivalent to:labelView(aComponentFactory.createHeaderLabel(markedText));
- Parameters:
markedText
- the label's text, may contain a mnemonic marker
-
filterView
public ListViewBuilder filterView(javax.swing.JComponent filterView)
Sets an optional view that will be placed in the upper right corner of the built list view panel. This can be a search field, a panel with filtering check boxes ("Only valid items"), etc.- Parameters:
filterView
- the view to be added.
-
filterViewColSpec
public ListViewBuilder filterViewColSpec(java.lang.String colSpec)
Changes the FormLayout column specification used to lay out the filter view. The default value is"[100dlu, p]"
, which is a column where the width is determined by the filter view's preferred width, but a minimum width of 100dlu is ensured. The filter view won't grow horizontally, if the container gets more space.- Parameters:
colSpec
- specifies the horizontal layout of the filter view- Throws:
java.lang.NullPointerException
- ifcolSpec
isnull
-
listView
public ListViewBuilder listView(javax.swing.JComponent listView)
Sets the given component as the the mandatory list view. IflistView
is a JTable, JList, or JTree, it is automatically wrapped with a JScrollPane, before the scroll pane is set as list view.- Parameters:
listView
- the component to be used as scrollable list view- Throws:
java.lang.NullPointerException
- iflistView
isnull
-
listViewRowSpec
public ListViewBuilder listViewRowSpec(java.lang.String rowSpec)
Changes the FormLayout row specification used to lay out the list view. The default value is"fill:[100dlu, pref]:grow"
, which is a row that is filled by the list view; the height is determined by the list view's preferred height, but a minimum of 100dlu is ensured. The list view grows vertically, if the container gets more vertical space.Examples:
.listViewRowSpec("fill:100dlu"); // fixed height .listViewRowSpec("f:100dlu:g"); // fixed start height, grows .listViewRowSpec("f:p"); // no minimum height
- Parameters:
rowSpec
- specifies the vertical layout of the list view- Throws:
java.lang.NullPointerException
- ifrowSpec
isnull
-
listBarView
public ListViewBuilder listBarView(javax.swing.JComponent listBarView)
Sets an optional list bar - often a button bar - that will be located in the lower left corner of the list view. If the list bar view consists only of buttons, uselistBar(JComponent...)
instead.- Parameters:
listBarView
- the component to set
-
listBar
public ListViewBuilder listBar(javax.swing.JComponent... buttons)
Builds a button bar using the given buttons and sets it as list bar. Although JButtons are expected, any JComponent is accepted to allow custom button component types.Equivalent to
listBarView(Forms.buildButtonBar(buttons))
.- Parameters:
buttons
- the buttons in the list bar- Throws:
java.lang.NullPointerException
- ifbuttons
isnull
java.lang.IllegalArgumentException
- if no buttons are provided- See Also:
ButtonBarBuilder.addButton(JComponent...)
-
listExtrasView
public ListViewBuilder listExtrasView(javax.swing.JComponent listExtrasView)
Sets an optional view that is located in the lower right corner of the list view, aligned with the list bar.- Parameters:
listExtrasView
- the component to set
-
detailsView
public ListViewBuilder detailsView(javax.swing.JComponent detailsView)
Sets an optional details view that is located under the list view. Often this is the details view or preview of a master-details view.- Parameters:
detailsView
- the component to set
-
build
public javax.swing.JComponent build()
Lazily builds and returns the list view panel.- Returns:
- the built panel
-
invalidatePanel
private void invalidatePanel()
-
buildPanel
private javax.swing.JComponent buildPanel()
-
buildDecoratedHeaderView
private javax.swing.JComponent buildDecoratedHeaderView()
-
buildDecoratedListBarAndExtras
private javax.swing.JComponent buildDecoratedListBarAndExtras()
-
buildDecoratedDetailsView
private javax.swing.JComponent buildDecoratedDetailsView()
-
setName
private void setName(javax.swing.JComponent component, java.lang.String suffix)
-
-