Example usage for javax.swing JFileChooser FILES_ONLY

List of usage examples for javax.swing JFileChooser FILES_ONLY

Introduction

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

Prototype

int FILES_ONLY

To view the source code for javax.swing JFileChooser FILES_ONLY.

Click Source Link

Document

Instruction to display only files.

Usage

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemJEPlusEAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemJEPlusEAActionPerformed
    // Check if JEPlus+EA folder is available
    if (JEPlusConfig.getDefaultInstance().getJEPlusEADir() == null) {
        // Select a file to open
        fc.resetChoosableFileFilters();// w  ww  .j  a  va 2 s .  c  om
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setCurrentDirectory(new File("./"));
        fc.setMultiSelectionEnabled(false);
        if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            String path = fc.getSelectedFile().getPath() + File.separator;
            JEPlusConfig.getDefaultInstance().setJEPlusEADir(path);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        } else {
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            return;
        }
    }
    // Launch JESS Client
    new Thread(new Runnable() {
        @Override
        public void run() {
            List<String> command = new ArrayList<>();
            command.add("java");
            command.add("-jar");
            command.add("jEPlus+EA.jar");
            command.add(getCurrentProjectFile());
            ProcessBuilder builder = new ProcessBuilder(command);
            builder.directory(new File(JEPlusConfig.getDefaultInstance().getJEPlusEADir()));
            builder.redirectErrorStream(true);
            try {
                Process proc = builder.start();
                // int ExitValue = proc.waitFor();
                try (BufferedReader ins = new BufferedReader(new InputStreamReader(proc.getInputStream()))) {
                    int res = ins.read();
                    while (res != -1) {
                        res = ins.read();
                    }
                }
            } catch (IOException ex) {
                logger.error("Cannot run jEPlus+EA.", ex);
            }
        }
    }, "jEPlus+EA").start();
}

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  w  w  . j av a  2 s . 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:v800_trainer.JCicloTronic.java

private void Info_Button_Suche_TrackLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Info_Button_Suche_TrackLogActionPerformed

    ExampleFileFilter filtera = new ExampleFileFilter();

    filtera.addExtension("kmz");

    filtera.addExtension("TCX");

    filtera.addExtension("GPX");
    filtera.setDescription("Track Datei");

    chooser.resetChoosableFileFilters();
    chooser.addChoosableFileFilter(filtera);
    chooser.setFileFilter(filtera);/*  w  ww  .j  a v a2  s .  c o m*/

    if (new java.io.File(Info_Track_Log.getText()).exists()) {
        chooser.setCurrentDirectory(new java.io.File(Info_Track_Log.getText()));
    } else {
        chooser.setCurrentDirectory(new java.io.File(Properties.getProperty("GPS.dir")));
    }
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    int returnVal = chooser.showDialog(this, null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        Info_Track_Log.setText(chooser.getSelectedFile().getPath());
    }
}

From source file:gui.images.ImageHubExplorer.java

/**
 * This method imports the distances and neighbor sets from the specified
 * files.//from   w  w w . j a va  2s  .  c o m
 *
 * @param evt ActionEvent object.
 */
private void distImportItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_distImportItemActionPerformed
    JFileChooser jfc = new JFileChooser(currentDirectory);
    jfc.setDialogTitle("Choose distances file. " + "Neighbor sets will be automatically loaded if available");
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int rVal = jfc.showOpenDialog(ImageHubExplorer.this);
    if (rVal == JFileChooser.APPROVE_OPTION) {
        currentDirectory = jfc.getSelectedFile().getParentFile();
        primaryDMatFile = jfc.getSelectedFile();
        busyCalculating = true;
        try {
            loadDistancesAndNeighbors(primaryDMatFile, PRIMARY_METRIC);
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            busyCalculating = false;
        }
    }
}

From source file:GUI.PizzaCat.java

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
    JFileChooser chooser = new JFileChooser("");
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int returnVal = chooser.showOpenDialog((java.awt.Component) null);

    if (returnVal == JFileChooser.APPROVE_OPTION) {

        java.io.File inFile;//from  w  w  w .j ava 2  s  .  c om
        inFile = chooser.getSelectedFile();
        String path;
        path = inFile.getAbsolutePath();
        jTextPane1.setText(path);
        //processFile(inFile);
    }
}

From source file:gui.images.ImageHubExplorer.java

/**
 * This method loads the codebook definition from the specified file.
 *
 * @param evt ActionEvent object.//from   w w w. j  av a  2  s.co m
 */
private void loadCodebookItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadCodebookItemActionPerformed
    JFileChooser jfc = new JFileChooser(currentDirectory);
    jfc.setDialogTitle("Load SIFT codebook");
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int rVal = jfc.showOpenDialog(ImageHubExplorer.this);
    if (rVal == JFileChooser.APPROVE_OPTION) {
        currentDirectory = jfc.getSelectedFile().getParentFile();
        File cbFile = jfc.getSelectedFile();
        busyCalculating = true;
        try {
            codebook = new GenericCodeBook();
            codebook.loadCodeBookFromFile(cbFile);
            JOptionPane.showMessageDialog(frameReference, "Load completed");
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            busyCalculating = false;
        }
    }
}

From source file:gui.images.ImageHubExplorer.java

/**
 * This method selects and image as the current image by browsing through
 * the image dataset directly and selecting the corresponding image file.
 *
 * @param evt ActionEvent object./*from w ww  . j  av a  2s. co m*/
 */
private void selImgPathMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selImgPathMenuItemActionPerformed
    JFileChooser jfc = new JFileChooser(currentDirectory);
    jfc.setDialogTitle("Select an image");
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int rVal = jfc.showOpenDialog(ImageHubExplorer.this);
    if (rVal == JFileChooser.APPROVE_OPTION) {
        currentDirectory = jfc.getSelectedFile().getParentFile();
        File imageFile = jfc.getSelectedFile();
        busyCalculating = true;
        try {
            // Look up the image index in the dataset by retrieving it from
            // the image path map.
            int index = pathIndexMap.get(imageFile.getPath());
            setSelectedImageForIndex(index);
            JOptionPane.showMessageDialog(frameReference, "Selection performed");
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            busyCalculating = false;
        }
    }
}

From source file:gui.images.ImageHubExplorer.java

/**
 * This method loads the secondary distances and neighbor sets from the
 * specified files, if available.//from   w ww  .  ja v  a  2  s .  c o  m
 *
 * @param evt ActionEvent object.
 */
private void loadSecondaryDistancesItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadSecondaryDistancesItemActionPerformed
    JFileChooser jfc = new JFileChooser(currentDirectory);
    jfc.setDialogTitle("Choose distances file. Neighbor sets will be " + "automatically loaded if available");
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int rVal = jfc.showOpenDialog(ImageHubExplorer.this);
    if (rVal == JFileChooser.APPROVE_OPTION) {
        currentDirectory = jfc.getSelectedFile().getParentFile();
        secondaryDMatFile = jfc.getSelectedFile();
        busyCalculating = true;
        try {
            loadDistancesAndNeighbors(secondaryDMatFile, SECONDARY_METRIC);
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            busyCalculating = false;
        }
    }
}

From source file:gui.images.ImageHubExplorer.java

/**
 * Select an image for the image query and extract its features.
 *
 * @param evt ActionEvent object.//from  w w w  .j a  va 2 s  . c  om
 */
private void imageBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imageBrowseButtonActionPerformed
    JFileChooser jfc = new JFileChooser(currentDirectory);
    jfc.setDialogTitle("Select Image Query");
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int rVal = jfc.showOpenDialog(ImageHubExplorer.this);
    if (rVal == JFileChooser.APPROVE_OPTION) {
        currentDirectory = jfc.getSelectedFile().getParentFile();
        try {
            File imageFile = jfc.getSelectedFile();
            queryImage = ImageIO.read(imageFile);
            queryImagePanel.setImage(queryImage);
            queryImagePanel.revalidate();
            queryImagePanel.repaint();
            if (codebook == null) {
                // If the codebook has not been loaded, it is impossible to
                // gemerate the quantized representation.
                JOptionPane.showMessageDialog(frameReference, "First load the codebook", "Error message",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
            String imgName = imageFile.getName();
            int pointIndex = imgName.lastIndexOf('.');
            String shortName = null;
            if (pointIndex != -1) {
                shortName = imgName.substring(0, pointIndex);
                shortName += ".pgm";
            } else {
                shortName = shortName + ".pgm";
            }
            // Generate the PGM file for SiftWin SIFT feature extraction.
            File pgmFile = new File(workspace, "tmp" + File.separator + shortName);
            File siftTempFile = new File(workspace, "tmp" + File.separator + "siftTemp.key");
            ConvertJPGToPGM.convertFile(imageFile, pgmFile);
            SiftUtil.siftFile(pgmFile, siftTempFile, "");
            pgmFile.delete();
            // Load the extracted SIFT features.
            queryImageLFeat = SiftUtil.importFeaturesFromSift(siftTempFile);
            DataInstance queryImageRepAlmost = codebook.getDistributionForImageRepresentation(queryImageLFeat,
                    imageFile.getPath());
            // Get the color histogram.
            ColorHistogramVector cHist = new ColorHistogramVector();
            cHist.populateFromImage(queryImage, imgName);
            queryImageRep = new DataInstance();
            queryImageRep.fAttr = new float[queryImageRepAlmost.getNumFAtt() + cHist.getNumFAtt()];
            queryImageRep.iAttr = new int[queryImageRepAlmost.getNumIAtt()];
            queryImageRep.sAttr = new String[queryImageRepAlmost.getNumNAtt()];
            System.arraycopy(cHist.fAttr, 0, queryImageRep.fAttr, 0, cHist.getNumFAtt());
            for (int i = 0; i < queryImageRepAlmost.getNumFAtt(); i++) {
                queryImageRep.fAttr[i + cHist.getNumFAtt()] = queryImageRepAlmost.fAttr[i];
                if (queryImageRep.iAttr != null && queryImageRepAlmost.iAttr != null) {
                    queryImageRep.iAttr[i] = queryImageRepAlmost.iAttr[i];
                }
                if (queryImageRep.sAttr != null && queryImageRepAlmost.sAttr != null) {
                    queryImageRep.sAttr[i] = queryImageRepAlmost.sAttr[i];
                }
            }
            // Reset the neighbor lists and the predictions in the query panel.
            queryNNPanel.removeAll();
            queryNNPanel.revalidate();
            queryNNPanel.repaint();

            classifierPredictionsPanel.removeAll();
            classifierPredictionsPanel.revalidate();
            classifierPredictionsPanel.repaint();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }
}

From source file:gui.images.ImageHubExplorer.java

/**
 * This method loads the codebook profile from a file that contains the
 * visual word occurrence probabilities per class and is used for visual
 * word utility estimation.//from  w w  w .java 2 s.com
 *
 * @param evt ActionEvent object.
 */
private void loadCodebookProfileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadCodebookProfileMenuItemActionPerformed
    BufferedReader br;
    JFileChooser jfc = new JFileChooser(currentDirectory);
    if (codebook == null) {
        JOptionPane.showMessageDialog(this, "no codebook loaded", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    jfc.setDialogTitle("Load Codebook Profiles: ");
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int rVal = jfc.showOpenDialog(ImageHubExplorer.this);
    if (rVal == JFileChooser.APPROVE_OPTION) {
        currentDirectory = jfc.getSelectedFile().getParentFile();
        codebookProfileFile = jfc.getSelectedFile();
        try {
            // Load the codebook profiles.
            br = new BufferedReader(new InputStreamReader(new FileInputStream(codebookProfileFile)));
            int size = Integer.parseInt(br.readLine());
            if (size != codebook.getSize()) {
                throw new Exception("codebook profile size not equal to " + "codebook size");
            }
            codebookProfiles = new double[codebook.getSize()][numClasses];
            String line;
            String[] lineItems;
            float[] codeClassMax = new float[codebook.getSize()];
            float[] codeClassSums = new float[codebook.getSize()];
            for (int i = 0; i < size; i++) {
                line = br.readLine();
                lineItems = line.split(",");
                if (lineItems.length != numClasses) {
                    throw new Exception("codebook profile class number " + "inappropriate " + lineItems.length
                            + " instead of " + numClasses);
                }
                // Keep track of the stats.
                codeClassMax[i] = 0;
                codeClassSums[i] = 0;
                for (int c = 0; c < numClasses; c++) {
                    codebookProfiles[i][c] = Double.parseDouble(lineItems[c]);
                    codeClassMax[i] = (float) Math.max(codeClassMax[i], codebookProfiles[i][c]);
                    codeClassSums[i] += codebookProfiles[i][c];
                }
            }
            // Calculate the goodness of each visual word.
            codebookGoodness = new float[codebook.getSize()];
            for (int codeIndex = 0; codeIndex < codebookGoodness.length; codeIndex++) {
                if (codeClassSums[codeIndex] > 0) {
                    codebookGoodness[codeIndex] = codeClassMax[codeIndex] / codeClassSums[codeIndex];
                } else {
                    codebookGoodness[codeIndex] = 0;
                }
            }
            float maxGoodness = ArrayUtil.max(codebookGoodness);
            float minGoodness = ArrayUtil.min(codebookGoodness);
            for (int codeIndex = 0; codeIndex < codebookGoodness.length; codeIndex++) {
                if ((maxGoodness - minGoodness) > 0) {
                    codebookGoodness[codeIndex] = (codebookGoodness[codeIndex] - minGoodness)
                            / (maxGoodness - minGoodness);
                }
            }
            codebookProfPanels = new CodebookVectorProfilePanel[codebook.getSize()];
            for (int cInd = 0; cInd < codebook.getSize(); cInd++) {
                CodebookVectorProfilePanel cProfPanel = new CodebookVectorProfilePanel();
                cProfPanel.setResults(codebookProfiles[cInd], cInd, classColors, classNames);
                cProfPanel.setPreferredSize(new Dimension(120, 120));
                cProfPanel.setMinimumSize(new Dimension(120, 120));
                cProfPanel.setMaximumSize(new Dimension(120, 120));
                codebookProfPanels[cInd] = cProfPanel;
            }
            JOptionPane.showMessageDialog(frameReference, "Load completed");
        } catch (Exception e) {
            System.err.println(e.getMessage());
            codebookProfiles = null;
            codebookGoodness = null;
        }
    }
}