/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
*
* A demo which makes extensive use of the file chooser.
*
* @author Jeff Dinkins
*/
@SuppressWarnings("serial")
new ArrayList<SupportedLaF>();
private static class SupportedLaF {
}
return name;
}
}
@SuppressWarnings("LeakingThisInConstructor")
public FileChooserDemo() {
try {
if (laf.isSupportedLookAndFeel()) {
}
}
// If ANYTHING weird happens, don't add this L&F
}
}
chooser = new JFileChooser();
// Create Custom FileView
fileView = new ExampleFileView();
"/resources/images/jpgIcon.jpg")));
"/resources/images/gifIcon.gif")));
// Create Custom FileSystemView
fileSystemView = new ExampleFileSystemView();
// create a radio listener to listen to option changes
// Create options
openRadioButton.setSelected(true);
public Dimension getMaximumSize() {
}
};
customField.setEnabled(false);
// filter buttons
accessoryCheckBox.setSelected(false);
// more options
useFileViewCheckBox.setSelected(false);
useEmbedInWizardCheckBox.setSelected(false);
useControlsCheckBox.setSelected(true);
// File or Directory chooser options
justFilesRadioButton.setSelected(true);
"Select Files or Directories");
// Create show button
showButton.addActionListener(this);
// Create laf combo box
lafComboBox.setEditable(false);
// ********************************************************
// ******************** Dialog Type ***********************
// ********************************************************
// ********************************************************
// ***************** Filter Controls **********************
// ********************************************************
// ********************************************************
// ****************** Display Options *********************
// ********************************************************
// ********************************************************
// ************* File & Directory Options *****************
// ********************************************************
"File and Directory Options"));
// ********************************************************
// **************** Look & Feel Switch ********************
// ********************************************************
// ********************************************************
// ****************** Wrap 'em all up *********************
// ********************************************************
}
if (customButton.isSelected()) {
}
if (chooser.isMultiSelectionEnabled()) {
} else {
}
// clear the preview from the previous display of the chooser
}
if (useEmbedInWizardCheckBox.isSelected()) {
wizard.setVisible(true);
return;
}
if (retval == APPROVE_OPTION) {
} else if (retval == CANCEL_OPTION) {
"User cancelled operation. No file was chosen.");
} else if (retval == ERROR_OPTION) {
"An error occured. No file was chosen.");
} else {
}
}
boolean showExtensionInDescription) {
if (enableFilters) {
"JPEG Compressed Image Files",
showExtensionInDescription, "jpg");
showExtensionInDescription, "gif");
showExtensionInDescription, "jpg",
"gif");
}
}
if (showExtensionInDescription) {
}
}
+ " (";
// build the description from the extension list
fullDescription += ", .";
fullDescription += extensions[i];
}
fullDescription += ")";
return fullDescription;
}
@SuppressWarnings("LeakingThisInConstructor")
cardLayout = new CardLayout();
chooser.addActionListener(this);
backButton.setEnabled(false);
backButton.addActionListener(this);
nextButton.addActionListener(this);
closeButton.addActionListener(this);
pack();
}
if (src == backButton) {
back();
} else if (src == nextButton) {
if (ui instanceof BasicFileChooserUI) {
// Workaround for bug 4528663. This is necessary to
// pick up the contents of the file chooser text field.
// This will trigger an APPROVE_SELECTION action.
} else {
next();
}
} else if (src == closeButton) {
close();
next();
close();
}
}
private void back() {
backButton.setEnabled(false);
nextButton.setEnabled(true);
}
private void next() {
backButton.setEnabled(true);
nextButton.setEnabled(false);
}
private void close() {
setVisible(false);
}
public void dispose() {
chooser.removeActionListener(this);
// The chooser is hidden by CardLayout on remove
// so fix it here
chooser.setVisible(true);
super.dispose();
}
}
filter = "";
} else {
}
if (isMulti) {
path = "";
}
}
} else {
}
}
? "directories" : "directory")
+ "</code><br><br>with filter: <br><code>" + filter;
} else {
resultString = "Nothing was chosen";
}
return resultString;
}
/** An ActionListener that listens to the radio buttons. */
boolean selected = false;
if (c instanceof JToggleButton) {
}
if (c == openRadioButton) {
customField.setEnabled(false);
repaint();
} else if (c == useEmbedInWizardCheckBox) {
} else if (c == useControlsCheckBox) {
} else if (c == enableDragCheckBox) {
} else if (c == saveRadioButton) {
customField.setEnabled(false);
repaint();
} else if (c == customButton || c == customField) {
customField.setEnabled(true);
repaint();
} else if (c == showAllFilesFilterCheckBox) {
} else if (c == showImageFilesFilterCheckBox) {
} else if (c == setHiddenCheckBox) {
} else if (c == accessoryCheckBox) {
if (selected) {
} else {
}
} else if (c == useFileViewCheckBox) {
if (selected) {
} else {
}
} else if (c == useFileSystemViewCheckBox) {
if (selected) {
} else {
// Restore default behaviour
}
} else if (c == showFullDescriptionCheckBox) {
selected);
} else if (c == justFilesRadioButton) {
} else if (c == justDirectoriesRadioButton) {
} else if (c == bothFilesAndDirectoriesRadioButton) {
} else if (c == singleSelectionRadioButton) {
if (selected) {
chooser.setMultiSelectionEnabled(false);
}
} else if (c == multiSelectionRadioButton) {
if (selected) {
chooser.setMultiSelectionEnabled(true);
}
} else if (c == lafComboBox) {
getSelectedItem());
try {
}
} catch (UnsupportedLookAndFeelException exc) {
// This should not happen because we already checked
}
}
}
}
@SuppressWarnings("LeakingThisInConstructor")
fc.addPropertyChangeListener(this);
}
if (f == null) {
} else {
} else {
}
}
}
if (isShowing()) {
repaint();
}
}
}
if (y < 0) {
y = 0;
}
if (x < 5) {
x = 5;
}
}
}
}
try {
public void run() {
/*
* NOTE: By default, the look and feel will be set to the
* Cross Platform Look and Feel (which is currently Metal).
* The following code tries to set the Look and Feel to Nimbus.
*/
try {
break;
}
}
}
frame.setVisible(true);
}
});
} catch (InterruptedException ex) {
null,
ex);
} catch (InvocationTargetException ex) {
null,
ex);
}
}
Insets i;
this.i = i;
}
return i;
}
}
}