From: <cr...@us...> - 2008-10-05 02:26:28
|
Revision: 4604 http://jnode.svn.sourceforge.net/jnode/?rev=4604&view=rev Author: crawley Date: 2008-10-05 02:25:18 +0000 (Sun, 05 Oct 2008) Log Message: ----------- Changing the keyboard layout manager to get the initial keyboard layout ID to keyboard interpreter class mappings from a plugin extension. Modified Paths: -------------- trunk/core/descriptors/org.jnode.driver.input.l10n.xml trunk/core/descriptors/org.jnode.driver.input.xml trunk/core/src/driver/org/jnode/driver/input/KeyboardInputPlugin.java trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java trunk/core/src/driver/org/jnode/driver/input/KeyboardLayoutManager.java Modified: trunk/core/descriptors/org.jnode.driver.input.l10n.xml =================================================================== --- trunk/core/descriptors/org.jnode.driver.input.l10n.xml 2008-10-05 02:02:08 UTC (rev 4603) +++ trunk/core/descriptors/org.jnode.driver.input.l10n.xml 2008-10-05 02:25:18 UTC (rev 4604) @@ -16,5 +16,36 @@ <export name="org.jnode.driver.input.l10n.*"/> </library> </runtime> + + <extension point="org.jnode.driver.input.keyboard-layouts"> + <layout name="BE_fr" class="org.jnode.driver.input.l10n.KeyboardInterpreter_BE_fr"/> + <layout name="CH_fr" class="org.jnode.driver.input.l10n.KeyboardInterpreter_CH_fr"/> + <layout name="DE" class="org.jnode.driver.input.l10n.KeyboardInterpreter_DE"/> + <layout name="DE_de" class="org.jnode.driver.input.l10n.KeyboardInterpreter_DE"/> + <layout name="DK" class="org.jnode.driver.input.l10n.KeyboardInterpreter_DK"/> + <layout name="DK_dk" class="org.jnode.driver.input.l10n.KeyboardInterpreter_DK"/> + <layout name="ES" class="org.jnode.driver.input.l10n.KeyboardInterpreter_ES"/> + <layout name="ES_es" class="org.jnode.driver.input.l10n.KeyboardInterpreter_ES"/> + <layout name="FR" class="org.jnode.driver.input.l10n.KeyboardInterpreter_FR"/> + <layout name="FR_fr" class="org.jnode.driver.input.l10n.KeyboardInterpreter_FR"/> + <layout name="GB" class="org.jnode.driver.input.l10n.KeyboardInterpreter_GB_en"/> + <layout name="GB_en" class="org.jnode.driver.input.l10n.KeyboardInterpreter_GB_en"/> + <layout name="HU" class="org.jnode.driver.input.l10n.KeyboardInterpreter_HU"/> + <layout name="HU_hu" class="org.jnode.driver.input.l10n.KeyboardInterpreter_HU"/> + <layout name="HU_hu_101" class="org.jnode.driver.input.l10n.KeyboardInterpreter_HU"/> + <layout name="HU_101" class="org.jnode.driver.input.l10n.KeyboardInterpreter_HU"/> + <layout name="IT" class="org.jnode.driver.input.l10n.KeyboardInterpreter_IT"/> + <layout name="IT_it" class="org.jnode.driver.input.l10n.KeyboardInterpreter_IT"/> + <layout name="NO" class="org.jnode.driver.input.l10n.KeyboardInterpreter_NO"/> + <layout name="NO_no" class="org.jnode.driver.input.l10n.KeyboardInterpreter_NO"/> + <layout name="RU" class="org.jnode.driver.input.l10n.KeyboardInterpreter_RU"/> + <layout name="RU_ru" class="org.jnode.driver.input.l10n.KeyboardInterpreter_RU"/> + <layout name="SE" class="org.jnode.driver.input.l10n.KeyboardInterpreter_SE"/> + <layout name="SE_se" class="org.jnode.driver.input.l10n.KeyboardInterpreter_SE"/> + <layout name="US" class="org.jnode.driver.input.l10n.KeyboardInterpreter_US_en"/> + <layout name="US_en" class="org.jnode.driver.input.l10n.KeyboardInterpreter_US_en"/> + <layout name="DV" class="org.jnode.driver.input.l10n.KeyboardInterpreter_DV"/> <!-- deprecated --> + <layout name="US_en_dvorak" class="org.jnode.driver.input.l10n.KeyboardInterpreter_DV"/> + </extension> </plugin> Modified: trunk/core/descriptors/org.jnode.driver.input.xml =================================================================== --- trunk/core/descriptors/org.jnode.driver.input.xml 2008-10-05 02:02:08 UTC (rev 4603) +++ trunk/core/descriptors/org.jnode.driver.input.xml 2008-10-05 02:25:18 UTC (rev 4604) @@ -17,6 +17,8 @@ <export name="org.jnode.driver.input.*"/> </library> </runtime> + + <extension-point id="keyboard-layouts" name="Standard keyboard layout identifier mappings"/> <extension point="org.jnode.security.permissions"> <permission class="org.jnode.driver.DriverPermission" name="setPreferredListener"/> Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardInputPlugin.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/input/KeyboardInputPlugin.java 2008-10-05 02:02:08 UTC (rev 4603) +++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInputPlugin.java 2008-10-05 02:25:18 UTC (rev 4604) @@ -1,3 +1,23 @@ +/* + * $Id: TextScreenConsolePlugin.java 4556 2008-09-13 08:02:20Z crawley $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ package org.jnode.driver.input; import javax.naming.NamingException; @@ -7,6 +27,12 @@ import org.jnode.plugin.PluginDescriptor; import org.jnode.plugin.PluginException; +/** + * The keyboard input plugin defines an extension point that is used to + * register keyboard interpreters, and hosts the keyboard layout manager. + * + * @author cr...@jn... + */ public class KeyboardInputPlugin extends Plugin { private KeyboardLayoutManager mgr; @@ -18,9 +44,9 @@ @Override protected void startPlugin() throws PluginException { try { - mgr = new KeyboardLayoutManager(); + mgr = new KeyboardLayoutManager( + getDescriptor().getExtensionPoint("keyboard-layouts")); InitialNaming.bind(KeyboardLayoutManager.NAME, mgr); - // TODO Load the initial layout mappings from the plugin descriptor. } catch (NamingException ex) { throw new PluginException(ex); } Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2008-10-05 02:02:08 UTC (rev 4603) +++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2008-10-05 02:25:18 UTC (rev 4604) @@ -31,9 +31,19 @@ */ public interface KeyboardInterpreter { + /** + * A factory API for keyboard interpreters + */ public interface Factory { - // Create a new interpreter instance. + /** + * Create a new interpreter instance. + */ public KeyboardInterpreter create() throws KeyboardInterpreterException; + + /** + * Provide a short description for the layout. + */ + public String describe(); } public static final int XT_RELEASE = 0x80; Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardLayoutManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/input/KeyboardLayoutManager.java 2008-10-05 02:02:08 UTC (rev 4603) +++ trunk/core/src/driver/org/jnode/driver/input/KeyboardLayoutManager.java 2008-10-05 02:25:18 UTC (rev 4604) @@ -1,10 +1,38 @@ +/* + * $Id: TextScreenConsolePlugin.java 4556 2008-09-13 08:02:20Z crawley $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ package org.jnode.driver.input; +import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.Locale; import java.util.ResourceBundle; +import java.util.TreeSet; import org.apache.log4j.Logger; +import org.apache.log4j.Priority; +import org.jnode.plugin.ConfigurationElement; +import org.jnode.plugin.Extension; +import org.jnode.plugin.ExtensionPoint; +import org.jnode.plugin.ExtensionPointListener; /** * The KeyboardManager provides methods for creating KeyboardInterpreter objects, and managing @@ -13,7 +41,7 @@ * @author Marc DENTY * @author cr...@jn... */ -public class KeyboardLayoutManager { +public class KeyboardLayoutManager implements ExtensionPointListener { private final Logger log = Logger.getLogger(KeyboardLayoutManager.class); @@ -21,14 +49,27 @@ * The name used to bind this manager in the InitialNaming namespace. */ public static Class<KeyboardLayoutManager> NAME = KeyboardLayoutManager.class; + + public static final String EP_NAME = "org.jnode.driver.input.keyboard-layouts"; - private HashMap<String, KeyboardInterpreter.Factory> map = + private final HashMap<String, KeyboardInterpreter.Factory> map = new HashMap<String, KeyboardInterpreter.Factory>(); + + private final ExtensionPoint keyboardLayoutEP; + + public KeyboardLayoutManager(ExtensionPoint keyboardLayoutEP) { + this.keyboardLayoutEP = keyboardLayoutEP; + keyboardLayoutEP.addListener(this); + for (Extension extension : keyboardLayoutEP.getExtensions()) { + addLayoutsToMap(extension); + } + } + /** * Load the default keyboard layout as specified in the 'org.jnode.driver.input.KeyboardLayout' * resource bundle. If none is specified or the specified layout cannot be used, we use the - * 'US_en' layout as a fallback. + * 'US_en' layout as a fall-back. * * @return a valid KeyboardInterpreter * @throws KeyboardInterpreterException @@ -59,7 +100,7 @@ "' keyboard interpreter", ex); } } - // Use the US_en keyboard layout as a fallback if there was no resource bundle, no + // Use the US_en keyboard layout as a fall-back if there was no resource bundle, no // usable default keyboard layout or the specified default layout had no interpreter. log.error("Trying the 'US_en' keyboard interpreter as a fallback"); try { @@ -171,22 +212,96 @@ * @param name the keyboard layout identifier. * @param factory the factory to be registered. */ - public synchronized void registerKeyboardLayout( - String name, KeyboardInterpreter.Factory factory) { + public synchronized void add(String name, KeyboardInterpreter.Factory factory) { map.put(name, factory); } /** - * Register a keyboard interpreter class. The class is + * Register a keyboard interpreter class. The classname will be wrapped in + * a new KeyboardInterpreter.Factory. * * @param name the keyboard layout identifier. - * @param factory the name of the class to be registered. + * @param className the name of the class to be registered. */ - public void registerKeyboardLayout(String name, String className) { - registerKeyboardLayout(name, new KIClassWrapper(className)); + public void add(String name, String className) { + add(name, new KIClassWrapper(className)); } /** + * Remove the keyboard interpreter factory for a given layout identifier. + * @param name keyboard layout identifier. + * @return the factory removed or <code>null</node> + */ + public synchronized KeyboardInterpreter.Factory remove(String name) { + return map.remove(name); + } + + /** + * Gets a collection of all layout identifiers known to this manager. + */ + public synchronized Collection<String> layouts() { + return new TreeSet<String>(map.keySet()); + } + + /** + * Gets an iterator for the layout identifiers known to this manager. + * + * @return An iterator the returns instances of String. + */ + public Iterator<String> layoutIterator() { + return layouts().iterator(); + } + + /** + * Add all keyboard layouts in the extension data to the map. + */ + @Override + public void extensionAdded(ExtensionPoint point, Extension extension) { + if (point.equals(keyboardLayoutEP)) { + addLayoutsToMap(extension); + } + } + + /** + * Remove from the map any keyboard layouts that are identical to the extension data. + */ + @Override + public void extensionRemoved(ExtensionPoint point, Extension extension) { + if (point.equals(keyboardLayoutEP)) { + removeLayoutsFromMap(extension); + } + } + + private synchronized void addLayoutsToMap(Extension extension) { + for (ConfigurationElement element : extension.getConfigurationElements()) { + if (element.getName().equals("layout")) { + String name = element.getAttribute("name"); + String className = element.getAttribute("class"); + if (name != null && className != null) { + add(name, className); + } + } + } + } + + private synchronized void removeLayoutsFromMap(Extension extension) { + for (ConfigurationElement element : extension.getConfigurationElements()) { + if (element.getName().equals("layout")) { + String name = element.getAttribute("name"); + String className = element.getAttribute("class"); + if (name == null || className == null) { + continue; + } + KeyboardInterpreter.Factory factory = map.get(name); + if (factory != null && (factory instanceof KIClassWrapper) && + ((KIClassWrapper) factory).className.equals(className)) { + map.remove(name); + } + } + } + } + + /** * This wrapper class allows us to treat a class name as a keyboard interpreter * factory. */ @@ -228,5 +343,10 @@ className, ex); } } + + @Override + public String describe() { + return className; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |