/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Basic L&F implementation of a FileChooser.
*
* @author Jeff Dinkins
*/
/* FileView icons */
/**
* The mnemonic keycode used for the approve button when a directory
* is selected and the current selection mode is FILES_ONLY.
*
* @since 1.4
*/
/**
* The label text displayed on the approve button when a directory
* is selected and the current selection mode is FILES_ONLY.
*
* @since 1.4
*/
/**
* The tooltip text displayed on the approve button when a directory
* is selected and the current selection mode is FILES_ONLY.
*
* @since 1.4
*/
// Some generic FileChooser functions
private boolean directorySelected = false;
private boolean usesSingleFilePane;
private boolean readOnly;
// The accessoryPanel is a container to place the JFileChooser accessory component
/**
* Creates a {@code BasicFileChooserUI} implementation
* for the specified component. By default
* the {@code BasicLookAndFeel} class uses
* {@code createUI} methods of all basic UIs classes
* to instantiate UIs.
*
* @param c the {@code JFileChooser} which needs a UI
* @return the {@code BasicFileChooserUI} object
*
* @see UIDefaults#getUI(JComponent)
* @since 1.7
*/
return new BasicFileChooserUI((JFileChooser) c);
}
}
filechooser = (JFileChooser) c;
createModel();
}
if(accessoryPanel != null) {
}
getFileChooser().removeAll();
}
}
}
if(propertyChangeListener != null) {
}
}
"FileChooser.ancestorInputMap");
}
return null;
}
return createActionMap();
}
}
};
return map;
}
if(propertyChangeListener != null) {
}
}
}
}
}
newFolderParentDoesntExistTitleText = UIManager.getString("FileChooser.newFolderParentDoesntExistTitleText", l);
newFolderParentDoesntExistText = UIManager.getString("FileChooser.newFolderParentDoesntExistText", l);
directoryOpenButtonToolTipText = UIManager.getString("FileChooser.directoryOpenButtonToolTipText",l);
}
}
}
computerIcon = null;
upFolderIcon = null;
listViewIcon = null;
viewMenuIcon = null;
}
}
protected void createModel() {
}
}
return model;
}
return null;
}
return null;
}
return null;
}
}
}
}
}
return filechooser;
}
return accessoryPanel;
}
return null;
}
return getApproveButton(fc);
}
if(tooltipText != null) {
return tooltipText;
}
return openButtonToolTipText;
return saveButtonToolTipText;
}
return null;
}
public void clearIconCache() {
}
// ********************************************
// ************ Create Listeners **************
// ********************************************
}
return handler;
}
}
return getHandler();
}
Handler() {
}
}
// Note: we can't depend on evt.getSource() because of backward
// compatability
if (index >= 0) {
try {
// Strip trailing ".."
f = ShellFolder.getNormalizedFile(f);
} catch (IOException ex) {
// That's ok, we'll use f as is
}
if(getFileChooser().isTraversable(f)) {
changeDirectory(f);
} else {
}
}
}
}
}
}
}
}
}
}
}
if(!evt.getValueIsAdjusting()) {
boolean useSetDirectory = usesSingleFilePane &&
if (chooser.isMultiSelectionEnabled()) {
setDirectorySelected(true);
} else {
boolean isDir = f.isDirectory();
&& fsv.isFileSystem(f)
&& isDir)) {
}
}
}
setDirectorySelected(false);
}
}
} else {
&& file.isDirectory()
setDirectorySelected(true);
if (usesSingleFilePane) {
}
} else {
setDirectorySelected(false);
}
}
}
}
}
}
// NOTE: This class exists only for backward compatability. All
// its functionality has been moved into Handler. If you need to add
// new functionality add it to the Handler, but make sure this
// class calls into the Handler.
}
/**
* The JList used for representing the files is created by subclasses, but the
* selection is monitored in this class. The TransferHandler installed in the
* JFileChooser is also installed in the file list as it is used as the actual
* transfer source. The list is updated on a mouse enter to reflect the current
* data transfer state of the file chooser.
*/
handler.mouseEntered(e);
}
handler.mouseClicked(e);
}
}
// NOTE: This class exists only for backward compatability. All
// its functionality has been moved into Handler. If you need to add
// new functionality add it to the Handler, but make sure this
// class calls into the Handler.
getHandler().valueChanged(e);
}
}
/**
* Property to remember whether a directory is currently selected in the UI.
*
* @return <code>true</code> iff a directory is currently selected.
* @since 1.4
*/
protected boolean isDirectorySelected() {
return directorySelected;
}
/**
* Property to remember whether a directory is currently selected in the UI.
* This is normally called by the UI on a selection event.
*
* @param b iff a directory is currently selected.
* @since 1.4
*/
protected void setDirectorySelected(boolean b) {
directorySelected = b;
}
/**
* Property to remember the directory that is currently selected in the UI.
*
* @return the value of the <code>directory</code> property
* @see #setDirectory
* @since 1.4
*/
return directory;
}
/**
* Property to remember the directory that is currently selected in the UI.
* This is normally called by the UI on a selection event.
*
* @param f the <code>File</code> object representing the directory that is
* currently selected
* @since 1.4
*/
directory = f;
}
/**
* Returns the mnemonic for the given key.
*/
}
// *******************************************************
// ************ FileChooser UI PLAF methods **************
// *******************************************************
/**
* Returns the default accept all file filter
*/
return acceptAllFileFilter;
}
return fileView;
}
/**
* Returns the title of this dialog
*/
if (dialogTitle != null) {
return dialogTitle;
return openDialogTitleText;
return saveDialogTitleText;
} else {
return getApproveButtonText(fc);
}
}
if (mnemonic > 0) {
return mnemonic;
return openButtonMnemonic;
return saveButtonMnemonic;
} else {
return mnemonic;
}
}
if (buttonText != null) {
return buttonText;
return openButtonText;
return saveButtonText;
} else {
return null;
}
}
// *****************************
// ***** Directory Actions *****
// *****************************
if (newFolderAction == null) {
newFolderAction = new NewFolderAction();
// Note: Don't return null for readOnly, it might
// break older apps.
if (readOnly) {
newFolderAction.setEnabled(false);
}
}
return newFolderAction;
}
return goHomeAction;
}
return changeToParentDirectoryAction;
}
return approveSelectionAction;
}
return cancelSelectionAction;
}
return updateAction;
}
/**
* Creates a new folder.
*/
protected NewFolderAction() {
super(FilePane.ACTION_NEW_FOLDER);
}
if (readOnly) {
return;
}
if (!currentDirectory.exists()) {
fc,
return;
}
try {
if (fc.isMultiSelectionEnabled()) {
} else {
}
} catch (IOException exc) {
fc,
return;
}
}
}
/**
* Acts on the "home" key event or equivalent event.
*/
protected GoHomeAction() {
super("Go Home");
}
}
}
protected ChangeToParentDirectoryAction() {
super("Go Up");
}
}
}
/**
* Responds to an Open or Save request
*/
protected ApproveSelectionAction() {
super(FilePane.ACTION_APPROVE_SELECTION);
}
if (isDirectorySelected()) {
try {
// Strip trailing ".."
} catch (IOException ex) {
// Ok, use f as is
}
return;
}
}
// Remove whitespaces from end of filename
i--;
}
}
// no file selected, multiple selection off, therefore cancel the approve action
return;
}
// Unix: Resolve '~' to user's home directory
}
}
// Optimize searching files by names in "children" array
int childIndex = 0;
if (!file.isAbsolute()) {
}
childIndex = l + 1;
break;
}
}
}
}
}
} else {
if (!selectedFile.isAbsolute()) {
}
// check for wildcard pattern
if (globFilter == null) {
globFilter = new GlobFilter();
}
try {
if (!(currentFilter instanceof GlobFilter)) {
}
return;
} catch (PatternSyntaxException pse) {
// Not a valid glob pattern. Abandon filter.
}
}
// Check for directory change action
return;
} else if ((isDir || !isFileSelEnabled)
&& (!isDir || !isDirSelEnabled)
selectedFile = null;
}
}
if (selectedFiles == null) {
}
// Do it again. This is a fix for bug 4949273 to force the
// selected value in case the ListSelectionModel clears it
// for non-existing file names.
} else {
}
} else {
if (chooser.isMultiSelectionEnabled()) {
} else {
}
}
}
}
private void resetGlobFilter() {
if (actualFileFilter != null) {
}
}
}
}
/* A file filter which accepts file patterns containing
* the special wildcards *? on Windows and *?[] on Unix.
*/
boolean inBrackets = false;
int j = 0;
this.globPattern = globPattern;
if (isWin32) {
// On windows, a pattern ending with *.* is equal to ending with *
len -= 2;
}
for (int i = 0; i < len; i++) {
switch(gPat[i]) {
case '*':
rPat[j++] = '.';
rPat[j++] = '*';
break;
case '?':
rPat[j++] = '.';
break;
case '\\':
rPat[j++] = '\\';
rPat[j++] = '\\';
break;
default:
rPat[j++] = '\\';
}
break;
}
}
} else {
switch(gPat[i]) {
case '*':
if (!inBrackets) {
rPat[j++] = '.';
}
rPat[j++] = '*';
break;
case '?':
break;
case '[':
inBrackets = true;
switch (gPat[i+1]) {
case '!':
case '^':
rPat[j++] = '^';
i++;
break;
case ']':
break;
}
}
break;
case ']':
inBrackets = false;
break;
case '\\':
} else {
rPat[j++] = '\\';
} else {
rPat[j++] = '\\';
}
}
break;
default:
//if ("+()|^$.{}<>".indexOf(gPat[i]) >= 0) {
rPat[j++] = '\\';
}
break;
}
}
}
}
if (f == null) {
return false;
}
if (f.isDirectory()) {
return true;
}
}
return globPattern;
}
}
/**
* Responds to a cancel request.
*/
}
}
/**
* Rescans the files in the current directory
*/
}
}
// Traverse shortcuts on Windows
try {
if (shellFolder.isLink()) {
// If linkedTo is null we try to use dir
} else {
return;
}
} else {
dir = shellFolder;
}
}
} catch (FileNotFoundException ex) {
return;
}
}
}
}
// *****************************************
// ***** default AcceptAll file filter *****
// *****************************************
public AcceptAllFileFilter() {
}
return true;
}
}
}
// ***********************
// * FileView operations *
// ***********************
/* FileView type descriptions */
// PENDING(jeff) - pass in the icon cache size
public BasicFileView() {
}
public void clearIconCache() {
}
// Note: Returns display name rather than file name
if(f != null) {
}
return fileName;
}
return f.getName();
}
if (f.isDirectory()) {
} else {
}
}
return type;
}
}
return;
}
}
return icon;
}
if (f != null) {
if (fsv.isFloppyDrive(f)) {
} else if (fsv.isComputerNode(f)) {
icon = computerIcon;
} else if (f.isDirectory()) {
}
}
return icon;
}
} else {
}
}
}
/**
* Data transfer support for the file chooser. Since files are currently presented
* as a list, the list support is reused with the added flavor of DataFlavor.javaFileListFlavor
*/
/**
* Create a Transferable to use as the source for a data transfer.
*
* @param c The component holding the data to be transfered. This
* argument is provided to enable sharing of TransferHandlers by
* multiple components.
* @return The representation of the data to be transfered.
*
*/
if (c instanceof JList) {
} else if (c instanceof JTable) {
}
}
}
return null;
}
}
// remove the last newline
}
return COPY;
}
}
/**
* Best format of the file chooser is DataFlavor.javaFileListFlavor.
*/
return flavors;
}
/**
* The only richer format supported is the file list flavor
*/
}
return files;
}
return null;
}
}
}
}