/*
     * Fires AccessibleActiveDescendant PropertyChangeEvent to notify listeners
     * on the popup menu invoker that a popup list item has been selected
     */
    private void fireActiveDescendant() {
      if (JPopupMenu.this instanceof BasicComboPopup) {
        // get the popup list
        JList popupList = ((BasicComboPopup) JPopupMenu.this).getList();
        if (popupList == null) {
          return;
        }

        // get the first selected item
        AccessibleContext ac = popupList.getAccessibleContext();
        AccessibleSelection selection = ac.getAccessibleSelection();
        if (selection == null) {
          return;
        }
        Accessible a = selection.getAccessibleSelection(0);
        if (a == null) {
          return;
        }
        AccessibleContext selectedItem = a.getAccessibleContext();

        // fire the event with the popup invoker as the source.
        if (selectedItem != null && invoker != null) {
          AccessibleContext invokerContext = invoker.getAccessibleContext();
          if (invokerContext != null) {
            // Check invokerContext because Component.getAccessibleContext
            // returns null. Classes that extend Component are responsible
            // for returning a non-null AccessibleContext.
            invokerContext.firePropertyChange(
                ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, null, selectedItem);
          }
        }
      }
    }
    public void valueChanged(ListSelectionEvent evt) {
      if (!evt.getValueIsAdjusting()) {
        JFileChooser chooser = getFileChooser();
        FileSystemView fsv = chooser.getFileSystemView();
        JList list = (JList) evt.getSource();

        int fsm = chooser.getFileSelectionMode();
        boolean useSetDirectory = usesSingleFilePane && (fsm == JFileChooser.FILES_ONLY);

        if (chooser.isMultiSelectionEnabled()) {
          File[] files = null;
          Object[] objects = list.getSelectedValues();
          if (objects != null) {
            if (objects.length == 1
                && ((File) objects[0]).isDirectory()
                && chooser.isTraversable(((File) objects[0]))
                && (useSetDirectory || !fsv.isFileSystem(((File) objects[0])))) {
              setDirectorySelected(true);
              setDirectory(((File) objects[0]));
            } else {
              ArrayList<File> fList = new ArrayList<File>(objects.length);
              for (Object object : objects) {
                File f = (File) object;
                boolean isDir = f.isDirectory();
                if ((chooser.isFileSelectionEnabled() && !isDir)
                    || (chooser.isDirectorySelectionEnabled() && fsv.isFileSystem(f) && isDir)) {
                  fList.add(f);
                }
              }
              if (fList.size() > 0) {
                files = fList.toArray(new File[fList.size()]);
              }
              setDirectorySelected(false);
            }
          }
          chooser.setSelectedFiles(files);
        } else {
          File file = (File) list.getSelectedValue();
          if (file != null
              && file.isDirectory()
              && chooser.isTraversable(file)
              && (useSetDirectory || !fsv.isFileSystem(file))) {

            setDirectorySelected(true);
            setDirectory(file);
            if (usesSingleFilePane) {
              chooser.setSelectedFile(null);
            }
          } else {
            setDirectorySelected(false);
            if (file != null) {
              chooser.setSelectedFile(file);
            }
          }
        }
      }
    }
 public void mouseEntered(MouseEvent evt) {
   if (list != null) {
     TransferHandler th1 = getFileChooser().getTransferHandler();
     TransferHandler th2 = list.getTransferHandler();
     if (th1 != th2) {
       list.setTransferHandler(th1);
     }
     if (getFileChooser().getDragEnabled() != list.getDragEnabled()) {
       list.setDragEnabled(getFileChooser().getDragEnabled());
     }
   }
 }
  protected JScrollPane createDirectoryList() {
    directoryList = new JList();
    align(directoryList);

    directoryList.setCellRenderer(new DirectoryCellRenderer());
    directoryList.setModel(new MotifDirectoryListModel());
    directoryList.addMouseListener(createDoubleClickListener(getFileChooser(), directoryList));
    directoryList.addListSelectionListener(createListSelectionListener(getFileChooser()));

    JScrollPane scrollpane = new JScrollPane(directoryList);
    scrollpane.setMaximumSize(MAX_SIZE);
    scrollpane.setPreferredSize(prefListSize);
    align(scrollpane);
    return scrollpane;
  }
  /** Export a list of user selected projections */
  public void doExport() {
    List projections = getProjections();

    Vector<String> projectionNames = new Vector<>(projections.size());
    for (int i = 0; i < projections.size(); i++) {
      ProjectionImpl projection = (ProjectionImpl) projections.get(i);
      projectionNames.add(projection.getName());
    }

    JList<String> jlist = new JList<>(projectionNames);
    JPanel contents =
        GuiUtils.topCenter(
            GuiUtils.cLabel("Please select the projections you want to export"),
            GuiUtils.makeScrollPane(jlist, 200, 400));

    if (!GuiUtils.showOkCancelDialog(null, "Export Projections", contents, null)) {
      return;
    }

    int[] indices = jlist.getSelectedIndices();
    if ((indices == null) || (indices.length == 0)) {
      return;
    }
    List<ProjectionImpl> selected = new ArrayList<>(indices.length);
    for (int i = 0; i < indices.length; i++) {
      selected.add((ProjectionImpl) projections.get(indices[i]));
    }
    String xml = (new XmlEncoder()).toXml(selected);
    String filename = FileManager.getWriteFile(FileManager.FILTER_XML, FileManager.SUFFIX_XML);
    if (filename == null) {
      return;
    }
    try {
      IOUtil.writeFile(filename, xml);
    } catch (Exception exc) {
      LogUtil.logException("Writing projection file: " + filename, exc);
    }
  }
    public void mouseClicked(MouseEvent evt) {
      // Note: we can't depend on evt.getSource() because of backward
      // compatability
      if (list != null && SwingUtilities.isLeftMouseButton(evt) && (evt.getClickCount() % 2 == 0)) {

        int index = SwingUtilities2.loc2IndexFileList(list, evt.getPoint());
        if (index >= 0) {
          File f = (File) list.getModel().getElementAt(index);
          try {
            // Strip trailing ".."
            f = ShellFolder.getNormalizedFile(f);
          } catch (IOException ex) {
            // That's ok, we'll use f as is
          }
          if (getFileChooser().isTraversable(f)) {
            list.clearSelection();
            changeDirectory(f);
          } else {
            getFileChooser().approveSelection();
          }
        }
      }
    }
  protected JScrollPane createFilesList() {
    fileList = new JList();

    if (getFileChooser().isMultiSelectionEnabled()) {
      fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    } else {
      fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }

    fileList.setModel(new MotifFileListModel());
    fileList.setCellRenderer(new FileCellRenderer());
    fileList.addListSelectionListener(createListSelectionListener(getFileChooser()));
    fileList.addMouseListener(createDoubleClickListener(getFileChooser(), fileList));
    align(fileList);
    JScrollPane scrollpane = new JScrollPane(fileList);
    scrollpane.setPreferredSize(prefListSize);
    scrollpane.setMaximumSize(MAX_SIZE);
    align(scrollpane);
    return scrollpane;
  }
 public void removeNotify() {
   KeyboardFocusManager.getCurrentKeyboardFocusManager()
       .removePropertyChangeListener("permanentFocusOwner", editorRemover); // NOI18N
   super.removeNotify();
 }