Example usage for javax.swing JFileChooser DIRECTORY_CHANGED_PROPERTY

List of usage examples for javax.swing JFileChooser DIRECTORY_CHANGED_PROPERTY

Introduction

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

Prototype

String DIRECTORY_CHANGED_PROPERTY

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

Click Source Link

Document

Identifies user's directory change.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }/*from  w  ww .j  av  a2 s  .c o m*/
        }
    });
}

From source file:Main.java

public static void main(String[] argv) {
    final JFileChooser chooser = new JFileChooser();

    File curDir = chooser.getCurrentDirectory();
    chooser.setDialogTitle("" + curDir.getAbsolutePath());

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                File curDir = chooser.getCurrentDirectory();

                chooser.setDialogTitle("" + curDir.getAbsolutePath());
            }/*from   www.j  a v  a2 s.  c  om*/
        }
    });
}

From source file:components.ImagePreview.java

public void propertyChange(PropertyChangeEvent e) {
    boolean update = false;
    String prop = e.getPropertyName();

    //If the directory changed, don't show an image.
    if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
        file = null;/*from w  ww . j a  v a2 s. c om*/
        update = true;

        //If a file became selected, find out which one.
    } else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) {
        file = (File) e.getNewValue();
        update = true;
    }

    //Update the preview accordingly.
    if (update) {
        thumbnail = null;
        if (isShowing()) {
            loadImage();
            repaint();
        }
    }
}

From source file:FileChooserDemo2.java

public void propertyChange(PropertyChangeEvent e) {
    boolean update = false;
    String prop = e.getPropertyName();

    // If the directory changed, don't show an image.
    if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
        file = null;/* w  w w .j  a  v  a 2  s  .c  o m*/
        update = true;

        // If a file became selected, find out which one.
    } else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) {
        file = (File) e.getNewValue();
        update = true;
    }

    // Update the preview accordingly.
    if (update) {
        thumbnail = null;
        if (isShowing()) {
            loadImage();
            repaint();
        }
    }
}

From source file:ome.formats.importer.gui.FileQueueHandler.java

public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();
    if (prop.equals(ADD)) {
        doSelection(false);//  w  w  w  . j a v  a 2  s.  c  om
    }

    else if (prop.equals(REMOVE)) {
        int[] rows = qTable.getQueue().getSelectedRows();

        if (rows.length == 0) {
            JOptionPane.showMessageDialog(viewer, "You must select at least one file in the queue to\n"
                    + "remove. Choose an image in the right-hand panel \n" + "first before removing.");
            return;
        }

        while (rows.length > 0) {
            if (qTable.getQueue().getValueAt(rows[0], 2) == "added"
                    || qTable.getQueue().getValueAt(rows[0], 2) == "pending") {
                removeFileFromQueue(rows[0]);
                rows = qTable.getQueue().getSelectedRows();
            }
        }
    }

    else if (prop.equals(CLEARDONE)) {
        int numRows = qTable.getQueue().getRowCount();

        for (int i = (numRows - 1); i >= 0; i--) {
            if (qTable.getQueue().getValueAt(i, 2) == "done") {
                removeFileFromQueue(i);
            }
        }
        qTable.clearDoneBtn.setEnabled(false);
    }

    else if (prop.equals(CLEARFAILED)) {
        int numRows = qTable.getQueue().getRowCount();

        for (int i = (numRows - 1); i >= 0; i--) {
            if (qTable.getQueue().getValueAt(i, 2) == "failed"
                    || qTable.getQueue().getValueAt(i, 2) == "unreadable") {
                removeFileFromQueue(i);
            }
        }
        qTable.clearFailedBtn.setEnabled(false);
    }

    else if (prop.equals(IMPORT)) {
        if (viewer.getLoggedIn() == false) {
            JOptionPane.showMessageDialog(viewer, "You must be logged in before you can import.");
            return;
        }

        qTable.clearDoneBtn.setEnabled(false);
        qTable.clearFailedBtn.setEnabled(false);
        try {
            if (qTable.importing == false) {
                ImportContainer[] candidates = qTable.getImportContainersFromTable();

                if (candidates != null) {
                    ImportLibrary library = new ImportLibrary(getOMEROMetadataStoreClient(), importReader);
                    library.addObserver(new LoggingImportMonitor());

                    if (getOMEROMetadataStoreClient() != null) {
                        ImportHandler importHandler = new ImportHandler(importEx, viewer, qTable, config,
                                library, candidates);
                        importHandler.addObserver(viewer);
                        importHandler.addObserver(qTable);
                    }
                }
                qTable.importing = true;
                qTable.getQueue().setRowSelectionAllowed(false);
                qTable.removeBtn.setEnabled(false);
            } else {
                qTable.importBtn.setText("Wait...");
                qTable.importBtn.setEnabled(false);
                viewer.getStatusBar().setStatusIcon("gfx/import_cancelling_16.png",
                        "Cancelling import... please wait.");
                //JOptionPane.showMessageDialog(viewer, 
                //        "You import will be cancelled after the " +
                //        "current file has finished importing.");
                if (cancelImportDialog(viewer) == true) {
                    qTable.cancel = true;
                    qTable.abort = true;
                    qTable.importing = false;
                    System.exit(0);
                } else {
                    qTable.cancel = true;
                    qTable.importing = false;
                }
            }
        } catch (Exception ex) {
            log.error("Generic error while updating GUI for import.", ex);
            return;
        }
    }

    else if (prop.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
        config.savedDirectory.set(new File(fileChooser.getCurrentDirectory().getAbsolutePath()));
    }

    else if (prop.equals(REFRESH)) {
        fileChooser.setVisible(false);
        fileChooser.rescanCurrentDirectory();
        fileChooser.setVisible(true);
    }
}