Пример #1
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);
  }
Пример #2
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();
          }
        });
  }