Package org.wikipediacleaner.gui.swing.action

Examples of org.wikipediacleaner.gui.swing.action.ReplaceLinkAction


    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK);
    inputMapFocused.put(keyStroke, "find-text");
    actionMap.put("find-text", new FindTextAction());

    inputMapInFocused.put(lastLinkKeyStroke, "last-link");
    actionMap.put("last-link", new ReplaceLinkAction(false));

    inputMapInFocused.put(lastReplaceKeyStroke, "last-replace");
    actionMap.put("last-replace", new ReplaceLinkAction(true));

    isInInternalModification = oldState;
    setModified(false);
  }
View Full Code Here


      String last = LinkReplacement.getLastReplacement(page.getTitle());
      if (withLastSuffix != null) {
        preferredDabs.remove(withLastSuffix);
        addItem(
            popup, null, GT._("&Link to {0}", withLastSuffix), false,
            new ReplaceLinkAction(page.getTitle(), withLastSuffix, text, element, textPane, false),
            lastLinkKeyStroke);
        lastLinkKeyStroke = null;
        addItem(
            popup, null, GT._("&Replace with {0}", withLastSuffix), false,
            new ReplaceLinkAction(page.getTitle(), withLastSuffix, text, element, textPane, true),
            lastReplaceKeyStroke);
        lastReplaceKeyStroke = null;
      } else {
        if ((last != null) && (!last.equals(withLastSuffix))) {
          preferredDabs.remove(last);
          addItem(
              popup, null, GT._("&Link to {0}", last), false,
              new ReplaceLinkAction(page.getTitle(), last, text, element, textPane, false),
              lastLinkKeyStroke);
          lastLinkKeyStroke = null;
          addItem(
              popup, null, GT._("&Replace with {0}", last), false,
              new ReplaceLinkAction(page.getTitle(), last, text, element, textPane, true),
              lastReplaceKeyStroke);
          lastReplaceKeyStroke = null;
        }
      }
      if (!preferredDabs.isEmpty()) {
        for (String title : preferredDabs) {
          fixedBeginLink += addItem(
              submenuLink, null, title, true,
              new ReplaceLinkAction(page.getTitle(), title, text, element, textPane, false),
              lastLinkKeyStroke);
          lastLinkKeyStroke = null;
          fixedBeginReplace += addItem(
              submenuReplace, null, title, true,
              new ReplaceLinkAction(page.getTitle(), title, text, element, textPane, true),
              lastReplaceKeyStroke);
          lastReplaceKeyStroke = null;
        }
      }

      // Separators
      if (separators) {
        fixedBeginLink += addSeparator(submenuLink);
        fixedBeginReplace += addSeparator(submenuReplace);
      }

      // Wiktionary links
      if ((wiktionary != null) && (wiktionary.size() > 0)) {
        for (String wikt : wiktionary) {
          String name = "wikt:" + wikt;
          addItem(
              submenuLink, null, name, true,
              new ReplaceLinkAction(page.getTitle(), ":" + name, text, element, textPane, false));
        }
      }

      // Possible links
      if ((links != null) && (links.size() > 0)) {
        for (Page p : links) {
          if (p.isRedirect()) {
            JMenu submenu1 = new JMenu(p.getTitle());
            JMenu submenu2 = new JMenu(p.getTitle());
            JMenu submenu3 = new JMenu(p.getTitle());
            Map<Page, List<String>> anchorsRedirectMap = new HashMap<Page, List<String>>();
            p.getLinksWithRedirect(anchorsRedirectMap);
           
            Iterator<Page> iter = p.getRedirectIteratorWithPage();
            while (iter.hasNext()) {
              Page pageTmp = iter.next();
              List<String> anchors = anchorsRedirectMap.get(pageTmp);

              addItem(
                  submenu1, pageTmp, null, true,
                  new ReplaceLinkAction(page.getTitle(), pageTmp.getTitle(), text, element, textPane, false));

              addItem(
                  submenu2, pageTmp, null, true,
                  new ReplaceLinkAction(page.getTitle(), pageTmp.getTitle(), text, element, textPane, true));

              addItem(
                  submenu3, pageTmp, null, true,
                  new ChangePreferredDisambiguationAction(
                      page.getWikipedia(), page.getTitle(), pageTmp.getTitle(), true));

              if ((anchors != null) && (anchors.size() > 0)) {
                for (String anchor : anchors) {
                  addItem(
                      submenu1, pageTmp, anchor, true,
                      new ReplaceLinkAction(page.getTitle(), anchor, text, element, textPane, false));

                  addItem(
                      submenu2, pageTmp, anchor, true,
                      new ReplaceLinkAction(page.getTitle(), anchor, text, element, textPane, true));

                  if (!preferredDabs.contains(anchor)) {
                    addItem(
                        submenu3, pageTmp, anchor, true,
                        new ChangePreferredDisambiguationAction(
                            page.getWikipedia(), page.getTitle(), anchor, true));
                  }
                }
              }
            }
           
            submenuLink.add(submenu1);
            submenuReplace.add(submenu2);
            submenuAddPreferred.add(submenu3);
          } else if ((p.getNamespace() != null) &&
                     (p.getNamespace().intValue() == Namespace.CATEGORY)) {
            JMenu submenu1 = new JMenu(p.getTitle());
            JMenu submenu2 = new JMenu(p.getTitle());

            addItem(
                submenu1, p, null, true,
                new ReplaceLinkAction(page.getTitle(), p.getTitle(), text, element, textPane, false));
            addItem(
                submenu2, p, null, true,
                new ReplaceLinkAction(page.getTitle(), p.getTitle(), text, element, textPane, true));

            addSeparator(submenu1);
            addSeparator(submenu2);

            List<Page> categoryMembers = p.getRelatedPages(Page.RelatedPages.CATEGORY_MEMBERS);
            if (categoryMembers == null) {
              addItem(
                  submenu1, null, GT._("Reload category members"), true,
                  new ReloadCategoryMembersAction(wiki, p, null));
            } else {
              for (Page p2 : categoryMembers) {
                boolean already = false;
                for (Page p3 : links) {
                  if (Page.areSameTitle(p2.getTitle(), p3.getTitle())) {
                    already = true;
                  }
                }
                if (!already) {
                  addItem(
                      submenu1, p2, null, true,
                      new ReplaceLinkAction(page.getTitle(), p2.getTitle(), text, element, textPane, false));
                  addItem(
                      submenu2, p2, null, true,
                      new ReplaceLinkAction(page.getTitle(), p2.getTitle(), text, element, textPane, true));
                }
              }
            }

            addSubmenu(submenuLink, submenu1, 2, 0);
            addSubmenu(submenuReplace, submenu2, 2, 0);
          } else {
            addItem(
                submenuLink, p, null, true,
                new ReplaceLinkAction(page.getTitle(), p.getTitle(), text, element, textPane, false));

            addItem(
                submenuReplace, p, null, true,
                new ReplaceLinkAction(page.getTitle(), p.getTitle(), text, element, textPane, true));

            if (!preferredDabs.contains(p.getTitle())) {
              addItem(
                  submenuAddPreferred, p, null, true,
                  new ChangePreferredDisambiguationAction(
                      page.getWikipedia(), page.getTitle(), p.getTitle(), true));
            }

            // Anchors
            List<String> anchors = anchorsMap.get(p);
            if (anchors != null) {
              for (String anchor : anchors) {
                addItem(
                    submenuLink, p, anchor, true,
                    new ReplaceLinkAction(page.getTitle(), anchor, text, element, textPane, false));

                addItem(
                    submenuReplace, p, anchor, true,
                    new ReplaceLinkAction(page.getTitle(), anchor, text, element, textPane, true));

                if (!preferredDabs.contains(anchor)) {
                  addItem(
                      submenuAddPreferred, p, anchor, true,
                      new ChangePreferredDisambiguationAction(
                          page.getWikipedia(), page.getTitle(), anchor, true));
                }
              }
            }
          }
        }
      }

      // Last replacement
      if (separators) {
        if (!preferredDabs.isEmpty()) {
          fixedEndLink += addSeparator(submenuLink);
          fixedEndReplace += addSeparator(submenuReplace);
          for (String title : preferredDabs) {
            if ((withLastSuffix != null) && (withLastSuffix.equals(title))) {
              withLastSuffix = null;
            }
            fixedEndLink += addItem(
                submenuLink, null, title, true,
                new ReplaceLinkAction(page.getTitle(), title, text, element, textPane, false),
                (preferredDabs.size() == 1) ? lastLinkKeyStroke : null);
            fixedEndReplace += addItem(
                submenuReplace, null, title, true,
                new ReplaceLinkAction(page.getTitle(), title, text, element, textPane, true),
                (preferredDabs.size() == 1) ? lastReplaceKeyStroke : null);
          }
        }
      }

      addSubmenu(popup, submenuLink, fixedBeginLink, fixedEndLink);
      addSubmenu(popup, submenuReplace, fixedBeginReplace, fixedEndReplace);

      submenuAddPreferred.addSeparator();
      addItem(
          submenuAddPreferred, null, GT._("Add other preferred disambiguation..."), true,
          new ChangePreferredDisambiguationAction(
              page.getWikipedia(),
              page.getTitle(), textPane,
              GT._("What link do you want to add to the preferred disambiguations?"),
              null,
              new StringCheckerUnauthorizedCharacters("[|]")),
          null);
      addSubmenu(popup, submenuAddPreferred, 0, 2);

      if (!preferredDabs.isEmpty()) {
        JMenu submenuRemove = new JMenu(GT._("Remove from preferred disambiguations"));
        for (String title : preferredDabs) {
          addItem(
              submenuRemove, null, title, true,
              new ChangePreferredDisambiguationAction(
                  page.getWikipedia(), page.getTitle(), title, false),
              null);
        }
        addSubmenu(popup, submenuRemove, 0, 0);
      }

      if (!Page.areSameTitle(text, page.getTitle())) {
        String newLink = PageElementInternalLink.createInternalLink(text, page.getTitle());
        addItem(
            popup, null, GT._("Reverse to {0}", newLink), true,
            new RevertLinkAction(page.getTitle(), text, element, textPane), null);
      }

    // Redirect page
    } else if (page.isRedirect()) {
      String title = page.getRedirectTitle();

      addItem(
          popup, null, GT._("&Link to {0}", title), false,
          new ReplaceLinkAction(page.getTitle(), title, text, element, textPane, false));

      addItem(
          popup, null, GT._("&Replace with {0}", title), false,
          new ReplaceLinkAction(page.getTitle(), title, text, element, textPane, true));

      if (!Page.areSameTitle(text, page.getTitle())) {
        String newLink = PageElementInternalLink.createInternalLink(text, page.getTitle());
        addItem(
            popup, null, GT._("Reverse to {0}", newLink), true,
View Full Code Here

TOP

Related Classes of org.wikipediacleaner.gui.swing.action.ReplaceLinkAction

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.