src/demo/share/jfc/FileChooserDemo/FileChooserDemo.java
author jcm
Mon, 06 Nov 2017 21:28:03 -0800
changeset 47799 1772ebf07d1f
parent 47216 71c04702a3d5
child 52252 de9486d74a74
permissions -rw-r--r--
8152470: Add COMPILER2_OR_JVMCI definition Summary: defined(COMPILER2) || INCLUDE_JVMCI changed replaced with COMPILER2_OR_JVMCI Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21591
diff changeset
     2
 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8968
diff changeset
    32
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8968
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8968
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8968
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8968
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8968
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8968
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8968
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8968
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    42
import java.lang.reflect.InvocationTargetException;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    43
import java.util.logging.Level;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    44
import java.util.logging.Logger;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    45
import javax.swing.UIManager.LookAndFeelInfo;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    46
import java.awt.BorderLayout;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    47
import java.awt.CardLayout;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    48
import java.awt.Component;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    49
import java.awt.Dimension;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    50
import java.awt.Graphics;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    51
import java.awt.Image;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    52
import java.awt.Insets;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    53
import java.awt.event.ActionEvent;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    54
import java.awt.event.ActionListener;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    55
import java.beans.PropertyChangeEvent;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    56
import java.beans.PropertyChangeListener;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    57
import java.util.List;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    58
import javax.swing.BorderFactory;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    59
import javax.swing.Box;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    60
import javax.swing.BoxLayout;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    61
import javax.swing.ButtonGroup;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    62
import javax.swing.DefaultComboBoxModel;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    63
import javax.swing.ImageIcon;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    64
import javax.swing.JButton;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    65
import javax.swing.JCheckBox;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    66
import javax.swing.JComboBox;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    67
import javax.swing.JComponent;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    68
import javax.swing.JDialog;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    69
import javax.swing.JFileChooser;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    70
import javax.swing.JFrame;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    71
import javax.swing.JLabel;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    72
import javax.swing.JOptionPane;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    73
import javax.swing.JPanel;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    74
import javax.swing.JRadioButton;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    75
import javax.swing.JTextField;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    76
import javax.swing.JToggleButton;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    77
import javax.swing.LookAndFeel;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    78
import javax.swing.SwingUtilities;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    79
import javax.swing.UIManager;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    80
import javax.swing.UnsupportedLookAndFeelException;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    81
import javax.swing.WindowConstants;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    82
import javax.swing.filechooser.FileFilter;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    83
import javax.swing.filechooser.FileNameExtensionFilter;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    84
import javax.swing.filechooser.FileSystemView;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    85
import java.util.ArrayList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
import javax.swing.plaf.FileChooserUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
import javax.swing.plaf.basic.BasicFileChooserUI;
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    88
import java.io.File;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    89
import static javax.swing.JFileChooser.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * A demo which makes extensive use of the file chooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 */
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
    98
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
public class FileChooserDemo extends JPanel implements ActionListener {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   100
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   101
    public static final String NIMBUS_LAF_NAME = "Nimbus";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static JFrame frame;
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   103
    private final List<SupportedLaF> supportedLaFs =
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   104
            new ArrayList<SupportedLaF>();
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   105
    private static SupportedLaF nimbusLaF;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static class SupportedLaF {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   109
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        private final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        private final LookAndFeel laf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        SupportedLaF(String name, LookAndFeel laf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            this.laf = laf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   118
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private JButton showButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private JCheckBox showAllFilesFilterCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private JCheckBox showImageFilesFilterCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private JCheckBox showFullDescriptionCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private JCheckBox useFileViewCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private JCheckBox useFileSystemViewCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private JCheckBox accessoryCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private JCheckBox setHiddenCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private JCheckBox useEmbedInWizardCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private JCheckBox useControlsCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private JCheckBox enableDragCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private JRadioButton singleSelectionRadioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private JRadioButton multiSelectionRadioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private JRadioButton openRadioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private JRadioButton saveRadioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private JRadioButton customButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private JComboBox lafComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private JRadioButton justFilesRadioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private JRadioButton justDirectoriesRadioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private JRadioButton bothFilesAndDirectoriesRadioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private JTextField customField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private final ExampleFileView fileView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private final ExampleFileSystemView fileSystemView;
32869
edd4354e4a09 8137059: Run blessed-modifier-order script on client demos and misc. sources
prr
parents: 25859
diff changeset
   146
    private static final Dimension hpad10 = new Dimension(10, 1);
edd4354e4a09 8137059: Run blessed-modifier-order script on client demos and misc. sources
prr
parents: 25859
diff changeset
   147
    private static final Dimension vpad20 = new Dimension(1, 20);
edd4354e4a09 8137059: Run blessed-modifier-order script on client demos and misc. sources
prr
parents: 25859
diff changeset
   148
    private static final Dimension vpad7 = new Dimension(1, 7);
edd4354e4a09 8137059: Run blessed-modifier-order script on client demos and misc. sources
prr
parents: 25859
diff changeset
   149
    private static final Dimension vpad4 = new Dimension(1, 4);
edd4354e4a09 8137059: Run blessed-modifier-order script on client demos and misc. sources
prr
parents: 25859
diff changeset
   150
    private static final Insets insets = new Insets(5, 10, 0, 10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private final FilePreviewer previewer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private final JFileChooser chooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   154
    @SuppressWarnings("LeakingThisInConstructor")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public FileChooserDemo() {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   156
        UIManager.LookAndFeelInfo[] installedLafs = UIManager.
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   157
                getInstalledLookAndFeels();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        for (UIManager.LookAndFeelInfo lafInfo : installedLafs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            try {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   160
                Class<?> lnfClass = Class.forName(lafInfo.getClassName());
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   161
                LookAndFeel laf = (LookAndFeel) (lnfClass.newInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                if (laf.isSupportedLookAndFeel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    String name = lafInfo.getName();
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   164
                    SupportedLaF supportedLaF = new SupportedLaF(name, laf);
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   165
                    supportedLaFs.add(supportedLaF);
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   166
                    if (NIMBUS_LAF_NAME.equals(name)) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   167
                        nimbusLaF = supportedLaF;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   168
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                }
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   170
            } catch (Exception ignored) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   171
                // If ANYTHING weird happens, don't add this L&F
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        chooser = new JFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        previewer = new FilePreviewer(chooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        // Create Custom FileView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        fileView = new ExampleFileView();
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   182
        fileView.putIcon("jpg", new ImageIcon(getClass().getResource(
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   183
                "/resources/images/jpgIcon.jpg")));
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   184
        fileView.putIcon("gif", new ImageIcon(getClass().getResource(
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   185
                "/resources/images/gifIcon.gif")));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // Create Custom FileSystemView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        fileSystemView = new ExampleFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        // create a radio listener to listen to option changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        OptionListener optionListener = new OptionListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        // Create options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        openRadioButton = new JRadioButton("Open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        openRadioButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        openRadioButton.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        saveRadioButton = new JRadioButton("Save");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        saveRadioButton.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        customButton = new JRadioButton("Custom");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        customButton.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        customField = new JTextField(8) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   205
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   206
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            public Dimension getMaximumSize() {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   208
                return new Dimension(getPreferredSize().width,
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   209
                        getPreferredSize().height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        customField.setText("Doit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        customField.setAlignmentY(JComponent.TOP_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        customField.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        customField.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        ButtonGroup group1 = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        group1.add(openRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        group1.add(saveRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        group1.add(customButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        // filter buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        showAllFilesFilterCheckBox = new JCheckBox("Show \"All Files\" Filter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        showAllFilesFilterCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        showAllFilesFilterCheckBox.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        showImageFilesFilterCheckBox = new JCheckBox("Show JPG and GIF Filters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        showImageFilesFilterCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        showImageFilesFilterCheckBox.setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        accessoryCheckBox = new JCheckBox("Show Preview");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        accessoryCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        accessoryCheckBox.setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        // more options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        setHiddenCheckBox = new JCheckBox("Show Hidden Files");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        setHiddenCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        showFullDescriptionCheckBox = new JCheckBox("With File Extensions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        showFullDescriptionCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        showFullDescriptionCheckBox.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        showFullDescriptionCheckBox.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        useFileViewCheckBox = new JCheckBox("Use FileView");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        useFileViewCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        useFileViewCheckBox.setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        useFileSystemViewCheckBox = new JCheckBox("Use FileSystemView", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        useFileSystemViewCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        useEmbedInWizardCheckBox = new JCheckBox("Embed in Wizard");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        useEmbedInWizardCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        useEmbedInWizardCheckBox.setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        useControlsCheckBox = new JCheckBox("Show Control Buttons");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        useControlsCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        useControlsCheckBox.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        enableDragCheckBox = new JCheckBox("Enable Dragging");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        enableDragCheckBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        // File or Directory chooser options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        ButtonGroup group3 = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        justFilesRadioButton = new JRadioButton("Just Select Files");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        justFilesRadioButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        group3.add(justFilesRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        justFilesRadioButton.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        justDirectoriesRadioButton = new JRadioButton("Just Select Directories");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        group3.add(justDirectoriesRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        justDirectoriesRadioButton.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   273
        bothFilesAndDirectoriesRadioButton = new JRadioButton(
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   274
                "Select Files or Directories");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        group3.add(bothFilesAndDirectoriesRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        bothFilesAndDirectoriesRadioButton.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        singleSelectionRadioButton = new JRadioButton("Single Selection", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        singleSelectionRadioButton.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        multiSelectionRadioButton = new JRadioButton("Multi Selection");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        multiSelectionRadioButton.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        ButtonGroup group4 = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        group4.add(singleSelectionRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        group4.add(multiSelectionRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // Create show button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        showButton = new JButton("Show FileChooser");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        showButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        showButton.setMnemonic('s');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // Create laf combo box
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   295
        lafComboBox = new JComboBox(supportedLaFs.toArray());
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   296
        lafComboBox.setSelectedItem(nimbusLaF);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        lafComboBox.setEditable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        lafComboBox.addActionListener(optionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        // ******************** Dialog Type ***********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        JPanel control1 = new InsetPanel(insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        control1.setBorder(BorderFactory.createTitledBorder("Dialog Type"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        control1.setLayout(new BoxLayout(control1, BoxLayout.Y_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        control1.add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        control1.add(openRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        control1.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        control1.add(saveRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        control1.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        control1.add(customButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        control1.add(Box.createRigidArea(vpad4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        JPanel fieldWrapper = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        fieldWrapper.setLayout(new BoxLayout(fieldWrapper, BoxLayout.X_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        fieldWrapper.setAlignmentX(Component.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        fieldWrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        fieldWrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        fieldWrapper.add(customField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        control1.add(fieldWrapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        control1.add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        control1.add(Box.createGlue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        // ***************** Filter Controls **********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        JPanel control2 = new InsetPanel(insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        control2.setBorder(BorderFactory.createTitledBorder("Filter Controls"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        control2.setLayout(new BoxLayout(control2, BoxLayout.Y_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        control2.add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        control2.add(showAllFilesFilterCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        control2.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        control2.add(showImageFilesFilterCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        control2.add(Box.createRigidArea(vpad4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        JPanel checkWrapper = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        checkWrapper.setLayout(new BoxLayout(checkWrapper, BoxLayout.X_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        checkWrapper.setAlignmentX(Component.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        checkWrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        checkWrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        checkWrapper.add(showFullDescriptionCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        control2.add(checkWrapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        control2.add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        control2.add(Box.createGlue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // ****************** Display Options *********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        JPanel control3 = new InsetPanel(insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        control3.setBorder(BorderFactory.createTitledBorder("Display Options"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        control3.setLayout(new BoxLayout(control3, BoxLayout.Y_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        control3.add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        control3.add(setHiddenCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        control3.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        control3.add(useFileViewCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        control3.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        control3.add(useFileSystemViewCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        control3.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        control3.add(accessoryCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        control3.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        control3.add(useEmbedInWizardCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        control3.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        control3.add(useControlsCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        control3.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        control3.add(enableDragCheckBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        control3.add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        control3.add(Box.createGlue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        // ************* File & Directory Options *****************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        JPanel control4 = new InsetPanel(insets);
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   372
        control4.setBorder(BorderFactory.createTitledBorder(
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   373
                "File and Directory Options"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        control4.setLayout(new BoxLayout(control4, BoxLayout.Y_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        control4.add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        control4.add(justFilesRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        control4.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        control4.add(justDirectoriesRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        control4.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        control4.add(bothFilesAndDirectoriesRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        control4.add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        control4.add(singleSelectionRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        control4.add(Box.createRigidArea(vpad7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        control4.add(multiSelectionRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        control4.add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        control4.add(Box.createGlue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        // **************** Look & Feel Switch ********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        JPanel panel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        panel.add(new JLabel("Look and Feel: "));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        panel.add(lafComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        panel.add(showButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        // ****************** Wrap 'em all up *********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        // ********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        JPanel wrapper = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        wrapper.setLayout(new BoxLayout(wrapper, BoxLayout.X_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        wrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        wrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        wrapper.add(control1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        wrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        wrapper.add(control2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        wrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        wrapper.add(control3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        wrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        wrapper.add(control4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        wrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        wrapper.add(Box.createRigidArea(hpad10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        add(wrapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        add(panel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        add(Box.createRigidArea(vpad20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (customButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            chooser.setApproveButtonText(customField.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        if (chooser.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            chooser.setSelectedFiles(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            chooser.setSelectedFile(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        // clear the preview from the previous display of the chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        JComponent accessory = chooser.getAccessory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (accessory != null) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   435
            ((FilePreviewer) accessory).loadImage(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        if (useEmbedInWizardCheckBox.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            WizardDialog wizard = new WizardDialog(frame, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            wizard.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            wizard.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        int retval = chooser.showDialog(frame, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        if (retval == APPROVE_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            JOptionPane.showMessageDialog(frame, getResultString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        } else if (retval == CANCEL_OPTION) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   449
            JOptionPane.showMessageDialog(frame,
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   450
                    "User cancelled operation. No file was chosen.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        } else if (retval == ERROR_OPTION) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   452
            JOptionPane.showMessageDialog(frame,
21591
35320b590d9b 8026491: Typos in string literals
malenkov
parents: 20455
diff changeset
   453
                    "An error occurred. No file was chosen.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        } else {
21591
35320b590d9b 8026491: Typos in string literals
malenkov
parents: 20455
diff changeset
   455
            JOptionPane.showMessageDialog(frame, "Unknown operation occurred.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    private void resetFileFilters(boolean enableFilters,
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   460
            boolean showExtensionInDescription) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        chooser.resetChoosableFileFilters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if (enableFilters) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   463
            FileFilter jpgFilter = createFileFilter(
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   464
                    "JPEG Compressed Image Files",
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   465
                    showExtensionInDescription, "jpg");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            FileFilter gifFilter = createFileFilter("GIF Image Files",
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   467
                    showExtensionInDescription, "gif");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            FileFilter bothFilter = createFileFilter("JPEG and GIF Image Files",
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   469
                    showExtensionInDescription, "jpg",
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   470
                    "gif");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            chooser.addChoosableFileFilter(bothFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            chooser.addChoosableFileFilter(jpgFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            chooser.addChoosableFileFilter(gifFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    private FileFilter createFileFilter(String description,
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   478
            boolean showExtensionInDescription, String... extensions) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (showExtensionInDescription) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            description = createFileNameFilterDescriptionFromExtensions(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    description, extensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return new FileNameExtensionFilter(description, extensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    private String createFileNameFilterDescriptionFromExtensions(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            String description, String[] extensions) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   488
        String fullDescription = (description == null) ? "(" : description
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   489
                + " (";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        // build the description from the extension list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        fullDescription += "." + extensions[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        for (int i = 1; i < extensions.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            fullDescription += ", .";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            fullDescription += extensions[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        fullDescription += ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return fullDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   500
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    private class WizardDialog extends JDialog implements ActionListener {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   502
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        CardLayout cardLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        JPanel cardPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        JLabel messageLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        JButton backButton, nextButton, closeButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   508
        @SuppressWarnings("LeakingThisInConstructor")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        WizardDialog(JFrame frame, boolean modal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            super(frame, "Embedded JFileChooser Demo", modal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            cardLayout = new CardLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            cardPanel = new JPanel(cardLayout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            getContentPane().add(cardPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            messageLabel = new JLabel("", JLabel.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            cardPanel.add(chooser, "fileChooser");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            cardPanel.add(messageLabel, "label");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            cardLayout.show(cardPanel, "fileChooser");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            chooser.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            JPanel buttonPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            backButton = new JButton("< Back");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            nextButton = new JButton("Next >");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            closeButton = new JButton("Close");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            buttonPanel.add(backButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            buttonPanel.add(nextButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            buttonPanel.add(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            getContentPane().add(buttonPanel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            backButton.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            getRootPane().setDefaultButton(nextButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            backButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            nextButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            closeButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            setLocationRelativeTo(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            Object src = evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            String cmd = evt.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            if (src == backButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                back();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            } else if (src == nextButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                FileChooserUI ui = chooser.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                if (ui instanceof BasicFileChooserUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    // Workaround for bug 4528663. This is necessary to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    // pick up the contents of the file chooser text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    // This will trigger an APPROVE_SELECTION action.
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   556
                    ((BasicFileChooserUI) ui).getApproveSelectionAction().
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   557
                            actionPerformed(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            } else if (src == closeButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                close();
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   563
            } else if (APPROVE_SELECTION.equals(cmd)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                next();
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   565
            } else if (CANCEL_SELECTION.equals(cmd)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        private void back() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            backButton.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            nextButton.setEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            cardLayout.show(cardPanel, "fileChooser");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            getRootPane().setDefaultButton(nextButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            chooser.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        private void next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            backButton.setEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            nextButton.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            messageLabel.setText(getResultString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            cardLayout.show(cardPanel, "label");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            getRootPane().setDefaultButton(closeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            closeButton.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        private void close() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   591
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            chooser.removeActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            // The chooser is hidden by CardLayout on remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            // so fix it here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            cardPanel.remove(chooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            chooser.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    private String getResultString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        String resultString;
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   606
        String filter;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   607
        if (chooser.getFileFilter() == null) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   608
            filter = "";
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   609
        } else {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   610
            filter = chooser.getFileFilter().getDescription();
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   611
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        String path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        boolean isDirMode = (chooser.getFileSelectionMode() == DIRECTORIES_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        boolean isMulti = chooser.isMultiSelectionEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if (isMulti) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   617
            File[] files = chooser.getSelectedFiles();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            if (files != null && files.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                path = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                for (File file : files) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    path = path + "<br>" + file.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            File file = chooser.getSelectedFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            if (file != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                path = "<br>" + file.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            path = path.replace(" ", "&nbsp;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            filter = filter.replace(" ", "&nbsp;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            resultString =
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   634
                    "<html>You chose " + (isMulti ? "these" : "this") + " " + (isDirMode ? (isMulti
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   635
                    ? "directories" : "directory")
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   636
                    : (isMulti ? "files" : "file")) + ": <code>" + path
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   637
                    + "</code><br><br>with filter: <br><code>" + filter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            resultString = "Nothing was chosen";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        return resultString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    /** An ActionListener that listens to the radio buttons. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    private class OptionListener implements ActionListener {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   647
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            JComponent c = (JComponent) e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            boolean selected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            if (c instanceof JToggleButton) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   652
                selected = ((JToggleButton) c).isSelected();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            if (c == openRadioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                chooser.setDialogType(OPEN_DIALOG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                customField.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            } else if (c == useEmbedInWizardCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                useControlsCheckBox.setEnabled(!selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                useControlsCheckBox.setSelected(!selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                chooser.setControlButtonsAreShown(!selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            } else if (c == useControlsCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                chooser.setControlButtonsAreShown(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            } else if (c == enableDragCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                chooser.setDragEnabled(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            } else if (c == saveRadioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                chooser.setDialogType(SAVE_DIALOG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                customField.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            } else if (c == customButton || c == customField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                customField.setEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                chooser.setDialogType(CUSTOM_DIALOG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            } else if (c == showAllFilesFilterCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                chooser.setAcceptAllFileFilterUsed(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            } else if (c == showImageFilesFilterCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                resetFileFilters(selected,
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   679
                        showFullDescriptionCheckBox.isSelected());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                showFullDescriptionCheckBox.setEnabled(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            } else if (c == setHiddenCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                chooser.setFileHidingEnabled(!selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            } else if (c == accessoryCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    chooser.setAccessory(previewer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    chooser.setAccessory(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            } else if (c == useFileViewCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    chooser.setFileView(fileView);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                    chooser.setFileView(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            } else if (c == useFileSystemViewCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    chooser.setFileSystemView(fileSystemView);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    // Restore default behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    chooser.setFileSystemView(FileSystemView.getFileSystemView());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            } else if (c == showFullDescriptionCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                resetFileFilters(showImageFilesFilterCheckBox.isSelected(),
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   704
                        selected);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            } else if (c == justFilesRadioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                chooser.setFileSelectionMode(FILES_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            } else if (c == justDirectoriesRadioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                chooser.setFileSelectionMode(DIRECTORIES_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            } else if (c == bothFilesAndDirectoriesRadioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                chooser.setFileSelectionMode(FILES_AND_DIRECTORIES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            } else if (c == singleSelectionRadioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    chooser.setMultiSelectionEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            } else if (c == multiSelectionRadioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    chooser.setMultiSelectionEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            } else if (c == lafComboBox) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   720
                SupportedLaF supportedLaF = ((SupportedLaF) lafComboBox.
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   721
                        getSelectedItem());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                LookAndFeel laf = supportedLaF.laf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                    UIManager.setLookAndFeel(laf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                    SwingUtilities.updateComponentTreeUI(frame);
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   726
                    if (chooser != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                        SwingUtilities.updateComponentTreeUI(chooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    frame.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                } catch (UnsupportedLookAndFeelException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                    // This should not happen because we already checked
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   732
                    ((DefaultComboBoxModel) lafComboBox.getModel()).
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   733
                            removeElement(supportedLaF);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   740
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   741
    private class FilePreviewer extends JComponent implements
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   742
            PropertyChangeListener {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   743
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        ImageIcon thumbnail = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   746
        @SuppressWarnings("LeakingThisInConstructor")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        public FilePreviewer(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            setPreferredSize(new Dimension(100, 50));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            fc.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        public void loadImage(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                thumbnail = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                ImageIcon tmpIcon = new ImageIcon(f.getPath());
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   757
                if (tmpIcon.getIconWidth() > 90) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                    thumbnail = new ImageIcon(
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   759
                            tmpIcon.getImage().getScaledInstance(90, -1,
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   760
                            Image.SCALE_DEFAULT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                    thumbnail = tmpIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            String prop = e.getPropertyName();
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   769
            if (SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   770
                if (isShowing()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    loadImage((File) e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   777
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        public void paint(Graphics g) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   779
            if (thumbnail != null) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   780
                int x = getWidth() / 2 - thumbnail.getIconWidth() / 2;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   781
                int y = getHeight() / 2 - thumbnail.getIconHeight() / 2;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   782
                if (y < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   786
                if (x < 5) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    x = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                thumbnail.paintIcon(this, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    public static void main(String s[]) {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   795
        try {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   796
            SwingUtilities.invokeAndWait(new Runnable() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   798
                public void run() {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   799
                    /*
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   800
                     * NOTE: By default, the look and feel will be set to the
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   801
                     * Cross Platform Look and Feel (which is currently Metal).
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   802
                     * The following code tries to set the Look and Feel to Nimbus.
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 10292
diff changeset
   803
                     * http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   804
                     */
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   805
                    try {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   806
                        for (LookAndFeelInfo info : UIManager.
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   807
                                getInstalledLookAndFeels()) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   808
                            if (NIMBUS_LAF_NAME.equals(info.getName())) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   809
                                UIManager.setLookAndFeel(info.getClassName());
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   810
                                break;
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   811
                            }
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   812
                        }
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   813
                    } catch (Exception ignored) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   814
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   816
                    FileChooserDemo panel = new FileChooserDemo();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   818
                    frame = new JFrame("FileChooserDemo");
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   819
                    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   820
                    frame.getContentPane().add("Center", panel);
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   821
                    frame.pack();
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   822
                    frame.setVisible(true);
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   823
                }
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   824
            });
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   825
        } catch (InterruptedException ex) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   826
            Logger.getLogger(FileChooserDemo.class.getName()).log(Level.SEVERE,
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   827
                    null,
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   828
                    ex);
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   829
        } catch (InvocationTargetException ex) {
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   830
            Logger.getLogger(FileChooserDemo.class.getName()).log(Level.SEVERE,
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   831
                    null,
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   832
                    ex);
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   833
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   836
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    private static class InsetPanel extends JPanel {
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   838
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        Insets i;
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   840
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        InsetPanel(Insets i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            this.i = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        }
8968
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   844
46991a517c09 7027694: /jfc/FileChooserDemo demo needs to be improved
mrkam
parents: 5506
diff changeset
   845
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
}