PATH  Documentation > Mac OS X > Application Kit Reference: Java

Table of Contents

NSOpenPanel


Inherits from:
NSSavePanel : NSPanel : NSWindow : NSResponder : NSObject
Package:
com.apple.yellow.application


Class Description


NSOpenPanel provides the Open panel for the Cocoa user interface. Applications use the Open panel as a convenient way to query the user for the name of a file to open. The Open panel can only be run modally.

Most of this class's behavior is defined by its superclass, NSSavePanel. NSOpenPanel adds to this behavior by:

Typically, you access an NSOpenPanel by invoking the openPanel static method. When the class receives an openPanel message, it tries to reuse an existing panel rather than create a new one. If a panel is reused, its attributes are reset to the default values so that the effect is the same as receiving a new panel. Because Open panels may be reused, you shouldn't modify the instance returned by openPanel except through the methods listed below (and those inherited from NSSavePanel). For example, you can set the panel's title and whether it allows multiple selection, but not the arrangement of the buttons within the panel. If you must modify the Open panel substantially, create and manage your own instance using the constructors rather than the openPanel method.




Method Types


Constructors
NSOpenPanel
Obtaining the shared instance
openPanel
Running the panel modally
runModalInDirectory
runModalForTypes
Getting the user selection
filenames
Allowing browser selections
setCanChooseFiles
canChooseFiles
setCanChooseDirectories
canChooseDirectories
Allowing multiple selections
setAllowsMultipleSelection
allowsMultipleSelection


Constructors



NSOpenPanel

public NSOpenPanel()

Description forthcoming.

public NSOpenPanel( NSRect aRect, int anInt, int anInt, boolean aBoolean)

Description forthcoming.

public NSOpenPanel( NSRect aRect, int anInt, int anInt, boolean aBoolean, NSScreen aScreen)

Description forthcoming.


Static Methods



openPanel

public static NSOpenPanel openPanel()

Returns a "recycled" NSOpenPanel or, if one doesn't yet exist, creates it before returning it. New and recycled NSOpenPanels are reset to default values, which include selection of single files only.


Instance Methods



allowsMultipleSelection

public boolean allowsMultipleSelection()

Returns whether the NSOpenPanel's browser allows the user to open multiple files (and directories) at a time. If multiple files or directories are allowed, then the filename method-inherited from NSSavePanel-returns a non-null value only if one and only one file is selected. By contrast, NSOpenPanel's filenames method always returns the selected files, even if only one file is selected.

See Also: filename (NSSavePanel), filenames, setAllowsMultipleSelection



canChooseDirectories

public boolean canChooseDirectories()

Returns whether the Open panel allows the user to choose directories to open.

See Also: setCanChooseDirectories



canChooseFiles

public boolean canChooseFiles()

Returns whether the Open panel allows the user to choose files to open.

See Also: setCanChooseFiles



filenames

public NSArray filenames()

Returns an array containing the absolute paths (as String objects) of the selected files and directories. If multiple selections aren't allowed, the array contains a single name. The filenames method is preferable over NSSavePanel's filename to get the name or names of files and directories that the user has selected.

runModalInDirectory

public int runModalInDirectory( String directory, String filename, NSArray fileTypes)

Displays the NSOpenPanel and begins a modal event loop that is terminated when the user clicks either OK or Cancel, resulting in the return of OKButton or CancelButton, respectively. The NSOpenPanel displays the files in directory (an absolute directory path) that match the types in fileTypes (an NSArray of file extensions). If directory is null the default directory is the application directory. If all files in a directory should appear in the browser, fileTypes should be null. You can control whether directories and files appear in the browser with the setCanChooseDirectories and setCanChooseFiles methods. The filename argument specifies a particular file in directory that is selected when the Open panel is presented to the user; otherwise, filename should be null.

See Also: runModalForTypes



runModalForTypes

public int runModalForTypes(NSArray fileTypes)

Invokes the runModalInDirectory method, using null for both the filename and directory arguments. See the description of runModalInDirectory for details. The fileTypes argument is an NSArray containing the extensions of files to be shown in the browser. Returns OKButton (if the user clicks the OK button) or CancelButton (if the user clicks the Cancel button).

setAllowsMultipleSelection

public void setAllowsMultipleSelection(boolean flag)

Sets whether the user can select multiple files (and directories) at one time for opening.

See Also: allowsMultipleSelection



setCanChooseDirectories

public void setCanChooseDirectories(boolean flag)

Sets whether the user can select directories in the NSOpenPanel's browser. When a directory is selected, the OK button is enabled only if flag is true.

See Also: canChooseDirectories



setCanChooseFiles

public void setCanChooseFiles(boolean flag)

Sets whether the user can select files in the NSOpenPanel's browser.

See Also: canChooseFiles



URLs

public NSArray URLs()

Description forthcoming.


Table of Contents