/** Listener to handle button actions */
 public void actionPerformed(ActionEvent e) {
   // Check if the user changed the service filter option
   if (e.getSource() == service_box) {
     service_list.setEnabled(service_box.isSelected());
     service_list.clearSelection();
     remove_service_button.setEnabled(false);
     add_service_field.setEnabled(service_box.isSelected());
     add_service_field.setText("");
     add_service_button.setEnabled(false);
   }
   // Check if the user pressed the add service button
   if ((e.getSource() == add_service_button) || (e.getSource() == add_service_field)) {
     String text = add_service_field.getText();
     if ((text != null) && (text.length() > 0)) {
       service_data.addElement(text);
       service_list.setListData(service_data);
     }
     add_service_field.setText("");
     add_service_field.requestFocus();
   }
   // Check if the user pressed the remove service button
   if (e.getSource() == remove_service_button) {
     Object[] sels = service_list.getSelectedValues();
     for (int i = 0; i < sels.length; i++) {
       service_data.removeElement(sels[i]);
     }
     service_list.setListData(service_data);
     service_list.clearSelection();
   }
 }
    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);
            }
          }
        }
      }
    }
Beispiel #3
0
  private Collection<Config.ConfigEntry> getSelectedCharacters() {
    final Collection<Config.ConfigEntry> entries = new ArrayList<Config.ConfigEntry>();

    Object[] selectedValues = herolabsCharacterList.getSelectedValues();
    for (Object object : selectedValues) {
      entries.add(config.getOrCreate(((Character) object).getName()));
    }

    return entries;
  }
 public void valueChanged(ListSelectionEvent e) {
   if (e.getValueIsAdjusting() == false) {
     Object[] tcs = list.getSelectedValues();
     typeCodes = new ArrayList<String>();
     for (int i = 0; i < tcs.length; i++) {
       String typeCode = (String) tcs[i];
       typeCodes.add(typeCode);
     }
   }
 }
Beispiel #5
0
  private void showContextMenu(JList characterList, MouseEvent mouseEvent) {
    // TODO: handle right-click outside of selected range correctly (should treat as single
    // selection, but not deselect)
    boolean multipleSelected = herolabsCharacterList.getSelectedValues().length > 1;
    if (mouseEvent.isPopupTrigger() && mouseEvent.getClickCount() == 1) {
      if (!multipleSelected) {
        herolabsCharacterList.setSelectedIndex(
            herolabsCharacterList.locationToIndex(mouseEvent.getPoint()));
      }

      if (contextMenuEnabled) {
        JPopupMenu menu = new JPopupMenu();
        JMenuItem menuItem;

        menuItem = new JMenuItem("Configure character" + (multipleSelected ? "s" : "") + "...");
        menuItem.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) {
                configureSelectedCharacters();
              }
            });
        menu.add(menuItem);

        menuItem = new JMenuItem("Configure using portfolio defaults");
        menuItem.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) {
                resetToDefaultsForSelectedCharacters();
              }
            });
        menu.add(menuItem);

        menuItem = new JMenuItem("Export character" + (multipleSelected ? "s" : ""));
        menuItem.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) {
                exportSelectedCharacters();
              }
            });
        menu.add(menuItem);

        menuItem = new JMenuItem("Clear configuration" + (multipleSelected ? "s" : ""));
        menuItem.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) {
                clearConfigForSelectedCharacters();
              }
            });
        menu.add(menuItem);

        menu.show(characterList, mouseEvent.getX(), mouseEvent.getY());
      }
    }
  }
  static List<Bookmark> getSelectedBookmarks(JList list) {
    List<Bookmark> answer = new ArrayList<Bookmark>();

    //noinspection deprecation
    for (Object value : list.getSelectedValues()) {
      if (value instanceof BookmarkItem) {
        answer.add(((BookmarkItem) value).getBookmark());
      } else {
        return Collections.emptyList();
      }
    }

    return answer;
  }
Beispiel #7
0
  private void clearConfigForSelectedCharacters() {
    int confirmation =
        JOptionPane.showConfirmDialog(
            panel,
            "WARNING:  this will erase the current configuration for all selected characters. \nAre you certain you wish to do this?",
            "Clear Selected Configurations?",
            JOptionPane.YES_NO_OPTION);

    if (confirmation == JOptionPane.YES_OPTION) {
      for (Object character : herolabsCharacterList.getSelectedValues()) {
        config.remove(((Character) character).getName());
      }
    }

    herolabsCharacterList.repaint();
  }
Beispiel #8
0
  private void resetToDefaultsForSelectedCharacters() {
    int confirmation =
        JOptionPane.showConfirmDialog(
            panel,
            "NOTE:  this will attempt to replace any custom configuration for the selected characters with the Portfolio defaults. \nAre you certain you wish to do this?",
            "Reset to portfolio defaults?",
            JOptionPane.YES_NO_OPTION);

    if (confirmation == JOptionPane.YES_OPTION) {
      for (Object character : herolabsCharacterList.getSelectedValues()) {
        config.populateCharacterWithDefaults(((Character) character).getName(), true);
      }
    }

    herolabsCharacterList.repaint();
  }
  @NotNull
  public static <T extends PsiElement> JBPopup getPsiElementPopup(
      @NotNull T[] elements,
      @NotNull final PsiElementListCellRenderer<T> renderer,
      @Nullable final String title,
      @NotNull final PsiElementProcessor<T> processor,
      @Nullable final T selection) {
    final JList list =
        new JBListWithHintProvider(elements) {
          @Nullable
          @Override
          protected PsiElement getPsiElementForHint(Object selectedValue) {
            return (PsiElement) selectedValue;
          }
        };
    list.setCellRenderer(renderer);

    list.setFont(EditorUtil.getEditorFont());

    if (selection != null) {
      list.setSelectedValue(selection, true);
    }

    final Runnable runnable =
        () -> {
          int[] ids = list.getSelectedIndices();
          if (ids == null || ids.length == 0) return;
          for (Object element : list.getSelectedValues()) {
            if (element != null) {
              processor.execute((T) element);
            }
          }
        };

    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    if (title != null) {
      builder.setTitle(title);
    }
    renderer.installSpeedSearch(builder, true);

    JBPopup popup = builder.setItemChoosenCallback(runnable).createPopup();

    builder.getScrollPane().setBorder(null);
    builder.getScrollPane().setViewportBorder(null);

    return popup;
  }
Beispiel #10
0
  private void exportCharacters() {
    Object[] selectedValues = herolabsCharacterList.getSelectedValues();
    HeroLabPathfinderDigester dig = new HeroLabPathfinderDigester();
    boolean success = true;
    ArrayList<Character> notExported = new ArrayList<Character>();

    for (Object object : selectedValues) {
      Character character = (Character) object;
      try {
        if (!dig.saveCharacter(config, character)) {
          notExported.add(character);
        }
      } catch (IOException io) {
        success = false;
        errorDialog(io.getMessage(), "Something bad happened:" + io.toString());

      } catch (SAXException saxe) {
        success = false;
        errorDialog(saxe.getMessage(), "Something bad happened:" + saxe.toString());
      } catch (Exception e) {
        success = false;
        errorDialog(e.getMessage(), "Something bad happened:" + e.toString());
      }
    }

    if (success) {
      String message =
          "Successfully exported "
              + (selectedValues.length - notExported.size())
              + " out of "
              + selectedValues.length
              + " Maptools token(s).";
      if (!notExported.isEmpty()) {
        message +=
            "  "
                + notExported.size()
                + " tokens were not exported as they are not fully configured.";
        // TODO: do something more useful with this collection
      }

      JOptionPane.showMessageDialog(panel, message);
    }
  }
 // -----------------------------------------
 public String[] getSelectedItems() {
   Object[] obj = listWindow.getSelectedValues();
   String[] s = new String[obj.length];
   for (int i = 0; i < obj.length; i++) s[i] = obj[i].toString();
   return s;
 }