/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.dlect.ui.prefs;
import java.awt.Window;
import java.io.File;
import javax.swing.JDialog;
import javax.swing.JRootPane;
import javax.swing.UIManager;
/**
*
* @author lee
*/
public class FileChooserDialog extends javax.swing.JDialog {
private boolean canceled;
/**
* Creates new form FileChooserDialog
*/
public FileChooserDialog(Window parent) {
super(parent, ModalityType.APPLICATION_MODAL);
this.setLocationRelativeTo(parent);
initComponents();
getRootPane().setDefaultButton(selectButton);
this.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
chooser = new javax.swing.JFileChooser();
newFolderButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
selectButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Move Data To...");
setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
getContentPane().setLayout(new java.awt.GridBagLayout());
chooser.setControlButtonsAreShown(false);
chooser.setFileFilter(null);
chooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
getContentPane().add(chooser, gridBagConstraints);
newFolderButton.setText("New Folder");
newFolderButton.setToolTipText("");
newFolderButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newFolderButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weightx = 1.0;
getContentPane().add(newFolderButton, gridBagConstraints);
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
getContentPane().add(cancelButton, gridBagConstraints);
selectButton.setText("Select");
selectButton.setToolTipText("");
selectButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
selectButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
getContentPane().add(selectButton, gridBagConstraints);
pack();
}// </editor-fold>//GEN-END:initComponents
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
this.canceled = true;
this.setVisible(false);
}//GEN-LAST:event_cancelButtonActionPerformed
private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
this.canceled = false;
this.setVisible(false);
}//GEN-LAST:event_selectButtonActionPerformed
private void newFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newFolderButtonActionPerformed
File folder = chooser.getCurrentDirectory();
FolderChooser fc = new FolderChooser(this, folder);
fc.setVisible(true);
if (fc.getNewFolderName() != null) {
File newF = new File(folder, fc.getNewFolderName() + "/");
newF.mkdir();
chooser.rescanCurrentDirectory();
chooser.setSelectedFile(newF);
}
}//GEN-LAST:event_newFolderButtonActionPerformed
public void setSelectedFile(File file) {
chooser.setSelectedFile(file);
}
public boolean isCanceled() {
return canceled;
}
public File getSelectedDirectory() {
File sel = chooser.getSelectedFile();
File cur = chooser.getCurrentDirectory();
return (sel == null || !sel.isDirectory()) ? cur : sel;
}
public static void main(String[] args) {
new FileChooserDialog(null).setVisible(true);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JFileChooser chooser;
private javax.swing.JButton newFolderButton;
private javax.swing.JButton selectButton;
// End of variables declaration//GEN-END:variables
}