Search in sources :

Example 1 with FalseFriendPatternRule

use of org.languagetool.rules.patterns.FalseFriendPatternRule in project languagetool by languagetool-org.

the class Tools method showRuleInfoDialog.

static void showRuleInfoDialog(Component parent, String title, String message, Rule rule, ResourceBundle messages, String lang) {
    int dialogWidth = 320;
    JTextPane textPane = new JTextPane();
    textPane.setEditable(false);
    textPane.setContentType("text/html");
    textPane.setBorder(BorderFactory.createEmptyBorder());
    textPane.setOpaque(false);
    textPane.setBackground(new Color(0, 0, 0, 0));
    Tools.addHyperlinkListener(textPane);
    textPane.setSize(dialogWidth, Short.MAX_VALUE);
    String messageWithBold = message.replaceAll("<suggestion>", "<b>").replaceAll("</suggestion>", "</b>");
    String exampleSentences = getExampleSentences(rule, messages);
    String url = "http://community.languagetool.org/rule/show/" + encodeUrl(rule) + "?lang=" + lang + "&amp;ref=standalone-gui";
    boolean isExternal = rule.getCategory().getLocation() == Category.Location.EXTERNAL;
    String ruleDetailLink = rule instanceof FalseFriendPatternRule || isExternal ? "" : "<a href='" + url + "'>" + messages.getString("ruleDetailsLink") + "</a>";
    textPane.setText("<html>" + messageWithBold + exampleSentences + formatURL(rule.getUrl()) + "<br><br>" + ruleDetailLink + "</html>");
    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(dialogWidth, textPane.getPreferredSize().height));
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    String cleanTitle = title.replace("<suggestion>", "'").replace("</suggestion>", "'");
    JOptionPane.showMessageDialog(parent, scrollPane, cleanTitle, JOptionPane.INFORMATION_MESSAGE);
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextPane(javax.swing.JTextPane) FalseFriendPatternRule(org.languagetool.rules.patterns.FalseFriendPatternRule)

Aggregations

JScrollPane (javax.swing.JScrollPane)1 JTextPane (javax.swing.JTextPane)1 FalseFriendPatternRule (org.languagetool.rules.patterns.FalseFriendPatternRule)1