Package net.laubenberger.bogatyr.view.swing.worker

Examples of net.laubenberger.bogatyr.view.swing.worker.Worker


          localizer.getTooltip(HelperResource.RES_ACTION_OK), localizer.getMnemonic(HelperResource.RES_ACTION_OK));
    }

    @Override
    public void actionPerformed(final ActionEvent e) {
      final Worker worker = new WorkerAbstract<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
          fireWorkerStart();

          try {

            final CryptoSymmetricAlgo algo = (CryptoSymmetricAlgo) cbCodecs.getSelectedItem();
            final CryptoSymmetric crypto = new CryptoSymmetricImpl(algo);
            final SecretKey key = crypto.generateKey(new String(password.getPassword())
                .getBytes(Constants.ENCODING_DEFAULT));
            crypto.decrypt(scrambler.getModuleData().getFile(KEY_UNSCRAMBLE_INPUT), scrambler.getModuleData()
                .getFile(KEY_UNSCRAMBLE_OUTPUT), key);
            scrambler.getModuleData().addValue(KEY_UNSCRAMBLE_ALGO, algo);
//          } catch (IOException ex) {
//            log.error("Could not unscramble file", ex); //$NON-NLS-1$
//            scrambler.displayMessage(scrambler.getModel().getName(), "Could not unscramble file",
//                MessageType.ERROR);
          } catch (Exception ex) {
            log.error("Could not unscramble file", ex); //$NON-NLS-1$
            scrambler.displayMessage(scrambler.getModel().getName(), localizer.getValue(HelperResource.RES_ERROR_UNSCRAMBLE),
                MessageType.ERROR);
          }
          return null;
        }
      };

      worker.addListener(scrambler);
      scrambler.getCallback().addWorker(
          worker,
          localizer.getValue(HelperResource.RES_ACTION_UNSCRAMBLE),
          scrambler.getModuleData().getFile(KEY_UNSCRAMBLE_INPUT).getName()
              + " -> " + scrambler.getModuleData().getFile(KEY_UNSCRAMBLE_OUTPUT).getName(), Icons.UNSCRAMBLE); //$NON-NLS-1$
View Full Code Here


    enableControls();
  }

  void play(final File file) {

    final Worker worker = new WorkerAbstract<Void, Void>() {
      @Override
      protected Void doInBackground() throws Exception {
        fireWorkerStart();

        BufferedInputStream bis = null;
        try {
          bis = new BufferedInputStream(new FileInputStream(file), FILE_BUFFER_SIZE);

          try {
            player = new AdvancedPlayer(bis);
            player.setPlayBackListener(new PlaybackListener() {
              @Override
              public void playbackStarted(final PlaybackEvent playbackevent) {

                isRunning = true;

                SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                    commander.setTitle(file.getName());
                    commander.getRootPane().setToolTipText(file.getAbsolutePath());
                    enableControls();
                  }

                });

              }

              @Override
              public void playbackFinished(final PlaybackEvent playbackevent) {
                if (isRunning) {
                  index++;
                  if (index >= list.size()) {
                    index = 0;
                  }

                  player.close();

                  play(list.get(index));
                }
              }
            });

            player.play();

          } catch (JavaLayerException e) {
            log.error("Could not process MP3 file", e); //$NON-NLS-1$
          }
        } catch (FileNotFoundException ex) {
          log.error("File not found", ex); //$NON-NLS-1$
        } finally {
          if (null != bis) {
            try {
              bis.close();
            } catch (IOException ex) {
              log.error("Could not close file", ex); //$NON-NLS-1$
            }
          }
        }

        return null;
      }
    };

    worker.addListener(this);
    worker.execute();
  }
View Full Code Here

          localizer.getTooltip(HelperResource.RES_ACTION_OK), localizer.getMnemonic(HelperResource.RES_ACTION_OK));
    }

    @Override
    public void actionPerformed(final ActionEvent e) {
      final Worker worker = new WorkerAbstract<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
          fireWorkerStart();

          try {
            final CryptoSymmetricAlgo algo = (CryptoSymmetricAlgo) cbCodecs.getSelectedItem();
            final CryptoSymmetric crypto = new CryptoSymmetricImpl(algo);
            final SecretKey key = crypto.generateKey(new String(password1.getPassword())
                .getBytes(Constants.ENCODING_DEFAULT));
            crypto.encrypt(scrambler.getModuleData().getFile(KEY_SCRAMBLE_INPUT), scrambler.getModuleData()
                .getFile(KEY_SCRAMBLE_OUTPUT), key);
            scrambler.getModuleData().addValue(KEY_SCRAMBLE_ALGO, algo);
//          } catch (IOException ex) {
//            log.error("Could not scramble file", ex); //$NON-NLS-1$
//            scrambler
//                .displayMessage(scrambler.getModel().getName(), "Could not scramble file", MessageType.ERROR);
          } catch (Exception ex) {
            log.error("Could not scramble file", ex); //$NON-NLS-1$
            scrambler
                .displayMessage(scrambler.getModel().getName(), localizer.getValue(HelperResource.RES_ERROR_SCRAMBLE), MessageType.ERROR);
          }

          return null;
        }
      };

      worker.addListener(scrambler);
      scrambler.getCallback().addWorker(
          worker,
          localizer.getValue(HelperResource.RES_ACTION_SCRAMBLE),
          scrambler.getModuleData().getFile(KEY_SCRAMBLE_INPUT).getName()
              + " -> " + scrambler.getModuleData().getFile(KEY_SCRAMBLE_OUTPUT).getName(), Icons.SCRAMBLE); //$NON-NLS-1$
View Full Code Here

    }

    @Override
    public void actionPerformed(final ActionEvent e) {

      final Worker worker = new WorkerAbstract<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
          fireWorkerStart();

          while (!isCancelled()) {
            Thread.sleep(250);
          }

          return null;
        }
      };

      worker.addListener(TestImpl.this);
      getCallback().addWorker(worker, localizer.getValue(HelperResource.RES_ACTION_TASK), "working...", Icons.TASK);

      // worker.execute();
      final Thread thread = new Thread(worker);
      thread.start();
View Full Code Here

        actionSkipForward.setEnabled(false);

        final File file = fc.getSelectedFile();

        if (file.isDirectory()) {
          final Worker worker = new WorkerAbstract<Void, Void>() {
            @Override
            protected Void doInBackground() throws Exception {
              fireWorkerStart();

              final FileFilter filter = new FileFilter() {
                @Override
                public boolean accept(final File file) {
                  return HelperString.endsWith(file.getName(), ".mp3"); //$NON-NLS-1$
                }
              };

              if (isRunning) {
                stop();
              }
             
              if (getModuleData().getBoolean(KEY_IS_ENQUEUE)) {
                list.addAll(HelperIO.getFiles(file, filter));
              } else {
                list = HelperIO.getFiles(file, filter);
                index = 0;
              }

              if (getModuleData().getBoolean(KEY_IS_RANDOM)) {
                Collections.shuffle(list);
              } else {
                Collections.sort(list);
              }

              return null;
            }

            @Override
            protected void done() {
              actionOpen.setEnabled(true);
              enableControls();

              super.done();
            }
          };
          worker.addListener(MusicPlayerImpl.this);

          // Thread thread = new Thread(worker);
          // thread.start();
          worker.execute();

          getCallback().addWorker(worker, localizer.getValue(HelperResource.RES_ACTION_START),
              localizer.getValue(HelperResource.RES_LABEL_SCANNING), Icons.START);
        } else {
          if (isRunning) {
View Full Code Here

TOP

Related Classes of net.laubenberger.bogatyr.view.swing.worker.Worker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.