cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r411842 - in /incubator/cayenne/main/branches/PROTO-3.0/swing-plugin: ./ src/main/java/org/apache/cayenne/swing/plugin/ src/main/java/org/apache/cayenne/swing/plugin/frame/
Date Mon, 05 Jun 2006 16:10:50 GMT
Author: aadamchik
Date: Mon Jun  5 09:10:50 2006
New Revision: 411842

URL: http://svn.apache.org/viewvc?rev=411842&view=rev
Log:
added frame localization

Modified:
    incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/pom.xml
    incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/CayennePluginEngine.java
    incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/Launcher.java
    incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameController.java
    incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameMenuBuilder.java

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/pom.xml?rev=411842&r1=411841&r2=411842&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/pom.xml (original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/pom.xml Mon Jun  5 09:10:50 2006
@@ -23,9 +23,9 @@
 			<scope>provided</scope>
 		</dependency>
 		<dependency>
-			<groupId>org.apache.cayenne</groupId>
-			<artifactId>cayenne-modeler-launcher</artifactId>
-			<version>3.0-SNAPSHOT</version>
+			<groupId>org.objectstyle.cayenne</groupId>
+			<artifactId>cayenne-modeler</artifactId>
+			<version>1.2-SNAPSHOT</version>
 			<scope>provided</scope>
 		</dependency>
   </dependencies>

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/CayennePluginEngine.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/CayennePluginEngine.java?rev=411842&r1=411841&r2=411842&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/CayennePluginEngine.java
(original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/CayennePluginEngine.java
Mon Jun  5 09:10:50 2006
@@ -27,82 +27,83 @@
 import org.platonos.pluginengine.logging.LoggerLevel;
 
 /**
- * An extension of PluginEngine that allows to store arbitrary attributes in the
- * engine and also load plugins from CLASSPATH.
+ * An extension of PluginEngine that allows to store arbitrary attributes in the engine
+ * and also load plugins from CLASSPATH.
  * 
  * @author andrus
  */
 public class CayennePluginEngine extends PluginEngine {
 
-	public static final String PLUGIN_LOCATION = "plugin.xml";
+    public static final String PLUGIN_LOCATION = "plugin.xml";
 
-	protected Map attributes = new HashMap();
+    protected Map attributes = new HashMap();
 
-	public CayennePluginEngine(String uid, ILogger logger) {
-		super(uid, logger);
-	}
-
-	public CayennePluginEngine(String uid) {
-		super(uid);
-	}
-
-	/**
-	 * Loads all plugin descriptors that are available to the current
-	 * ClassLoader.
-	 */
-	public void loadBundledPlugins() {
-		Enumeration urls;
-
-		try {
-			urls = Thread.currentThread().getContextClassLoader().getResources(
-					PLUGIN_LOCATION);
-
-		} catch (IOException e) {
-			throw new RuntimeException(
-					"Error reading plugins infor from ClassLoader", e);
-		}
-
-		while (urls.hasMoreElements()) {
-			URL pluginURL = (URL) urls.nextElement();
-			try {
-				// TODO, andrus, 6/5/2006 - plugins loaded in this fashion will
-				// only be able to resolve classes from the same filesystem
-				// folder as plugin.xml. Will need a specialized ClassLoader for
-				// this case.
-				loadPluginXML(pluginURL);
-			} catch (PluginEngineException ex) {
-				getLogger().log(LoggerLevel.SEVERE,
-						"Error loading Plugin archive from URL: " + pluginURL,
-						ex);
-			}
-		}
-	}
-
-	/**
-	 * Returns a previously stored attribute for a given key or null if no
-	 * attribute matches the key.
-	 */
-	public Object getAttribute(String key) {
-		if (key == null) {
-			throw new NullPointerException("Invalid argument: key");
-		}
-
-		return (String) attributes.get(key);
-	}
-
-	public void setAttribute(String key, Object value) {
-		if (key == null) {
-			throw new NullPointerException("Invalid argument: key");
-		}
-
-		attributes.put(key, value);
-	}
-
-	public void removeAttribute(String key) {
-		if (key == null) {
-			throw new NullPointerException("Invalid argument: key");
-		}
+    public CayennePluginEngine(String uid, ILogger logger) {
+        super(uid, logger);
+    }
+
+    public CayennePluginEngine(String uid) {
+        super(uid);
+    }
+
+    /**
+     * Loads all plugin descriptors that are available to the current ClassLoader.
+     */
+    public void loadBundledPlugins() {
+        Enumeration urls;
+
+        try {
+            urls = Thread.currentThread().getContextClassLoader().getResources(
+                    PLUGIN_LOCATION);
+
+        }
+        catch (IOException e) {
+            throw new RuntimeException("Error reading plugins infor from ClassLoader", e);
+        }
+
+        while (urls.hasMoreElements()) {
+            URL pluginURL = (URL) urls.nextElement();
+            try {
+                // TODO, andrus, 6/5/2006 - plugins loaded in this fashion will
+                // only be able to resolve classes from the same filesystem
+                // folder as plugin.xml. Will need a specialized ClassLoader for
+                // this case.
+                loadPluginXML(pluginURL);
+            }
+            catch (PluginEngineException ex) {
+                getLogger().log(
+                        LoggerLevel.SEVERE,
+                        "Error loading Plugin archive from URL: " + pluginURL,
+                        ex);
+            }
+        }
+    }
+
+    /**
+     * Returns a previously stored attribute for a given key or null if no attribute
+     * matches the key.
+     */
+    public Object getAttribute(String key) {
+        if (key == null) {
+            throw new NullPointerException("Invalid argument: key");
+        }
+
+        return (String) attributes.get(key);
+    }
+
+    public void setAttribute(String key, Object value) {
+        if (key == null) {
+            throw new NullPointerException("Invalid argument: key");
+        }
+
+        attributes.put(key, value);
+    }
+
+    public void removeAttribute(String key) {
+        if (key == null) {
+            throw new NullPointerException("Invalid argument: key");
+        }
 
-		attributes.remove(key);
-	}
+        attributes.remove(key);
+    }
 }

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/Launcher.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/Launcher.java?rev=411842&r1=411841&r2=411842&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/Launcher.java
(original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/Launcher.java
Mon Jun  5 09:10:50 2006
@@ -16,6 +16,7 @@
 package org.apache.cayenne.swing.plugin;
 
 import java.util.Iterator;
+import java.util.Locale;
 import java.util.StringTokenizer;
 
 import org.platonos.pluginengine.Plugin;
@@ -26,53 +27,83 @@
  */
 public class Launcher {
 
-	public static final String COMMAND_LINE_ATTRIBUTE = "command.line";
+    public static final String COMMAND_LINE_ATTRIBUTE = "command.line";
 
-	static final String ENGINE_NAME = "Cayenne Plugin Engine";
+    static final String ENGINE_NAME = "Cayenne Plugin Engine";
 
-	/**
-	 * A property specifying a location of the plugins directory. It can be a
-	 * comma separated list of directories. If not set, current directory is
-	 * used.
-	 */
-	public static final String PLUGINS_DIR_PROPERTY = "plugins.dirs";
-
-	public static void main(String[] args) {
-
-		CayennePluginEngine pluginEngine = new CayennePluginEngine(ENGINE_NAME);
-		pluginEngine.setAttribute(COMMAND_LINE_ATTRIBUTE, args);
-
-		// load plugins from ClassPath
-		pluginEngine.loadBundledPlugins();
-
-		// load plugins from extra directories
-		String pluginDirectories = System.getProperty(PLUGINS_DIR_PROPERTY);
-		if (pluginDirectories != null) {
-			StringTokenizer toks = new StringTokenizer(pluginDirectories, ",");
-			while (toks.hasMoreTokens()) {
-				pluginEngine.loadPlugins(toks.nextToken());
-			}
-		}
-
-		pluginEngine.start();
-
-		boolean hasStartedPlugins = false;
-		Iterator it = pluginEngine.getPlugins().iterator();
-		while (it.hasNext()) {
-			Plugin p = (Plugin) it.next();
-			if (p.isStarted()) {
-				hasStartedPlugins = true;
-				break;
-			}
-		}
-
-		// either no plugins configured, all all of them failed to start.
-		if (!hasStartedPlugins) {
-			pluginEngine.getLogger().log(LoggerLevel.INFO,
-					"No plugins started, exiting", null);
-			
-			// must explicitly kill all UI threads
-			System.exit(0);
-		}
-	}
+    /**
+     * A property specifying a location of the plugins directory. It can be a comma
+     * separated list of directories. If not set, current directory is used.
+     */
+    public static final String PLUGINS_DIR_PROPERTY = "cayenne.plugins.dirs";
+
+    public static final String LOCALE_PROPERTY = "cayenne.ui.locale";
+
+    public static void main(String[] args) {
+
+        CayennePluginEngine pluginEngine = new CayennePluginEngine(ENGINE_NAME);
+        pluginEngine.setAttribute(COMMAND_LINE_ATTRIBUTE, args);
+
+        // set default locale
+        String locale = System.getProperty(LOCALE_PROPERTY);
+        if (locale != null) {
+
+            StringTokenizer toks = new StringTokenizer(locale, "_");
+
+            if (toks.hasMoreTokens()) {
+                // note that default local parts must be empty strings, not nulls...
+                String language = "";
+                String country = "";
+                String variant = "";
+
+                language = toks.nextToken();
+
+                if (toks.hasMoreTokens()) {
+                    country = toks.nextToken();
+
+                    if (toks.hasMoreTokens()) {
+                        variant = toks.nextToken();
+                    }
+                }
+
+                Locale.setDefault(new Locale(language, country, variant));
+            }
+
+        }
+
+        // load plugins from ClassPath
+        pluginEngine.loadBundledPlugins();
+
+        // load plugins from extra directories
+        String pluginDirectories = System.getProperty(PLUGINS_DIR_PROPERTY);
+        if (pluginDirectories != null) {
+            StringTokenizer toks = new StringTokenizer(pluginDirectories, ",");
+            while (toks.hasMoreTokens()) {
+                pluginEngine.loadPlugins(toks.nextToken());
+            }
+        }
+
+        pluginEngine.start();
+
+        boolean hasStartedPlugins = false;
+        Iterator it = pluginEngine.getPlugins().iterator();
+        while (it.hasNext()) {
+            Plugin p = (Plugin) it.next();
+            if (p.isStarted()) {
+                hasStartedPlugins = true;
+                break;
+            }
+        }
+
+        // either no plugins configured, all all of them failed to start.
+        if (!hasStartedPlugins) {
+            pluginEngine.getLogger().log(
+                    LoggerLevel.INFO,
+                    "No plugins started, exiting",
+                    null);
+
+            // must explicitly kill all UI threads
+            System.exit(0);
+        }
+    }
 }

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameController.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameController.java?rev=411842&r1=411841&r2=411842&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameController.java
(original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameController.java
Mon Jun  5 09:10:50 2006
@@ -32,7 +32,6 @@
 
 public class FrameController extends CayenneController {
 
-    protected String name;
     protected JFrame frame;
     protected FramePlugin framePlugin;
     protected ObjectBinding boundsBinding;
@@ -80,12 +79,8 @@
      */
     public void startup() {
 
-        if (name == null) {
-            name = framePlugin.getPlugin().getName();
-        }
-
         if (frame.getTitle() == null || frame.getTitle().trim().length() == 0) {
-            frame.setTitle(name);
+            frame.setTitle(framePlugin.getPlugin().getName());
         }
 
         // make closeable frame
@@ -124,14 +119,6 @@
         System.exit(0);
     }
 
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
     public Rectangle getBounds() {
         Preferences prefs = getPreferences();
 
@@ -155,7 +142,7 @@
     }
 
     protected Preferences getPreferences() {
-        return Preferences.userNodeForPackage(getClass()).node(name);
+        return Preferences.userNodeForPackage(getClass()).node(frame.getTitle());
     }
 
     public int getNewFrameOffset() {

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameMenuBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameMenuBuilder.java?rev=411842&r1=411841&r2=411842&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameMenuBuilder.java
(original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameMenuBuilder.java
Mon Jun  5 09:10:50 2006
@@ -20,6 +20,7 @@
 import java.util.List;
 
 import javax.swing.Action;
+import javax.swing.JComponent;
 import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
@@ -66,33 +67,41 @@
         List children = XMLUtil.getChildren(doc.getDocumentElement(), "menu");
         Iterator it = children.iterator();
         while (it.hasNext()) {
-            menu.add(processMenu((Element) it.next()));
+            menu.add(processMenu(plugin, (Element) it.next(), 1));
         }
-
     }
 
     /**
      * Recursively loads menus from the DOM tree.
      */
-    protected JMenuItem processMenu(Element menuXML) {
+    protected JComponent processMenu(Plugin plugin, Element menuXML, int depth) {
 
         List children = XMLUtil.getChildren(menuXML, "menu");
 
         Action action = framePlugin.getActionMap().get(menuXML.getAttribute("action"));
         String key = menuXML.getAttribute("name");
 
-        JMenuItem menu = (children.isEmpty()) ? new JMenuItem() : new JMenu();
+        JMenuItem menu = (children.isEmpty() && depth > 1)
+                ? new JMenuItem()
+                : new JMenu();
 
         if (action != null) {
             menu.setAction(action);
         }
         else if (key != null) {
-            menu.setText(key);
+            menu.setText(plugin.replaceToken(key));
         }
 
+        depth++;
         Iterator it = children.iterator();
         while (it.hasNext()) {
-            menu.add(processMenu((Element) it.next()));
+            JComponent component = processMenu(plugin, (Element) it.next(), depth);
+            menu.add(component);
+        }
+
+        // disable empty menus
+        if (children.isEmpty() && action == null) {
+            menu.setEnabled(false);
         }
 
         return menu;



Mime
View raw message