All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.widget.MessageDialog Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
/* *##% Graphical Widget
 * Copyright (C) 2004 - 2008 CodeLutin
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 *
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * . ##%*/

/* *
 * MessageDialog.java
 *
 * Created: 6 avr. 2004
 *
 * @author Benjamin Poussin 
 * Copyright Code Lutin
 * @version $Revision: 228 $
 *
 * Mise a jour: $Date: 2009-10-15 14:27:39 +0200 (jeu., 15 oct. 2009) $
 * par : $Author: echatellier $
 */

package org.nuiton.widget;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import org.nuiton.i18n.I18n;
import org.nuiton.util.ExceptionUtil;

public class MessageDialog { // MessageDialog

    public static void error(String title, String message, Throwable eee) {
        JOptionPane.showMessageDialog(null, message + "\n"
                + ExceptionUtil.stackTrace(eee), title,
                JOptionPane.ERROR_MESSAGE);
    }

    static protected File currentDirectory = new File(".");

    static public File getLastChoice() {
        return currentDirectory;
    }

    static public void setCurrentDirectory(String dir) {
        currentDirectory = new File(dir);
    }

    /**
     * @return le nom du fichier entre dans la boite de dialogue. Si le bouton
     * annuler est utilisé, ou qu'il y a une erreur retourne null.
     */
    static public String getFile() {
        return getFile(I18n._("nuitonwidgets.message.file"));
    }

    static public String getFile(String buttonText) {
        try {
            JFileChooser chooser = new JFileChooser(currentDirectory);
            chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
            chooser.setApproveButtonText(buttonText);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int returnVal = chooser.showDialog(null, null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File theFile = chooser.getSelectedFile();
                if (theFile != null) {
                    currentDirectory = theFile;
                    return theFile.getAbsolutePath();
                }
            } else {
                return null;
            }
        } catch (Exception e) {
            java.util.logging.Logger.getLogger(
                    "org.nuiton.widget.MessageDialog.getFile").severe(
                    "Erreur:");
        }
        return null;
    }

    /**
     * @return le nom du repertoire entre dans la boite de dialogue. Si le
     * bouton annuler est utilisé, ou qu'il y a une erreur retourne null.
     */
    static public String getDirectory() {
        try {
            JFileChooser chooser = new JFileChooser(currentDirectory);
            chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
            chooser.setApproveButtonText(I18n._("nuitonwidgets.message.folder"));
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showDialog(null, null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File theFile = chooser.getSelectedFile();
                if (theFile != null) {
                    currentDirectory = theFile;
                    if (theFile.isDirectory()) {
                        return theFile.getAbsolutePath();
                    }
                }
            } else {
                return null;
            }
        } catch (Exception e) {
            java.util.logging.Logger.getLogger(
                    "org.nuiton.widget.MessageDialog.getDirectory").severe(
                    "Erreur:");
        }
        return null;
    }

} // MessageDialog





© 2015 - 2024 Weber Informatics LLC | Privacy Policy