Exemplo n.º 1
0
  @Override
  public String getTooltipString() {
    StringBuilder toolTip = new StringBuilder(300);

    // html header and card name
    toolTip.append("<br><b>");
    toolTip.append(LanguageManager.getString("source"));
    toolTip.append(": </b>");
    if (isVisibleForYou()) {
      toolTip.append(database.getLocalName());
      toolTip.append("<br><b>");
      toolTip.append(LanguageManager.getString("triggeredability"));
      toolTip.append(": </b>");
      toolTip.append(triggeredAbility.toHtmlString(context));
      if (either != null) {
        for (int i = 0; i < either.size(); i++) {
          toolTip.append(either.get(i).toHtmlString(context));
        }
      }
      toolTip.append(CardFactory.ttSource);
      toolTip.append(triggeredAbility.getCard().toString());

      // credits
      if (database.getRulesCredit() != null) {
        toolTip.append(CardFactory.ttRulesAuthor);
        toolTip.append(database.getRulesCredit());
      }
    } else {
      toolTip.append("??");
    }
    toolTip.append("</html>");
    return toolTip.toString();
  }
Exemplo n.º 2
0
  /**
   * @param cardModel the card model.
   * @param constraints the constraints.
   * @return the string read from one of the streams of this proxy.
   * @throws IOException If some other I/O error occurs
   */
  private String getStringFromStream(CardModel cardModel, Map<String, String> constraints)
      throws IOException {

    // Determine the best stream configuration
    int highestScore = -1;
    UrlTokenizer stream = null;
    for (int i = 0; i < streams.size(); i++) {
      int score = streams.get(i).getUrlScore(constraints);
      if (score > highestScore) {
        highestScore = score;
        stream = streams.get(i);
      }
    }

    // No stream available for this proxy + card
    if (stream == null) {
      return null;
    }

    // read stream from the built URL
    final URL mainPage = new URL(streamBaseUrl + stream.getUrl(cardModel, constraints, this));
    final StringBuilder res = new StringBuilder(2000);
    final InputStream proxyStream;
    try {
      proxyStream = MToolKit.getHttpConnection(mainPage).getInputStream();
    } catch (Throwable e) {
      // Error during the IP get
      throw new IOException(LanguageManager.getString("error.stream.null"));
    }
    if (proxyStream == null) {
      // Error during the IP get
      throw new IOException(LanguageManager.getString("error.stream.null"));
    }
    final BufferedReader br = new BufferedReader(new InputStreamReader(proxyStream, encoding));
    String line = null;
    while ((line = br.readLine()) != null) {
      res.append(StringUtils.trim(line));
    }
    return res.toString();
  }
Exemplo n.º 3
0
  /** @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */
  public void actionPerformed(ActionEvent e) {
    if ("menu_options_tbs_more".equals(e.getActionCommand())) {
      // goto "more TBS" page
      try {
        WebBrowser.launchBrowser(
            "http://sourceforge.net/project/showfiles.php?group_id="
                + IdConst.PROJECT_ID
                + "&package_id=107882");
      } catch (Exception e1) {
        JOptionPane.showOptionDialog(
            MagicUIComponents.magicForm,
            LanguageManager.getString("error") + " : " + e1.getMessage(),
            LanguageManager.getString("web-pb"),
            JOptionPane.OK_OPTION,
            JOptionPane.INFORMATION_MESSAGE,
            UIHelper.getIcon("wiz_update_error.gif"),
            null,
            null);
      }
      return;
    }
    if ("menu_options_tbs_update".equals(e.getActionCommand())) {
      // update the current TBS
      XmlConfiguration.main(new String[] {"-g", MToolKit.tbsName});
      return;
    }
    if ("menu_options_tbs_rebuild".equals(e.getActionCommand())) {
      /*
       * rebuild completely the current TBS
       */
      XmlConfiguration.main(new String[] {"-f", "-g", MToolKit.tbsName});
      return;
    }

    // We change the TBS

    // Wait for confirmation
    if (JOptionPane.YES_OPTION
        == JOptionPane.showOptionDialog(
            MagicUIComponents.magicForm,
            LanguageManager.getString("warn-disconnect"),
            LanguageManager.getString("disconnect"),
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            UIHelper.getIcon("wiz_update.gif"),
            null,
            null)) {

      // Save the current settings before changing TBS
      Magic.saveSettings();

      // Copy this settings file to the profile directory of this TBS
      final File propertyFile = MToolKit.getFile(IdConst.FILE_SETTINGS);
      try {
        FileUtils.copyFile(propertyFile, MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false));

        // Delete the current settings file of old TBS
        propertyFile.delete();

        // Load the one of the new TBS
        abstractMainForm.setMdb(e.getActionCommand());
        Configuration.loadTemplateFile(
            MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false).getAbsolutePath());

        // Copy the saved configuration of new TBS
        FileUtils.copyFile(MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false), propertyFile);
        Log.info("Successful TBS swith to " + MToolKit.tbsName);

        // Restart the game
        System.exit(IdConst.EXIT_CODE_RESTART);
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }