Revision: 7291
http://languagetool.svn.sourceforge.net/languagetool/?rev=7291&view=rev
Author: dnaber
Date: 2012-06-07 19:22:55 +0000 (Thu, 07 Jun 2012)
Log Message:
-----------
refactoring: move language auto-detect checkbox to its own class
Modified Paths:
--------------
trunk/JLanguageTool/src/java/org/languagetool/gui/Main.java
Added Paths:
-----------
trunk/JLanguageTool/src/java/org/languagetool/gui/LanguageDetectionCheckbox.java
Added:
trunk/JLanguageTool/src/java/org/languagetool/gui/LanguageDetectionCheckbox.java
===================================================================
---
trunk/JLanguageTool/src/java/org/languagetool/gui/LanguageDetectionCheckbox.java
(rev 0)
+++
trunk/JLanguageTool/src/java/org/languagetool/gui/LanguageDetectionCheckbox.java
2012-06-07 19:22:55 UTC (rev 7291)
@@ -0,0 +1,63 @@
+/* LanguageTool, a natural language style checker
+ * Copyright (C) 2012 Daniel Naber (http://www.danielnaber.de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+package org.languagetool.gui;
+
+import org.apache.tika.language.LanguageIdentifier;
+import org.languagetool.Language;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ResourceBundle;
+
+class LanguageDetectionCheckbox extends JCheckBox {
+
+ private final ResourceBundle messages;
+ private final LanguageComboBox languageBox;
+
+ LanguageDetectionCheckbox(final ResourceBundle messages, final
LanguageComboBox languageBox, final Configuration config) {
+ super(messages.getString("atd"));
+ addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ languageBox.setEnabled(!isSelected());
+ config.setAutoDetect(isSelected());
+ }
+ });
+ setSelected(config.getAutoDetect());
+ this.messages = messages;
+ this.languageBox = languageBox;
+ }
+
+ Language autoDetectLanguage(String text) {
+ final LanguageIdentifier langIdentifier = new LanguageIdentifier(text);
+ Language lang =
Language.getLanguageForShortName(langIdentifier.getLanguage());
+ if (lang == null) {
+ lang = Language.ENGLISH;
+ }
+ for (int i = 0; i < languageBox.getItemCount(); i++) {
+ final I18nLanguage boxLanguage = (I18nLanguage) languageBox.getItemAt(i);
+ if (boxLanguage.toString().equals(lang.getTranslatedName(messages))) {
+ languageBox.setSelectedIndex(i);
+ }
+ }
+ return lang;
+ }
+
+}
Modified: trunk/JLanguageTool/src/java/org/languagetool/gui/Main.java
===================================================================
--- trunk/JLanguageTool/src/java/org/languagetool/gui/Main.java 2012-06-07
19:10:36 UTC (rev 7290)
+++ trunk/JLanguageTool/src/java/org/languagetool/gui/Main.java 2012-06-07
19:22:55 UTC (rev 7291)
@@ -77,7 +77,7 @@
private JTextPane resultArea;
private JButton checkTextButton;
private LanguageComboBox languageBox;
- private JCheckBox autoDetectBox;
+ private LanguageDetectionCheckbox autoDetectBox;
private Cursor prevCursor;
private HTTPServer httpServer;
@@ -140,16 +140,8 @@
buttonCons.gridx = 2;
buttonCons.gridy = 0;
insidePanel.add(checkTextButton, buttonCons);
-
- autoDetectBox = new JCheckBox(messages.getString("atd"));
- autoDetectBox.addActionListener( new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- languageBox.setEnabled(!autoDetectBox.isSelected());
- config.setAutoDetect(autoDetectBox.isSelected());
- }
- });
- autoDetectBox.setSelected(config.getAutoDetect());
+
+ autoDetectBox = new LanguageDetectionCheckbox(messages, languageBox,
config);
languageBox.setEnabled(!autoDetectBox.isSelected());
buttonCons.gridx = 1;
@@ -401,18 +393,7 @@
// method modified to add automatic language detection
private Language getCurrentLanguage() {
if (autoDetectBox.isSelected()) {
- final LanguageIdentifier langIdentifier = new
LanguageIdentifier(textArea.getText());
- Language lang =
Language.getLanguageForShortName(langIdentifier.getLanguage());
- if (lang == null) {
- lang = Language.ENGLISH;
- }
- for (int i = 0; i < languageBox.getItemCount(); i++) {
- final I18nLanguage boxLanguage = (I18nLanguage)
languageBox.getItemAt(i);
- if (boxLanguage.toString().equals(lang.getTranslatedName(messages))) {
- languageBox.setSelectedIndex(i);
- }
- }
- return lang;
+ return autoDetectBox.autoDetectLanguage(textArea.getText());
} else {
return ((I18nLanguage) languageBox.getSelectedItem()).getLanguage();
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs