PageRenderTime 72ms CodeModel.GetById 9ms app.highlight 56ms RepoModel.GetById 1ms app.codeStats 1ms

/GtkJFileChooser/demo/com/google/code/gtkjfilechooser/demo/FileChooserDemo.java

http://gtkjfilechooser.googlecode.com/
Java | 666 lines | 491 code | 89 blank | 86 comment | 99 complexity | 72c7ecfb1c8a14eee3ec819085c332b4 MD5 | raw file
  1/*******************************************************************************
  2 * Copyright (c) 2010 Costantino Cerbo.
  3 * All rights reserved. This program and the accompanying materials
  4 * are made available under the terms of the GNU Lesser Public License v2.1
  5 * which accompanies this distribution, and is available at
  6 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  7 * 
  8 * Contributors:
  9 *     Costantino Cerbo - initial API and implementation
 10 *     Yuvi Masory - Issue 69
 11 ******************************************************************************/
 12package com.google.code.gtkjfilechooser.demo;
 13
 14/*
 15 * @(#)FileChooserDemo.java	1.31 06/02/03
 16 * 
 17 * Copyright 2006, 2009006 Sun Microsystems, Inc. All Rights Reserved.
 18 * 
 19 * Redistribution and use in source and binary forms, with or without
 20 * modification, are permitted provided that the following conditions are met:
 21 * 
 22 * -Redistribution of source code must retain the above copyright notice, this
 23 *  list of conditions and the following disclaimer.
 24 * 
 25 * -Redistribution in binary form must reproduce the above copyright notice, 
 26 *  this list of conditions and the following disclaimer in the documentation
 27 *  and/or other materials provided with the distribution.
 28 * 
 29 * Neither the name of Sun Microsystems, Inc. or the names of contributors may 
 30 * be used to endorse or promote products derived from this software without 
 31 * specific prior written permission.
 32 * 
 33 * This software is provided "AS IS," without a warranty of any kind. ALL 
 34 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 35 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 36 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
 37 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 38 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 39 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST 
 40 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, 
 41 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY 
 42 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, 
 43 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 44 * 
 45 * You acknowledge that this software is not designed, licensed or intended
 46 * for use in the design, construction, operation or maintenance of any
 47 * nuclear facility.
 48 */
 49
 50/*
 51 * @(#)FileChooserDemo.java	1.31 06/02/03
 52 */
 53
 54import static javax.swing.JFileChooser.*;
 55
 56import java.awt.BorderLayout;
 57import java.awt.CardLayout;
 58import java.awt.Component;
 59import java.awt.Dimension;
 60import java.awt.Insets;
 61import java.awt.Toolkit;
 62import java.awt.event.ActionEvent;
 63import java.awt.event.ActionListener;
 64import java.awt.event.WindowAdapter;
 65import java.awt.event.WindowEvent;
 66import java.io.File;
 67
 68import javax.swing.BorderFactory;
 69import javax.swing.Box;
 70import javax.swing.BoxLayout;
 71import javax.swing.ButtonGroup;
 72import javax.swing.JButton;
 73import javax.swing.JCheckBox;
 74import javax.swing.JComponent;
 75import javax.swing.JDialog;
 76import javax.swing.JFileChooser;
 77import javax.swing.JFrame;
 78import javax.swing.JLabel;
 79import javax.swing.JOptionPane;
 80import javax.swing.JPanel;
 81import javax.swing.JRadioButton;
 82import javax.swing.JTextField;
 83import javax.swing.JToggleButton;
 84import javax.swing.UIManager;
 85import javax.swing.filechooser.FileFilter;
 86import javax.swing.filechooser.FileNameExtensionFilter;
 87import javax.swing.plaf.FileChooserUI;
 88import javax.swing.plaf.basic.BasicFileChooserUI;
 89
 90import com.google.code.gtkjfilechooser.GtkFileChooserSettings;
 91import com.google.code.gtkjfilechooser.ui.ImagePreviewer;
 92import com.sun.java.swing.plaf.gtk.GTKLookAndFeel;
 93
 94
 95/**
 96 * 
 97 * A demo which makes extensive use of the file chooser.
 98 * 
 99 * 1.31 02/03/06
100 * 
101 * @author Jeff Dinkins
102 */
103public class FileChooserDemo extends JPanel implements ActionListener {
104	static JFrame frame;
105
106	JButton showButton;
107
108	JCheckBox showAllFilesFilterCheckBox;
109	JCheckBox showImageFilesFilterCheckBox;
110	JCheckBox showFullDescriptionCheckBox;
111
112	JCheckBox previewCheckBox;
113	JCheckBox setHiddenCheckBox;
114	JCheckBox useEmbedInWizardCheckBox;
115	JCheckBox useControlsCheckBox;
116
117	JRadioButton singleSelectionRadioButton;
118	JRadioButton multiSelectionRadioButton;
119
120	JRadioButton openRadioButton;
121	JRadioButton saveRadioButton;
122	JRadioButton customButton;
123
124	JRadioButton justFilesRadioButton;
125	JRadioButton justDirectoriesRadioButton;
126	JRadioButton bothFilesAndDirectoriesRadioButton;
127
128	JTextField customField;
129
130	FileFilter jpgFilter, gifFilter, bothFilter;
131
132	JPanel buttonPanel;
133
134	public final static Dimension hpad10 = new Dimension(10, 1);
135	public final static Dimension vpad20 = new Dimension(1, 20);
136	public final static Dimension vpad7 = new Dimension(1, 7);
137	public final static Dimension vpad4 = new Dimension(1, 4);
138	public final static Insets insets = new Insets(5, 10, 0, 10);
139
140	ImagePreviewer previewer;
141	JFileChooser chooser;
142
143	public FileChooserDemo() {
144
145		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
146
147		chooser = new JFileChooser();
148		previewer = new ImagePreviewer(chooser);
149
150		// create a radio listener to listen to option changes
151		OptionListener optionListener = new OptionListener();
152
153		// Create options
154		openRadioButton = new JRadioButton("Open");
155		openRadioButton.setSelected(true);
156		openRadioButton.addActionListener(optionListener);
157
158		saveRadioButton = new JRadioButton("Save");
159		saveRadioButton.addActionListener(optionListener);
160
161		customButton = new JRadioButton("Custom");
162		customButton.addActionListener(optionListener);
163
164		customField = new JTextField(8) {
165			@Override
166			public Dimension getMaximumSize() {
167				return new Dimension(getPreferredSize().width, getPreferredSize().height);
168			}
169		};
170		customField.setText("Doit");
171		customField.setAlignmentY(JComponent.TOP_ALIGNMENT);
172		customField.setEnabled(false);
173		customField.addActionListener(optionListener);
174
175		ButtonGroup group1 = new ButtonGroup();
176		group1.add(openRadioButton);
177		group1.add(saveRadioButton);
178		group1.add(customButton);
179
180		// filter buttons
181		showAllFilesFilterCheckBox = new JCheckBox("Show \"All Files\" Filter");
182		showAllFilesFilterCheckBox.addActionListener(optionListener);
183		showAllFilesFilterCheckBox.setSelected(true);
184
185		showImageFilesFilterCheckBox = new JCheckBox("Show JPG and GIF Filters");
186		showImageFilesFilterCheckBox.addActionListener(optionListener);
187		showImageFilesFilterCheckBox.setSelected(false);
188
189		previewCheckBox = new JCheckBox("Show Preview");
190		previewCheckBox.addActionListener(optionListener);
191		previewCheckBox.setSelected(false);
192
193		// more options
194		setHiddenCheckBox = new JCheckBox("Show Hidden Files");
195		setHiddenCheckBox.setSelected(GtkFileChooserSettings.get().getShowHidden());
196
197		setHiddenCheckBox.addActionListener(optionListener);
198
199		showFullDescriptionCheckBox = new JCheckBox("With File Extensions");
200		showFullDescriptionCheckBox.addActionListener(optionListener);
201		showFullDescriptionCheckBox.setSelected(true);
202		showFullDescriptionCheckBox.setEnabled(false);
203
204		useEmbedInWizardCheckBox = new JCheckBox("Embed in Wizard");
205		useEmbedInWizardCheckBox.addActionListener(optionListener);
206		useEmbedInWizardCheckBox.setSelected(false);
207
208		useControlsCheckBox = new JCheckBox("Show Control Buttons");
209		useControlsCheckBox.addActionListener(optionListener);
210		useControlsCheckBox.setSelected(true);
211
212		// File or Directory chooser options
213		ButtonGroup group3 = new ButtonGroup();
214		justFilesRadioButton = new JRadioButton("Just Select Files");
215		justFilesRadioButton.setSelected(true);
216		group3.add(justFilesRadioButton);
217		justFilesRadioButton.addActionListener(optionListener);
218
219		justDirectoriesRadioButton = new JRadioButton("Just Select Directories");
220		group3.add(justDirectoriesRadioButton);
221		justDirectoriesRadioButton.addActionListener(optionListener);
222
223		bothFilesAndDirectoriesRadioButton = new JRadioButton(
224		"Select Files or Directories");
225		group3.add(bothFilesAndDirectoriesRadioButton);
226		bothFilesAndDirectoriesRadioButton.addActionListener(optionListener);
227
228		singleSelectionRadioButton = new JRadioButton("Single Selection", true);
229		singleSelectionRadioButton.addActionListener(optionListener);
230
231		multiSelectionRadioButton = new JRadioButton("Multi Selection");
232		multiSelectionRadioButton.addActionListener(optionListener);
233
234		ButtonGroup group4 = new ButtonGroup();
235		group4.add(singleSelectionRadioButton);
236		group4.add(multiSelectionRadioButton);
237
238		// Create show button
239		showButton = new JButton("Show FileChooser");
240		showButton.addActionListener(this);
241		showButton.setMnemonic('s');
242
243		// ********************************************************
244		// ******************** Dialog Type ***********************
245		// ********************************************************
246		JPanel control1 = new InsetPanel(insets);
247		control1.setBorder(BorderFactory.createTitledBorder("Dialog Type"));
248
249		control1.setLayout(new BoxLayout(control1, BoxLayout.Y_AXIS));
250		control1.add(Box.createRigidArea(vpad20));
251		control1.add(openRadioButton);
252		control1.add(Box.createRigidArea(vpad7));
253		control1.add(saveRadioButton);
254		control1.add(Box.createRigidArea(vpad7));
255		control1.add(customButton);
256		control1.add(Box.createRigidArea(vpad4));
257		JPanel fieldWrapper = new JPanel();
258		fieldWrapper.setLayout(new BoxLayout(fieldWrapper, BoxLayout.X_AXIS));
259		fieldWrapper.setAlignmentX(Component.LEFT_ALIGNMENT);
260		fieldWrapper.add(Box.createRigidArea(hpad10));
261		fieldWrapper.add(Box.createRigidArea(hpad10));
262		fieldWrapper.add(customField);
263		control1.add(fieldWrapper);
264		control1.add(Box.createRigidArea(vpad20));
265		control1.add(Box.createGlue());
266
267		// ********************************************************
268		// ***************** Filter Controls **********************
269		// ********************************************************
270		JPanel control2 = new InsetPanel(insets);
271		control2.setBorder(BorderFactory.createTitledBorder("Filter Controls"));
272		control2.setLayout(new BoxLayout(control2, BoxLayout.Y_AXIS));
273		control2.add(Box.createRigidArea(vpad20));
274		control2.add(showAllFilesFilterCheckBox);
275		control2.add(Box.createRigidArea(vpad7));
276		control2.add(showImageFilesFilterCheckBox);
277		control2.add(Box.createRigidArea(vpad4));
278		JPanel checkWrapper = new JPanel();
279		checkWrapper.setLayout(new BoxLayout(checkWrapper, BoxLayout.X_AXIS));
280		checkWrapper.setAlignmentX(Component.LEFT_ALIGNMENT);
281		checkWrapper.add(Box.createRigidArea(hpad10));
282		checkWrapper.add(Box.createRigidArea(hpad10));
283		checkWrapper.add(showFullDescriptionCheckBox);
284		control2.add(checkWrapper);
285		control2.add(Box.createRigidArea(vpad20));
286		control2.add(Box.createGlue());
287
288		// ********************************************************
289		// ****************** Display Options *********************
290		// ********************************************************
291		JPanel control3 = new InsetPanel(insets);
292		control3.setBorder(BorderFactory.createTitledBorder("Display Options"));
293		control3.setLayout(new BoxLayout(control3, BoxLayout.Y_AXIS));
294		control3.add(Box.createRigidArea(vpad20));
295		control3.add(setHiddenCheckBox);
296		control3.add(Box.createRigidArea(vpad7));
297		control3.add(previewCheckBox);
298		control3.add(Box.createRigidArea(vpad7));
299		control3.add(useEmbedInWizardCheckBox);
300		control3.add(Box.createRigidArea(vpad7));
301		control3.add(useControlsCheckBox);
302		control3.add(Box.createGlue());
303
304		// ********************************************************
305		// ************* File & Directory Options *****************
306		// ********************************************************
307		JPanel control4 = new InsetPanel(insets);
308		control4
309		.setBorder(BorderFactory.createTitledBorder("File and Directory Options"));
310		control4.setLayout(new BoxLayout(control4, BoxLayout.Y_AXIS));
311		control4.add(Box.createRigidArea(vpad20));
312		control4.add(justFilesRadioButton);
313		control4.add(Box.createRigidArea(vpad7));
314		control4.add(justDirectoriesRadioButton);
315		control4.add(Box.createRigidArea(vpad7));
316		control4.add(bothFilesAndDirectoriesRadioButton);
317		control4.add(Box.createRigidArea(vpad20));
318		control4.add(singleSelectionRadioButton);
319		control4.add(Box.createRigidArea(vpad7));
320		control4.add(multiSelectionRadioButton);
321		control4.add(Box.createRigidArea(vpad20));
322		control4.add(Box.createGlue());
323
324		JPanel panel = new JPanel();
325		panel.add(showButton);
326
327		// ********************************************************
328		// ****************** Wrap 'em all up *********************
329		// ********************************************************
330		JPanel wrapper = new JPanel();
331		wrapper.setLayout(new BoxLayout(wrapper, BoxLayout.X_AXIS));
332
333		add(Box.createRigidArea(vpad20));
334
335		wrapper.add(Box.createRigidArea(hpad10));
336		wrapper.add(Box.createRigidArea(hpad10));
337		wrapper.add(control1);
338		wrapper.add(Box.createRigidArea(hpad10));
339		wrapper.add(control2);
340		wrapper.add(Box.createRigidArea(hpad10));
341		wrapper.add(control3);
342		wrapper.add(Box.createRigidArea(hpad10));
343		wrapper.add(control4);
344		wrapper.add(Box.createRigidArea(hpad10));
345		wrapper.add(Box.createRigidArea(hpad10));
346
347		add(wrapper);
348		add(Box.createRigidArea(vpad20));
349		add(panel);
350		add(Box.createRigidArea(vpad20));
351	}
352
353	public void actionPerformed(ActionEvent e) {
354		if (customButton.isSelected()) {
355			chooser.setApproveButtonText(customField.getText());
356		}
357		if (chooser.isMultiSelectionEnabled()) {
358			chooser.setSelectedFiles(null);
359		} else {
360			chooser.setSelectedFile(null);
361		}
362		// clear the preview from the previous display of the chooser
363		JComponent accessory = chooser.getAccessory();
364		if (accessory != null) {
365			((ImagePreviewer) accessory).loadImage(null);
366		}
367
368		if (useEmbedInWizardCheckBox.isSelected()) {
369			WizardDialog wizard = new WizardDialog(frame, true);
370			wizard.setVisible(true);
371			wizard.dispose();
372			return;
373		}
374
375		int retval = chooser.showDialog(frame, null);
376		if (retval == APPROVE_OPTION) {
377			JOptionPane.showMessageDialog(frame, getResultString());
378		} else if (retval == CANCEL_OPTION) {
379			JOptionPane.showMessageDialog(frame,
380			"User cancelled operation. No file was chosen.");
381		} else if (retval == ERROR_OPTION) {
382			JOptionPane.showMessageDialog(frame, "An error occured. No file was chosen.");
383		} else {
384			JOptionPane.showMessageDialog(frame, "Unknown operation occured.");
385		}
386	}
387
388	private void resetFileFilters(boolean enableFilters,
389			boolean showExtensionInDescription) {
390		chooser.resetChoosableFileFilters();
391		if (enableFilters) {
392			jpgFilter = createFileFilter("JPEG Compressed Image Files",
393					showExtensionInDescription, "jpg");
394			gifFilter = createFileFilter("GIF Image Files", showExtensionInDescription,
395			"gif");
396			bothFilter = createFileFilter("JPEG and GIF Image Files",
397					showExtensionInDescription, "jpg", "gif");
398			chooser.addChoosableFileFilter(bothFilter);
399			chooser.addChoosableFileFilter(jpgFilter);
400			chooser.addChoosableFileFilter(gifFilter);
401		}
402	}
403
404	private FileFilter createFileFilter(String description,
405			boolean showExtensionInDescription, String... extensions) {
406		if (showExtensionInDescription) {
407			description = createFileNameFilterDescriptionFromExtensions(description,
408					extensions);
409		}
410		return new FileNameExtensionFilter(description, extensions);
411	}
412
413	private String createFileNameFilterDescriptionFromExtensions(String description,
414			String[] extensions) {
415		String fullDescription = (description == null) ? "(" : description + " (";
416		// build the description from the extension list
417		fullDescription += "." + extensions[0];
418		for (int i = 1; i < extensions.length; i++) {
419			fullDescription += ", .";
420			fullDescription += extensions[i];
421		}
422		fullDescription += ")";
423		return fullDescription;
424	}
425
426	class WizardDialog extends JDialog implements ActionListener {
427		CardLayout cardLayout;
428		JPanel cardPanel;
429		JLabel messageLabel;
430		JButton backButton, nextButton, closeButton;
431
432		WizardDialog(JFrame frame, boolean modal) {
433			super(frame, "Embedded JFileChooser Demo", modal);
434
435			cardLayout = new CardLayout();
436			cardPanel = new JPanel(cardLayout);
437			getContentPane().add(cardPanel, BorderLayout.CENTER);
438
439			messageLabel = new JLabel("", JLabel.CENTER);
440			cardPanel.add(chooser, "fileChooser");
441			cardPanel.add(messageLabel, "label");
442			cardLayout.show(cardPanel, "fileChooser");
443			chooser.addActionListener(this);
444
445			JPanel buttonPanel = new JPanel();
446			backButton = new JButton("< Back");
447			nextButton = new JButton("Next >");
448			closeButton = new JButton("Close");
449
450			buttonPanel.add(backButton);
451			buttonPanel.add(nextButton);
452			buttonPanel.add(closeButton);
453
454			getContentPane().add(buttonPanel, BorderLayout.SOUTH);
455
456			backButton.setEnabled(false);
457			getRootPane().setDefaultButton(nextButton);
458
459			backButton.addActionListener(this);
460			nextButton.addActionListener(this);
461			closeButton.addActionListener(this);
462
463			pack();
464			setLocationRelativeTo(frame);
465		}
466
467		public void actionPerformed(ActionEvent evt) {
468			Object src = evt.getSource();
469			String cmd = evt.getActionCommand();
470
471			if (src == backButton) {
472				back();
473			} else if (src == nextButton) {
474				FileChooserUI ui = chooser.getUI();
475				if (ui instanceof BasicFileChooserUI) {
476					// Workaround for bug 4528663. This is necessary to
477					// pick up the contents of the file chooser text field.
478					// This will trigger an APPROVE_SELECTION action.
479					((BasicFileChooserUI) ui).getApproveSelectionAction()
480					.actionPerformed(null);
481				} else {
482					next();
483				}
484			} else if (src == closeButton) {
485				close();
486			} else if (cmd == APPROVE_SELECTION) {
487				next();
488			} else if (cmd == CANCEL_SELECTION) {
489				close();
490			}
491		}
492
493		private void back() {
494			backButton.setEnabled(false);
495			nextButton.setEnabled(true);
496			cardLayout.show(cardPanel, "fileChooser");
497			getRootPane().setDefaultButton(nextButton);
498			chooser.requestFocus();
499		}
500
501		private void next() {
502			backButton.setEnabled(true);
503			nextButton.setEnabled(false);
504			messageLabel.setText(getResultString());
505			cardLayout.show(cardPanel, "label");
506			getRootPane().setDefaultButton(closeButton);
507			closeButton.requestFocus();
508		}
509
510		private void close() {
511			setVisible(false);
512		}
513
514		@Override
515		public void dispose() {
516			chooser.removeActionListener(this);
517
518			// The chooser is hidden by CardLayout on remove
519			// so fix it here
520			cardPanel.remove(chooser);
521			chooser.setVisible(true);
522
523			super.dispose();
524		}
525	}
526
527	private String getResultString() {
528		String resultString = null;
529		String filter = chooser.getFileFilter().getDescription();
530		String path = null;
531		boolean isDirMode = (chooser.getFileSelectionMode() == DIRECTORIES_ONLY);
532		boolean isMulti = chooser.isMultiSelectionEnabled();
533
534		if (isMulti) {
535			File[] files = chooser.getSelectedFiles();
536			if (files != null && files.length > 0) {
537				path = "";
538				for (int i = 0; i < files.length; i++) {
539					path = path + "<br>" + files[i].getAbsolutePath();
540				}
541			}
542		} else {
543			File file = chooser.getSelectedFile();
544			if (file != null) {
545				path = "<br>" + file.getAbsolutePath();
546			}
547		}
548		if (path != null) {
549			path = path.replace(" ", "&nbsp;");
550			filter = filter.replace(" ", "&nbsp;");
551			resultString = "<html>You chose "
552				+ (isMulti ? "these" : "this")
553				+ " "
554				+ (isDirMode ? (isMulti ? "directories" : "directory")
555						: (isMulti ? "files" : "file")) + ": <code>" + path
556						+ "</code><br><br>with filter: <br><code>" + filter;
557		} else {
558			resultString = "Nothing was chosen";
559		}
560		return resultString;
561	}
562
563	/** An ActionListener that listens to the radio buttons. */
564	class OptionListener implements ActionListener {
565		public void actionPerformed(ActionEvent e) {
566			JComponent c = (JComponent) e.getSource();
567			boolean selected = false;
568			if (c instanceof JToggleButton) {
569				selected = ((JToggleButton) c).isSelected();
570			}
571
572			if (c == openRadioButton) {
573				chooser.setDialogType(OPEN_DIALOG);
574				customField.setEnabled(false);
575				repaint();
576			} else if (c == useEmbedInWizardCheckBox) {
577				useControlsCheckBox.setEnabled(!selected);
578				useControlsCheckBox.setSelected(!selected);
579				chooser.setControlButtonsAreShown(!selected);
580			} else if (c == useControlsCheckBox) {
581				chooser.setControlButtonsAreShown(selected);
582			} else if (c == saveRadioButton) {
583				chooser.setDialogType(SAVE_DIALOG);
584				customField.setEnabled(false);
585				repaint();
586			} else if (c == customButton || c == customField) {
587				customField.setEnabled(true);
588				chooser.setDialogType(CUSTOM_DIALOG);
589				repaint();
590			} else if (c == showAllFilesFilterCheckBox) {
591				chooser.setAcceptAllFileFilterUsed(selected);
592			} else if (c == showImageFilesFilterCheckBox) {
593				resetFileFilters(selected, showFullDescriptionCheckBox.isSelected());
594				showFullDescriptionCheckBox.setEnabled(selected);
595			} else if (c == setHiddenCheckBox) {
596				chooser.setFileHidingEnabled(!selected);
597			} else if (c == previewCheckBox) {
598				if (selected) {
599					chooser.setAccessory(previewer);
600				} else {
601					chooser.setAccessory(null);
602				}
603			} else if (c == showFullDescriptionCheckBox) {
604				resetFileFilters(showImageFilesFilterCheckBox.isSelected(), selected);
605			} else if (c == justFilesRadioButton) {
606				chooser.setFileSelectionMode(FILES_ONLY);
607			} else if (c == justDirectoriesRadioButton) {
608				chooser.setFileSelectionMode(DIRECTORIES_ONLY);
609			} else if (c == bothFilesAndDirectoriesRadioButton) {
610				chooser.setFileSelectionMode(FILES_AND_DIRECTORIES);
611			} else if (c == singleSelectionRadioButton) {
612				if (selected) {
613					chooser.setMultiSelectionEnabled(false);
614				}
615			} else if (c == multiSelectionRadioButton) {
616				if (selected) {
617					chooser.setMultiSelectionEnabled(true);
618				}
619			}
620		}
621	}
622
623	class InsetPanel extends JPanel {
624		Insets i;
625
626		InsetPanel(Insets i) {
627			this.i = i;
628		}
629
630		@Override
631		public Insets getInsets() {
632			return i;
633		}
634	}
635
636	public static void main(String s[]) {
637		try {
638			UIManager.setLookAndFeel(GTKLookAndFeel.class.getName());
639		} catch (Exception exc) {
640			JOptionPane.showMessageDialog(null, exc.getLocalizedMessage(),
641					"Look and Feel error", JOptionPane.ERROR_MESSAGE);
642			return;
643		}
644
645		if ("GTK look and feel".equals(UIManager.getLookAndFeel().getName())) {
646			UIManager.put("FileChooserUI",
647					com.google.code.gtkjfilechooser.ui.GtkFileChooserUI.class.getName());
648		}
649
650		FileChooserDemo panel = new FileChooserDemo();
651
652		frame = new JFrame("FileChooserDemo");		
653		frame.setIconImage(Toolkit.getDefaultToolkit().getImage(
654				FileChooserDemo.class.getResource("/gnome_foot.png")));
655			
656		frame.addWindowListener(new WindowAdapter() {
657			@Override
658			public void windowClosing(WindowEvent e) {
659				System.exit(0);
660			}
661		});
662		frame.getContentPane().add("Center", panel);
663		frame.pack();
664		frame.setVisible(true);
665	}
666}