Example usage for java.awt FileDialog show

List of usage examples for java.awt FileDialog show

Introduction

In this page you can find the example usage for java.awt FileDialog show.

Prototype

@Deprecated
public void show() 

Source Link

Document

Makes the Dialog visible.

Usage

From source file:GUIMediaStatistics.java

/************************************************************************
* Respond to user button presses - either browsing for a file or
* gathering format info on the current file.
************************************************************************/
public void actionPerformed(ActionEvent e) {

    /////////////////////////////////
    // Browse - use FileDialog class.
    /////////////////////////////////
    if (e.getSource() == browseButton) {
        FileDialog choice = new FileDialog(this, "Media File Choice", FileDialog.LOAD);
        if (lastDirectory != null)
            choice.setDirectory(lastDirectory);
        choice.show();
        String selection = choice.getFile();
        if (selection != null) {
            lastDirectory = choice.getDirectory();
            mediaField.setText("file://" + choice.getDirectory() + selection);
        }/*  w  w  w  .j  a  v a  2  s . co  m*/
    }
    ////////////////////////////////////////////////////////
    // Get statistics - create a MediaStatistics object and
    // monitor its progress.
    ///////////////////////////////////////////////////////
    else {
        stats = new MediaStatistics(mediaField.getText());
        monitorAndReport();
    }
}

From source file:FileViewer.java

/**
 * Handle button clicks/* w  w w. java  2s  .c  o m*/
 */
public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    if (cmd.equals("open")) { // If user clicked "Open" button
        // Create a file dialog box to prompt for a new file to display
        FileDialog f = new FileDialog(this, "Open File", FileDialog.LOAD);
        f.setDirectory(directory); // Set the default directory

        // Display the dialog and wait for the user's response
        f.show();

        directory = f.getDirectory(); // Remember new default directory
        setFile(directory, f.getFile()); // Load and display selection
        f.dispose(); // Get rid of the dialog box
    } else if (cmd.equals("close")) // If user clicked "Close" button
        this.dispose(); // then close the window
}

From source file:Sampler.java

private void createUI() {
    setFont(new Font("Serif", Font.PLAIN, 12));
    setLayout(new BorderLayout());
    // Set our location to the left of the image frame.
    setSize(200, 350);// w  w  w. j a  v  a2 s.  c  om
    Point pt = mImageFrame.getLocation();
    setLocation(pt.x - getSize().width, pt.y);

    final Checkbox accumulateCheckbox = new Checkbox("Accumulate", false);
    final Label statusLabel = new Label("");

    // Make a sorted list of the operators.
    Enumeration e = mOps.keys();
    Vector names = new Vector();
    while (e.hasMoreElements())
        names.addElement(e.nextElement());
    Collections.sort(names);
    final java.awt.List list = new java.awt.List();
    for (int i = 0; i < names.size(); i++)
        list.add((String) names.elementAt(i));
    add(list, BorderLayout.CENTER);

    // When an item is selected, do the corresponding transformation.
    list.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ie) {
            if (ie.getStateChange() != ItemEvent.SELECTED)
                return;
            String key = list.getSelectedItem();
            BufferedImageOp op = (BufferedImageOp) mOps.get(key);
            BufferedImage source = mSplitImageComponent.getSecondImage();
            boolean accumulate = accumulateCheckbox.getState();
            if (source == null || accumulate == false)
                source = mSplitImageComponent.getImage();
            String previous = mImageFrame.getTitle() + " + ";
            if (accumulate == false)
                previous = "";
            mImageFrame.setTitle(previous + key);
            statusLabel.setText("Performing " + key + "...");
            list.setEnabled(false);
            accumulateCheckbox.setEnabled(false);
            BufferedImage destination = op.filter(source, null);
            mSplitImageComponent.setSecondImage(destination);
            mSplitImageComponent.setSize(mSplitImageComponent.getPreferredSize());
            mImageFrame.setSize(mImageFrame.getPreferredSize());
            list.setEnabled(true);
            accumulateCheckbox.setEnabled(true);
            statusLabel.setText("Performing " + key + "...done.");
        }
    });

    Button loadButton = new Button("Load...");
    loadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            FileDialog fd = new FileDialog(Sampler.this);
            fd.show();
            if (fd.getFile() == null)
                return;
            String path = fd.getDirectory() + fd.getFile();
            mSplitImageComponent.setImage(path);
            mSplitImageComponent.setSecondImage(null);
            //            Utilities.sizeContainerToComponent(mImageFrame,
            //               mSplitImageComponent);
            mImageFrame.validate();
            mImageFrame.repaint();
        }
    });

    Panel bottom = new Panel(new GridLayout(2, 1));
    Panel topBottom = new Panel();
    topBottom.add(accumulateCheckbox);
    topBottom.add(loadButton);
    bottom.add(topBottom);
    bottom.add(statusLabel);
    add(bottom, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            mImageFrame.dispose();
            dispose();
            System.exit(0);
        }
    });
}

From source file:PlayerOfMedia.java

/***************************************************************************
 * React to menu selections (quit or open) or one of the the buttons on the
 * dialog boxes./*  w  w  w  . j  a v  a2 s  .c o m*/
 **************************************************************************/
public void actionPerformed(ActionEvent e) {

    if (e.getSource() instanceof MenuItem) {
        //////////////////////////////////////////////////
        // Quit and free up any player acquired resources.
        //////////////////////////////////////////////////
        if (e.getActionCommand().equalsIgnoreCase("QUIT")) {
            if (player != null) {
                player.stop();
                player.close();
            }
            System.exit(0);
        }
        /////////////////////////////////////////////////////////
        // User to open/play media. Show the selection dialog box.
        /////////////////////////////////////////////////////////
        else if (e.getActionCommand().equalsIgnoreCase("OPEN")) {
            selectionDialog.show();
        }
    }
    //////////////////////
    // One of the Buttons.
    //////////////////////
    else {
        /////////////////////////////////////////////////////////////
        // User to browse the local file system. Popup a file dialog.
        /////////////////////////////////////////////////////////////
        if (e.getSource() == choose) {
            FileDialog choice = new FileDialog(this, "Media File Choice", FileDialog.LOAD);
            if (lastDirectory != null)
                choice.setDirectory(lastDirectory);
            choice.show();
            String selection = choice.getFile();
            if (selection != null) {
                lastDirectory = choice.getDirectory();
                mediaName.setText("file://" + choice.getDirectory() + selection);
            }
        }
        ///////////////////////////////////////////////
        // User chooses to cancel opening of new media.
        ///////////////////////////////////////////////
        else if (e.getSource() == cancel) {
            selectionDialog.hide();
        }
        ///////////////////////////////////////////////////////
        // User has selected the name of the media. Attempt to
        // create a Player.
        ///////////////////////////////////////////////////////
        else if (e.getSource() == open) {
            selectionDialog.hide();
            createAPlayer(mediaName.getText());
        }
        ////////////////////////////////////////////
        // User has seen error message. Now hide it.
        ////////////////////////////////////////////
        else if (e.getSource() == ok)
            errorDialog.hide();
    }
}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

/**
 * For XSB only// w w w .  j av  a2s  . co m
 */
void load_dynFile() {
    String nome, directorio;
    File filetoreconsult = null;
    FileDialog d = new FileDialog(this, "load_dyn file...");
    d.show();
    nome = d.getFile();
    directorio = d.getDirectory();
    if (nome != null) {
        filetoreconsult = new File(directorio, nome);
        if (successfulCommand(
                "load_dyn('" + engine.unescapedFilePath(filetoreconsult.getAbsolutePath()) + "')")) {
            addToReloaders(filetoreconsult, "load_dyn");
        }
    }
}

From source file:org.mbs3.juniuploader.gui.pnlWoWDirectories.java

private void btnAddDirectoryActionPerformed(ActionEvent evt) {
    if (evt.getSource() == this.btnAddDirectory) {
        boolean failed = false;
        boolean mac = Util.isMac();
        if (mac) {
            java.awt.Frame f = jUniUploader.inst;
            FileDialog fd = new FileDialog(f, "Select a World of Warcraft Directory", FileDialog.LOAD);
            try {
                fd.show();

                String fileName = fd.getFile();
                String rootDir = fd.getDirectory();
                String completePath = (rootDir == null ? "" : rootDir) + (fileName == null ? "" : fileName);
                log.debug("Adding OS X style " + completePath);
                if (completePath != null) {
                    File file = new File(completePath);
                    if (file != null && file.exists() && file.isDirectory()) {
                        WDirectory wd = new WDirectory(file);
                        frmMain.wowDirectories.addElement(wd);
                    }//from   ww  w  . ja va2  s.co  m

                }

            } catch (Exception ex) {
                failed = true;
                log.warn("Failed trying to display a FileDialog, falling back to JFileChooser", ex);
            }

        }
        if (!mac || failed) {
            JFileChooser fc = new JFileChooser();
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = fc.showOpenDialog(this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                if (file != null && file.exists() && file.isDirectory()) {
                    WDirectory wd = new WDirectory(file);
                    frmMain.wowDirectories.addElement(wd);
                }

            } else {
                log.trace("Open command cancelled by user.");
            }

        }
    }
}