package org.dclermonte.siba.gui; import java.awt.Color; import java.awt.Component; import java.io.File; import java.util.ResourceBundle; import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * * @author Christian Pierre MOMON (christian.momon@devinsy.fr) * */ public class CheckDirectorySelector extends JFileChooser { private static final long serialVersionUID = 3782597353602048214L; private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ private static Logger logger = LoggerFactory.getLogger(CheckDirectorySelector.class); /** * * @param targetFile */ public CheckDirectorySelector(final File targetFile) { super(); setBackground(new Color(152, 251, 152)); // File file; if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath()))) { file = null; } else if (targetFile.isFile()) { file = targetFile.getParentFile(); } else { file = targetFile; } // setSelectedFile(file); setDialogTitle(BUNDLE.getString("CheckDirectorySelector.this.dialogTitle")); //$NON-NLS-1$ setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichiers md5", "md5"); setAcceptAllFileFilterUsed(false); addChoosableFileFilter(filter); setApproveButtonText(BUNDLE.getString("BackupPanel.checkFileChooserButton.text")); setDialogType(CUSTOM_DIALOG); } /** * */ @Override public final void setSelectedFile(final File file) { // super.setSelectedFile(file); logger.debug("==== SET SELECTED FILE================="); logger.debug("SELECED FILE {}", file); } /** * */ @Override public void setVisible(final boolean visible) { // super.setVisible(visible); if (!visible) { // resetChoosableFileFilters(); } } /** * This method is the main one of the selector. * * @param parent * @return */ public static File showSelectorDialog(final Component parent, final File targetFile) { File result; // CheckDirectorySelector selector = new CheckDirectorySelector(targetFile); // if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION) { // result = selector.getSelectedFile(); } else { // result = null; } // return result; } }