Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Package | com.apple.cocoa.application |
Companion guide |
NSToolbar and NSToolbarItem provide the mechanism for a titled window to display a toolbar just below its title bar, as shown below:
displayMode
setDisplayMode
showsBaselineSeparator
setShowsBaselineSeparator
allowsUserCustomization
setAllowsUserCustomization
identifier
items
visibleItems
sizeMode
setSizeMode
insertItemWithItemIdentifierAtIndex
removeItemAtIndex
setSelectedItemIdentifier
selectedItemIdentifier
autosavesConfiguration
setAutosavesConfiguration
configurationDictionary
setConfigurationFromDictionary
toolbarWillAddItem
delegate method
toolbarDidRemoveItem
delegate method
toolbarAllowedItemIdentifiers
delegate method
toolbarDefaultItemIdentifiers
delegate method
toolbarItemForItemIdentifier
delegate method
toolbarSelectableItemIdentifiers
delegate method
Creates and initializes an NSToolbar with identifier, which is used by the toolbar to identify the kind of the toolbar.
public NSToolbar
(String identifier)
identifier is never seen by users and should not be localized. See identifier
for important information.
Answers whether or not users are allowed to modify the toolbar.
public boolean allowsUserCustomization
()
The default value is false
. If the value is false
, then the Customize Toolbar… menu item is disabled and other modification is disabled. If the value is true
, be sure to also set autosavesConfiguration
to true
, so the user’s changes persist. This attribute does not affect the user’s ability to show or hide the toolbar.
Returns whether the receiver autosaves its configuration.
public boolean autosavesConfiguration
()
If true
, the receiver will automatically write the toolbar settings to user defaults if the toolbar configuration changes. The default is false
.
The information about the toolbar configuration is identified in user defaults by the toolbar identifier. If there are multiple toolbars active with the same identifier, then they all share the same configuration, so it is this shared configuration that is saved.
Returns the receiver’s configuration as a dictionary.
public NSDictionary configurationDictionary
()
Contains displayMode
, isVisible
, and a list of the item identifiers currently in the toolbar. You can add your own items if you need to.
Do not depend on any details of the normal contents of a configuration dictionary.
Returns whether the receiver’s customization palette is running (in use).
public boolean customizationPaletteIsRunning
()
Returns the receiver’s delegate.
public Object delegate
()
Every toolbar must have a delegate, which must implement the required delegate methods.
Returns the receiver’s display mode, which is one of the values described in “Constants.”
public int displayMode
()
Returns the receiver’s identifier, which identifies the kind of the toolbar.
public String identifier
()
Within the application all toolbars with the same identifier are synchronized to maintain the same state, including for example, the display mode and item order. Also, if a toolbar autosaves its configuration, the item identifier is used as the autosave name.
Inserts the item identified by itemIdentifier at index.
public void insertItemWithItemIdentifierAtIndex
(String itemIdentifier, int index)
If the toolbar needs a new instance, it will get it from toolbarItemForItemIdentifier
. Typically, you should not call this method; you should let the user reconfigure the toolbar. See identifier
for important information.
Returns whether the receiver is visible.
public boolean isVisible
()
Returns all current items in the receiver, in order.
public NSArray items
()
Removes the item at index.
public void removeItemAtIndex
(int index)
Typically, you should not call this method; you should let the user reconfigure the toolbar. See identifier
for important information.
Runs the receiver’s customization palette.
public void runCustomizationPalette
(Object sender)
When the user is done customizing, the palette will be dismissed.
Returns the identifier of the receiver’s currently selected item, or null
public String selectedItemIdentifier
()
if there is no selection.
Sets whether or not users are allowed to modify the toolbar to allowsCustomization.
public void setAllowsUserCustomization
(boolean allowsCustomization)
This value can be changed at any time. For instance, you may not want users to be able to customize the toolbar while some event is being processed. This attribute does not affect the user’s ability to show or hide the toolbar.
Sets whether the receiver autosaves its configuration.
public void setAutosavesConfiguration
(boolean flag)
If true
, the receiver will automatically write changes the user makes to user defaults. Customizable toolbars will want to set flag to true
. Setting it to false
means changes in configuration are not written automatically; however you can use the configurationDictionary
to do it yourself.
Sets the receiver’s configuration using configDict.
public void setConfigurationFromDictionary
(NSDictionary configDict)
This method also immediately affects toolbars of the same kind in other windows.
Sets the receiver’s delegate to delegate.
public void setDelegate
(Object delegate)
Every toolbar must have a delegate, which must implement the required delegate methods.
Sets the receiver’s display mode.
public void setDisplayMode
(int displayMode)
displayMode is one of the values described in “Constants.”
Sets the receiver's selected item to the toolbar item specified by identifier.
public void setSelectedItemIdentifier
(String itemIdentifier)
Typically, a toolbar will manage the selection of items automatically. This method can be used to select identifiers of custom view items, or to force a selection change. See toolbarSelectableItemIdentifiers
for more details. If itemIdentifier is not recognized by the receiver, the current selected item identifier does not change.
itemIdentifier may be any identifier returned by toolbarSelectableItemIdentifiers
, even if it is not currently in the toolbar. If the selected item is removed from the toolbar, the selectedItemIdentifier
does not change.
Sets whether the toolbar shows the separator between the toolbar and the main window contents.
public void setShowsBaselineSeparator
(boolean flag)
If flag is true
the baseline is shown. The default is true
.
Sets the receiver’s size mode.
public void setSizeMode
(int sizeMode)
The size can be:
SizeModeRegular
.The toolbar uses regular-sized controls and 32 by 32 pixel icons.
SizeModeSmall
. The toolbar uses small-sized controls and 24 by 24 pixel icons.
If there is no icon of the given size for a toolbar item, the toolbar item creates one by scaling another icon.
Sets whether the receiver is visible or hidden to shown.
public void setVisible
(boolean shown)
Returns whether the toolbar shows the separator between the toolbar and the main window contents.
public boolean showsBaselineSeparator
The default is true
.
Returns the receiver’s size mode, which is one of the values described in “Constants.”
public int sizeMode
()
Called on window updates with the purpose of validating each of the visible items.
public void validateVisibleItems
()
You use this method by overriding it in a subclass; you should not invoke this method. The toolbar calls this method to iterate through the list of visible items, sending each a validate
message. Override it and call super
if you want to know when this happens.
Returns the receiver’s currently visible items. An item can be invisible if it has spilled over into the overflow menu.
public NSArray visibleItems
()
The following constants toolbar display modes and are used by displayMode
and setDisplayMode
:
The following constants specify toolbar sizes and are used by sizeMode
and setSizeMode
:
Returns an array of toolbar item identifiers for toolbar, specifying the contents and the order of the items in the configuration palette.
public abstract NSArray toolbarAllowedItemIdentifiers
(NSToolbar toolbar)
Every allowed item must be explicitly listed, even the standard ones. The identifiers returned should include all of those returned by toolbarDefaultItemIdentifiers
.
Implementation of this method is required.
Returns an array of toolbar item identifiers for toolbar, specifying the contents and the order of the items in the default toolbar configuration.
public abstract NSArray toolbarDefaultItemIdentifiers
(NSToolbar toolbar)
During initialization of toolbar, this method is called only if a toolbar configuration for the identifier of toolbar is not found in the user preferences. This method is called during initialization of the toolbar customization palette.
Implementation of this method is required.
Posted just after an item has been removed from toolbar.
public abstract void toolbarDidRemoveItem
(NSNotification notification)
This method allows the chance to remove information related to the item that may have been cached. The notification‘s object
is the toolbar from which the item is being removed. The notification‘s userInfo
dictionary contains the item being removed under the key "item"
. If this method is implemented, then when you set the toolbar’s delegate, the toolbar automatically registers this method for DidRemoveItemNotification
.
Implementation of this method is optional.
Returns a toolbar item of the kind identified by the given toolbar itemIdentifier.
public abstract NSToolbarItem toolbarItemForItemIdentifier
(NSToolbar toolbar, String itemIdentifier, boolean flag)
This is where you create new toolbar item instances. This method is called lazily on behalf of a toolbar instance, which must be the sole owner of the toolbar item. A toolbar may ask again for a kind of toolbar item already supplied to it, in which case this method can and should return the same toolbar item it returned before.
If the item is a custom view item, the NSView must be fully-formed when the item is returned. Do not assume that the returned item is going to be added as an active item in the toolbar, as it could be that it will be used only in the customization palette. (The customization palette makes a copy of the returned item.)
A null
return value tells the toolbar that the identified kind of toolbar item is not supported.
If flag is true
, the returned item will be inserted into the toolbar, and you can expect that toolbarWillAddItem
is about to be called.
Implementation of this method is required.
Returns an array of item identifiers that should indicate selection in the specified toolbar.
public abstract NSArray toolbarSelectableItemIdentifiers
(NSToolbar toolbar)
Toolbars that need to indicate item selection should return an array containing the identifiers of the selectable toolbar items.
If implemented, toolbar will display the currently selected item with a visual highlight. Clicking on an item whose identifier is selectable will automatically update the toolbars selected item identifier, when possible.
Implementation of this method is optional.
Posted just before a new item is added to the toolbar.
public abstract void toolbarWillAddItem
(NSNotification notification)
If you need to cache a reference to the toolbar item or need to set up some initial state, this is where to do it. The object attribute of notification is the toolbar to which the item is being added. The notification‘s userInfo
dictionary contains the item being added under the key "item"
. If this method is implemented, then when you set the toolbar’s delegate, the toolbar automatically registers this method for WillAddItemNotification
.
Implementation of this method is optional.
Posted after an item is removed from a toolbar. The notification item is the NSToolbar that had an item removed from it. The userInfo dictionary contains the following information:
Key |
Value |
---|---|
|
The NSToolbarItem that was removed. |
Posted before a new item is added to the toolbar. The notification item is the NSToolbar having an item added to it. The userInfo dictionary contains the following information:
Key |
Value |
---|---|
|
The NSToolbarItem being added. |
© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)