Example usage for javax.swing JFileChooser getCurrentDirectory

List of usage examples for javax.swing JFileChooser getCurrentDirectory

Introduction

In this page you can find the example usage for javax.swing JFileChooser getCurrentDirectory.

Prototype

public File getCurrentDirectory() 

Source Link

Document

Returns the current directory.

Usage

From source file:com.dfki.av.sudplan.ui.MainFrame.java

private void miOpenDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miOpenDataActionPerformed
    try {//w w  w  .  j  av a  2s. c o m
        String cmd = evt.getActionCommand();
        final JFileChooser fc = new JFileChooser();

        FileFilter fileFilter;
        // Set file filter..
        if (cmd.equalsIgnoreCase(miOpenKMLFile.getActionCommand())) {
            fileFilter = new FileNameExtensionFilter("KML/KMZ File", "kml", "kmz");
        } else if (cmd.equalsIgnoreCase(miAddGeoTiff.getActionCommand())) {
            fileFilter = new FileNameExtensionFilter("GeoTiff File ( *.tif, *.tiff)", "tif", "tiff");
        } else if (cmd.equalsIgnoreCase(miAddShape.getActionCommand())) {
            fileFilter = new FileNameExtensionFilter("ESRI Shapefile (*.shp)", "shp", "SHP");
        } else if (cmd.equalsIgnoreCase(miAddShapeZip.getActionCommand())) {
            fileFilter = new FileNameExtensionFilter("ESRI Shapefile ZIP (*.zip)", "zip", "ZIP");
        } else {
            log.warn("No valid action command.");
            fileFilter = null;
        }
        fc.setFileFilter(fileFilter);

        // Set latest working directory...
        XMLConfiguration xmlConfig = Configuration.getXMLConfiguration();
        String path = xmlConfig.getString("sudplan3D.working.dir");
        File dir;
        if (path != null) {
            dir = new File(path);
            if (dir.exists()) {
                fc.setCurrentDirectory(dir);
            }
        }

        // Show dialog...
        int ret = fc.showOpenDialog(this);

        // Save currently selected working directory...
        dir = fc.getCurrentDirectory();
        path = dir.getAbsolutePath();
        xmlConfig.setProperty("sudplan3D.working.dir", path);

        if (ret != JFileChooser.APPROVE_OPTION) {
            return;
        }

        if (cmd.equalsIgnoreCase(miOpenKMLFile.getActionCommand())) {
            wwPanel.addKMLLayer(fc.getSelectedFile());
        } else if (cmd.equalsIgnoreCase(miAddGeoTiff.getActionCommand())) {
            wwPanel.addGeoTiffLayer(fc.getSelectedFile());
        } else if (cmd.equalsIgnoreCase(miAddShape.getActionCommand())
                || cmd.equalsIgnoreCase(miAddShapeZip.getActionCommand())) {
            IVisAlgorithm algo = VisAlgorithmFactory.newInstance(VisPointCloud.class.getName());
            if (algo != null) {
                wwPanel.addLayer(fc.getSelectedFile(), algo, null);
            } else {
                log.error("VisAlgorithm {} not supported.", VisPointCloud.class.getName());
                JOptionPane.showMessageDialog(this, "Algorithm not supported.", "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        } else {
            log.warn("No valid action command.");
        }
    } catch (Exception ex) {
        log.error(ex.toString());
        JOptionPane.showMessageDialog(this, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:ffx.ui.MainPanel.java

/**
 * Prompt the user to select an alternate log file
 *//*from  w  w w  . java  2s. com*/
private void chooseLog() {
    JFileChooser d = resetFileChooser();
    FFXSystem sys = getHierarchy().getActive();
    if (sys != null) {
        File newCWD = sys.getFile();
        if (newCWD != null && newCWD.getParentFile() != null) {
            d.setCurrentDirectory(newCWD.getParentFile());
        }
    } else {
        return;
    }
    d.setDialogTitle("Select a log file");
    d.setAcceptAllFileFilterUsed(true);
    int result = d.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        File f = d.getSelectedFile();
        if (f != null) {
            sys.setLogFile(f);
            setCWD(d.getCurrentDirectory());
            //getModelingPanel().selected();
        }
    }
}

From source file:de.main.sessioncreator.DesktopApplication1View.java

private boolean checkTestsession() {
    if (wizardtfBugInvestigation.getText().isEmpty() || wizardtfSessionSetup.getText().isEmpty()
            || wizardtfTestDesignExecution.getText().isEmpty() || wizardtfCharter.getText().isEmpty()
            || wizardtfOpportunity.getText().isEmpty()) {
        JOptionPane.showMessageDialog(wizardPanelTaskBreakd, "Please fill out all text fields!",
                "Missing Value", JOptionPane.ERROR_MESSAGE);
        return false;
    }//ww w  . j av a 2s  .  co  m
    percent.clear();
    percent.put(wizardLblBugReporting, wizardtfBugInvestigation.getText().toString());
    percent.put(wizardLblSetup, wizardtfSessionSetup.getText().toString());
    percent.put(wizardLblDesignExecution, wizardtfTestDesignExecution.getText().toString());

    if (textHelper.checkTaskBreakdown(percent)) {
        percent.clear();
        percent.put(wizardLblChartervs, wizardtfCharter.getText().toString());
        percent.put(wizardLblOpportunity, wizardtfOpportunity.getText().toString());
    } else {
        return false;
    }
    if (textHelper.checkTaskBreakdown(percent)) {
        //Prfen des Dateinamens
        submittedFolder = wizardTfPathSubmitted.getText();
        realFilename = "et-" + TesterRealname.substring(0, 3) + "-" + textHelper.Timestamp("yyMMdd") + "-a.ses";
        if (submittedFolder.isEmpty()) {
            JFileChooser chooser = new JFileChooser();
            chooser.setCurrentDirectory(new java.io.File("."));
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            if (chooser.showOpenDialog(wizardbtnSave) == JFileChooser.APPROVE_OPTION) {
                wizardTfPathSubmitted.setText(chooser.getCurrentDirectory().toString() + "\\");
                checkTestsession();
            }
        } else {
            return true;
        }

    }
    return false;
}

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

/**
 * Asks for the type of export and the file name.
 * @param props the properties object to be filled in.
 * @return true if everything was asked for and received.
 *///from   ww  w  .  j  a  v  a2 s. c  o  m
public static boolean getExportInfo(final Properties props, final String defaultFileName) {
    String extension = "";
    //String fileTypeCaption = "";
    if (true) {
        for (ExportFileConfigurationFactory.ExportableType type : ExportFileConfigurationFactory
                .getExportList()) {
            if (type.getMimeType() == ExportFileConfigurationFactory.XLS_MIME_TYPE) {
                props.setProperty("mimetype", type.getMimeType());
                extension = type.getExtension();
                //fileTypeCaption = type.getCaption();
                break;
            }
        }

    } else {
        ChooseFromListDlg<ExportFileConfigurationFactory.ExportableType> dlg = new ChooseFromListDlg<ExportFileConfigurationFactory.ExportableType>(
                (Frame) UIRegistry.get(UIRegistry.FRAME), getResourceString("WB_FILE_FORMAT"), null,
                ChooseFromListDlg.OKCANCELHELP, ExportFileConfigurationFactory.getExportList(),
                "WorkbenchImportCvs");
        dlg.setModal(true);
        UIHelper.centerAndShow(dlg);

        if (!dlg.isCancelled()) {
            props.setProperty("mimetype", dlg.getSelectedObject().getMimeType());

        } else {
            return false;
        }
        extension = dlg.getSelectedObject().getExtension();
        dlg.dispose();
    }

    //        FileDialog fileDialog = new FileDialog((Frame) UIRegistry.get(UIRegistry.FRAME),
    //                                               String.format(getResourceString("CHOOSE_WORKBENCH_EXPORT_FILE"), fileTypeCaption), FileDialog.SAVE);
    //        fileDialog.setDirectory(getDefaultDirPath(EXPORT_FILE_PATH));
    //        UIHelper.centerAndShow(fileDialog);
    //        fileDialog.dispose();

    JFileChooser chooser = new JFileChooser(getDefaultDirPath(EXPORT_FILE_PATH));
    chooser.setDialogTitle(getResourceString("CHOOSE_WORKBENCH_EXPORT_FILE"));
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileFilter(new UIFileFilter("xls", getResourceString("WB_EXCELFILES")));
    if (defaultFileName != null) {
        chooser.setSelectedFile(
                new File(chooser.getCurrentDirectory().getPath() + File.separator + defaultFileName + ".xls"));
    }

    if (chooser.showSaveDialog(UIRegistry.get(UIRegistry.FRAME)) != JFileChooser.APPROVE_OPTION) {
        UIRegistry.getStatusBar().setText("");
        return false;
    }

    File file = chooser.getSelectedFile();
    if (file == null) {
        UIRegistry.getStatusBar().setText(getResourceString("WB_EXPORT_NOFILENAME"));
        return false;
    }

    String path = chooser.getCurrentDirectory().getPath();
    //String path = FilenameUtils.getPath(file.getPath());
    if (StringUtils.isNotEmpty(path)) {
        AppPreferences localPrefs = AppPreferences.getLocalPrefs();
        localPrefs.put(EXPORT_FILE_PATH, path);
    }

    //        String fileName = fileDialog.getFile();
    String fileName = file.getName();
    //        if (StringUtils.isEmpty(fileName))
    //        {
    //            UIRegistry.getStatusBar().setText(getResourceString("WB_EXPORT_NOFILENAME"));
    //            return false;
    //        }

    if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) {
        fileName += (fileName.endsWith(".") ? "" : ".") + extension;
    }

    if (StringUtils.isEmpty(fileName)) {
        return false;
    }

    if (file.exists()) {
        PanelBuilder builder = new PanelBuilder(new FormLayout("p:g", "c:p:g"));
        CellConstraints cc = new CellConstraints();

        String msg = String.format("<html><p>%s<br><br>%s<br></p></html>", getResourceString("WB_FILE_EXISTS"),
                getResourceString("WB_OK_TO_OVERWRITE"));
        builder.add(createLabel(msg), cc.xy(1, 1));
        builder.setDefaultDialogBorder();

        CustomDialog confirmer = new CustomDialog((Frame) UIRegistry.get(UIRegistry.FRAME),
                getResourceString("WB_FILE_EXISTS_TITLE"), true, CustomDialog.OKCANCEL, builder.getPanel(),
                CustomDialog.CANCEL_BTN);
        UIHelper.centerAndShow(confirmer);
        confirmer.dispose();
        if (confirmer.isCancelled()) {
            return false;
        }
    }
    props.setProperty("fileName", path + File.separator + fileName);
    return true;
}

From source file:com.mirth.connect.client.ui.ChannelPanel.java

private boolean exportGroups(List<ChannelGroup> groups) {
    JFileChooser exportFileChooser = new JFileChooser();
    exportFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    File currentDir = new File(Frame.userPreferences.get("currentDirectory", ""));
    if (currentDir.exists()) {
        exportFileChooser.setCurrentDirectory(currentDir);
    }//  ww w . j a  v a  2  s.  c om

    int returnVal = exportFileChooser.showSaveDialog(this);
    File exportFile = null;
    File exportDirectory = null;
    String exportPath = "/";

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        Frame.userPreferences.put("currentDirectory", exportFileChooser.getCurrentDirectory().getPath());

        int exportCollisionCount = 0;
        exportDirectory = exportFileChooser.getSelectedFile();
        exportPath = exportDirectory.getAbsolutePath();

        for (ChannelGroup group : groups) {
            exportFile = new File(
                    exportPath + "/" + group.getName().replaceAll("[^a-zA-Z_0-9\\-\\s]", "") + ".xml");

            if (exportFile.exists()) {
                exportCollisionCount++;
            }
        }

        try {
            int exportCount = 0;

            boolean overwriteAll = false;
            boolean skipAll = false;
            for (int i = 0, size = groups.size(); i < size; i++) {
                ChannelGroup group = groups.get(i);
                String groupName = group.getName().replaceAll("[^a-zA-Z_0-9\\-\\s]", "");
                exportFile = new File(exportPath + "/" + groupName + ".xml");

                boolean fileExists = exportFile.exists();
                if (fileExists) {
                    if (!overwriteAll && !skipAll) {
                        if (exportCollisionCount == 1) {
                            if (!parent.alertOption(parent, "The file " + groupName
                                    + ".xml already exists.  Would you like to overwrite it?")) {
                                continue;
                            }
                        } else {
                            ConflictOption conflictStatus = parent.alertConflict(parent,
                                    "<html>The file " + groupName
                                            + ".xml already exists.<br>Would you like to overwrite it?</html>",
                                    exportCollisionCount);

                            if (conflictStatus == ConflictOption.YES_APPLY_ALL) {
                                overwriteAll = true;
                            } else if (conflictStatus == ConflictOption.NO) {
                                exportCollisionCount--;
                                continue;
                            } else if (conflictStatus == ConflictOption.NO_APPLY_ALL) {
                                skipAll = true;
                                continue;
                            }
                        }
                    }
                    exportCollisionCount--;
                }

                if (!fileExists || !skipAll) {
                    String groupXML = ObjectXMLSerializer.getInstance().serialize(group);
                    FileUtils.writeStringToFile(exportFile, groupXML, UIConstants.CHARSET);
                    exportCount++;
                }
            }

            if (exportCount > 0) {
                parent.alertInformation(parent,
                        exportCount + " files were written successfully to " + exportPath + ".");
                return true;
            }
        } catch (IOException ex) {
            parent.alertError(parent, "File could not be written.");
        }
    }

    return false;
}

From source file:com.mirth.connect.client.ui.ChannelPanel.java

private void exportChannels(List<Channel> channelList) {
    if (channelHasLinkedCodeTemplates(channelList)) {
        boolean addLibraries;
        String exportChannelCodeTemplateLibraries = Preferences.userNodeForPackage(Mirth.class)
                .get("exportChannelCodeTemplateLibraries", null);

        if (exportChannelCodeTemplateLibraries == null) {
            JCheckBox alwaysChooseCheckBox = new JCheckBox(
                    "Always choose this option by default in the future (may be changed in the Administrator settings)");
            Object[] params = new Object[] {
                    "<html>One or more channels has code template libraries linked to them.<br/>Do you wish to include these libraries in each respective channel export?</html>",
                    alwaysChooseCheckBox };
            int result = JOptionPane.showConfirmDialog(this, params, "Select an Option",
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);

            if (result == JOptionPane.YES_OPTION || result == JOptionPane.NO_OPTION) {
                addLibraries = result == JOptionPane.YES_OPTION;
                if (alwaysChooseCheckBox.isSelected()) {
                    Preferences.userNodeForPackage(Mirth.class).putBoolean("exportChannelCodeTemplateLibraries",
                            addLibraries);
                }/*w w w. j a v a  2s  .co m*/
            } else {
                return;
            }
        } else {
            addLibraries = Boolean.parseBoolean(exportChannelCodeTemplateLibraries);
        }

        if (addLibraries) {
            for (Channel channel : channelList) {
                addCodeTemplateLibrariesToChannel(channel);
            }
        }
    }

    for (Channel channel : channelList) {
        addDependenciesToChannel(channel);
    }

    JFileChooser exportFileChooser = new JFileChooser();
    exportFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    File currentDir = new File(Frame.userPreferences.get("currentDirectory", ""));
    if (currentDir.exists()) {
        exportFileChooser.setCurrentDirectory(currentDir);
    }

    int returnVal = exportFileChooser.showSaveDialog(this);
    File exportFile = null;
    File exportDirectory = null;
    String exportPath = "/";

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        Frame.userPreferences.put("currentDirectory", exportFileChooser.getCurrentDirectory().getPath());

        int exportCollisionCount = 0;
        exportDirectory = exportFileChooser.getSelectedFile();
        exportPath = exportDirectory.getAbsolutePath();

        for (Channel channel : channelList) {
            exportFile = new File(exportPath + "/" + channel.getName() + ".xml");

            if (exportFile.exists()) {
                exportCollisionCount++;
            }

            // Update resource names
            parent.updateResourceNames(channel);
        }

        try {
            int exportCount = 0;

            boolean overwriteAll = false;
            boolean skipAll = false;
            for (int i = 0, size = channelList.size(); i < size; i++) {
                Channel channel = channelList.get(i);
                exportFile = new File(exportPath + "/" + channel.getName() + ".xml");

                boolean fileExists = exportFile.exists();
                if (fileExists) {
                    if (!overwriteAll && !skipAll) {
                        if (exportCollisionCount == 1) {
                            if (!parent.alertOption(parent, "The file " + channel.getName()
                                    + ".xml already exists.  Would you like to overwrite it?")) {
                                continue;
                            }
                        } else {
                            ConflictOption conflictStatus = parent.alertConflict(parent,
                                    "<html>The file " + channel.getName()
                                            + ".xml already exists.<br>Would you like to overwrite it?</html>",
                                    exportCollisionCount);

                            if (conflictStatus == ConflictOption.YES_APPLY_ALL) {
                                overwriteAll = true;
                            } else if (conflictStatus == ConflictOption.NO) {
                                exportCollisionCount--;
                                continue;
                            } else if (conflictStatus == ConflictOption.NO_APPLY_ALL) {
                                skipAll = true;
                                continue;
                            }
                        }
                    }
                    exportCollisionCount--;
                }

                if (!fileExists || !skipAll) {
                    String channelXML = ObjectXMLSerializer.getInstance().serialize(channel);
                    FileUtils.writeStringToFile(exportFile, channelXML, UIConstants.CHARSET);
                    exportCount++;
                }
            }

            if (exportCount > 0) {
                parent.alertInformation(parent,
                        exportCount + " files were written successfully to " + exportPath + ".");
            }
        } catch (IOException ex) {
            parent.alertError(parent, "File could not be written.");
        }
    }

    // Reset the libraries on the cached channels
    for (Channel channel : channelList) {
        channel.getCodeTemplateLibraries().clear();
        channel.clearDependencies();
    }
}

From source file:com.att.aro.diagnostics.GraphPanel.java

/**
 * Implements the saving of the graph snapshot.
 *///  w ww  .j  av  a  2s  .com
private void saveAs() throws IOException {

    // Determine save directory
    File saveDir = traceData.getTraceDir();
    if (graphPanelSaveDirectory != null) {
        saveDir = new File(graphPanelSaveDirectory);
    }
    JFileChooser fc = new JFileChooser(saveDir);

    // Set up file types
    String[] fileTypesJPG = new String[2];
    String fileDisplayTypeJPG = rb.getString("fileChooser.contentDisplayType.jpeg");
    fileTypesJPG[0] = rb.getString("fileChooser.contentType.jpeg");
    fileTypesJPG[1] = rb.getString("fileChooser.contentType.jpg");
    FileFilter filterJPG = new ExtensionFileFilter(fileDisplayTypeJPG, fileTypesJPG);

    fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
    String[] fileTypesPng = new String[1];
    String fileDisplayTypePng = rb.getString("fileChooser.contentDisplayType.png");
    fileTypesPng[0] = rb.getString("fileChooser.contentType.png");
    FileFilter filterPng = new ExtensionFileFilter(fileDisplayTypePng, fileTypesPng);
    fc.addChoosableFileFilter(filterPng);
    fc.setFileFilter(filterJPG);
    File plotImageFile = null;

    boolean bSavedOrCancelled = false;
    while (!bSavedOrCancelled) {
        if (fc.showSaveDialog(this.getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
            String strFile = fc.getSelectedFile().toString();
            String strFileLowerCase = strFile.toLowerCase();
            String fileDesc = fc.getFileFilter().getDescription();
            String fileType = rb.getString("fileChooser.contentType.jpg");
            if ((fileDesc.equalsIgnoreCase(rb.getString("fileChooser.contentDisplayType.png"))
                    || strFileLowerCase
                            .endsWith(rb.getString("fileType.filters.dot") + fileTypesPng[0].toLowerCase()))) {
                fileType = fileTypesPng[0];
            }
            if (strFile.length() > 0) {
                // Save current directory
                graphPanelSaveDirectory = fc.getCurrentDirectory().getPath();

                if ((fileType != null) && (fileType.length() > 0)) {
                    String fileTypeLowerCaseWithDot = rb.getString("fileType.filters.dot")
                            + fileType.toLowerCase();
                    if (!strFileLowerCase.endsWith(fileTypeLowerCaseWithDot)) {
                        strFile += rb.getString("fileType.filters.dot") + fileType;
                    }
                }
                plotImageFile = new File(strFile);
                boolean bAttemptToWriteToFile = true;
                if (plotImageFile.exists()) {
                    if (MessageDialogFactory.showConfirmDialog(this,
                            MessageFormat.format(rb.getString("fileChooser.fileExists"),
                                    plotImageFile.getAbsolutePath()),
                            rb.getString("fileChooser.confirm"),
                            JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
                        bAttemptToWriteToFile = false;
                    }
                }
                if (bAttemptToWriteToFile) {
                    try {
                        if (fileType.equalsIgnoreCase(fileTypesPng[0])) {
                            BufferedImage bufImage = createImage(pane);
                            ImageIO.write(bufImage, "png", plotImageFile);
                        } else {
                            BufferedImage bufImage = createImage(pane);
                            ImageIO.write(bufImage, "jpg", plotImageFile);
                        }
                        bSavedOrCancelled = true;
                    } catch (IOException e) {
                        MessageDialogFactory.showMessageDialog(this,
                                rb.getString("fileChooser.errorWritingToFile" + plotImageFile.toString()));
                    }
                }
            }
        } else {
            bSavedOrCancelled = true;
        }
    }
}

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

/**
 * Imports a set of image files, creating a new row per file, to the provided {@link Workbench} parameter.  If the
 * given {@link Workbench} is <code>null</code>, a new {@link Workbench} is created.
 * // w  ww .jav a  2s. c  om
 * @param workbenchArg the {@link Workbench} to append rows to, or <code>null</code> if a new {@link Workbench} should be created
 * @param doOneImagePerRow indicates whether the images are assign to a single row or not.
 */
public void importCardImages(Workbench workbench, final boolean doOneImagePerRow) {
    // ask the user to select the files to import
    final ImageFilter imageFilter = new ImageFilter();
    JFileChooser chooser = new JFileChooser(getDefaultDirPath(IMAGES_FILE_PATH));
    chooser.setDialogTitle(getResourceString("WB_CHOOSE_IMAGES"));
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(true);
    chooser.setFileFilter(imageFilter);

    if (chooser.showOpenDialog(UIRegistry.get(UIRegistry.FRAME)) != JFileChooser.APPROVE_OPTION) {
        UIRegistry.getStatusBar().setText("");
        return;
    }

    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.put(IMAGES_FILE_PATH, chooser.getCurrentDirectory().getAbsolutePath());

    // Start by looping through the files and checking for image file extensions
    // weed out the bad files.
    final Vector<File> fileList = new Vector<File>();
    if (!filterSelectedFileNames(chooser.getSelectedFiles(), fileList, imageFilter)) {
        return;
    }

    for (File f : fileList) {
        if (!ImageFrame.testImageFile(f.getAbsolutePath())) {
            JOptionPane.showMessageDialog(UIRegistry.getMostRecentWindow(),
                    String.format(getResourceString("WB_WRONG_IMAGE_TYPE_OR_CORRUPTED_IMAGE"),
                            new Object[] { f.getAbsolutePath() }),
                    UIRegistry.getResourceString("WARNING"), JOptionPane.ERROR_MESSAGE);
            return;
        }
    }

    boolean creatingNewWb = workbench == null;

    if (creatingNewWb) // create a new Workbench
    {
        List<?> selection = selectExistingTemplate(null, "WorkbenchImportImages");
        //Pair<Boolean, WorkbenchTemplate> selection = selectExistingTemplate(null, "WorkbenchImportImages");

        if (selection.size() == 0 || !(Boolean) selection.get(0)) {
            return; //cancelled
        }

        WorkbenchTemplate workbenchTemplate = selection.size() > 1 ? (WorkbenchTemplate) selection.get(1)
                : null;

        if (workbenchTemplate == null) {
            // create a new WorkbenchTemplate
            TemplateEditor dlg = null;
            try {
                dlg = showColumnMapperDlg(null, null, "WB_MAPPING_EDITOR");
            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(WorkbenchTask.class, ex);
                log.error(ex);
            }
            if (dlg != null && !dlg.isCancelled()) {
                workbenchTemplate = createTemplate(dlg, null);
            }
            if (dlg != null) {
                dlg.dispose();
            }

        } else {
            workbenchTemplate = cloneWorkbenchTemplate(workbenchTemplate);
        }
        if (workbenchTemplate != null) {
            workbench = createNewWorkbenchDataObj("", workbenchTemplate);
        }

    }

    if (workbench != null) // this should always hold, but whatev
    {
        UIRegistry.writeGlassPaneMsg(String.format(getResourceString("WB_LOADING_IMGS_DATASET"),
                new Object[] { workbench.getName() }), GLASSPANE_FONT_SIZE);
        doImageImport(workbench, fileList, creatingNewWb, doOneImagePerRow);
    }
}

From source file:com.pianobakery.complsa.MainGui.java

public void importSearchFile() {
    searchDocValue.setText("loading...");

    try {//from  w w  w . jav a 2  s.co  m
        File selected;
        searchFileString = "";
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
        chooser.setDialogTitle("Choose Search File");
        chooser.setFileHidingEnabled(Boolean.TRUE);
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        int whatChoose = chooser.showOpenDialog(null);
        if (whatChoose == JFileChooser.APPROVE_OPTION) {
            selected = chooser.getSelectedFile();
            logger.debug("AddCorpDir is: " + selected.toString());
            logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory());
            logger.debug("getSelectedFile() : " + chooser.getSelectedFile());
            enableUIElements(true);
            if (selected.exists()) {

                Parser parser = new Parser(selected);
                try {
                    parser.parseDocToPlainText();

                    searchFileString = Utilities.removeQuoteFromString(parser.getPlainText());
                    logger.debug("The Search File: " + searchFileString);
                    searchDocValue
                            .setText(selected.getParentFile().getName() + File.separator + selected.getName());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (SAXException e) {
                    e.printStackTrace();
                } catch (TikaException e) {
                    e.printStackTrace();
                }
            }

        }

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Falsche Eingabe");
    }

}

From source file:com.pianobakery.complsa.MainGui.java

public File chooseAddCorpusFolder() {

    try {/*w  w  w . j a v a2s  .c  om*/

        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
        chooser.setDialogTitle("Create Working Folder");
        chooser.setFileHidingEnabled(Boolean.TRUE);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        int whatChoose = chooser.showOpenDialog(null);
        File selected;
        if (whatChoose == JFileChooser.APPROVE_OPTION) {
            selected = chooser.getSelectedFile();
            logger.debug("AddCorpDir is: " + selected.toString());
            logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory());
            logger.debug("getSelectedFile() : " + chooser.getSelectedFile());
            enableUIElements(true);

            return selected;

        }

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Falsche Eingabe");
    }

    return null;
}