Example usage for java.awt FileDialog dispose

List of usage examples for java.awt FileDialog dispose

Introduction

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

Prototype

public void dispose() 

Source Link

Document

Releases all of the native screen resources used by this Window , its subcomponents, and all of its owned children.

Usage

From source file:Main.java

/**
 * Select the file path via {@linkplain FileDialog}.
 * /* www.j  a va2s .c  o  m*/
 * @param parent
 *            the parent of {@linkplain FileDialog}
 * @param title
 *            the title of {@linkplain FileDialog}
 * @return the selected path
 */
public static String selectPath(Frame parent, String title) {
    FileDialog dialog = new FileDialog(parent, title, FileDialog.LOAD);
    dialog.setVisible(true);
    String dir = dialog.getDirectory();
    dialog.dispose();
    return dir;
}

From source file:FileViewer.java

/**
 * Handle button clicks/*from   www . ja  v a  2 s. 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:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java

/**
 * Method for enabling a user to choose a toolbar icon.
 * @param appLabel the label used to display the icon.
 * @param clearIconBtn the button used to clear the icon
 *///  ww  w.jav  a  2  s . c om
protected void chooseToolbarIcon(final JLabel appLabel, final JButton clearIconBtn) {
    FileDialog fileDialog = new FileDialog((Frame) UIRegistry.get(UIRegistry.FRAME),
            getResourceString("PREF_CHOOSE_APPICON_TITLE"), FileDialog.LOAD); //$NON-NLS-1$
    fileDialog.setFilenameFilter(new ImageFilter());
    UIHelper.centerAndShow(fileDialog);
    fileDialog.dispose();

    String path = fileDialog.getDirectory();
    if (StringUtils.isNotEmpty(path)) {
        String fullPath = path + File.separator + fileDialog.getFile();
        File imageFile = new File(fullPath);
        if (imageFile.exists()) {
            ImageIcon newIcon = null;
            ImageIcon icon = new ImageIcon(fullPath);
            if (icon.getIconWidth() != -1 && icon.getIconHeight() != -1) {
                if (icon.getIconWidth() > 32 || icon.getIconHeight() > 32) {
                    Image img = GraphicsUtils.getScaledImage(icon, 32, 32, false);
                    if (img != null) {
                        newIcon = new ImageIcon(img);
                    }
                } else {
                    newIcon = icon;
                }
            }

            ImageIcon appIcon;
            if (newIcon != null) {
                appLabel.setIcon(newIcon);
                clearIconBtn.setEnabled(true);
                String imgBufStr = GraphicsUtils.uuencodeImage(newAppIconName, newIcon);
                AppPreferences.getRemote().put(iconImagePrefName, imgBufStr);
                appIcon = newIcon;

            } else {
                appIcon = IconManager.getIcon("AppIcon");
                appLabel.setIcon(appIcon); //$NON-NLS-1$
                clearIconBtn.setEnabled(false);
                AppPreferences.getRemote().remove(iconImagePrefName);
            }

            IconEntry entry = IconManager.getIconEntryByName(INNER_APPICON_NAME);
            entry.setIcon(appIcon);
            if (entry.getIcons().get(IconManager.IconSize.Std32) != null) {
                entry.getIcons().get(IconManager.IconSize.Std32).setImageIcon(appIcon);
            }

            //((FormViewObj)form).getMVParent().set
            form.getValidator().dataChanged(null, null, null);
        }
    }

}

From source file:com.awesheet.models.Workbook.java

@Override
public void onMessage(final UIMessage message) {
    switch (message.getType()) {
    case UIMessageType.CREATE_SHEET: {
        addSheet(new Sheet(this, "Sheet " + (newSheetID + 1)));
        break;/*from w ww.  j a va  2s  .  co  m*/
    }

    case UIMessageType.SELECT_SHEET: {
        SelectSheetMessage uiMessage = (SelectSheetMessage) message;
        selectSheet(uiMessage.getSheet());
        break;
    }

    case UIMessageType.DELETE_SHEET: {
        DeleteSheetMessage uiMessage = (DeleteSheetMessage) message;
        removeSheet(uiMessage.getSheet());
        break;
    }

    case UIMessageType.CREATE_BAR_CHART: {
        CreateBarChartMessage uiMessage = (CreateBarChartMessage) message;

        // Get selected cells.
        Cell selectedCells[] = getSelectedSheet().collectSelectedCells();

        BarChart chart = new BarChart(selectedCells);
        chart.setNameX(uiMessage.getXaxis());
        chart.setNameY(uiMessage.getYaxis());
        chart.setTitle(uiMessage.getTitle());

        if (!chart.generateImageData()) {
            UIMessageManager.getInstance().dispatchAction(
                    new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error",
                            "Could not create a chart. Please make sure the cells you selected are in the correct format.")));
            break;
        }

        UIMessageManager.getInstance()
                .dispatchAction(new ShowPopupAction<ChartPopup>(UIPopupType.VIEW_CHART_POPUP,
                        new ChartPopup(new Base64().encodeAsString(chart.getImageData()))));

        break;
    }

    case UIMessageType.CREATE_LINE_CHART: {
        CreateLineChartMessage uiMessage = (CreateLineChartMessage) message;

        // Get selected cells.
        Cell selectedCells[] = getSelectedSheet().collectSelectedCells();

        LineChart chart = new LineChart(selectedCells);
        chart.setNameX(uiMessage.getXaxis());
        chart.setNameY(uiMessage.getYaxis());
        chart.setTitle(uiMessage.getTitle());

        if (!chart.generateImageData()) {
            UIMessageManager.getInstance().dispatchAction(
                    new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error",
                            "Could not create a chart. Please make sure the cells you selected are in the correct format.")));
            break;
        }

        UIMessageManager.getInstance()
                .dispatchAction(new ShowPopupAction<ChartPopup>(UIPopupType.VIEW_CHART_POPUP,
                        new ChartPopup(new Base64().encodeAsString(chart.getImageData()))));

        break;
    }

    case UIMessageType.SAVE_CHART_IMAGE: {
        final SaveChartImageMessage uiMessage = (SaveChartImageMessage) message;

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {

                byte imageData[] = new Base64().decode(uiMessage.getImageData());

                FileDialog dialog = new FileDialog(MainFrame.getInstance(), "Save Chart Image",
                        FileDialog.SAVE);
                dialog.setFile("*.png");
                dialog.setVisible(true);
                dialog.setFilenameFilter(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return (dir.isFile() && name.endsWith(".png"));
                    }
                });

                String filePath = dialog.getFile();
                String directory = dialog.getDirectory();
                dialog.dispose();

                if (directory != null && filePath != null) {
                    String absolutePath = new File(directory + filePath).getAbsolutePath();

                    if (!FileManager.getInstance().saveFile(absolutePath, imageData)) {
                        UIMessageManager.getInstance()
                                .dispatchAction(new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP,
                                        new MessagePopup("Error", "Could not save chart image.")));
                    }
                }
            }
        });

        break;
    }
    }
}

From source file:edu.ku.brc.specify.tasks.ReportsBaseTask.java

protected void importReport() {
    FileDialog fileDialog = new FileDialog((Frame) UIRegistry.get(UIRegistry.FRAME),
            getResourceString("CHOOSE_WORKBENCH_IMPORT_FILE"), FileDialog.LOAD);
    //Really shouldn't override workbench prefs with report stuff???
    fileDialog.setDirectory(WorkbenchTask.getDefaultDirPath(WorkbenchTask.IMPORT_FILE_PATH));
    fileDialog.setFilenameFilter(new java.io.FilenameFilter() {
        public boolean accept(File dir, String filename) {
            return FilenameUtils.getExtension(filename).equalsIgnoreCase("jrxml");
        }/*from   w  w w  . j  a v a 2  s .c  o  m*/

    });
    UIHelper.centerAndShow(fileDialog);
    fileDialog.dispose();

    String fileName = fileDialog.getFile();
    String path = fileDialog.getDirectory();
    if (StringUtils.isNotEmpty(path)) {
        AppPreferences localPrefs = AppPreferences.getLocalPrefs();
        localPrefs.put(WorkbenchTask.IMPORT_FILE_PATH, path);
    }

    File file;
    if (StringUtils.isNotEmpty(fileName) && StringUtils.isNotEmpty(path)) {
        file = new File(path + File.separator + fileName);
    } else {
        return;
    }

    if (file.exists()) {
        if (MainFrameSpecify.importJasperReport(file, true, null)) {
            refreshCommands();
        }
        //else -- assume feedback during importJasperReport()
    }
}