Ejemplo n.º 1
0
  /**
   * Builds a deck out of the selected block/set/format.
   *
   * @return a path to the generated deck.
   */
  public static String generateDeck() {

    genDialog = new DeckGeneratorDialog();
    if (genDialog.getSelectedColors() != null) {
      Deck deck = buildDeck();
      return genDialog.saveDeck(deck);
    }
    // If the deck couldn't be generated or the user cancelled, repopulate the deck selection with
    // its cached value
    return PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_DECK_FILE, null);
  }
Ejemplo n.º 2
0
 private static void checkAndPlayClip(Clip clip) {
   try {
     if (clip != null) {
       String soundsOn = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SOUNDS_ON, "true");
       if (soundsOn.equals("true")) {
         audioManager.play(clip);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 3
0
  @Override
  public void run() {
    this.cardIndex = 0;

    File base = new File(Constants.IO.imageBaseDir);
    if (!base.exists()) {
      base.mkdir();
    }

    Connection.ProxyType configProxyType =
        Connection.ProxyType.valueByText(
            PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));

    Proxy.Type type = Proxy.Type.DIRECT;
    switch (configProxyType) {
      case HTTP:
        type = Proxy.Type.HTTP;
        break;
      case SOCKS:
        type = Proxy.Type.SOCKS;
        break;
      case NONE:
      default:
        p = Proxy.NO_PROXY;
        break;
    }

    if (type != Proxy.Type.DIRECT) {
      try {
        String address = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, "");
        Integer port =
            Integer.parseInt(
                PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "80"));
        p = new Proxy(type, new InetSocketAddress(address, port));
      } catch (Exception ex) {
        throw new RuntimeException("Gui_DownloadPictures : error 1 - " + ex);
      }
    }

    if (p != null) {
      HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();

      ArrayList<CardDownloadData> cardsToDownload = this.checkBox.isSelected() ? type2cards : cards;

      update(0, cardsToDownload.size());

      ExecutorService executor = Executors.newFixedThreadPool(10);
      for (int i = 0; i < cardsToDownload.size() && !cancel; i++) {
        try {

          CardDownloadData card = cardsToDownload.get(i);

          logger.debug("Downloading card: " + card.getName() + " (" + card.getSet() + ")");

          String url;
          if (ignoreUrls.contains(card.getSet()) || card.isToken()) {
            if (card.getCollectorId() != 0) {
              continue;
            }
            url = cardImageSource.generateTokenUrl(card);
          } else {
            url = cardImageSource.generateURL(card);
          }

          if (url != null) {
            Runnable task = new DownloadTask(card, new URL(url), cardsToDownload.size());
            executor.execute(task);
          } else {
            logger.info(
                "Card not available on "
                    + cardImageSource.getSourceName()
                    + ": "
                    + card.getName()
                    + " ("
                    + card.getSet()
                    + ")");
            synchronized (sync) {
              update(cardIndex + 1, cardsToDownload.size());
            }
          }

        } catch (Exception ex) {
          logger.error(ex, ex);
        }
      }
      executor.shutdown();
      while (!executor.isTerminated()) {
        try {
          Thread.sleep(1000);
        } catch (InterruptedException ie) {
        }
      }
    }
    try {
      TVFS.umount();
    } catch (FsSyncException e) {
      logger.fatal("Couldn't unmount zip files", e);
      JOptionPane.showMessageDialog(
          null, "Couldn't unmount zip files", "Error", JOptionPane.ERROR_MESSAGE);
    } finally {
      System.gc();
    }
    closeButton.setText("Close");
  }