Search in sources :

Example 56 with FileDialog

use of java.awt.FileDialog in project megameklab by MegaMek.

the class StatusBar method getFluffImage.

private void getFluffImage() {
    // copied from structureTab
    FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD);
    fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
    /*
         //This does not seem to be working
        if (getMech().getFluff().getMMLImagePath().trim().length() > 0) {
            String fullPath = new File(getMech().getFluff().getMMLImagePath()).getAbsolutePath();
            String imageName = fullPath.substring(fullPath.lastIndexOf(File.separatorChar) + 1);
            fullPath = fullPath.substring(0, fullPath.lastIndexOf(File.separatorChar) + 1);
            fDialog.setDirectory(fullPath);
            fDialog.setFile(imageName);
        } else {
            fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
            fDialog.setFile(getMech().getChassis() + " " + getMech().getModel() + ".png");
        }
        */
    fDialog.setLocationRelativeTo(this);
    fDialog.setVisible(true);
    if (fDialog.getFile() != null) {
        String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
        relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1);
        getTank().getFluff().setMMLImagePath(relativeFilePath);
    }
    refresh.refreshPreview();
    return;
}
Also used : FileDialog(java.awt.FileDialog) File(java.io.File)

Example 57 with FileDialog

use of java.awt.FileDialog in project algs4 by kevin-wayne.

the class StdDraw method actionPerformed.

/**
 * This method cannot be called directly.
 */
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog chooser = new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
    chooser.setVisible(true);
    String filename = chooser.getFile();
    if (filename != null) {
        StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
    }
}
Also used : FileDialog(java.awt.FileDialog)

Example 58 with FileDialog

use of java.awt.FileDialog in project Spark by igniterealtime.

the class ChatRoomTransferDecorator method showFilePicker.

private void showFilePicker() {
    SwingWorker worker = new SwingWorker() {

        public Object construct() {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e1) {
                Log.error(e1);
            }
            return true;
        }

        public void finished() {
            FileDialog fileChooser = SparkManager.getTransferManager().getFileChooser(SparkManager.getChatManager().getChatContainer().getChatFrame(), Res.getString("title.select.file.to.send"));
            if (SparkManager.getTransferManager().getDefaultDirectory() != null) {
                fileChooser.setDirectory(SparkManager.getTransferManager().getDefaultDirectory().getAbsolutePath());
            }
            fileChooser.setVisible(true);
            final File[] files = fileChooser.getFiles();
            if (files.length == 0) {
                // no selection
                return;
            }
            // Single-file selection is used. Using the first array item is safe.
            File file = files[0];
            if (file.exists()) {
                SparkManager.getTransferManager().setDefaultDirectory(file.getParentFile());
                SparkManager.getTransferManager().sendFile(file, ((ChatRoomImpl) chatRoom).getParticipantJID());
            }
        }
    };
    worker.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) FileDialog(java.awt.FileDialog) File(java.io.File)

Example 59 with FileDialog

use of java.awt.FileDialog in project Spark by igniterealtime.

the class SparkTransferManager method sendFileTo.

public void sendFileTo(ContactItem item) {
    FileDialog fileChooser = getFileChooser(SparkManager.getMainWindow(), Res.getString("title.select.file.to.send"));
    if (defaultDirectory != null) {
        fileChooser.setDirectory(defaultDirectory.getAbsolutePath());
    }
    fileChooser.setVisible(true);
    final File[] files = fileChooser.getFiles();
    if (files.length == 0) {
        // no selection
        return;
    }
    // Single-file selection is used. Using the first array item is safe.
    File file = files[0];
    if (file.exists()) {
        defaultDirectory = file.getParentFile();
        sendFile(file, item.getJID());
    }
}
Also used : FileDialog(java.awt.FileDialog) File(java.io.File)

Example 60 with FileDialog

use of java.awt.FileDialog in project Spark by igniterealtime.

the class AvatarPanel method initFileChooser.

public void initFileChooser() {
    if (fileChooser == null) {
        fileChooser = new FileDialog(dlg, "Choose Avatar", FileDialog.LOAD);
        fileChooser.setFilenameFilter(new ImageFilter());
    }
}
Also used : FileDialog(java.awt.FileDialog)

Aggregations

FileDialog (java.awt.FileDialog)78 File (java.io.File)43 JFileChooser (javax.swing.JFileChooser)18 Frame (java.awt.Frame)16 IOException (java.io.IOException)16 FilenameFilter (java.io.FilenameFilter)10 Dialog (java.awt.Dialog)8 FileFilter (javax.swing.filechooser.FileFilter)7 FileOutputStream (java.io.FileOutputStream)5 PrintStream (java.io.PrintStream)4 Button (java.awt.Button)3 Dimension (java.awt.Dimension)3 MenuItem (java.awt.MenuItem)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 MalformedURLException (java.net.MalformedURLException)3 SQLException (java.sql.SQLException)3 JLabel (javax.swing.JLabel)3 Component (java.awt.Component)2 GridLayout (java.awt.GridLayout)2