/** * Show a file chooser dialog and return the file selected by the user or * <code>null</code>. */ static File openFileDialog(Frame frame, FileFilter fileFilter) { return openFileDialog(frame, fileFilter, null); }
static void showRuleInfoDialog(Component parent, String title, String message, Rule rule, URL matchUrl, 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 + "&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(matchUrl) + "<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); }
private JPanel getWord2VecPanel(GridBagConstraints cons) { JPanel panel = new JPanel(); panel.add(new JLabel(messages.getString("guiWord2VecDir")), cons); File dir = config.getWord2VecDirectory(); int maxDirDisplayLength = 45; String buttonText = dir != null ? StringUtils.abbreviate(dir.getAbsolutePath(), maxDirDisplayLength) : messages.getString("guiWord2VecDirSelect"); JButton word2vecDirButton = new JButton(buttonText); word2vecDirButton.addActionListener(e -> { File newDir = Tools.openDirectoryDialog(owner, dir); if (newDir != null) { try { config.setWord2VecDirectory(newDir); word2vecDirButton.setText(StringUtils.abbreviate(newDir.getAbsolutePath(), maxDirDisplayLength)); } catch (Exception ex) { Tools.showErrorMessage(ex); } } else { // not the best UI, but this way user can turn off word2vec feature without another checkbox config.setWord2VecDirectory(null); word2vecDirButton.setText(StringUtils.abbreviate(messages.getString("guiWord2VecDirSelect"), maxDirDisplayLength)); } }); panel.add(word2vecDirButton, cons); JButton helpButton = new JButton(messages.getString("guiWord2VecHelp")); helpButton.addActionListener(e -> { Tools.openURL("https://github.com/gulp21/languagetool-neural-network"); }); panel.add(helpButton, cons); return panel; }
private void createNonOfficeElements(GridBagConstraints cons, JPanel portPanel) { serverCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiRunOnPort"))); serverCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("guiRunOnPort"))); serverCheckbox.setSelected(config.getRunServer()); portPanel.add(serverCheckbox, cons); serverSettingsCheckbox = new JCheckBox(Tools.getLabel(messages.getString("useGUIConfig"))); serverPortField.setMinimumSize(new Dimension(100, 25)); // without this the box is just a few pixels small, but why? cons.gridx = 1; serverSettingsCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("useGUIConfig"))); serverSettingsCheckbox.setSelected(config.getUseGUIConfig()); serverSettingsCheckbox.setEnabled(config.getRunServer());
public void show() { String aboutText = Tools.getLabel(messages.getString("guiMenuAbout")); Runtime.getRuntime().freeMemory()/1024/1024)); Tools.addHyperlinkListener(aboutPane);
@Override public void actionPerformed(ActionEvent e) { File newDir = Tools.openDirectoryDialog(owner, dir); if (newDir != null) { try { if (config.getLanguage() != null) { // may happen in office context File checkDir = new File(newDir, config.getLanguage().getShortCode()); LuceneLanguageModel.validateDirectory(checkDir); } config.setNgramDirectory(newDir); ngramDirButton.setText(StringUtils.abbreviate(newDir.getAbsolutePath(), maxDirDisplayLength)); } catch (Exception ex) { Tools.showErrorMessage(ex); } } else { // not the best UI, but this way user can turn off ngram feature without another checkbox config.setNgramDirectory(null); ngramDirButton.setText(StringUtils.abbreviate(messages.getString("guiNgramDirSelect"), maxDirDisplayLength)); } } });
@Override public void actionPerformed(ActionEvent e) { Tools.openURL("http://wiki.languagetool.org/finding-errors-using-n-gram-data"); } });
private void configureFromRulesFile(JLanguageTool langTool, Language lang) throws IOException { ServerTools.print("Using options configured in " + config.getRulesConfigFile()); // If we are explicitly configuring from rules, ignore the useGUIConfig flag if (config.getRulesConfigFile() != null) { org.languagetool.gui.Tools.configureFromRules(langTool, new Configuration(config.getRulesConfigFile() .getCanonicalFile().getParentFile(), config.getRulesConfigFile().getName(), lang)); } else { throw new RuntimeException("config.getRulesConfigFile() is null"); } }
JRadioButton[] radioButtons = new JRadioButton[3]; ButtonGroup numParaGroup = new ButtonGroup(); radioButtons[0] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckOnlyParagraph"))); radioButtons[0].setActionCommand("ParagraphCheck"); radioButtons[1] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckFullText"))); radioButtons[1].setActionCommand("FullTextCheck"); radioButtons[2] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckNumParagraphs"))); radioButtons[2].setActionCommand("NParagraphCheck"); radioButtons[2].setSelected(true); portPanel.add(numParaField, cons); JCheckBox resetCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiDoResetCheck"))); resetCheckbox.setSelected(config.isResetCheck()); resetCheckbox.addItemListener(new ItemListener() {
JButton okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton"))); okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton"))); okButton.setActionCommand(ACTION_COMMAND_OK); okButton.addActionListener(this); JButton cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton"))); cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton"))); cancelButton.setActionCommand(ACTION_COMMAND_CANCEL); cancelButton.addActionListener(this);
@Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { Tools.openURL(e.getURL()); } } });
private void configureFromGUI(JLanguageTool langTool, Language lang) throws IOException { Configuration config = new Configuration(lang); if (internalServer && config.getUseGUIConfig()) { ServerTools.print("Using options configured in the GUI"); org.languagetool.gui.Tools.configureFromRules(langTool, config); } }
/** * Show a file chooser dialog in a specified directory * @param frame Owner frame * @param fileFilter The pattern of files to choose from * @param initialDir The initial directory * @return the selected file * @since 2.6 */ static File openFileDialog(Frame frame, FileFilter fileFilter, File initialDir) { return openFileDialog(frame, fileFilter, initialDir, JFileChooser.FILES_ONLY); }
/** * Show a directory chooser dialog, starting with a specified directory * @param frame Owner frame * @param initialDir The initial directory * @return the selected file * @since 3.0 */ static File openDirectoryDialog(Frame frame, File initialDir) { return openFileDialog(frame, null, initialDir, JFileChooser.DIRECTORIES_ONLY); }