Example usage for javax.swing JFileChooser FILES_AND_DIRECTORIES

List of usage examples for javax.swing JFileChooser FILES_AND_DIRECTORIES

Introduction

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

Prototype

int FILES_AND_DIRECTORIES

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

Click Source Link

Document

Instruction to display both files and directories.

Usage

From source file:pdfreader.PDFReader.java

private void converttoList(java.awt.event.ActionEvent evt) throws IOException, CryptographyException {

    JFileChooser jfc = new JFileChooser("G:/From Fuad sir DOCX to PDF");
    jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html"));
    jfc.showSaveDialog(PDFReader.this);
    File saveFile = jfc.getSelectedFile();
    int[] regioon = null;
    ExtractTextByArea ETB = new ExtractTextByArea();
    try {/* ww w.  j  a  v a2 s  .  c  o m*/
        regioon = ETB.extractTextByArea(name, rectangle, currentPage, 0);
    } catch (IOException | CryptographyException ex) {
        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
    }
    int positionOfRowStart[] = ETB.getPointOfRowStart();
    int numberofRows = ETB.returnNumberofRows();
    int numberofColumns = ETB.returnNumberofColumns();

    ExtractTextByColumn ETBC = new ExtractTextByColumn();
    Rectangle[] ColumnWiseRect = new Rectangle[(numberofColumns - 1) * numberofRows];
    int q = 0;
    for (int row = 0; row <= numberofRows - 1; row++) {
        for (int column = 0; column < numberofColumns - 1; column++) {
            if (column == 0 && row == 0) {
                ColumnWiseRect[q] = new Rectangle(rectangle.x, rectangle.y,
                        (regioon[column + 1] * 5 - rectangle.x) - 2, positionOfRowStart[row] - rectangle.y);
                //                    pdfPagePanel.drawrect(rectangle.x,rectangle.y,(regioon[column+1]*5-rectangle.x)-2,positionOfRowStart[row]-rectangle.y);
                //                    System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height);
                //                    try {
                //                        ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column);
                //                    } catch (IOException ex) {
                //                        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
                //                    } catch (CryptographyException ex) {
                //                        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
                //                    }
            } else if (row == 0 && column > 0) {
                ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, rectangle.y,
                        (regioon[column + 1] * 5 - regioon[column] * 5), positionOfRowStart[row] - rectangle.y);
                //                    pdfPagePanel.drawrect(regioon[column]*5-2,rectangle.y,(regioon[column+1]*5-regioon[column]*5),positionOfRowStart[row]-rectangle.y);
                //                    System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height);
                //                    try {
                //                        ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column);
                //                    } catch (IOException ex) {
                //                        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
                //                    } catch (CryptographyException ex) {
                //                        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
                //                    }
            } else if (column == 0 && row > 0) {
                ColumnWiseRect[q] = new Rectangle(rectangle.x, positionOfRowStart[row - 1],
                        (regioon[column + 1] * 5 - rectangle.x),
                        (positionOfRowStart[row] - positionOfRowStart[row - 1]));
                //                    pdfPagePanel.drawrect(rectangle.x,positionOfRowStart[row-1]+2,(regioon[column+1]*5-rectangle.x),(positionOfRowStart[row]-positionOfRowStart[row-1]));
                //                    System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height);
                //                    try {
                //                        ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column);
                //                    } catch (IOException ex) {
                //                        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
                //                    } catch (CryptographyException ex) {
                //                        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
                //                    }
            } else if (column > 0 && row > 0) {
                ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, positionOfRowStart[row - 1],
                        (regioon[column + 1] * 5 - regioon[column] * 5),
                        (positionOfRowStart[row] - positionOfRowStart[row - 1]));
                //                    pdfPagePanel.drawrect(regioon[column]*5-2,positionOfRowStart[row-1]+2,(regioon[column+1]*5-regioon[column]*5),(positionOfRowStart[row]-positionOfRowStart[row-1]));
                //                    System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height);
                //                    try {
                //                        ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column);
                //                    } catch (IOException ex) {
                //                        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
                //                    } catch (CryptographyException ex) {
                //                        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
                //                    }
            }
            q++;
        }
    }

    //pdfPagePanel.pdfpagepanelrec = ColumnWiseRect;
    try {
        ETBC.getList(numberofRows, numberofColumns, saveFile);
    } catch (IOException ex) {
        Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:processing.app.Base.java

public void handleAddLibrary() {
    JFileChooser fileChooser = new JFileChooser(System.getProperty("user.home"));
    fileChooser.setDialogTitle(tr("Select a zip file or a folder containing the library you'd like to add"));
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileChooser.setFileFilter(new FileNameExtensionFilter(tr("ZIP files or folders"), "zip"));

    Dimension preferredSize = fileChooser.getPreferredSize();
    fileChooser.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200));

    int returnVal = fileChooser.showOpenDialog(activeEditor);

    if (returnVal != JFileChooser.APPROVE_OPTION) {
        return;//from ww  w  .j  a v  a2  s .  co m
    }

    File sourceFile = fileChooser.getSelectedFile();
    File tmpFolder = null;

    try {
        // unpack ZIP
        if (!sourceFile.isDirectory()) {
            try {
                tmpFolder = FileUtils.createTempFolder();
                ZipDeflater zipDeflater = new ZipDeflater(sourceFile, tmpFolder);
                zipDeflater.deflate();
                File[] foldersInTmpFolder = tmpFolder.listFiles(new OnlyDirs());
                if (foldersInTmpFolder.length != 1) {
                    throw new IOException(tr("Zip doesn't contain a library"));
                }
                sourceFile = foldersInTmpFolder[0];
            } catch (IOException e) {
                activeEditor.statusError(e);
                return;
            }
        }

        File libFolder = sourceFile;
        if (FileUtils.isSubDirectory(new File(PreferencesData.get("sketchbook.path")), libFolder)) {
            activeEditor.statusError(tr("A subfolder of your sketchbook is not a valid library"));
            return;
        }

        if (FileUtils.isSubDirectory(libFolder, new File(PreferencesData.get("sketchbook.path")))) {
            activeEditor.statusError(tr("You can't import a folder that contains your sketchbook"));
            return;
        }

        String libName = libFolder.getName();
        if (!BaseNoGui.isSanitaryName(libName)) {
            String mess = I18n.format(tr("The library \"{0}\" cannot be used.\n"
                    + "Library names must contain only basic letters and numbers.\n"
                    + "(ASCII only and no spaces, and it cannot start with a number)"), libName);
            activeEditor.statusError(mess);
            return;
        }

        String[] headers;
        File libProp = new File(libFolder, "library.properties");
        File srcFolder = new File(libFolder, "src");
        if (libProp.exists() && srcFolder.isDirectory()) {
            headers = BaseNoGui.headerListFromIncludePath(srcFolder);
        } else {
            headers = BaseNoGui.headerListFromIncludePath(libFolder);
        }
        if (headers.length == 0) {
            activeEditor.statusError(tr("Specified folder/zip file does not contain a valid library"));
            return;
        }

        // copy folder
        File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder().folder,
                sourceFile.getName());
        if (!destinationFolder.mkdir()) {
            activeEditor
                    .statusError(I18n.format(tr("A library named {0} already exists"), sourceFile.getName()));
            return;
        }
        try {
            FileUtils.copy(sourceFile, destinationFolder);
        } catch (IOException e) {
            activeEditor.statusError(e);
            return;
        }
        activeEditor.statusNotice(tr("Library added to your libraries. Check \"Include library\" menu"));
    } catch (IOException e) {
        // FIXME error when importing. ignoring :(
    } finally {
        // delete zip created temp folder, if exists
        newLibraryImported = true;
        FileUtils.recursiveDelete(tmpFolder);
    }
}

From source file:qrcode.JavaQR.java

@Override
public void run() {

    setLayout(new BorderLayout());

    JPanel topPanel = new JPanel();
    JPanel centerPanel = new JPanel();
    JPanel bottomPanel = new JPanel();

    topPanel.setLayout(new GridLayout(0, 1));
    topPanel.setBorder(BorderFactory.createTitledBorder("Input Data"));

    JPanel rowTopPanel = new JPanel();
    rowTopPanel.setLayout(new GridLayout(0, 2));

    JLabel accKey = new JLabel("Access Key");
    JTextField accField = new JTextField(5);

    accField.setEditable(false);/*w ww.ja v a2  s. c o  m*/
    accField.setText(Data.accessKey);

    JLabel regNo = new JLabel("Registration Number");
    JTextField regField = new JTextField(5);

    regField.setEditable(false);
    regField.setText(Data.registrationNumber);

    JLabel licNo = new JLabel("License Number");
    JFormattedTextField licField = new JFormattedTextField();

    licField.setEditable(false);
    licField.setText(Data.licenseNumber);

    rowTopPanel.add(accKey);
    rowTopPanel.add(accField);
    rowTopPanel.add(regNo);
    rowTopPanel.add(regField);
    rowTopPanel.add(licNo);
    rowTopPanel.add(licField);

    topPanel.add(rowTopPanel);

    centerPanel.setLayout(new GridLayout(0, 1));
    centerPanel.setBorder(BorderFactory.createTitledBorder("QR Code"));

    JPanel rowCenPanel = new JPanel();
    rowCenPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

    JButton genBtn = new JButton("Download QR Code");
    JButton homeBtn = new JButton("Back to Start");

    String accessKey = accField.getText().toString();
    String regKey = regField.getText().toString();
    String licKey = licField.getText().toString();
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("accessKey", accessKey);
        jsonObject.put("registrationNumber", regKey);
        jsonObject.put("licenseNumber", licKey);
    } catch (JSONException e1) {
        e1.printStackTrace();
    }

    QRLogic qrGen = new QRLogic();
    BufferedImage image = qrGen.generateQR(jsonObject);
    centerPanel.add(new JLabel(new ImageIcon(image)));

    bottomPanel.setLayout(new GridLayout(2, 1));

    rowCenPanel.add(homeBtn);
    rowCenPanel.add(genBtn);
    bottomPanel.add(rowCenPanel);
    add(topPanel, BorderLayout.NORTH);
    add(bottomPanel, BorderLayout.SOUTH);
    add(centerPanel, BorderLayout.CENTER);
    Data.mainFrame.setSize(1000, 500);

    genBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Date date = new Date();
            String newDate = new SimpleDateFormat("yyyy-MM-dd h-m-a").format(date);
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            File myFile = new File(Data.registrationNumber + ".png");
            fileChooser.setSelectedFile(myFile);
            fileChooser.showSaveDialog(null);
            String dlDir = fileChooser.getSelectedFile().getPath();
            System.out.println(dlDir);
            String fileName = fileChooser.getSelectedFile().getName();
            String filePath = "";
            if (fileName != null) {
                filePath = dlDir + ".png";
            } else {
                filePath = dlDir + "/" + Data.registrationNumber + ".png";
            }

            String fileType = "png";
            myFile = new File(filePath);

            if (dlDir != null) {

                try {
                    ImageIO.write(image, fileType, myFile);
                    JOptionPane.showMessageDialog(Data.mainFrame, "QR Code Saved in " + dlDir);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

            }
        }
    });

    homeBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Data.mainFrame.showPanel("inventory");
        }
    });

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e1) {
        e1.printStackTrace();
    } catch (InstantiationException e1) {
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        e1.printStackTrace();
    } catch (UnsupportedLookAndFeelException e1) {
        e1.printStackTrace();
    }

}

From source file:ropes.MainWindow.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    //TODO display loader animation while liberys are loading
    DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();

    final JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fc.setMultiSelectionEnabled(true);//  w  w  w.jav  a 2  s. c o  m

    int returnVal = fc.showOpenDialog(MainWindow.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File[] files = fc.getSelectedFiles();
        for (File file : files) {

            if (file.isFile()) {
                addFileToList(file);
            } else if (file.isDirectory()) {
                //adds the parent to tree
                root.add(new DefaultMutableTreeNode(file));
                //adds all the subfolders and files to the parent
                addFileRecursive(file.toString());

            }

        }

    }

}

From source file:se.trixon.almond.dialogs.SimpleDialog.java

public static boolean openFileAndDirectoy(boolean multiSelection) {
    sFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    sFileChooser.setMultiSelectionEnabled(multiSelection);
    sPaths = new File[0];

    int result = sFileChooser.showOpenDialog(sParent);
    if (result == JFileChooser.APPROVE_OPTION) {
        if (multiSelection) {
            sPaths = sFileChooser.getSelectedFiles();
        } else {//w w  w  .j  a  v a 2s  . co m
            sPath = sFileChooser.getSelectedFile();
        }
    }

    return result == JFileChooser.APPROVE_OPTION;
}

From source file:se.trixon.mapollage.ui.config.ModuleSourcePanel.java

private void init() {
    sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI);
    sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES);
    sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true);
    sourceChooserPanel.setButtonListener(this);
    sourceChooserPanel.getTextField().addFocusListener(new FocusAdapter() {
        @Override//ww w .j av a  2  s.com
        public void focusLost(java.awt.event.FocusEvent evt) {
            saveSourcePath();
        }
    });

    sourceChooserPanel.getTextField().getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveSourcePath();
        }
    });

    patternTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveOption();
        }

        private void saveOption() {
            mSource.setFilePattern(patternTextField.getText());
        }
    });

    excludeTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveOption();
        }

        private void saveOption() {
            mSource.setExcludePattern(excludeTextField.getText());
        }
    });
}

From source file:se.trixon.toolbox.checksum.ChecksumTopComponent.java

private void init() {
    openButton.setIcon(Pict.Actions.DOCUMENT_OPEN.get(ICON_SIZE));
    openButton.setToolTipText(Dict.OPEN.getString());
    openButton.setVisible(false);//from   w w w.j  a  va 2  s.  c  om

    saveButton.setIcon(Pict.Actions.DOCUMENT_SAVE.get(ICON_SIZE));
    saveButton.setToolTipText(Dict.SAVE_AS.getString());
    saveButton.setEnabled(false);

    clearButton.setIcon(Pict.Actions.EDIT_CLEAR.get(ICON_SIZE));
    clearButton.setToolTipText(Dict.CLEAR.getString());
    clearButton.setVisible(false);

    calcButton.setIcon(Pict.Actions.ARROW_RIGHT.get(ICON_SIZE));
    calcButton.setToolTipText(Dict.START.getString());

    compareButton.setIcon(Pict.Actions.MERGE.get(ICON_SIZE));
    compareButton.setToolTipText(Dict.COMPARE.getString());

    File file = new File(System.getProperty("user.home"), "checksum.zero");
    sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI);
    sourceChooserPanel.setPath(file.getAbsolutePath());

    sourceChooserPanel.setHeader(Dict.SOURCE.getString());
    //        sourceChooserPanel.getButton().setVisible(false);
    sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES);
    sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true);
    sourceChooserPanel.setButtonListener(this);

    checksumChooserPanel.setHeader(mBundle.getString("checksumChooser.header"));

    if (SystemUtils.IS_OS_WINDOWS) {
        algorithmComboBox.setMaximumSize(new Dimension(300, 32767));
    }
}

From source file:se.trixon.toolbox.dbtext.DbTextTopComponent.java

private void initSourceChooser() {
    sourceChooserPanel.setPath(mOptions.getSourcePaths());
    sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI);
    sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES);
    sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true);
    sourceChooserPanel.setButtonListener(this);
    sourceChooserPanel.getTextField().addFocusListener(new FocusAdapter() {
        @Override//from w  w  w. java 2  s .c o  m
        public void focusLost(java.awt.event.FocusEvent evt) {
            saveSourcePath();
        }
    });

    sourceChooserPanel.getTextField().getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveSourcePath();
        }
    });
}

From source file:se.trixon.toolbox.photokml.config.ModuleSourcePanel.java

private void init() {
    sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI);
    sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES);
    sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true);
    sourceChooserPanel.setButtonListener(this);
    sourceChooserPanel.getTextField().addFocusListener(new FocusAdapter() {
        @Override/*from   ww  w. ja  va  2  s  . co  m*/
        public void focusLost(java.awt.event.FocusEvent evt) {
            saveSourcePath();
        }
    });

    sourceChooserPanel.getTextField().getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveSourcePath();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveSourcePath();
        }
    });

    patternTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            saveOption();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            saveOption();
        }

        private void saveOption() {
            mOptions.setSourcePattern(patternTextField.getText());
        }
    });
}

From source file:se.trixon.toolbox.relocator.RelocatorTopComponent.java

private void init() {
    mHelpId = "se.trixon.toolbox.relocator.about";

    startButton.setIcon(Pict.Actions.ARROW_RIGHT.get(ICON_SIZE));
    startButton.setToolTipText(Dict.START.getString());

    helpButton.setIcon(Pict.Actions.HELP_CONTENTS.get(ICON_SIZE));
    helpButton.setToolTipText(Dict.HELP.getString());

    opComboBox.setModel(new DefaultComboBoxModel(mBundle.getString("operations").split("\\|")));
    dateSourceComboBox.setModel(new DefaultComboBoxModel(mBundle.getString("dateSource").split("\\|")));
    followLinksCheckBox.setEnabled(!SystemUtils.IS_OS_WINDOWS);

    sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI);
    sourceChooserPanel.setHeader(Dict.SOURCE.getString());
    sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES);
    sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true);
    sourceChooserPanel.setButtonListener(this);

    previewDateFormat();//from  w  w w. j  av a 2 s  .c om

    dateFormatTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            previewDateFormat();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            previewDateFormat();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            previewDateFormat();
        }

    });

    loadOptions();
}