@Override
 public void actionPerformed(ActionEvent arg0) {
   WrappedFileChooser fc =
       new WrappedFileChooser(this.getParent(), new BriefcaseFolderChooser(this.getParent()));
   // figure out the initial directory path...
   String candidateDir = txtBriefcaseLocation.getText();
   File base = null;
   if (candidateDir == null || candidateDir.trim().length() == 0) {
     // nothing -- use default
     base = new File(BriefcasePreferences.getBriefcaseDirectoryProperty());
   } else {
     // start with candidate parent and move up the tree until we have a valid directory.
     base = new File(candidateDir).getParentFile();
     while (base != null && (!base.exists() || !base.isDirectory())) {
       base = base.getParentFile();
     }
   }
   if (base != null) {
     fc.setSelectedFile(base);
   }
   int retVal = fc.showDialog();
   if (retVal == JFileChooser.APPROVE_OPTION) {
     File parentFolder = fc.getSelectedFile();
     if (parentFolder != null) {
       String briefcasePath = parentFolder.getAbsolutePath();
       txtBriefcaseLocation.setText(
           briefcasePath + File.separator + FileSystemUtils.BRIEFCASE_DIR);
     }
   }
 }
  public BriefcaseStorageLocationDialog(Window app) {
    super(app, MessageStrings.BRIEFCASE_STORAGE_LOCATION_DIALOG_TITLE, ModalityType.DOCUMENT_MODAL);
    setRootPaneCheckingEnabled(true);
    lblTheBriefcaseStorage = new JEditorPane();
    lblTheBriefcaseStorage.setContentType("text/html");
    lblTheBriefcaseStorage.setEditorKit(new HTMLEditorKit());
    lblTheBriefcaseStorage.setOpaque(false);
    // lblTheBriefcaseStorage.setBackground(UIManager.getColor("Panel.background"));
    lblTheBriefcaseStorage.setEnabled(true);
    lblTheBriefcaseStorage.setEditable(false);
    lblTheBriefcaseStorage.setPreferredSize(new Dimension(650, 250));
    lblTheBriefcaseStorage.setText(MessageStrings.BRIEFCASE_STORAGE_LOCATION_EXPLANATION_HTML);

    JLabel lblBriefcaseStorageLocation = new JLabel(MessageStrings.BRIEFCASE_STORAGE_LOCATION);

    txtBriefcaseLocation = new JTextField();
    String directoryPath = BriefcasePreferences.getBriefcaseDirectoryIfSet();
    if (directoryPath == null || directoryPath.length() == 0) {
      txtBriefcaseLocation.setColumns(10);
    } else {
      txtBriefcaseLocation.setText(directoryPath + File.separator + FileSystemUtils.BRIEFCASE_DIR);
    }
    txtBriefcaseLocation.setEditable(false);

    JButton btnChange = new JButton("Change...");
    btnChange.addActionListener(this);

    btnOK = new JButton("OK");
    btnOK.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            try {
              String filename = txtBriefcaseLocation.getText();
              if (filename == null || filename.trim().length() == 0) {
                ODKOptionPane.showErrorDialog(
                    BriefcaseStorageLocationDialog.this,
                    "Please change the " + MessageStrings.BRIEFCASE_STORAGE_LOCATION + ".",
                    MessageStrings.INVALID_BRIEFCASE_STORAGE_LOCATION);
                return;
              }
              File folder = new File(txtBriefcaseLocation.getText());
              File parentFolder = folder.getParentFile();
              FileSystemUtils.assertBriefcaseStorageLocationParentFolder(parentFolder);
              BriefcasePreferences.setBriefcaseDirectoryProperty(parentFolder.getAbsolutePath());
              BriefcaseStorageLocationDialog.this.setVisible(false);
            } catch (FileSystemException e) {
              e.printStackTrace();
              ODKOptionPane.showErrorDialog(
                  BriefcaseStorageLocationDialog.this,
                  "Unable to create "
                      + FileSystemUtils.BRIEFCASE_DIR
                      + ".  Please change the "
                      + MessageStrings.BRIEFCASE_STORAGE_LOCATION
                      + ".",
                  "Failed to Create " + FileSystemUtils.BRIEFCASE_DIR);
            }
          }
        });

    btnCancel = new JButton("Cancel");
    btnCancel.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            isCancelled = true;
            BriefcaseStorageLocationDialog.this.setVisible(false);
          }
        });

    GroupLayout groupLayout = new GroupLayout(getContentPane());
    groupLayout.setHorizontalGroup(
        groupLayout
            .createSequentialGroup()
            .addContainerGap()
            .addGroup(
                groupLayout
                    .createParallelGroup(Alignment.LEADING)
                    .addGroup(
                        groupLayout
                            .createParallelGroup(Alignment.LEADING)
                            .addComponent(
                                lblTheBriefcaseStorage,
                                GroupLayout.PREFERRED_SIZE,
                                GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(lblBriefcaseStorageLocation)
                            .addGroup(
                                groupLayout
                                    .createSequentialGroup()
                                    .addComponent(
                                        txtBriefcaseLocation,
                                        GroupLayout.PREFERRED_SIZE,
                                        GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addComponent(btnChange))
                            .addGroup(
                                Alignment.TRAILING,
                                groupLayout
                                    .createSequentialGroup()
                                    .addComponent(btnOK)
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addComponent(btnCancel))))
            .addContainerGap());
    groupLayout.setVerticalGroup(
        groupLayout
            .createSequentialGroup()
            .addContainerGap()
            .addComponent(
                lblTheBriefcaseStorage,
                GroupLayout.PREFERRED_SIZE,
                GroupLayout.PREFERRED_SIZE,
                GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(lblBriefcaseStorageLocation)
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(
                groupLayout
                    .createParallelGroup(Alignment.BASELINE)
                    .addComponent(
                        txtBriefcaseLocation,
                        GroupLayout.PREFERRED_SIZE,
                        GroupLayout.DEFAULT_SIZE,
                        GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnChange))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(
                groupLayout
                    .createParallelGroup(Alignment.BASELINE)
                    .addComponent(btnOK)
                    .addComponent(btnCancel))
            .addContainerGap());
    getContentPane().setLayout(groupLayout);
    pack();
  }
 public static File getBriefcaseFolder() {
   return new File(new File(BriefcasePreferences.getBriefcaseDirectoryProperty()), BRIEFCASE_DIR);
 }