aboutsummaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorPurvesh Sahoo <jimpu2@gmail.com>2011-08-28 03:55:43 +0000
committerPurvesh Sahoo <jimpu2@gmail.com>2011-08-28 03:55:43 +0000
commita4752915054bc9b456d4583e1a596e6f83dbaa6e (patch)
tree64f68904a0ba4cf1f847b49da992d4e3a37976d7 /src/net
parenta538e0f6e2d8ded78275b49d20d9c224910c7b60 (diff)
downloadjitsi-a4752915054bc9b456d4583e1a596e6f83dbaa6e.zip
jitsi-a4752915054bc9b456d4583e1a596e6f83dbaa6e.tar.gz
jitsi-a4752915054bc9b456d4583e1a596e6f83dbaa6e.tar.bz2
Adds support to uninstall dictionary and persist enable state across reboots.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/java/sip/communicator/plugin/spellcheck/CheckerToggleButton.java89
-rw-r--r--src/net/java/sip/communicator/plugin/spellcheck/LanguageSelectionField.java212
-rw-r--r--src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java31
3 files changed, 308 insertions, 24 deletions
diff --git a/src/net/java/sip/communicator/plugin/spellcheck/CheckerToggleButton.java b/src/net/java/sip/communicator/plugin/spellcheck/CheckerToggleButton.java
new file mode 100644
index 0000000..0d7840c
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/spellcheck/CheckerToggleButton.java
@@ -0,0 +1,89 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.plugin.spellcheck;
+
+import java.awt.event.*;
+
+import javax.swing.*;
+
+import net.java.sip.communicator.service.contactlist.*;
+import net.java.sip.communicator.service.gui.*;
+import net.java.sip.communicator.service.protocol.Contact;
+
+/**
+ * Toggle-able button that sets the spell checker to be either enabled or
+ * disabled.
+ *
+ * @author Damian Johnson
+ */
+public class CheckerToggleButton
+ implements PluginComponent
+{
+ private final JToggleButton toggleButton;
+
+ CheckerToggleButton(final SpellChecker checker)
+ {
+ this.toggleButton =
+ new JToggleButton(Resources.getImage("plugin.spellcheck.DISABLE"));
+ this.toggleButton.setSelectedIcon(Resources
+ .getImage("plugin.spellcheck.ENABLE"));
+ this.toggleButton.setSelected(checker.isEnabled());
+ this.toggleButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ checker.setEnabled(toggleButton.isSelected());
+ }
+ });
+ }
+
+ public Object getComponent()
+ {
+ return this.toggleButton;
+ }
+
+ public String getConstraints()
+ {
+ return Container.RIGHT;
+ }
+
+ public Container getContainer()
+ {
+ return Container.CONTAINER_CHAT_TOOL_BAR;
+ }
+
+ public String getName()
+ {
+ return "Spell Checker Toggle";
+ }
+
+ public int getPositionIndex()
+ {
+ return -1;
+ }
+
+ public boolean isNativeComponent()
+ {
+ return false;
+ }
+
+ public void setCurrentContact(MetaContact metaContact)
+ {
+
+ }
+
+ public void setCurrentContactGroup(MetaContactGroup metaGroup)
+ {
+
+ }
+
+ @Override
+ public void setCurrentContact(Contact contact)
+ {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/spellcheck/LanguageSelectionField.java b/src/net/java/sip/communicator/plugin/spellcheck/LanguageSelectionField.java
index 2986ed2..96ecb46 100644
--- a/src/net/java/sip/communicator/plugin/spellcheck/LanguageSelectionField.java
+++ b/src/net/java/sip/communicator/plugin/spellcheck/LanguageSelectionField.java
@@ -7,6 +7,7 @@ package net.java.sip.communicator.plugin.spellcheck;
import java.awt.*;
import java.awt.image.*;
+import java.awt.event.*;
import java.io.*;
import java.util.*;
@@ -15,6 +16,7 @@ import javax.swing.*;
import javax.swing.event.*;
import net.java.sip.communicator.plugin.spellcheck.Parameters.Default;
+import net.java.sip.communicator.plugin.spellcheck.Parameters.Locale;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.gui.Container;
@@ -64,6 +66,9 @@ public class LanguageSelectionField
private final ArrayList<Parameters.Locale> localeList =
new ArrayList<Parameters.Locale>();
+
+ private final SIPCommTextButton removeItem = new SIPCommTextButton(
+ Resources.getString("plugin.spellcheck.UNINSTALL_DICTIONARY"));
/**
* Provides instance of this class associated with a spell checker. If ones
@@ -108,7 +113,7 @@ public class LanguageSelectionField
this.menu.setOpaque(false);
this.setOpaque(false);
- DefaultListModel model = new DefaultListModel();
+ final DefaultListModel model = new DefaultListModel();
final JList list = new JList(model);
this.languageSelectionRenderer = new LanguageListRenderer();
@@ -122,10 +127,11 @@ public class LanguageSelectionField
spellChecker.isLocaleAvailable(locale));
}
- model.addElement(locale);
localeList.add(locale);
}
-
+
+ setModelElements(model);
+
JScrollPane scroll = new JScrollPane(list);
scroll.setBorder(null);
@@ -136,38 +142,123 @@ public class LanguageSelectionField
list.setSelectedIndex(localeList.indexOf(loc) + 1);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+
+ removeItem.setPreferredSize(new Dimension(30, 28));
+
+ list.addListSelectionListener(new LanguageListSelectionListener());
+
+ menu.add(scroll);
+
+ ImageIcon flagIcon =
+ getLocaleIcon(checker.getLocale(),
+ localeAvailabilityCache.get(checker.getLocale()));
+ SelectedObject selectedObject =
+ new SelectedObject(flagIcon, checker.getLocale());
+ menu.setSelected(selectedObject);
+
+ this.menu.addSeparator();
+
+ menu.add(removeItem);
- list.addListSelectionListener(new ListSelectionListener()
+ list.addKeyListener(new KeyListener()
{
+ long time = 0;
- public void valueChanged(ListSelectionEvent e)
+ String key = "";
+
+ @Override
+ public void keyTyped(KeyEvent e)
{
+ char ch = e.getKeyChar();
- if (!e.getValueIsAdjusting())
- {
- final JList source = (JList) e.getSource();
- final Parameters.Locale locale =
- (Parameters.Locale) source.getSelectedValue();
+ if (!Character.isLetter(ch))
+ return;
+
+ if (time + 1000 < System.currentTimeMillis())
+ key = "";
- source.setEnabled(false);
+ time = System.currentTimeMillis();
- // Indicate to the user that the language is currently
- // loading.
- locale.setLoading(true);
+ key += ch;
- new SetSpellChecker(locale, source).start();
+ for (int i = 0; i < model.getSize(); i++)
+ {
+ String label =
+ ((Parameters.Locale) model.getElementAt(i)).getLabel()
+ .toLowerCase();
+ if (label.startsWith(key.toLowerCase()))
+ {
+ list.setSelectedIndex(i);
+ list.ensureIndexIsVisible(i);
+ break;
+ }
}
+
+ list.requestFocusInWindow();
+
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e)
+ {
+
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e)
+ {
+
}
});
+
+ removeItem.setEnabled(!spellChecker.getLocale().getIsoCode()
+ .equals(Parameters.getDefault(Parameters.Default.LOCALE)));
+
+ removeItem.addActionListener(new ActionListener()
+ {
- menu.add(scroll);
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ list.setEnabled(false);
+ Locale locale = (Locale) menu.getSelectedObject();
- ImageIcon flagIcon =
- getLocaleIcon(checker.getLocale(),
- localeAvailabilityCache.get(checker.getLocale()));
- SelectedObject selectedObject =
- new SelectedObject(flagIcon, checker.getLocale());
- menu.setSelected(selectedObject);
+ localeAvailabilityCache.put(locale, false);
+
+ spellChecker.removeLocale(locale);
+
+ list.setEnabled(true);
+
+ ImageIcon flagIcon =
+ getLocaleIcon(spellChecker.getLocale(),
+ localeAvailabilityCache.get(spellChecker
+ .getLocale()));
+ SelectedObject selectedObject =
+ new SelectedObject(flagIcon, spellChecker.getLocale());
+ menu.setSelected(selectedObject);
+
+ }
+ catch (Exception ex)
+ {
+ PopupDialog dialog =
+ SpellCheckActivator.getUIService().getPopupDialog();
+
+ String message =
+ Resources
+ .getString("plugin.spellcheck.DICT_ERROR_DELETE")
+ + ex.getMessage();
+
+ dialog.showMessagePopupDialog(
+ message,
+ Resources
+ .getString("plugin.spellcheck.DICT_ERROR_DELETE_TITLE"),
+ PopupDialog.WARNING_MESSAGE);
+ ex.printStackTrace();
+ }
+ }
+ });
}
/**
@@ -354,11 +445,49 @@ public class LanguageSelectionField
public void stateChanged(ChangeEvent evt)
{
spellChecker.setEnabled(checkBox.isSelected());
+ SpellCheckActivator.getConfigService().setProperty(
+ "plugin.spellcheck.ENABLE", checkBox.isSelected());
}
});
return checkBox;
}
+
+ /**
+ * Set the elements for list model
+ *
+ * @param model the model whose elements are to be set
+ */
+ private void setModelElements(DefaultListModel model)
+ {
+ synchronized (model)
+ {
+
+
+ model.clear();
+
+ Collections.sort(localeList, new Comparator<Parameters.Locale>()
+ {
+
+ @Override
+ public int compare(Locale o1, Locale o2)
+ {
+ boolean b1 = spellChecker.isLocaleAvailable(o1);
+ boolean b2 = spellChecker.isLocaleAvailable(o2);
+
+ if (b1 == b2)
+ return 0;
+
+ return (b1 ? -1 : 1);
+ }
+
+ });
+
+ for (Parameters.Locale loc : localeList)
+ model.addElement(loc);
+
+ }
+ }
private class SetSpellChecker extends SwingWorker
{
@@ -418,6 +547,16 @@ public class LanguageSelectionField
// Indicate to the user that the language is currently
// loading.
locale.setLoading(false);
+
+ sourceList.removeListSelectionListener(sourceList
+ .getListSelectionListeners()[0]);
+ setModelElements((DefaultListModel) sourceList.getModel());
+ sourceList.setSelectedValue(locale, true);
+ removeItem.setEnabled(!spellChecker.getLocale().getIsoCode()
+ .equals(Parameters.getDefault(Parameters.Default.LOCALE)));
+ sourceList
+ .addListSelectionListener(new LanguageListSelectionListener());
+
}
/**
@@ -499,10 +638,35 @@ public class LanguageSelectionField
+ " <font color='gray'><i>loading...</i></font><html>");
else
setText(localeLabel);
-
+
setIcon(flagIcon);
-
+
return this;
}
}
+
+ private class LanguageListSelectionListener
+ implements ListSelectionListener
+ {
+ public void valueChanged(ListSelectionEvent e)
+ {
+ if (!e.getValueIsAdjusting())
+ {
+ final JList source = (JList) e.getSource();
+ final Parameters.Locale locale =
+ (Parameters.Locale) source.getSelectedValue();
+
+ source.setEnabled(false);
+
+ // Indicate to the user that the language is currently
+ // loading.
+ locale.setLoading(true);
+
+ new SetSpellChecker(locale, source).start();
+ source.requestFocusInWindow();
+ removeItem.setEnabled(false);
+
+ }
+ }
+ }
}
diff --git a/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java b/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java
index 24f253e..ee7460c 100644
--- a/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java
+++ b/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java
@@ -70,6 +70,9 @@ class SpellChecker
*/
synchronized void start(BundleContext bc) throws Exception
{
+ isEnabled = SpellCheckActivator.getConfigService()
+ .getBoolean("plugin.spellcheck.ENABLE", true);
+
FileAccessService faService =
SpellCheckActivator.getFileAccessService();
@@ -328,6 +331,34 @@ class SpellChecker
}
/**
+ * Removes the dictionary from the system, and sets the default locale
+ * dictionary as the current dictionary
+ *
+ * @param locale locale to be removed
+ */
+ void removeLocale(Parameters.Locale locale) throws Exception
+ {
+ synchronized (this.locale)
+ {
+ String path = locale.getDictUrl().getFile();
+
+ int filenameStart = path.lastIndexOf('/') + 1;
+ String filename = path.substring(filenameStart);
+
+ File dictLocation =
+ SpellCheckActivator.getFileAccessService()
+ .getPrivatePersistentFile(DICT_DIR + filename);
+
+ if (dictLocation.exists())
+ dictLocation.delete();
+
+ String localeIso = Parameters.getDefault(Parameters.Default.LOCALE);
+ Parameters.Locale loc = Parameters.getLocale(localeIso);
+ setLocale(loc);
+ }
+ }
+
+ /**
* Determines if locale's dictionary is locally available or not.
*
* @param locale locale to be checked