Пример #1
0
  public void initialize() {
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    getContentPane().setLayout(gridbag);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new Insets(2, 2, 2, 2);

    int col = 0;
    Utility.buildConstraints(c, col, 0, 1, 1, 100, 20);
    JLabel label =
        new JLabel(LanguageBundle.getFormattedString("in_SolverView_Perspective")); // $NON-NLS-1$
    gridbag.setConstraints(label, c);
    getContentPane().add(label);

    Utility.buildConstraints(c, col++, 1, 1, 1, 0, 20);
    gridbag.setConstraints(identifierChooser, c);
    getContentPane().add(identifierChooser);

    Utility.buildConstraints(c, col++, 1, 1, 1, 0, 20);
    gridbag.setConstraints(scopeChooser, c);
    getContentPane().add(scopeChooser);

    Utility.buildConstraints(c, col++, 1, 1, 1, 0, 20);
    gridbag.setConstraints(objectChooser, c);
    getContentPane().add(objectChooser);

    Utility.buildConstraints(c, col++, 1, 1, 1, 0, 20);
    label =
        new JLabel(
            LanguageBundle.getFormattedString("in_SolverView_VarName") // $NON-NLS-1$
            );
    gridbag.setConstraints(label, c);
    getContentPane().add(label);

    Utility.buildConstraints(c, col++, 1, 1, 1, 0, 20);
    gridbag.setConstraints(varName, c);
    getContentPane().add(varName);

    tableModel = new SolverTableModel();
    viewTable = new JTable(tableModel);

    viewTable.getColumnModel().getColumn(0).setPreferredWidth(25);
    viewTable.getColumnModel().getColumn(1).setPreferredWidth(50);
    viewTable.getColumnModel().getColumn(2).setPreferredWidth(25);
    viewTable.getColumnModel().getColumn(3).setPreferredWidth(50);

    Utility.buildConstraints(c, 0, 2, col, 1, 0, 1000);
    JScrollPane pane = new JScrollPane(viewTable);
    viewTable.setFillsViewportHeight(true);
    pane.setPreferredSize(new Dimension(500, 300));
    gridbag.setConstraints(pane, c);
    getContentPane().add(pane);

    setTitle("Core Variable Debug View");
    getContentPane().setSize(500, 400);
    pack();
    Utility.centerFrame(this, true);
  }
Пример #2
0
  /* (non-Javadoc)
   * @see pcgen.core.prereq.PrerequisiteTest#toHtmlString(pcgen.core.prereq.Prerequisite)
   */
  @Override
  public String toHtmlString(final Prerequisite prereq) {
    final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance();

    StringBuilder str = new StringBuilder(250);
    String delimiter = ""; // $NON-NLS-1$
    for (Prerequisite element : prereq.getPrerequisites()) {
      final PrerequisiteTest test = factory.getTest(element.getKind());
      if (test == null) {
        Logging.errorPrintLocalised(
            "PreMult.cannot_find_subformatter", element.getKind()); // $NON-NLS-1$
      } else {
        str.append(delimiter);
        if (test instanceof PreMult && !delimiter.equals("")) {
          str.append("##BR##");
        }
        str.append(test.toHtmlString(element));
        delimiter = LanguageBundle.getString("PreMult.html_delimiter"); // $NON-NLS-1$
      }
    }

    // Handle some special cases - all required, one required or none required
    int numRequired = -1;
    if (StringUtils.isNumeric(prereq.getOperand())) {
      numRequired = Integer.parseInt(prereq.getOperand());
    }
    if ((prereq.getOperator() == PrerequisiteOperator.GTEQ
            || prereq.getOperator() == PrerequisiteOperator.GT
            || prereq.getOperator() == PrerequisiteOperator.EQ)
        && numRequired == prereq.getPrerequisites().size()) {
      return LanguageBundle.getFormattedString(
          "PreMult.toHtmlAllOf", //$NON-NLS-1$
          str.toString());
    }
    if ((prereq.getOperator() == PrerequisiteOperator.GTEQ
            || prereq.getOperator() == PrerequisiteOperator.EQ)
        && numRequired == 1) {
      return LanguageBundle.getFormattedString(
          "PreMult.toHtmlEither", //$NON-NLS-1$
          str.toString());
    }
    if ((prereq.getOperator() == PrerequisiteOperator.LT && numRequired == 1)
        || ((prereq.getOperator() == PrerequisiteOperator.EQ
                || prereq.getOperator() == PrerequisiteOperator.LTEQ)
            && numRequired == 0)) {
      return LanguageBundle.getFormattedString(
          "PreMult.toHtmlNone", //$NON-NLS-1$
          str.toString());
    }

    return LanguageBundle.getFormattedString(
        "PreMult.toHtml", //$NON-NLS-1$
        prereq.getOperator().toDisplayString(),
        prereq.getOperand(),
        str.toString());
  }
Пример #3
0
 /* (non-Javadoc)
  * @see pcgen.core.prereq.PrerequisiteTest#toHtmlString(pcgen.core.prereq.Prerequisite)
  */
 @Override
 public String toHtmlString(final Prerequisite prereq) {
   return LanguageBundle.getFormattedString(
       "PreDeityAlign.toHtml",
       prereq.getOperator().toDisplayString(),
       getPCAlignment(prereq.getOperand()).getKeyName()); // $NON-NLS-1$
 }
Пример #4
0
  /* (non-Javadoc)
   * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
   */
  @Override
  public int passes(final Prerequisite prereq, final PlayerCharacter aPC, CDOMObject source)
      throws PrerequisiteException {
    final int number;
    try {
      number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException exceptn) {
      throw new PrerequisiteException(
          LanguageBundle.getFormattedString("PreFact.error", prereq.toString())); // $NON-NLS-1$
    }

    String location = prereq.getCategoryName();
    String[] locationElements = location.split("\\.");
    Iterable<Reducible> objModel =
        (Iterable<Reducible>) OutputDB.getIterable(aPC.getCharID(), locationElements);
    if (objModel == null) {
      throw new PrerequisiteException("Output System does not have model for: " + location);
    }

    String[] factinfo = prereq.getKey().split("=");
    FactKey<?> fk = FactKey.valueOf(factinfo[0]);
    Object targetVal = fk.getFormatManager().convertIndirect(factinfo[1]);

    int runningTotal = 0;
    for (Reducible r : objModel) {
      Indirect<?> cdoVal = r.getCDOMObject().get(fk);
      if (targetVal.equals(cdoVal)) {
        runningTotal++;
      }
    }

    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
  }
Пример #5
0
 /**
  * Print localised information message if PCGen is debugging.
  *
  * @param message String information message (usually variable)
  * @param param1 Object information message (usually value)
  * @param param2 Object information message (usually value)
  */
 public static void debugPrintLocalised(final String message, Object... params) {
   Logger l = getLogger();
   if (l.isLoggable(DEBUG)) {
     String msg = LanguageBundle.getFormattedString(message, params);
     l.log(DEBUG, msg);
   }
 }
Пример #6
0
 public void setCompanionType(String type) {
   companionType = type;
   model.setCompanionType(type);
   selectButton.setText(
       LanguageBundle.getFormattedString("in_companionCreateType", type)); // $NON-NLS-1$
   newCompanion = null;
 }
Пример #7
0
 @Override
 public void actionPerformed(ActionEvent e) {
   CompanionSupportFacade support = character.getCompanionSupport();
   if (REMOVE_COMMAND.equals(e.getActionCommand())) {
     CompanionFacade companion = (CompanionFacade) selectedElement;
     int ret =
         JOptionPane.showConfirmDialog(
             button,
             LanguageBundle.getFormattedString(
                 "in_companionConfirmRemovalMsg",
                 companion //$NON-NLS-1$
                     .getNameRef()
                     .getReference()),
             LanguageBundle.getString("in_companionConfirmRemoval"), // $NON-NLS-1$
             JOptionPane.YES_NO_OPTION);
     if (ret == JOptionPane.YES_OPTION) {
       support.removeCompanion(companion);
     }
   }
   if (CREATE_COMMAND.equals(e.getActionCommand())) {
     initDialog();
     String type = (String) selectedElement;
     companionDialog.setCharacter(character);
     companionDialog.setCompanionType(type);
     Utility.setDialogRelativeLocation(CompanionInfoTab.this, companionDialog);
     companionDialog.setVisible(true);
     CharacterFacade comp = companionDialog.getNewCompanion();
     if (comp != null) {
       selectCompanion(comp);
     }
   }
   cancelCellEditing();
 }
Пример #8
0
  /**
   * Print a localized error message including parameter substitution. The method will issue a beep
   * if the application is running in Debug mode.
   *
   * <p>This method accepts a variable number of parameters and will replace <code>{argno}</code> in
   * the string with each passed paracter in turn.
   *
   * @param aKey A key for the localized string in the language bundle
   * @param varargs Variable number of parameters to substitute into the string
   */
  public static void errorPrintLocalised(final String aKey, Object... varargs) {
    if (isDebugMode()) {
      s_TOOLKIT.beep();
    }

    final String msg = LanguageBundle.getFormattedString(aKey, varargs);
    Logger l = getLogger();
    if (l.isLoggable(ERROR)) {
      l.log(ERROR, msg);
    }
  }
Пример #9
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (availTable != null && (e.getActionCommand().equals("ADD") || e.getSource() == availTable)) {
      List<Object> data = availTable.getSelectedData();
      if (!data.isEmpty()) {
        for (Object object : data) {
          if (object instanceof InfoFacade) {
            chooser.addSelected((InfoFacade) object);
          }
        }
      }
      return;
    }
    if (availInput != null && (e.getActionCommand().equals("ADD") || e.getSource() == availInput)) {
      String data = availInput.getText();
      if (StringUtils.isNotBlank(data)) {
        chooser.addSelected(new InfoWrapper(data));
      }
      availInput.setText("");
      return;
    }

    if (e.getActionCommand().equals("REMOVE") || e.getSource() == list) {
      Object value = list.getSelectedValue();
      if (value != null && value instanceof InfoFacade) {
        chooser.removeSelected((InfoFacade) value);
        if (availInput != null) {
          availInput.setText(value.toString());
        }
      }
      return;
    }
    if (e.getActionCommand().equals("OK")) {
      if (chooser.isRequireCompleteSelection() && chooser.getRemainingSelections().get() > 0) {
        JOptionPane.showMessageDialog(
            this,
            LanguageBundle.getFormattedString(
                "in_chooserRequireComplete", //$NON-NLS-1$
                chooser.getRemainingSelections().get()),
            chooser.getName(),
            JOptionPane.INFORMATION_MESSAGE);
        return;
      } else {
        chooser.commit();
      }
    } else {
      chooser.rollback();
    }
    committed = e.getActionCommand().equals("OK");
    dispose();
  }
Пример #10
0
 @Override
 public String toString() {
   String countStr = "";
   if (count != 1) {
     countStr = " (x" + count + ")"; // $NON-NLS-1$ //$NON-NLS-2$
   }
   if (spell != null) {
     return spell.toString() + countStr;
   } else if (cls != null) {
     return cls.toString() + countStr;
   } else if (rootNode != null) {
     return rootNode.toString() + countStr;
   }
   return LanguageBundle.getFormattedString("in_spellEmptyNode", countStr); // $NON-NLS-1$
 }
Пример #11
0
  /* (non-Javadoc)
   * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
   */
  @Override
  public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source)
      throws PrerequisiteException {
    int runningTotal;
    try {
      final int targetHands = Integer.parseInt(prereq.getOperand());

      runningTotal = prereq.getOperator().compare(display.getHands(), targetHands);
    } catch (NumberFormatException nfe) {
      throw new PrerequisiteException(
          LanguageBundle.getFormattedString(
              "PreHands.error.badly_formed", prereq.getOperand())); // $NON-NLS-1$
    }
    return countedTotal(prereq, runningTotal);
  }
Пример #12
0
  /* (non-Javadoc)
   * @see pcgen.core.prereq.PrerequisiteTest#toHtmlString(pcgen.core.prereq.Prerequisite)
   */
  @Override
  public String toHtmlString(final Prerequisite prereq) {
    // Simplify the output when requiring a single source
    if (prereq.getOperator() == PrerequisiteOperator.GTEQ && ("1".equals(prereq.getOperand()))) {
      return prereq.getKey();
    }

    final String foo =
        LanguageBundle.getFormattedString(
            "PreFact.toHtml", //$NON-NLS-1$
            new Object[] {
              prereq.getOperator().toDisplayString(), prereq.getOperand(), prereq.getKey()
            });
    return foo;
  }
Пример #13
0
  /* (non-Javadoc)
   * @see pcgen.core.facade.SpellSupportFacade#addSpellList(java.lang.String)
   */
  @Override
  public void addSpellList(String spellList) {
    if (StringUtils.isEmpty(spellList)) {
      return;
    }

    // Prevent spellbooks being given the same name as a class
    for (PCClass current :
        Globals.getContext().getReferenceContext().getConstructedCDOMObjects(PCClass.class)) {
      if ((spellList.equals(current.getKeyName()))) {
        JOptionPane.showMessageDialog(
            null,
            LanguageBundle.getString("in_spellbook_name_error"), // $NON-NLS-1$
            Constants.APPLICATION_NAME,
            JOptionPane.ERROR_MESSAGE);

        return;
      }
    }

    if (pc.addSpellBook(spellList)) {
      pc.setDirty(true);

      DummySpellNodeImpl spellListNode = new DummySpellNodeImpl(getRootNode(spellList));
      preparedSpellLists.add(spellListNode);
      addDummyNodeIfSpellListEmpty(spellList);
    } else {
      JOptionPane.showMessageDialog(
          null,
          LanguageBundle.getFormattedString(
              "InfoPreparedSpells.add.list.fail", spellList), // $NON-NLS-1$
          Constants.APPLICATION_NAME,
          JOptionPane.ERROR_MESSAGE);

      return;
    }
  }
Пример #14
0
  // TODO use pcgen save methods rather than implementing it again
  public boolean savePC(PlayerCharacter aPC, boolean saveas) {
    boolean newPC = false;
    File prevFile;
    File file = null;
    String aPCFileName = aPC.getFileName();

    if (aPCFileName.isEmpty()) {
      prevFile =
          new File(
              PCGenSettings.getPcgDir(),
              aPC.getDisplay().getDisplayName() + Constants.EXTENSION_CHARACTER_FILE);
      aPCFileName = prevFile.getAbsolutePath();
      newPC = true;
    } else {
      prevFile = new File(aPCFileName);
    }

    if (saveas || newPC) {
      JFileChooser fc = ImagePreview.decorateWithImagePreview(new JFileChooser());
      String[] pcgs = new String[] {FILENAME_PCG};
      SimpleFileFilter ff =
          new SimpleFileFilter(pcgs, LanguageBundle.getString("in_pcgen_file_char")); // $NON-NLS-1$
      fc.setFileFilter(ff);
      fc.setSelectedFile(prevFile);

      FilenameChangeListener listener = new FilenameChangeListener(aPCFileName, fc);

      fc.addPropertyChangeListener(listener);

      int returnVal = fc.showSaveDialog(GMGenSystem.inst);
      fc.removePropertyChangeListener(listener);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = fc.getSelectedFile();

        if (!PCGFile.isPCGenCharacterFile(file)) {
          file = new File(file.getParent(), file.getName() + Constants.EXTENSION_CHARACTER_FILE);
        }

        if (file.isDirectory()) {
          JOptionPane.showMessageDialog(
              null,
              LanguageBundle.getString("in_savePcDirOverwrite"), // $NON-NLS-1$
              Constants.APPLICATION_NAME,
              JOptionPane.ERROR_MESSAGE);

          return false;
        }

        if (file.exists() && (newPC || !file.getName().equals(prevFile.getName()))) {
          int reallyClose =
              JOptionPane.showConfirmDialog(
                  GMGenSystem.inst,
                  LanguageBundle.getFormattedString(
                      "in_savePcConfirmOverMsg", //$NON-NLS-1$
                      file.getName()),
                  LanguageBundle.getFormattedString(
                      "in_savePcConfirmOverTitle", file.getName()), // $NON-NLS-1$
                  JOptionPane.YES_NO_OPTION);

          if (reallyClose != JOptionPane.YES_OPTION) {
            return false;
          }
        }

        aPC.setFileName(file.getAbsolutePath());
      } else { // not saving

        return false;
      }
    } else { // simple save
      file = prevFile;
    }

    try {
      (new PCGIOHandler()).write(aPC, null, null, file);
    } catch (Exception ex) {
      String formattedString =
          LanguageBundle.getFormattedString(
              "in_saveFailMsg", aPC.getDisplay().getDisplayName()); // $NON-NLS-1$
      JOptionPane.showMessageDialog(
          null, formattedString, Constants.APPLICATION_NAME, JOptionPane.ERROR_MESSAGE);
      Logging.errorPrint(formattedString);
      Logging.errorPrint(ex.getMessage(), ex);

      return false;
    }

    return true;
  }
Пример #15
0
  @Override
  public void exportSpells() {
    final String template =
        PCGenSettings.getInstance().getProperty(PCGenSettings.SELECTED_SPELL_SHEET_PATH);
    if (StringUtils.isEmpty(template)) {
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME, LanguageBundle.getString("in_spellNoSheet")); // $NON-NLS-1$
      return;
    }
    String ext = template.substring(template.lastIndexOf('.'));

    // Get the name of the file to output to.
    JFileChooser fcExport = new JFileChooser();
    fcExport.setCurrentDirectory(new File(PCGenSettings.getPcgDir()));
    fcExport.setDialogTitle(
        LanguageBundle.getString("InfoSpells.export.spells.for")
            + charDisplay.getDisplayName()); // $NON-NLS-1$

    if (fcExport.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) {
      return;
    }
    final String aFileName = fcExport.getSelectedFile().getAbsolutePath();
    if (aFileName.length() < 1) {
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME,
          LanguageBundle.getString("InfoSpells.must.set.filename")); // $NON-NLS-1$
      return;
    }

    try {
      final File outFile = new File(aFileName);

      if (outFile.isDirectory()) {
        delegate.showErrorMessage(
            Constants.APPLICATION_NAME,
            LanguageBundle.getString("InfoSpells.can.not.overwrite.directory")); // $NON-NLS-1$
        return;
      }

      if (outFile.exists()) {
        int reallyClose =
            JOptionPane.showConfirmDialog(
                null,
                LanguageBundle.getFormattedString(
                    "InfoSpells.confirm.overwrite", outFile.getName()), // $NON-NLS-1$
                LanguageBundle.getFormattedString("InfoSpells.overwriting", outFile.getName()),
                JOptionPane.YES_NO_OPTION); // $NON-NLS-1$

        if (reallyClose != JOptionPane.YES_OPTION) {
          return;
        }
      }

      // Output the file
      File templateFile = new File(template);
      boolean success;
      if (ExportUtilities.isPdfTemplate(templateFile)) {
        success = BatchExporter.exportCharacterToPDF(pcFacade, outFile, templateFile);
      } else {
        success = BatchExporter.exportCharacterToNonPDF(pcFacade, outFile, templateFile);
      }

      if (!success) {
        delegate.showErrorMessage(
            Constants.APPLICATION_NAME,
            LanguageBundle.getFormattedString(
                "InfoSpells.export.failed", charDisplay.getDisplayName())); // $NON-NLS-1$
      }
    } catch (Exception ex) {
      Logging.errorPrint(
          LanguageBundle.getFormattedString(
              "InfoSpells.export.failed", charDisplay.getDisplayName()),
          ex); //$NON-NLS-1$
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME,
          LanguageBundle.getFormattedString(
              "InfoSpells.export.failed.retry", charDisplay.getDisplayName())); // $NON-NLS-1$
    }
  }
Пример #16
0
 public void setConnectionText(String title, String text) {
   noteTitle.setText(LanguageBundle.getFormattedString("{0}: ", title));
   noteText.setText(text);
 }
Пример #17
0
  // TODO Refactor this with all the equipment tests.
  @Override
  public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source)
      throws PrerequisiteException {
    final int number;
    try {
      number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException e) {
      throw new PrerequisiteException(
          LanguageBundle.getFormattedString(
              "PreItem.error.bad_operand", prereq.toString())); // $NON-NLS-1$
    }

    int runningTotal = 0;

    if (display.hasEquipment()) {
      // Work out exactlywhat we are going to test.
      final String aString = prereq.getKey();
      List<String> typeList = null;
      if (aString.startsWith(Constants.LST_TYPE_EQUAL)
          || aString.startsWith(Constants.LST_TYPE_DOT)) {
        String stripped = aString.substring(Constants.SUBSTRING_LENGTH_FIVE);
        typeList = CoreUtility.split(stripped, '.');
      }

      for (Equipment eq : display.getEquipmentSet()) {
        if (typeList != null) {
          // Check to see if the equipment matches
          // all of the types in the requested list;
          boolean bMatches = true;
          for (int i = 0, x = typeList.size(); i < x; ++i) {
            if (!eq.isType(typeList.get(i))) {
              bMatches = false;
              break;
            }
          }
          if (bMatches) {
            runningTotal++;
          }
        } else { // not a TYPE string
          final String eqName = eq.getName().toUpperCase();

          if (aString.indexOf('%') >= 0) {
            // handle wildcards (always assume
            // they end the line)
            final int percentPos = aString.indexOf('%');
            final String substring = aString.substring(0, percentPos).toUpperCase();
            if ((eqName.startsWith(substring))) {
              ++runningTotal;
              break;
            }
          } else if (eqName.equalsIgnoreCase(aString)) {
            // just a straight String compare
            ++runningTotal;
            break;
          }
        }
      }
    }

    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
  }