Package org.wikipediacleaner.gui.swing.action

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


  /* (non-Javadoc)
   * @see org.wikipediacleaner.api.check.ActionProvider#getAction(javax.swing.text.Element, javax.swing.JTextPane)
   */
  public Action getAction(Element element, JTextPane textPane) {
    return new ReplaceTextAction(newText, element, textPane);
  }
View Full Code Here


            if ((template.length > 1) && (template[1].trim().length() > 0)) {
              message += " - " + template[1].trim();
            }
            addItem(
                submenu, null, message, true,
                new ReplaceTextAction(replacement, element, textPane));
          }
          popup.add(submenu);
        } else {
          String replacement = createTextForTemplate(templates.get(0)[0], page.getTitle(), text);
          addItem(
              popup, null, GT._("Mark as normal link using template"), true,
              new ReplaceTextAction(replacement, element, textPane));
        }
      }

      // Add a menu for marking as normal links using a comment
      List<String> comments = wiki.getConfiguration().getStringList(
          WPCConfigurationStringList.COMMENTS_FOR_DAB_LINK);
      if ((comments != null) && !comments.isEmpty()) {
        if (comments.size() > 1) {
          JMenu submenu = new JMenu(GT._("Mark as normal link"));
          for (String comment : comments) {
            String replacement =
                PageElementInternalLink.createInternalLink(page.getTitle(), text) +
                PageElementComment.createComment(comment);
            addItem(
                submenu, null, GT._("Using {0}", comment), true,
                new ReplaceTextAction(replacement, element, textPane));
          }
          popup.add(submenu);
        } else {
          String replacement =
              PageElementInternalLink.createInternalLink(page.getTitle(), text) +
              PageElementComment.createComment(comments.get(0));
          addItem(
              popup, null, GT._("Mark as normal link using comment"), true,
              new ReplaceTextAction(replacement, element, textPane));
        }
      }
    }
  }
View Full Code Here

        if (!preferredDabs.isEmpty()) {
          // Preferred disambiguations
          for (String preferredDab : preferredDabs) {
            fixedBegin += addItem(
                submenu, null, preferredDab, true,
                new ReplaceTextAction(
                    matcher.getReplacement(page, template, indexReplacement, preferredDab),
                    element, textPane));
          }
        } else {
          // Last replacement
          String title = LinkReplacement.getLastReplacement(disambigPage.getTitle());
          if (title != null) {
            fixedBegin += addItem(
                submenu, null, title, true,
                new ReplaceTextAction(
                    matcher.getReplacement(page, template, indexReplacement, title),
                    element, textPane));
          }
        }

        // Wiktionary links
        if ((wiktionary != null) && (wiktionary.size() > 0)) {
          if ((!separators) && (fixedBegin > 0)) {
            fixedBegin += addSeparator(submenu);
            separators = true;
          }
          for (String wikt : wiktionary) {
            String name = "wikt:" + wikt;
            addItem(
                submenu, null, name, true,
                new ReplaceTextAction(
                    matcher.getReplacement(page, template, indexReplacement, name),
                    element, textPane));
          }
        }

        // Possible links
        if ((links != null) && (links.size() > 0)) {
          if ((!separators) && (fixedBegin > 0)) {
            fixedBegin += addSeparator(submenu);
            separators = true;
          }
          for (Page p : links) {
            if (p.isRedirect()) {
              JMenu submenu1 = 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 ReplaceTextAction(
                        matcher.getReplacement(page, template, indexReplacement, pageTmp.getTitle()),
                        element, textPane));
       
                if ((anchors != null) && (anchors.size() > 0)) {
                  for (String anchor : anchors) {
                    addItem(
                        submenu1, pageTmp, anchor, true,
                        new ReplaceTextAction(
                            matcher.getReplacement(page, template, indexReplacement, anchor),
                            element, textPane));
                  }
                }
              }
             
              submenu.add(submenu1);
            } else {
              addItem(
                  submenu, p, null, true,
                  new ReplaceTextAction(
                      matcher.getReplacement(page, template, indexReplacement, p.getTitle()),
                      element, textPane));

              // Anchors
              List<String> anchors = anchorsMap.get(p);
              if (anchors != null) {
                for (String anchor : anchors) {
                  addItem(
                      submenu, p, anchor, true,
                      new ReplaceTextAction(
                          matcher.getReplacement(page, template, indexReplacement, anchor),
                          element, textPane));
                }
              }
            }
          }
        }

        if (separators) {
          if (!preferredDabs.isEmpty()) {
            // Preferred disambiguations
            fixedEnd += addSeparator(submenu);
            for (String preferredDab : preferredDabs) {
              fixedEnd += addItem(
                  submenu, null, preferredDab, true,
                  new ReplaceTextAction(
                      matcher.getReplacement(page, template, indexReplacement, preferredDab),
                      element, textPane));
            }
          } else {
            // Last replacement
            String title = LinkReplacement.getLastReplacement(disambigPage.getTitle());
            if (title != null) {
              fixedEnd += addSeparator(submenu);
              fixedEnd += addItem(
                  submenu, null, title, true,
                  new ReplaceTextAction(
                      matcher.getReplacement(page, template, indexReplacement, title),
                      element, textPane));
            }
          }
        }
View Full Code Here

TOP

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

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.