Ejemplo n.º 1
0
  @Override
  public void actionPerformed(ActionEvent e) {
    switch (e.getActionCommand()) {
      case "run":
        if (!validate()) return;

        new Thread(this).start();
        break;

      case "stop":
        service.shutdownNow();
        System.exit(0);
    }
    window.switchButtonState();
  }
Ejemplo n.º 2
0
 private synchronized Settings getSettings() {
   User credentials =
       new User(
           window.getFdUsername().getText(), new String(window.getFdPassword().getPassword()));
   return new Settings(
       credentials,
       (SendMode) window.getCbMode().getSelectedItem(),
       window.getFdHomepage().getText(),
       window.getFdMessage().getText(),
       Integer.parseInt(window.getFdInterval().getText()));
 }
Ejemplo n.º 3
0
 private boolean hasValidInteger() {
   return Utils.hasValidInteger(window.getFdInterval());
 }
Ejemplo n.º 4
0
 private boolean hasAllSettings() {
   return !Utils.isNullOrEmpty(window.getFdUsername())
       && !Utils.isNullOrEmpty(window.getFdPassword())
       && !Utils.isNullOrEmpty(window.getFdHomepage())
       && !Utils.isNullOrEmpty(window.getFdMessage());
 }
Ejemplo n.º 5
0
 public ApplicationHandler(InviteVBWindow window) {
   this.window = window;
   window.getBtAction().addActionListener(this);
   window.setVisible(true);
 }
Ejemplo n.º 6
0
  @Override
  public void run() {

    window.setMessage("Verificando/validando suas configurações...");
    settings = getSettings();
    if (!hasPermission()) System.exit(0);

    window.setMessage("Acessando o fórum...");
    actions.login(settings);
    window.setMessage("Login efetuado, buscando usuários online...");

    members = new Scrap().getOnlineMembers(actions.getHtmlFrom(settings.getHomePage()), settings);
    if (members.isEmpty()) {
      JOptionPane.showMessageDialog(
          window,
          "Lista de usuários vazia ou não foi possível se conectar ao fórum no momento.",
          "",
          JOptionPane.WARNING_MESSAGE);
      System.exit(0);
    }

    if (!window.getCbStaff().isSelected())
      members =
          new Scrap()
              .getModerators(
                  actions.getHtmlFrom(
                      settings.getHomePage() + Attributes.get().getProperty("resource.staff")),
                  settings,
                  members);

    Collections.sort(members, new MemberComparator());

    beginIndex = endIndex = messagesTotal = 0;
    switch (settings.getSendMode()) {
      case BEGIN_TO_END:
        beginIndex = 0;
        endIndex = members.size();
        break;

      case BEGIN_TO_MIDDLE:
        beginIndex = 0;
        endIndex = members.size() / 2;
        break;

      case MIDDLE_TO_END:
        beginIndex = members.size() / 2;
        endIndex = members.size();
        break;

      case SHUFFLE:
        beginIndex = 0;
        endIndex = members.size();
        Collections.shuffle(members);
        break;
    }

    currentIndex = beginIndex;

    window.getPbProgress().setMinimum(beginIndex);
    window.getPbProgress().setMaximum(endIndex);
    window.getPbProgress().setValue(currentIndex);

    window.setMessage(
        "OK! " + members.size() + " usuário(s) encontrados. Iniciando o envio das mensagens...");
    service.scheduleAtFixedRate(
        new Runnable() {
          @Override
          public void run() {

            Member member = members.get(currentIndex);
            boolean sended = actions.sendMessageTo(member.getProfileUrl(), settings.getMessage());
            if (sended) {
              messagesTotal++;

              String messages =
                  "<b>" + messagesTotal + " mensage" + (messagesTotal > 1 ? "ns" : "m") + "</b>";
              String info =
                  ": Última foi para '" + member.getUsername() + "' - Horário: " + LocalTime.now();
              window.setMessage(messages + " - " + info + ". Aguardando intervalo...");
            }

            currentIndex++;
            window.getPbProgress().setValue(currentIndex);
            if (currentIndex >= endIndex) {
              service.shutdown();
              window.setMessage("Processo finalizado, você já pode fechar o programa.");
            }
          }
        },
        0,
        settings.getInterval(),
        TimeUnit.SECONDS);
  }