Ejemplo n.º 1
0
 private AddAccountDialog(final PluginForHost plugin, Account acc) {
   super(
       UserIO.NO_ICON,
       _GUI.T.jd_gui_swing_components_AccountDialog_title(),
       null,
       _GUI.T.lit_save(),
       null);
   this.defaultAccount = acc;
   this.plugin = plugin;
   cl = PluginClassLoader.getInstance().getChild();
   setLocator(
       new RememberRelativeDialogLocator("AddAccountDialog2", JDGui.getInstance().getMainFrame()));
   setDimensor(new RememberLastDialogDimension("AddAccountDialog2"));
 }
 public static void main(String[] args) {
   try {
     Dialog.getInstance()
         .showConfirmDialog(
             0,
             _GUI.T.AutoDetectAction_actionPerformed_dooptimization_title(),
             _GUI.T.AutoDetectAction_actionPerformed_dooptimization_msg(1, "ff", "ggf"),
             new AbstractIcon(IconKey.ICON_OK, 32),
             _GUI.T.AutoDetectAction_run_optimization(),
             _GUI.T.AutoDetectAction_skip_optimization());
   } catch (DialogClosedException e) {
     e.printStackTrace();
   } catch (DialogCanceledException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 3
0
 protected String getDateFormatString() {
   String custom = CFG_GUI.CFG.getDateTimeFormatDownloadListAddedDateColumn();
   if (StringUtils.isNotEmpty(custom)) {
     return custom;
   }
   DateFormat sd = SimpleDateFormat.getDateTimeInstance();
   if (sd instanceof SimpleDateFormat) {
     return ((SimpleDateFormat) sd).toPattern();
   }
   return _GUI.T.added_date_column_dateformat();
 }
Ejemplo n.º 4
0
  public static ProgressDialog checkAccount(final Account ac) throws Throwable {
    ProgressDialog pd =
        new ProgressDialog(
            new ProgressGetter() {
              public void run() throws Exception {
                final PluginForHost hostPlugin = new PluginFinder().assignPlugin(ac, true);
                if (hostPlugin != null) {
                  ac.setPlugin(hostPlugin);
                }
                AccountCheckJob job = AccountChecker.getInstance().check(ac, true);
                job.waitChecked();
              }

              public String getString() {
                return null;
              }

              public int getProgress() {
                return -1;
              }

              @Override
              public String getLabelString() {
                return null;
              }
            },
            0,
            _GUI.T.accountdialog_check(),
            _GUI.T.accountdialog_check_msg(),
            DomainInfo.getInstance(ac.getHosterByPlugin()).getFavIcon());
    try {
      Dialog.getInstance().showDialog(pd);
    } catch (DialogCanceledException e) {
      if (pd.getThrowable() == null) {
        throw e;
      } else {
        throw pd.getThrowable();
      }
    }
    return pd;
  }
Ejemplo n.º 5
0
 public DownloadFolderColumn() {
   super(_GUI.T.LinkGrabberTableModel_initColumns_folder());
   setClickcount(0);
 }
  public java.util.List<ReconnectResult> autoFind(final ProcessCallBack feedback)
      throws InterruptedException {

    StatsManager.I().track("reconnectAutoFind/start");
    final java.util.List<ReconnectResult> scripts = new ArrayList<ReconnectResult>();

    for (final RouterPlugin plg : ReconnectPluginController.this.plugins) {
      if (Thread.currentThread().isInterrupted()) {
        throw new InterruptedException();
      }
      if (plg instanceof UPNPRouterPlugin || plg instanceof LiveHeaderReconnect) {
        try {

          feedback.setStatus(plg, null);

          java.util.List<ReconnectResult> founds = plg.runDetectionWizard(feedback);

          if (founds != null) {
            scripts.addAll(founds);
          }
          if (scripts.size() > 0) {
            break;
          }
        } catch (InterruptedException e) {
          throw e;
        } catch (Exception e) {

        }
      }
    }
    if (scripts.size() > 0) {
      HashMap<String, String> map = new HashMap<String, String>();
      map.put("plg", scripts.get(0).getInvoker().getPlugin().getID());
      StatsManager.I().track("reconnectAutoFind/success", map);
    } else {
      StatsManager.I().track("reconnectAutoFind/failed");
    }
    if (JsonConfig.create(ReconnectConfig.class).getOptimizationRounds() > 1
        && scripts.size() > 0) {
      int i = 1;
      long bestTime = Long.MAX_VALUE;
      long optiduration = 0;
      for (ReconnectResult found : scripts) {

        bestTime = Math.min(bestTime, found.getSuccessDuration());
        optiduration +=
            found.getSuccessDuration()
                * (JsonConfig.create(ReconnectConfig.class).getOptimizationRounds() - 1)
                * 1.5;
      }
      try {

        Dialog.getInstance()
            .showConfirmDialog(
                0,
                _GUI.T.AutoDetectAction_actionPerformed_dooptimization_title(),
                _GUI.T.AutoDetectAction_actionPerformed_dooptimization_msg(
                    scripts.size(),
                    TimeFormatter.formatMilliSeconds(optiduration, 0),
                    TimeFormatter.formatMilliSeconds(bestTime, 0)),
                new AbstractIcon(IconKey.ICON_OK, 32),
                _GUI.T.AutoDetectAction_run_optimization(),
                _GUI.T.AutoDetectAction_skip_optimization());
        feedback.setProgress(this, 0);
        for (int ii = 0; ii < scripts.size(); ii++) {
          ReconnectResult found = scripts.get(ii);
          feedback.setStatusString(
              this, _GUI.T.AutoDetectAction_run_optimize(found.getInvoker().getName()));
          final int step = ii;
          found.optimize(
              new ProcessCallBackAdapter() {

                public void setProgress(Object caller, int percent) {
                  feedback.setProgress(
                      caller, (step) * (100 / scripts.size()) + percent / scripts.size());
                }

                public void setStatusString(Object caller, String string) {
                  feedback.setStatusString(caller, _GUI.T.AutoDetectAction_run_optimize(string));
                }
              });
        }
      } catch (DialogNoAnswerException e) {

      }
    }
    try {
      Collections.sort(
          scripts,
          new Comparator<ReconnectResult>() {

            public int compare(ReconnectResult o1, ReconnectResult o2) {
              return new Long(o1.getAverageSuccessDuration())
                  .compareTo(new Long(o2.getAverageSuccessDuration()));
            }
          });
    } catch (final Throwable e) {

      org.appwork.utils.logging2.extmanager.LoggerFactory.getDefaultLogger().log(e);
    }
    return scripts;
  }
Ejemplo n.º 7
0
 private PluginForHost updatePanel(PluginForHost plugin) {
   try {
     if (content == null) {
       return null;
     }
     if (plugin == null) {
       LazyHostPlugin p = HostPluginController.getInstance().get(getPreselectedHoster());
       if (p == null) {
         Iterator<LazyHostPlugin> it = HostPluginController.getInstance().list().iterator();
         if (it.hasNext()) {
           p = it.next();
         }
       }
       plugin = p.newInstance(cl);
     }
     link.setText(_GUI.T.gui_menu_action_premium_buy_name2(plugin.getHost()));
     header2.setText(
         _GUI.T.AddAccountDialog_layoutDialogContent_enterlogininfo2(plugin.getHost()));
     final AccountBuilderInterface accountFactory = plugin.getAccountFactory(this);
     if (accountBuilderUI != null) {
       defaultAccount = accountBuilderUI.getAccount();
       content.remove(accountBuilderUI.getComponent());
     }
     accountBuilderUI = accountFactory;
     final JComponent comp;
     content.add(comp = accountBuilderUI.getComponent(), "gapleft 32,spanx");
     accountBuilderUI.setAccount(defaultAccount);
     final ArrayList<Component> focusOrder = new ArrayList<Component>();
     focusOrder.add(filter);
     focusOrder.addAll(inputComponents = ListFocusTraversalPolicy.getFocusableComponents(comp));
     focusOrder.add(okButton);
     focusOrder.add(cancelButton);
     dialog.setFocusTraversalPolicyProvider(true);
     dialog.setFocusTraversalPolicy(new ListFocusTraversalPolicy(focusOrder));
     // content.setFocusTraversalPolicy(new FocusTraversalPolicy() {
     //
     // @Override
     // public Component getLastComponent(Container aContainer) {
     // return comp;
     // }
     //
     // @Override
     // public Component getFirstComponent(Container aContainer) {
     // return filter;
     // }
     //
     // @Override
     // public Component getDefaultComponent(Container aContainer) {
     // return filter;
     // }
     //
     // @Override
     // public Component getComponentBefore(Container aContainer, Component aComponent) {
     //
     // return null;
     // }
     //
     // @Override
     // public Component getComponentAfter(Container aContainer, Component aComponent) {
     // if (aComponent == filter) {
     // return hoster;
     // } else if (aComponent == hoster || aComponent instanceof JViewport) {
     // return comp.getComponent(0);
     // }
     // return filter;
     // }
     // });
     onChangedInput(null);
     // getDialog().pack();
     return plugin;
   } catch (UpdateRequiredClassNotFoundException e) {
     e.printStackTrace();
     return null;
   }
 }
Ejemplo n.º 8
0
  @Override
  public JComponent layoutDialogContent() {
    final Collection<LazyHostPlugin> allPLugins = HostPluginController.getInstance().list();
    // Filter - only premium plugins should be here
    final java.util.List<LazyHostPlugin> plugins = new ArrayList<LazyHostPlugin>();
    for (LazyHostPlugin lhp : allPLugins) {
      if (lhp.isPremium()) {
        plugins.add(lhp);
      }
    }
    if (plugins.size() == 0) {
      throw new RuntimeException("No Plugins Loaded Exception");
      // final HostPluginWrapper[] array = plugins.toArray(new
      // HostPluginWrapper[plugins.size()]);
    }
    filter =
        new ExtTextField() {
          private static final long serialVersionUID = 1L;

          @Override
          protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            Composite comp = g2.getComposite();
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
            new AbstractIcon(IconKey.ICON_SEARCH, 16).paintIcon(this, g2, 3, 3);
            g2.setComposite(comp);
          }
        };
    filter.addFocusListener(
        new FocusListener() {
          @Override
          public void focusLost(FocusEvent e) {}

          @Override
          public void focusGained(FocusEvent e) {
            filter.selectAll();
          }
        });
    filter.setHelpText("Search Plugins");
    filter.addKeyListener(
        new KeyListener() {
          @Override
          public void keyTyped(KeyEvent e) {}

          @Override
          public void keyReleased(KeyEvent e) {}

          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
              hoster.onKeyDown();
            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {
              hoster.onKeyUp();
            }
          }
        });
    // filterText.setOpaque(false);
    // filterText.putClientProperty("Synthetica.opaque", Boolean.FALSE);
    // filterText.setBorder(null);
    filter.setBorder(
        BorderFactory.createCompoundBorder(
            filter.getBorder(), BorderFactory.createEmptyBorder(0, 20, 0, 0)));
    hoster =
        new HosterChooserTable(plugins) {
          @Override
          protected void processEvent(AWTEvent e) {
            if (e instanceof KeyEvent) {
              if (((KeyEvent) e).getKeyCode() == KeyEvent.VK_TAB) {
                content.dispatchEvent(e);
                return;
              }
            }
            super.processEvent(e);
          }

          @Override
          protected boolean processKeyBinding(
              KeyStroke stroke, KeyEvent evt, int condition, boolean pressed) {
            return super.processKeyBinding(stroke, evt, condition, pressed);
          }

          public void valueChanged(javax.swing.event.ListSelectionEvent e) {
            super.valueChanged(e);
            if (e.getValueIsAdjusting() || getModel().isTableSelectionClearing()) {
              return;
            }
            try {
              scrollToSelection(0);
              final PluginForHost plg = getSelectedPlugin().newInstance(cl);
              if (plg != null
                  && (lazyHostPlugin == null || !lazyHostPlugin.equals(plg.getLazyP()))) {
                final PluginForHost ret = updatePanel(plg);
                if (ret != null) {
                  lazyHostPlugin = ret.getLazyP();
                }
              }
            } catch (UpdateRequiredClassNotFoundException e1) {
              e1.printStackTrace();
            }
          }
        };
    filter
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              private DelayedRunnable delayedRefresh =
                  new DelayedRunnable(200, 1000) {
                    String lastText = null;

                    @Override
                    public String getID() {
                      return "AddAccountDialog";
                    }

                    @Override
                    public void delayedrun() {
                      new EDTRunner() {
                        @Override
                        protected void runInEDT() {
                          final String text = filter.getText();
                          if (!StringUtils.equals(lastText, text)) {
                            lastText = text;
                            hoster.refresh(text);
                          }
                        }
                      }.waitForEDT();
                    }
                  };

              @Override
              public void removeUpdate(DocumentEvent e) {
                delayedRefresh.resetAndStart();
              }

              @Override
              public void insertUpdate(DocumentEvent e) {
                delayedRefresh.resetAndStart();
              }

              @Override
              public void changedUpdate(DocumentEvent e) {
                delayedRefresh.resetAndStart();
              }
            });
    link = new JButton(new AbstractIcon(IconKey.ICON_MONEY, 16));
    link.setText(_GUI.T.gui_menu_action_premium_buy_name());
    link.setToolTipText(_GUI.T.gui_menu_action_premium_buy_name());
    link.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            try {
              final PluginForHost plugin = hoster.getSelectedPlugin().newInstance(cl);
              if (plugin != null) {
                StatsManager.I().openAfflink(plugin, null, "accountmanager/table");
              }
            } catch (UpdateRequiredClassNotFoundException e1) {
              e1.printStackTrace();
            }
          }
        });
    link.setFocusable(false);
    content = new JPanel(new MigLayout("ins 0, wrap 1", "[grow,fill]"));
    content.add(
        header(_GUI.T.AddAccountDialog_layoutDialogContent_choosehoster_()),
        "gapleft 15,spanx,pushx,growx");
    content.add(filter, "gapleft 32,pushx,growx");
    JScrollPane sp;
    content.add(sp = new JScrollPane(hoster), "gapleft 32,pushy,growy");
    sp.setFocusable(false);
    sp.getVerticalScrollBar().setFocusable(false);
    sp.getViewport().setFocusable(false);
    content.add(link, "height 20!,gapleft 32");
    content.add(
        header2 = header(_GUI.T.AddAccountDialog_layoutDialogContent_enterlogininfo()),
        "gapleft 15,spanx,pushx,growx,gaptop 15");
    final LazyHostPlugin lazyp;
    if (this.plugin != null) {
      lazyp = plugin.getLazyP();
    } else {
      lazyp = HostPluginController.getInstance().get(getPreselectedHoster());
    }
    if (lazyp != null) {
      hoster.setSelectedPlugin(lazyp);
    }
    getDialog()
        .addWindowFocusListener(
            new WindowFocusListener() {
              @Override
              public void windowLostFocus(final WindowEvent windowevent) {
                // TODO Auto-generated method stub
              }

              @Override
              public void windowGainedFocus(final WindowEvent windowevent) {
                final Component focusOwner = getDialog().getFocusOwner();
                if (focusOwner != null) {
                  // dialog component has already focus...
                  return;
                }
                /* we only want to force focus on first window open */
                getDialog().removeWindowFocusListener(this);
                focusFirstInputComponent();
              }
            });
    getDialog().setMinimumSize(new Dimension(400, 300));
    return content;
  }
Ejemplo n.º 9
0
 public static boolean addAccount(final Account ac) throws DialogNoAnswerException {
   try {
     checkAccount(ac);
   } catch (DialogNoAnswerException e) {
     throw e;
   } catch (Throwable e) {
     Dialog.getInstance()
         .showExceptionDialog(
             _GUI.T.accountdialog_check_failed(), _GUI.T.accountdialog_check_failed_msg(), e);
   }
   AccountError error = ac.getError();
   String errorMessage = ac.getErrorString();
   if (StringUtils.isEmpty(errorMessage)) {
     AccountInfo ai = ac.getAccountInfo();
     if (ai != null) {
       errorMessage = ai.getStatus();
     }
   }
   if (error != null) {
     switch (error) {
       case PLUGIN_ERROR:
         if (StringUtils.isEmpty(errorMessage)) {
           errorMessage = _JDT.T.AccountController_updateAccountInfo_status_plugin_defect();
         }
         Dialog.getInstance().showMessageDialog(_GUI.T.accountdialog_check_invalid(errorMessage));
         return false;
       case EXPIRED:
         Dialog.getInstance()
             .showConfirmDialog(
                 0,
                 _GUI.T.accountdialog_check_expired_title(),
                 _GUI.T.accountdialog_check_expired(ac.getUser()),
                 null,
                 _GUI.T.accountdialog_check_expired_renew(),
                 null);
         AccountController.getInstance().addAccount(ac, false);
         return true;
       case TEMP_DISABLED:
         if (StringUtils.isEmpty(errorMessage)) {
           errorMessage = _GUI.T.accountdialog_check_failed();
         }
         Dialog.getInstance().showMessageDialog(_GUI.T.accountdialog_check_result(errorMessage));
         AccountController.getInstance().addAccount(ac, false);
         return true;
       default:
       case INVALID:
         if (StringUtils.isEmpty(errorMessage)) {
           errorMessage = _GUI.T.accountdialog_check_failed_msg();
         }
         Dialog.getInstance().showMessageDialog(_GUI.T.accountdialog_check_invalid(errorMessage));
         return false;
     }
   } else {
     String message = null;
     AccountInfo ai = ac.getAccountInfo();
     if (ai != null) {
       message = ai.getStatus();
     }
     if (StringUtils.isEmpty(message)) {
       message = _GUI.T.lit_yes();
     }
     Dialog.getInstance().showMessageDialog(_GUI.T.accountdialog_check_valid(message));
     AccountController.getInstance().addAccount(ac, false);
     return true;
   }
 }
Ejemplo n.º 10
0
 public CheckForUpdatesAction() {
   setIconKey(IconKey.ICON_UPDATE);
   setName(_GUI.T.CheckForUpdatesAction_CheckForUpdatesAction());
 }
Ejemplo n.º 11
0
 public RenameActionLink() {
   setName(_GUI.T.RenameAction_RenameAction());
   setTooltipText(_GUI.T.RenameAction_RenameAction_tt());
   setIconKey(IconKey.ICON_EDIT);
   setAccelerator(KeyStroke.getKeyStroke("F2"));
 }
Ejemplo n.º 12
0
 public SplitPackagesByHost() {
   super();
   setName(_GUI.T.SplitPackagesByHost_SplitPackagesByHost_object_());
   setIconKey(IconKey.ICON_SPLIT_PACKAGES);
 }
Ejemplo n.º 13
0
 public AddedDateColumn() {
   super(_GUI.T.added_date_column_title());
   rendererField.setHorizontalAlignment(SwingConstants.CENTER);
 }
Ejemplo n.º 14
0
public class AddedDateColumn extends ExtDateColumn<AbstractNode> {

  /** */
  private static final long serialVersionUID = -8841119846403017974L;

  private final String bad = _GUI.T.added_date_column_invalid();

  public JPopupMenu createHeaderPopup() {

    return FileColumn.createColumnPopup(this, getMinWidth() == getMaxWidth() && getMaxWidth() > 0);
  }

  public AddedDateColumn() {
    super(_GUI.T.added_date_column_title());
    rendererField.setHorizontalAlignment(SwingConstants.CENTER);
  }

  @Override
  public boolean isEnabled(AbstractNode obj) {
    if (obj instanceof FilePackage) {
      return ((FilePackage) obj).getView().isEnabled();
    }
    if (obj instanceof CrawledPackage) {
      return ((CrawledPackage) obj).getView().isEnabled();
    }
    return obj.isEnabled();
  }

  @Override
  public boolean isDefaultVisible() {
    return false;
  }

  @Override
  protected boolean isDefaultResizable() {
    return false;
  }

  @Override
  public int getDefaultWidth() {
    return 95;
  }

  @Override
  protected String getBadDateText(AbstractNode value) {
    return bad;
  }

  protected String getDateFormatString() {
    String custom = CFG_GUI.CFG.getDateTimeFormatDownloadListAddedDateColumn();
    if (StringUtils.isNotEmpty(custom)) {
      return custom;
    }
    DateFormat sd = SimpleDateFormat.getDateTimeInstance();
    if (sd instanceof SimpleDateFormat) {
      return ((SimpleDateFormat) sd).toPattern();
    }
    return _GUI.T.added_date_column_dateformat();
  }

  @Override
  protected Date getDate(AbstractNode node, Date date) {
    if (node.getCreated() <= 0) return null;
    date.setTime(node.getCreated());
    return date;
  }
}