Exemplo n.º 1
0
 /** Returns the title of this dialog */
 public String getDialogTitle(JFileChooser fc) {
   String dialogTitle = fc.getDialogTitle();
   if (dialogTitle != null) {
     return dialogTitle;
   } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
     return openDialogTitleText;
   } else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
     return saveDialogTitleText;
   } else {
     return getApproveButtonText(fc);
   }
 }
Exemplo n.º 2
0
  /** @return file chooser in dialog */
  public Component getCustomEditor() {
    final JFileChooser chooser = createFileChooser();

    final javax.swing.JDialog dialog =
        new javax.swing.JDialog(
            TopManager.getDefault().getWindowManager().getMainWindow(),
            chooser.getDialogTitle(),
            true);

    // attach cancel also to Escape key
    dialog
        .getRootPane()
        .registerKeyboardAction(
            new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                dialog.setVisible(false);
                dialog.dispose();
              }
            },
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, true),
            javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW);

    dialog.addKeyListener(
        new java.awt.event.KeyAdapter() {
          public void keyPressed(java.awt.event.KeyEvent evt) {
            if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) {
              dialog.setVisible(false);
              dialog.dispose();
            }
          }
        });

    dialog.getContentPane().setLayout(new java.awt.BorderLayout());
    dialog.getContentPane().add(chooser, java.awt.BorderLayout.CENTER);
    chooser.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {
              File f = chooser.getSelectedFile();
              setValue(f);
              dialog.setVisible(false);
              dialog.dispose();
            } else if (JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) {
              dialog.setVisible(false);
              dialog.dispose();
            }
          }
        });

    HelpCtx.setHelpIDString(dialog.getRootPane(), getHelpCtx().getHelpID());
    return dialog;
  }
 @Override
 protected boolean isMatching(@Nonnull JFileChooser fileChooser) {
   return TITLE.equals(fileChooser.getDialogTitle());
 }