Package com.explodingpixels.macwidgets
Class SourceList
java.lang.Object
com.explodingpixels.macwidgets.SourceList
An implementation of an OS X Source List. For a full descrption of what a Source List is, see the
Source Lists
section of Apple's Human Interface Guidelines.
This component provides the two basic sytles of Source List: focusble and non-focusable.
As the name implies, focusable Source Lists and recieve keyboard focus, and thus can be navigated
using the arrow keys. Non-focusable, cannot receive keyboard focus, and thus cannot be
navigated via the arrow keys. The two styles of
Here's how to create a simple
SourceList are pictured below:
![]() |
![]() |
| Focusable SourceList | Non-focusable SourceList |
Here's how to create a simple
SourceList with one item:
SourceListModel model = new SourceListModel();
SourceListCategory category = new SourceListCategory("Category");
model.addCategory(category);
model.addItemToCategory(new SourceListItem("Item"), category);
SourceList sourceList = new SourceList(model);
To install a selection listener on the SourceList, add a
SourceListSelectionListener.
setSourceListContextMenuProvider(SourceListContextMenuProvider) with an implementation
of SourceListContextMenuProvider.-
Constructor Summary
ConstructorsConstructorDescriptionCreates aSourceListwith an emptySourceListModel.SourceList(SourceListModel model) Creates aSourceListwith the givenSourceListModel. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds theSourceListClickListenerto the list of listeners.voidAdds theSourceListExpansionListenerto the list of listeners.voidAdds theSourceListSelectionListenerto the list of listeners.voidClears the current selection, if there is one.voiddispose()Uninstalls any listeners that thisSourceListinstalled on creation, thereby allowing it to be garbage collected.Gets theSourceListColorSchemethat thisSourceListuses.Gets the user interface component representing thisSourceList.getModel()Gets theSourceListModelbacking thisSourceList.Gets the selectedSourceListItem.voidinstallSourceListControlBar(SourceListControlBar sourceListControlBar) Installs the givenSourceListControlBarat the base of thisSourceList.booleanTrue if there is aSourceListControlBarinstalled on thisSourceList.voidRemoves theSourceListClickListenerto the list of listeners.voidRemoves theSourceListExpansionListenerfrom the list of listeners.voidRemoves theSourceListSelectionListenerfrom the list of listeners.voidScrolls the givenSourceListItemto be visible.voidsetColorScheme(SourceListColorScheme colorScheme) Sets theSourceListColorSchemethat thisSourceListuses.voidsetExpanded(SourceListCategory category, boolean expanded) Sets the expanded state of the givenSourceListCategory.voidsetExpanded(SourceListItem item, boolean expanded) Sets the expanded state of the givenSourceListItem.voidsetFocusable(boolean focusable) Sets whether thisSourceListcan have focus.voidSelects the givenSourceListItemin the list.voidsetSourceListContextMenuProvider(SourceListContextMenuProvider contextMenuProvider) Sets theSourceListContextMenuProviderto use for thisSourceList.voidsetToolTipProvider(SourceListToolTipProvider toolTipProvider) Sets theSourceListToolTipProviderto use.voidsetTransferHandler(TransferHandler transferHandler) Set's theTransferHandlerthat thisSourceListshould use during drag and drop operations.voidInstalls iApp style scroll bars on thisSourceList.
-
Constructor Details
-
SourceList
public SourceList()Creates aSourceListwith an emptySourceListModel. -
SourceList
Creates aSourceListwith the givenSourceListModel.- Parameters:
model- theSourceListModelto use.
-
-
Method Details
-
installSourceListControlBar
Installs the givenSourceListControlBarat the base of thisSourceList. This method can be called only once, and should generally be called during creation of theSourceList.- Parameters:
sourceListControlBar- theSourceListControlBarto add.- Throws:
IllegalStateException- if aSourceListControlBarhas already been installed on thisSourceList.IllegalArgumentException- if theSourceListControlBaris null.
-
isSourceListControlBarInstalled
public boolean isSourceListControlBarInstalled()True if there is aSourceListControlBarinstalled on thisSourceList.- Returns:
- true if there is a
SourceListControlBarinstalled on thisSourceList.
-
setSourceListContextMenuProvider
Sets theSourceListContextMenuProviderto use for thisSourceList.- Parameters:
contextMenuProvider- theSourceListContextMenuProviderto use for thisSourceList.- Throws:
IllegalArgumentException- if theSourceListContextMenuProvideris null.
-
dispose
public void dispose()Uninstalls any listeners that thisSourceListinstalled on creation, thereby allowing it to be garbage collected. -
getSelectedItem
Gets the selectedSourceListItem.- Returns:
- the selected
SourceListItem.
-
setSelectedItem
Selects the givenSourceListItemin the list.- Parameters:
item- the item to select.- Throws:
IllegalArgumentException- if the given item is not in the list.
-
clearSelection
public void clearSelection()Clears the current selection, if there is one. -
setFocusable
public void setFocusable(boolean focusable) Sets whether thisSourceListcan have focus. When focusable and thisSourceListhas focus, the keyboard can be used for navigation.- Parameters:
focusable- true if thisSourceListshould be focusable.
-
useIAppStyleScrollBars
public void useIAppStyleScrollBars()Installs iApp style scroll bars on thisSourceList.- See Also:
-
getColorScheme
Gets theSourceListColorSchemethat thisSourceListuses.- Returns:
- the
SourceListColorSchemethat thisSourceListuses.
-
setColorScheme
Sets theSourceListColorSchemethat thisSourceListuses.- Parameters:
colorScheme- theSourceListColorSchemethat thisSourceListuses.
-
setTransferHandler
Set's theTransferHandlerthat thisSourceListshould use during drag and drop operations. If the given handler not null, then dragging will be turned on for theSourceList. If the handler is null, then dragging will be turned off.- Parameters:
transferHandler- theTransferHandlerfor thisSourceList. Can be null.
-
scrollItemToVisible
Scrolls the givenSourceListItemto be visible.- Parameters:
item- theSourceListItemto scroll to visible.
-
setExpanded
Sets the expanded state of the givenSourceListCategory.- Parameters:
category- the category to set the expanded state on.expanded- true if the given category should be expanded, false if it should be collapsed.- Throws:
IllegalArgumentException- if the givenSourceListCategoryis not part of the associatedSourceListModel.
-
setExpanded
Sets the expanded state of the givenSourceListItem.- Parameters:
item- the item to set the expanded state on.expanded- true if the given item should be expanded, false if it should be collapsed.- Throws:
IllegalArgumentException- if the givenSourceListItemis not part of the associatedSourceListModel.
-
getComponent
Gets the user interface component representing thisSourceList. The returnedJComponentshould be added to a container that will be displayed.- Returns:
- the user interface component representing this
SourceList.
-
getModel
Gets theSourceListModelbacking thisSourceList.- Returns:
- the
SourceListModelbacking thisSourceList.
-
setToolTipProvider
Sets theSourceListToolTipProviderto use.- Parameters:
toolTipProvider- theinvalid @code
{@code SourceListToolTipProvider to use.
-
addSourceListClickListener
Adds theSourceListClickListenerto the list of listeners.- Parameters:
listener- theSourceListClickListenerto add.
-
removeSourceListClickListener
Removes theSourceListClickListenerto the list of listeners.- Parameters:
listener- theSourceListClickListenerto remove.
-
addSourceListSelectionListener
Adds theSourceListSelectionListenerto the list of listeners.- Parameters:
listener- theSourceListSelectionListenerto add.
-
removeSourceListSelectionListener
Removes theSourceListSelectionListenerfrom the list of listeners.- Parameters:
listener- theSourceListSelectionListenerto remove.
-
addSourceListExpansionListener
Adds theSourceListExpansionListenerto the list of listeners.- Parameters:
listener- theSourceListExpansionListenerto add.
-
removeSourceListExpansionListener
Removes theSourceListExpansionListenerfrom the list of listeners.- Parameters:
listener- theSourceListExpansionListenerto remove.
-

