Package com.explodingpixels.macwidgets
Class SourceList
- java.lang.Object
-
- com.explodingpixels.macwidgets.SourceList
-
public class SourceList extends java.lang.ObjectAn 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 ofSourceListare pictured below:


Focusable SourceList Non-focusable SourceList
Here's how to create a simpleSourceListwith 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
To install a context-menu provider, callSourceList, add aSourceListSelectionListener.setSourceListContextMenuProvider(SourceListContextMenuProvider)with an implementation ofSourceListContextMenuProvider.
-
-
Constructor Summary
Constructors Constructor Description SourceList()Creates aSourceListwith an emptySourceListModel.SourceList(SourceListModel model)Creates aSourceListwith the givenSourceListModel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSourceListClickListener(SourceListClickListener listener)Adds theSourceListClickListenerto the list of listeners.voidaddSourceListExpansionListener(SourceListExpansionListener listener)Adds theSourceListExpansionListenerto the list of listeners.voidaddSourceListSelectionListener(SourceListSelectionListener listener)Adds theSourceListSelectionListenerto the list of listeners.voidclearSelection()Clears the current selection, if there is one.voiddispose()Uninstalls any listeners that thisSourceListinstalled on creation, thereby allowing it to be garbage collected.SourceListColorSchemegetColorScheme()Gets theSourceListColorSchemethat thisSourceListuses.javax.swing.JComponentgetComponent()Gets the user interface component representing thisSourceList.SourceListModelgetModel()Gets theSourceListModelbacking thisSourceList.SourceListItemgetSelectedItem()Gets the selectedSourceListItem.voidinstallSourceListControlBar(SourceListControlBar sourceListControlBar)Installs the givenSourceListControlBarat the base of thisSourceList.booleanisSourceListControlBarInstalled()True if there is aSourceListControlBarinstalled on thisSourceList.voidremoveSourceListClickListener(SourceListClickListener listener)Removes theSourceListClickListenerto the list of listeners.voidremoveSourceListExpansionListener(SourceListExpansionListener listener)Removes theSourceListExpansionListenerfrom the list of listeners.voidremoveSourceListSelectionListener(SourceListSelectionListener listener)Removes theSourceListSelectionListenerfrom the list of listeners.voidscrollItemToVisible(SourceListItem item)Scrolls 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.voidsetSelectedItem(SourceListItem item)Selects the givenSourceListItemin the list.voidsetSourceListContextMenuProvider(SourceListContextMenuProvider contextMenuProvider)Sets theSourceListContextMenuProviderto use for thisSourceList.voidsetToolTipProvider(SourceListToolTipProvider toolTipProvider)Sets theSourceListToolTipProviderto use.voidsetTransferHandler(javax.swing.TransferHandler transferHandler)Set's theTransferHandlerthat thisSourceListshould use during drag and drop operations.voiduseIAppStyleScrollBars()Installs iApp style scroll bars on thisSourceList.
-
-
-
Constructor Detail
-
SourceList
public SourceList()
Creates aSourceListwith an emptySourceListModel.
-
SourceList
public SourceList(SourceListModel model)
Creates aSourceListwith the givenSourceListModel.- Parameters:
model- theSourceListModelto use.
-
-
Method Detail
-
installSourceListControlBar
public void installSourceListControlBar(SourceListControlBar sourceListControlBar)
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:
java.lang.IllegalStateException- if aSourceListControlBarhas already been installed on thisSourceList.java.lang.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
public void setSourceListContextMenuProvider(SourceListContextMenuProvider contextMenuProvider)
Sets theSourceListContextMenuProviderto use for thisSourceList.- Parameters:
contextMenuProvider- theSourceListContextMenuProviderto use for thisSourceList.- Throws:
java.lang.IllegalArgumentException- if theSourceListContextMenuProvideris null.
-
dispose
public void dispose()
Uninstalls any listeners that thisSourceListinstalled on creation, thereby allowing it to be garbage collected.
-
getSelectedItem
public SourceListItem getSelectedItem()
Gets the selectedSourceListItem.- Returns:
- the selected
SourceListItem.
-
setSelectedItem
public void setSelectedItem(SourceListItem item)
Selects the givenSourceListItemin the list.- Parameters:
item- the item to select.- Throws:
java.lang.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.
-
getColorScheme
public SourceListColorScheme getColorScheme()
Gets theSourceListColorSchemethat thisSourceListuses.- Returns:
- the
SourceListColorSchemethat thisSourceListuses.
-
setColorScheme
public void setColorScheme(SourceListColorScheme colorScheme)
Sets theSourceListColorSchemethat thisSourceListuses.- Parameters:
colorScheme- theSourceListColorSchemethat thisSourceListuses.
-
setTransferHandler
public void setTransferHandler(javax.swing.TransferHandler transferHandler)
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
public void scrollItemToVisible(SourceListItem item)
Scrolls the givenSourceListItemto be visible.- Parameters:
item- theSourceListItemto scroll to visible.
-
setExpanded
public void setExpanded(SourceListCategory category, boolean expanded)
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:
java.lang.IllegalArgumentException- if the givenSourceListCategoryis not part of the associatedSourceListModel.
-
setExpanded
public void setExpanded(SourceListItem item, boolean expanded)
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:
java.lang.IllegalArgumentException- if the givenSourceListItemis not part of the associatedSourceListModel.
-
getComponent
public javax.swing.JComponent 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
public SourceListModel getModel()
Gets theSourceListModelbacking thisSourceList.- Returns:
- the
SourceListModelbacking thisSourceList.
-
setToolTipProvider
public void setToolTipProvider(SourceListToolTipProvider toolTipProvider)
Sets theSourceListToolTipProviderto use.- Parameters:
toolTipProvider- the {@code SourceListToolTipProvider to use.
-
addSourceListClickListener
public void addSourceListClickListener(SourceListClickListener listener)
Adds theSourceListClickListenerto the list of listeners.- Parameters:
listener- theSourceListClickListenerto add.
-
removeSourceListClickListener
public void removeSourceListClickListener(SourceListClickListener listener)
Removes theSourceListClickListenerto the list of listeners.- Parameters:
listener- theSourceListClickListenerto remove.
-
addSourceListSelectionListener
public void addSourceListSelectionListener(SourceListSelectionListener listener)
Adds theSourceListSelectionListenerto the list of listeners.- Parameters:
listener- theSourceListSelectionListenerto add.
-
removeSourceListSelectionListener
public void removeSourceListSelectionListener(SourceListSelectionListener listener)
Removes theSourceListSelectionListenerfrom the list of listeners.- Parameters:
listener- theSourceListSelectionListenerto remove.
-
addSourceListExpansionListener
public void addSourceListExpansionListener(SourceListExpansionListener listener)
Adds theSourceListExpansionListenerto the list of listeners.- Parameters:
listener- theSourceListExpansionListenerto add.
-
removeSourceListExpansionListener
public void removeSourceListExpansionListener(SourceListExpansionListener listener)
Removes theSourceListExpansionListenerfrom the list of listeners.- Parameters:
listener- theSourceListExpansionListenerto remove.
-
-