예제 #1
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());
      }
    }
  }
예제 #2
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();
  }
예제 #3
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();
  }
예제 #4
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;
  }
예제 #5
0
 private void exportSelectedCharacters() {
   if (herolabsCharacterList.getSelectedIndex() >= 0) {
     Character c =
         (Character)
             herolabsCharacterList
                 .getModel()
                 .getElementAt(herolabsCharacterList.getSelectedIndex());
     Config.ConfigEntry ce = config.get(c.getName());
     if (ce != null && ce.isOk()) {
       exportCharacters();
     } else {
       JOptionPane.showMessageDialog(
           panel,
           "The character you selected hasn't been configured yet.  Please configure "
               + "and try again.",
           "Export Warning",
           JOptionPane.WARNING_MESSAGE);
     }
   }
 }
예제 #6
0
  public void setDefaults() throws IOException {

    herolabsXMLChooser = new JFileChooser(prefs.get(HEROLABS_XML_DIR, ""));

    importButton.setEnabled(true);
    configurePortfolioButton.setEnabled(true);
    exportAllButton.setEnabled(false);
    exportSelectedButton.setEnabled(false);

    setXMLChooserFileFilter(herolabsXMLChooser);

    IconListRenderer listRenderer = new IconListRenderer(config, this);
    herolabsCharacterList.setCellRenderer(listRenderer);
  }
예제 #7
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);
    }
  }
예제 #8
0
  public TokenLabUI() throws IOException {
    prefs = Preferences.userNodeForPackage(this.getClass());
    config = new Config(prefs);

    importButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int returnVal = herolabsXMLChooser.showOpenDialog(null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {

              File mostRecentOutputDirectory = herolabsXMLChooser.getSelectedFile();
              prefs.put(HEROLABS_XML_DIR, mostRecentOutputDirectory.getAbsolutePath());

              File xmlFile = herolabsXMLChooser.getSelectedFile();

              if (!xmlFile.exists()) {
                errorDialog(
                    "File not found",
                    "File " + xmlFile + " does not exists, please select accept valid file\",");
                return;
              }

              HeroLabPathfinderDigester dig = new HeroLabPathfinderDigester();

              try {

                dig.parse(xmlFile);
                DefaultListModel model = new DefaultListModel();
                herolabsCharacterList.setModel(model);

                for (Character c : dig.getCharacters()) {
                  model.addElement(c);
                }

                herolabsCharacterList.validate();

              } catch (JAXBException je) {
                je.printStackTrace();
              }
            }
          }
        });

    configurePortfolioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            PortfolioConfigurationDialog dialog = new PortfolioConfigurationDialog(config);
            dialog.pack();
            dialog.setVisible(true);

            if (dialog.isOkPressed()) {
              config.setOutputTokenDirectory(dialog.getOutputTokenDirectory());
              config.setPortraitDirectory(dialog.getPortraitDirectory());
              config.setPogDirectory(dialog.getPogDirectory());

              defaultNonOverriddenConfigurations();
            }
          }
        });

    herolabsCharacterList.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            contextMenuEnabled = true;
            exportSelectedButton.setEnabled(true);
          }
        });

    herolabsCharacterList.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent mouseEvent) {
            if (mouseEvent.getClickCount() == 2) {
              configureSelectedCharacters();
            }
          }

          public void mouseReleased(MouseEvent mouseEvent) {
            showContextMenu(herolabsCharacterList, mouseEvent);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            showContextMenu(herolabsCharacterList, mouseEvent);
          }
        });

    exportSelectedButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            exportSelectedCharacters();
          }
        });

    exportAllButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // first select only valid characters
            ListModel lm = herolabsCharacterList.getModel();
            LinkedList<Integer> selectedIndices = new LinkedList<Integer>();
            for (int i = 0; i < lm.getSize(); i++) {
              Character c = (Character) lm.getElementAt(i);
              Config.ConfigEntry ce = config.get(c.getName());
              if (ce != null && ce.isOk()) {
                selectedIndices.add(i);
              }
            }
            int[] index = new int[selectedIndices.size()];
            for (int i = 0; i < selectedIndices.size(); i++) {
              index[i] = selectedIndices.get(i);
            }

            herolabsCharacterList.setSelectedIndices(index);
            exportCharacters();
          }
        });
  }
예제 #9
0
 private void defaultNonOverriddenConfigurations() {
   ListModel model = herolabsCharacterList.getModel();
   for (int i = 0; i < model.getSize(); i++) {
     config.populateCharacterWithDefaults(((Character) model.getElementAt(i)).getName(), false);
   }
 }