@Override
    public void actionPerformed() {

        ExtFileChooserDialog d = new ExtFileChooserDialog(0, _GUI._.ExportAllMenusAdvancedAction_actionPerformed(), null, null);
        d.setFileFilter(new FileFilter() {

            @Override
            public String getDescription() {

                return _GUI._.lit_directory();
            }

            @Override
            public boolean accept(File f) {
                return f.isDirectory();
            }
        });

        d.setFileSelectionMode(FileChooserSelectionMode.DIRECTORIES_ONLY);
        d.setMultiSelection(false);

        d.setStorageID("menus");
        d.setType(FileChooserType.SAVE_DIALOG);
        try {
            Dialog.getInstance().showDialog(d);

            File saveTo = d.getSelectedFile();
            File file = null;
            int i = 0;
            while (file == null || file.exists()) {

                file = new File(saveTo, "JDownloader Menustructure " + i);

                i++;
            }
            file.mkdirs();
            MenuManagerDownloadTabBottomBar.getInstance().exportTo(file);
            MenuManagerDownloadTableContext.getInstance().exportTo(file);
            MenuManagerLinkgrabberTabBottombar.getInstance().exportTo(file);
            MenuManagerLinkgrabberTableContext.getInstance().exportTo(file);
            MenuManagerMainToolbar.getInstance().exportTo(file);
            MenuManagerTrayIcon.getInstance().exportTo(file);
            MenuManagerMainmenu.getInstance().exportTo(file);
            CrossSystem.openFile(file);

        } catch (DialogClosedException e1) {
            e1.printStackTrace();
        } catch (DialogCanceledException e1) {
            e1.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            Dialog.getInstance().showExceptionDialog(_GUI._.lit_error_occured(), e1.getMessage(), e1);
        } catch (IOException e1) {
            Dialog.getInstance().showExceptionDialog(_GUI._.lit_error_occured(), e1.getMessage(), e1);
        }
    }
示例#2
0
  @Override
  public void actionPerformed(ActionEvent e) {
    final ComboBoxDialog d =
        new ComboBoxDialog(
            0,
            "Clone Translation",
            "Choose the Language you want to clone",
            owner.getTranslations().toArray(new TLocale[] {}),
            PRE == null ? 0 : owner.getTranslations().indexOf(PRE),
            new AbstractIcon(IconKey.ICON_LANGUAGE, 32),
            null,
            null,
            null);

    int ret;
    try {
      ret = Dialog.getInstance().showDialog(d);

      if (ret >= 0) {
        TLocale sel = owner.getTranslations().get(ret);
        PRE = sel;

        owner.setTranslation(selection, sel);
      }
    } catch (DialogClosedException e1) {
      e1.printStackTrace();
    } catch (DialogCanceledException e1) {
      e1.printStackTrace();
    }
  }
示例#3
0
  /** Close Order: A B */
  private static void test2() {
    final InputDialog dialog =
        new InputDialog(0, "title", "message", "defaultMessage", null, null, null);

    dialog.setLeftActions(
        new AbstractAction("CLICK HERE!!!") {

          private static final long serialVersionUID = 3916626551625222343L;

          public void actionPerformed(final ActionEvent e) {

            Dialog.getInstance().showMessageDialog("INTERNAL");

            System.out.println("Closed A");
          }
        });
    try {
      Dialog.getInstance().showDialog(dialog);
    } catch (final DialogClosedException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (final DialogCanceledException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    System.out.println("Closed B");
  }
示例#4
0
  @Override
  public void run(Storage config, AbstractMyJDClientForDesktopJVM api) throws Exception {
    final String session = config.get("session", "");
    final SessionInfo sessioninfo = JSonStorage.restoreFromString(session, SessionInfo.class);
    api.setSessionInfo(sessioninfo);

    api.reconnect();
    Dialog.getInstance()
        .showMessageDialog(
            "Done. New SessionToken: " + JSonStorage.serializeToJson(api.getSessionInfo()));
  }
 public void actionPerformed(ActionEvent e) {
     final List<Archive> lArchives = getArchives();
     if (!isEnabled() || lArchives == null) {
         return;
     } else {
         for (Archive archive : lArchives) {
             archive.setAutoExtract(isSelected() ? BooleanStatus.TRUE : BooleanStatus.FALSE);
         }
         if (JDGui.bugme(WarnLevel.NORMAL)) {
             Dialog.getInstance().showMessageDialog(Dialog.STYLE_SHOW_DO_NOT_DISPLAY_AGAIN, isSelected() ? org.jdownloader.extensions.extraction.translate.T._.set_autoextract_true() : org.jdownloader.extensions.extraction.translate.T._.set_autoextract_false());
         }
     }
 }
 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();
   }
 }
示例#7
0
 public static void showDialog(final PluginForHost pluginForHost, Account acc) {
   final AddAccountDialog dialog = new AddAccountDialog(pluginForHost, acc);
   try {
     Dialog.getInstance().showDialog(dialog);
     if (dialog.getHoster() == null) {
       return;
     }
     final Account ac = dialog.getAccount();
     ac.setHoster(dialog.getHoster().getDisplayName());
     if (!addAccount(ac)) {
       showDialog(dialog.getHoster().getPrototype(null), ac);
     }
   } catch (Throwable e) {
     org.appwork.utils.logging2.extmanager.LoggerFactory.getDefaultLogger().log(e);
   }
 }
示例#8
0
  /** @return */
  public File doFileChooser() {

    final ExtFileChooserDialog d = new ExtFileChooserDialog(0, this.getDialogTitle(), null, null);
    d.setStorageID(this.getID());
    d.setFileSelectionMode(this.getSelectionMode());
    d.setFileFilter(this.getFileFilter());
    d.setType(this.getType());
    d.setMultiSelection(false);
    d.setPreSelection(this.getFile());
    try {
      Dialog.I().showDialog(d);
    } catch (final DialogClosedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (final DialogCanceledException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return d.getSelectedFile();
  }
示例#9
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;
  }
示例#10
0
  @Override
  protected void setStringValue(final String value, final AbstractNode object) {
    if (StringUtils.isEmpty(value) || object == null) {
      return;
    }
    File oldPath = LinkTreeUtils.getDownloadDirectory(object);
    File newPath = LinkTreeUtils.getDownloadDirectory(value, null, object);
    if (oldPath.equals(newPath)) {
      /* both paths are same, so nothing to do */
      return;
    }
    if (object instanceof CrawledPackage) {
      LinkCollector.getInstance()
          .getQueue()
          .add(
              new QueueAction<Object, RuntimeException>(
                  org.appwork.utils.event.queue.Queue.QueuePriority.HIGH) {
                @Override
                protected Object run() {
                  ((CrawledPackage) object).setDownloadFolder(value);
                  return null;
                }
              });
      return;
    } else if (object instanceof CrawledLink) {
      final CrawledPackage p = ((CrawledLink) object).getParentNode();
      try {
        Dialog.getInstance()
            .showConfirmDialog(
                Dialog.LOGIC_DONOTSHOW_BASED_ON_TITLE_ONLY | Dialog.STYLE_SHOW_DO_NOT_DISPLAY_AGAIN,
                _JDT.T.SetDownloadFolderAction_actionPerformed_(p.getName()),
                _JDT.T.SetDownloadFolderAction_msg(p.getName(), 1),
                null,
                _JDT.T.SetDownloadFolderAction_yes(),
                _JDT.T.SetDownloadFolderAction_no());
        LinkCollector.getInstance()
            .getQueue()
            .add(
                new QueueAction<Object, RuntimeException>(
                    org.appwork.utils.event.queue.Queue.QueuePriority.HIGH) {
                  @Override
                  protected Object run() {
                    p.setDownloadFolder(value);
                    return null;
                  }
                });
        return;
      } catch (DialogClosedException e) {
        return;
      } catch (DialogCanceledException e) {
        /* user clicked no */
      }

      final CrawledPackage pkg = new CrawledPackage();
      pkg.setExpanded(CFG_LINKCOLLECTOR.CFG.isPackageAutoExpanded());
      if (TYPE.NORMAL != p.getType()) {
        final String pkgName;
        if (object instanceof AbstractPackageNode) {
          pkgName =
              LinknameCleaner.cleanFileName(
                  object.getName(),
                  false,
                  true,
                  LinknameCleaner.EXTENSION_SETTINGS.REMOVE_KNOWN,
                  true);
        } else {
          pkgName =
              LinknameCleaner.cleanFileName(
                  object.getName(),
                  false,
                  true,
                  LinknameCleaner.EXTENSION_SETTINGS.REMOVE_ALL,
                  true);
        }
        pkg.setName(pkgName);
      } else {
        pkg.setName(p.getName());
      }
      pkg.setComment(p.getComment());
      pkg.setDownloadFolder(value);

      final java.util.List<CrawledLink> links = new ArrayList<CrawledLink>();
      links.add((CrawledLink) object);
      LinkCollector.getInstance()
          .getQueue()
          .add(
              new QueueAction<Object, RuntimeException>(
                  org.appwork.utils.event.queue.Queue.QueuePriority.HIGH) {

                @Override
                protected Object run() {
                  LinkCollector.getInstance().moveOrAddAt(pkg, links, -1);
                  return null;
                }
              });
    }
  }
  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;
  }
示例#12
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;
   }
 }
  @SuppressWarnings("unchecked")
  private void loadUnpacked() {
    URL ret = getClass().getResource("/");
    File root;
    if (ret.getProtocol().equalsIgnoreCase("file")) {
      try {
        root = new File(ret.toURI());
      } catch (URISyntaxException e) {
        Log.exception(e);
        Log.L.finer("Did not load unpacked Extensions from " + ret);
        return;
      }
    } else {
      Log.L.finer("Did not load unpacked Extensions from " + ret);
      return;
    }
    root = new File(root, AbstractExtension.class.getPackage().getName().replace('.', '/'));
    Log.L.finer("Load Extensions from: " + root.getAbsolutePath());
    File[] folders =
        root.listFiles(
            new FileFilter() {

              public boolean accept(File pathname) {
                return pathname.isDirectory();
              }
            });
    ClassLoader cl = getClass().getClassLoader();
    main:
    for (File f : folders) {
      File[] modules =
          f.listFiles(
              new FilenameFilter() {

                public boolean accept(File dir, String name) {
                  return name.endsWith("Extension.class");
                }
              });
      boolean loaded = false;
      for (File module : modules) {

        Class<?> cls;
        try {
          cls =
              cl.loadClass(
                  AbstractExtension.class.getPackage().getName()
                      + "."
                      + module.getParentFile().getName()
                      + "."
                      + module.getName().substring(0, module.getName().length() - 6));

          if (AbstractExtension.class.isAssignableFrom(cls)) {
            loaded = true;
            initModule((Class<AbstractExtension<?>>) cls);
            continue main;
          }
        } catch (IllegalArgumentException e) {
          Log.L.warning("Did not init Extension " + module + " : " + e.getMessage());
        } catch (Throwable e) {
          Log.exception(e);
          Dialog.getInstance().showExceptionDialog("Error", e.getMessage(), e);
        }
      }
      if (!loaded) {
        Log.L.warning("Could not load any Extension Module from " + f);
      }
    }
  }
示例#14
0
  public void actionPerformed(ActionEvent e) {
    final SelectionInfo<CrawledPackage, CrawledLink> finalSelecction = getSelection();
    final String newName;
    final String newDownloadFolder;
    if (isMergePackages() && finalSelecction.getPackageViews().size() > 1) {
      if (isAskForNewDownloadFolderAndPackageName()) {
        try {
          final NewPackageDialog d =
              new NewPackageDialog(finalSelecction) {
                @Override
                public String getDontShowAgainKey() {
                  return "ABSTRACTDIALOG_DONT_SHOW_AGAIN_"
                      + SplitPackagesByHost.this.getClass().getSimpleName();
                }
              };

          Dialog.getInstance().showDialog(d);

          newName = d.getName();
          newDownloadFolder = d.getDownloadFolder();
          if (StringUtils.isEmpty(newName)) {
            return;
          }
        } catch (Throwable ignore) {
          return;
        }
      } else {
        newName = "";
        newDownloadFolder = finalSelecction.getFirstPackage().getRawDownloadFolder();
      }
    } else {
      newName = null;
      newDownloadFolder = null;
    }
    LinkCollector.getInstance()
        .getQueue()
        .add(
            new QueueAction<Void, RuntimeException>() {

              @Override
              protected Void run() throws RuntimeException {
                final HashMap<CrawledPackage, HashMap<String, ArrayList<CrawledLink>>> splitMap =
                    new HashMap<CrawledPackage, HashMap<String, ArrayList<CrawledLink>>>();
                int insertAt = -1;
                switch (getLocation()) {
                  case BEFORE_SELECTION:
                    insertAt = Integer.MAX_VALUE;
                }
                for (AbstractNode child : finalSelecction.getChildren()) {
                  if (child instanceof CrawledLink) {
                    final CrawledLink cL = (CrawledLink) child;
                    final CrawledPackage parent = isMergePackages() ? null : cL.getParentNode();

                    HashMap<String, ArrayList<CrawledLink>> parentMap = splitMap.get(parent);
                    if (parentMap == null) {
                      parentMap = new HashMap<String, ArrayList<CrawledLink>>();
                      splitMap.put(parent, parentMap);
                    }
                    final String host = cL.getDomainInfo().getTld();
                    ArrayList<CrawledLink> hostList = parentMap.get(host);
                    if (hostList == null) {
                      hostList = new ArrayList<CrawledLink>();
                      parentMap.put(host, hostList);
                    }
                    hostList.add(cL);
                    switch (getLocation()) {
                      case AFTER_SELECTION:
                        insertAt =
                            Math.max(
                                insertAt,
                                LinkCollector.getInstance()
                                        .indexOf(((CrawledLink) child).getParentNode())
                                    + 1);
                        break;
                      case BEFORE_SELECTION:
                        insertAt =
                            Math.min(
                                insertAt,
                                LinkCollector.getInstance()
                                    .indexOf(((CrawledLink) child).getParentNode()));
                        break;
                      case END_OF_LIST:
                        insertAt = -1;
                        break;
                      case TOP_OF_LIST:
                        insertAt = 0;
                        break;
                    }
                  }
                }
                if (insertAt == Integer.MAX_VALUE) {
                  insertAt = 0;
                }
                final String nameFactory =
                    JsonConfig.create(LinkgrabberSettings.class)
                        .getSplitPackageNameFactoryPattern();
                final boolean merge =
                    JsonConfig.create(LinkgrabberSettings.class).isSplitPackageMergeEnabled();
                final HashMap<String, CrawledPackage> mergedPackages =
                    new HashMap<String, CrawledPackage>();
                final Iterator<Entry<CrawledPackage, HashMap<String, ArrayList<CrawledLink>>>> it =
                    splitMap.entrySet().iterator();
                while (it.hasNext()) {
                  final Entry<CrawledPackage, HashMap<String, ArrayList<CrawledLink>>> next =
                      it.next();
                  // sourcePackage may be null
                  final CrawledPackage sourcePackage = next.getKey();
                  final HashMap<String, ArrayList<CrawledLink>> items = next.getValue();
                  final Iterator<Entry<String, ArrayList<CrawledLink>>> it2 =
                      items.entrySet().iterator();
                  while (it2.hasNext()) {
                    final Entry<String, ArrayList<CrawledLink>> next2 = it2.next();
                    final String host = next2.getKey();
                    final String newPackageName =
                        getNewPackageName(
                            nameFactory,
                            sourcePackage == null ? newName : sourcePackage.getName(),
                            host);
                    final CrawledPackage newPkg;
                    if (merge) {
                      CrawledPackage destPackage = mergedPackages.get(newPackageName);
                      if (destPackage == null) {
                        destPackage = new CrawledPackage();
                        destPackage.setExpanded(CFG_LINKCOLLECTOR.CFG.isPackageAutoExpanded());
                        if (sourcePackage != null) {
                          sourcePackage.copyPropertiesTo(destPackage);
                        } else {
                          destPackage.setDownloadFolder(newDownloadFolder);
                        }
                        destPackage.setName(newPackageName);
                        mergedPackages.put(newPackageName, destPackage);
                      }
                      newPkg = destPackage;
                    } else {
                      newPkg = new CrawledPackage();
                      newPkg.setExpanded(CFG_LINKCOLLECTOR.CFG.isPackageAutoExpanded());
                      if (sourcePackage != null) {
                        sourcePackage.copyPropertiesTo(newPkg);
                      } else {
                        newPkg.setDownloadFolder(newDownloadFolder);
                      }
                      newPkg.setName(newPackageName);
                    }
                    LinkCollector.getInstance().moveOrAddAt(newPkg, next2.getValue(), 0, insertAt);
                    insertAt++;
                  }
                }
                return null;
              }
            });
  }