Example usage for java.awt FileDialog getDirectory

List of usage examples for java.awt FileDialog getDirectory

Introduction

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

Prototype

public String getDirectory() 

Source Link

Document

Gets the directory of this file dialog.

Usage

From source file:utybo.branchingstorytree.swing.editor.StoryEditor.java

public boolean saveAs() {
    FileDialog fd = new FileDialog(OpenBSTGUI.getInstance(), Lang.get("editor.saveloc"), FileDialog.SAVE);
    fd.setLocationRelativeTo(OpenBSTGUI.getInstance());
    fd.setVisible(true);//from   w w  w.  j  a  v a2s .  c o  m
    if (fd.getFile() != null) {
        final File file = new File(fd.getFile().endsWith(".bst") ? fd.getDirectory() + fd.getFile()
                : fd.getDirectory() + fd.getFile() + ".bst");
        try {
            doSave(file);
            lastFileLocation = file;
            return true;
        } catch (IOException | BSTException e1) {
            OpenBST.LOG.error("Failed saving a file", e1);
            Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.savefail"), e1);
        }
    }
    return false;
}

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);/*from w  ww . j ava 2 s  .  c o m*/
    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:uk.nhs.cfh.dsp.srth.desktop.modules.resultexplanationpanel.QueryStatisticsCollectionPanel.java

/**
 * Creates the statements panel./*from w  w  w .j  a v  a 2 s.c om*/
 * 
 * @param textArea the text area
 * @param title the title
 * 
 * @return the j panel
 */
private synchronized JPanel createStatementsPanel(final JTextArea textArea, String title) {

    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(),
            BorderFactory.createTitledBorder(title)));

    // create buttons for copy and export
    JButton copyButton = new JButton(new AbstractAction("Copy") {

        public void actionPerformed(ActionEvent event) {
            StringSelection selection = new StringSelection(textArea.getSelectedText());
            // get contents of text area and copy to system clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(selection, QueryStatisticsCollectionPanel.this);
        }
    });

    JButton exportButton = new JButton(new AbstractAction("Export") {

        public void actionPerformed(ActionEvent event) {
            // open a file dialog and export the contents
            FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(),
                    "Select file to export to", FileDialog.SAVE);
            fd.setVisible(true);

            String fileName = fd.getFile();
            String fileDirectory = fd.getDirectory();

            if (fileDirectory != null && fileName != null) {
                File file = new File(fileDirectory, fileName);
                try {
                    String contents = textArea.getText();
                    FileWriter fw = new FileWriter(file);
                    fw.flush();
                    fw.write(contents);
                    fw.close();
                    // inform user
                    //                  manager.getStatusMessageLabel().setText("Successfully saved contents to file "+fileName);
                    logger.info("Successfully saved contents to file " + fileName);

                } catch (IOException e) {
                    logger.warn(e.fillInStackTrace());
                    //                  manager.getStatusMessageLabel().setText("Errors saving contents to file "+fileName);
                }
            }
        }
    });
    // create buttons panel
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS));
    buttonsPanel.add(Box.createHorizontalStrut(200));
    buttonsPanel.add(copyButton);
    buttonsPanel.add(exportButton);

    panel.add(buttonsPanel, BorderLayout.SOUTH);
    panel.add(new JScrollPane(textArea), BorderLayout.CENTER);

    return panel;
}

From source file:de.mycrobase.jcloudapp.Main.java

public void doUploadFile() {
    FileDialog dlg = new FileDialog((Dialog) null, "Upload File...");
    dlg.setVisible(true);// ww  w .ja  v a2  s . c  o  m
    if (dlg.getDirectory() == null || dlg.getFile() == null) {
        return;
    }
    File f = new File(dlg.getDirectory() + File.separator + dlg.getFile());
    if (f.exists()) {
        setImageWorking();
        JSONObject drop = upload(f);
        if (drop != null) {
            String url = getDropUrl(drop);
            System.out.println("Upload complete, URL:\n" + url);
            setClipboard(url);
            icon.displayMessage("Upload finished", String.format("Item: %s", f.getName()),
                    TrayIcon.MessageType.INFO);
        }
        setImageNormal();
    }
}

From source file:no.java.swing.SingleSelectionFileDialog.java

private Result showNativeDialog(Component target, boolean open) {
    Window window = target == null ? null : (Frame) SwingUtilities.getWindowAncestor(target);
    FileDialog dialog;
    if (window instanceof Frame) {
        dialog = new FileDialog((Frame) window);
    } else if (window instanceof Dialog) {
        dialog = new FileDialog((Dialog) window);
    } else {//ww w . j  av  a  2 s . c o  m
        throw new IllegalStateException("Unknown window type");
    }
    dialog.setDirectory(previousDirectory.getAbsolutePath());
    dialog.setMode(open ? FileDialog.LOAD : FileDialog.SAVE);
    dialog.setVisible(true);
    if (rememberPreviousLocation) {
        previousDirectory = new File(dialog.getDirectory());
    }
    if (dialog.getFile() == null) {
        return Result.CANCEL;
    }
    selected = new File(dialog.getFile());
    return Result.APPROVE;
}

From source file:org.sbml.bargraph.MainWindow.java

/**
 * Handles the "Open" menu item in the File menu.
 * @param evt/*www  .  j  a  v  a 2 s.c om*/
 */
public void openFileHandler(java.awt.event.ActionEvent evt) {
    Log.note("'Open' menu item invoked.");
    FileDialog dialog = new FileDialog(this, "Choose file to graph");
    dialog.setVisible(true);

    if (dialog.getFile() == null) {
        Log.note("User cancelled file selection");
        return;
    }

    VerifiableFile theFile = new VerifiableFile(dialog.getDirectory() + dialog.getFile());
    if (theFile.isVerifiedFile()) {
        Log.note("User selected file '" + theFile.getPath() + "'");
        try {
            updatePanelForSBMLFile(theFile);
        } catch (Exception e) {
            Log.error(e.getMessage());
        }
    } else {
        Log.note("Invalid file selected: '" + theFile.getPath() + "'");
        Dialog.error(this, "Invalid file selected: " + theFile.getName(), "File error");
    }
}

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  a  2s. com
 **************************************************************************/
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:jpad.MainEditor.java

public void openFile_OSX_Nix() {
    isOpen = true;/*from  w w  w.  ja  va 2s.co  m*/
    FilenameFilter awtFilter = new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            String lowercaseName = name.toLowerCase();
            if (lowercaseName.endsWith(".txt"))
                return true;
            else
                return false;
        }
    };
    FileDialog fd = new FileDialog(this, "Open Text File", FileDialog.LOAD);
    fd.setFilenameFilter(awtFilter);
    fd.setVisible(true);
    if (fd.getFile() == null)
        return;
    else
        curFile = fd.getDirectory() + fd.getFile();
    //TODO: actually open the file
    try (FileInputStream inputStream = new FileInputStream(curFile)) {
        String allText = org.apache.commons.io.IOUtils.toString(inputStream);
        mainTextArea.setText(allText);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage(), "Error While Reading", JOptionPane.ERROR_MESSAGE);
    }
    JRootPane root = this.getRootPane();
    root.putClientProperty("Window.documentFile", new File(curFile));
    root.putClientProperty("Window.documentModified", Boolean.FALSE);
    hasChanges = false;
    hasSavedToFile = true;
    this.setTitle(String.format("JPad - %s", curFile));
    isOpen = false;
}

From source file:ec.display.chart.StatisticsChartPaneTab.java

/**
 * This method initializes jButton  /*from  w ww . j a v  a 2s. c om*/
 *  
 * @return javax.swing.JButton      
 */
private JButton getPrintButton() {
    if (printButton == null) {
        printButton = new JButton();
        printButton.setText("Export to PDF...");
        final JFreeChart chart = chartPane.getChart();
        printButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                try

                {
                    int width = chartPane.getWidth();
                    int height = chartPane.getHeight();

                    FileDialog fileDialog = new FileDialog(new Frame(), "Export...", FileDialog.SAVE);
                    fileDialog.setDirectory(System.getProperty("user.dir"));
                    fileDialog.setFile("*.pdf");
                    fileDialog.setVisible(true);
                    String fileName = fileDialog.getFile();
                    if (fileName != null)

                    {
                        if (!fileName.endsWith(".pdf")) {
                            fileName = fileName + ".pdf";
                        }
                        File f = new File(fileDialog.getDirectory(), fileName);
                        Document document = new Document(new com.lowagie.text.Rectangle(width, height));
                        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(f));
                        document.addAuthor("ECJ Console");
                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(width, height);
                        Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
                        Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height);
                        chart.draw(g2, rectangle2D);
                        g2.dispose();
                        cb.addTemplate(tp, 0, 0);
                        document.close();
                    }
                } catch (Exception ex)

                {
                    ex.printStackTrace();
                }
            }
        });
    }
    return printButton;
}

From source file:de.uka.ilkd.key.dl.gui.initialdialog.gui.ToolInstaller.java

public void install(JComponent parent, Window dialog) {

    final File installDirectory;
    switch (OSInfosDefault.INSTANCE.getOs()) {
    case OSX://ww w.  j a v  a2 s.  co m
        System.setProperty("apple.awt.fileDialogForDirectories", "true");
        FileDialog d = new FileDialog(Frame.getFrames()[0], "Choose directory for installation of " + toolName,
                FileDialog.LOAD);
        d.setVisible(true);
        System.setProperty("apple.awt.fileDialogForDirectories", "false");
        if (d.getFile() != null) {
            installDirectory = new File(d.getDirectory(), d.getFile());
        } else {
            installDirectory = null;
        }
        break;
    default:
        final JFileChooser chooser = new JFileChooser();
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setDialogTitle("Choose directory for installation of " + toolName);
        chooser.setDialogType(JFileChooser.SAVE_DIALOG);
        chooser.setApproveButtonText("Install " + toolName + " here");
        int result = chooser.showDialog(parent, "Install " + toolName + " here");
        if (result == JFileChooser.APPROVE_OPTION) {
            installDirectory = chooser.getSelectedFile();
        } else {
            installDirectory = null;
        }
    }

    if (installDirectory != null) {
        try {
            final File tmp = File.createTempFile("keymaeraDownload", "." + ft.toString().toLowerCase());
            final FileInfo info = new FileInfo(url, tmp.getName(), false);
            final DownloadManager dlm = new DownloadManager();
            ProgressBarWindow pbw = new ProgressBarWindow(parent, installDirectory, tmp, ft, ps, dialog);
            dlm.addListener(pbw);
            Runnable down = new Runnable() {

                @Override
                public void run() {
                    dlm.downloadAll(new FileInfo[] { info }, 2000, tmp.getParentFile().getAbsolutePath(), true);
                }
            };
            Thread thread = new Thread(down);
            thread.start();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}