cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r412051 - in /incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java: ./ org/apache/cayenne/swing/plugin/frame/
Date Tue, 06 Jun 2006 09:13:26 GMT
Author: aadamchik
Date: Tue Jun  6 02:13:25 2006
New Revision: 412051

URL: http://svn.apache.org/viewvc?rev=412051&view=rev
Log:
added support for toolbars and late assembl

Modified:
    incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameBuilder.java
    incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameBuilderExtension.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/FramePlugin.java
    incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin.properties
    incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin_ru.properties

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameBuilder.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/FrameBuilder.java?rev=412051&r1=412050&r2=412051&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameBuilder.java
(original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameBuilder.java
Tue Jun  6 02:13:25 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.cayenne.swing.plugin.frame;
 
+import java.awt.FlowLayout;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.io.InputStream;
@@ -23,11 +24,14 @@
 
 import javax.swing.AbstractAction;
 import javax.swing.Action;
+import javax.swing.ActionMap;
+import javax.swing.ImageIcon;
 import javax.swing.JComponent;
-import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JToolBar;
 import javax.swing.KeyStroke;
 
 import org.apache.cayenne.swing.CayenneSwingException;
@@ -40,9 +44,47 @@
 public class FrameBuilder {
 
     protected FramePlugin framePlugin;
+    protected ActionMap actionMap;
+    protected JPanel toolbarsPanel;
+    protected JMenuBar menuBar;
 
     public FrameBuilder(FramePlugin framePlugin) {
         this.framePlugin = framePlugin;
+        this.actionMap = new ActionMap();
+        this.toolbarsPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
+        this.menuBar = new JMenuBar();
+    }
+
+    public ActionMap getActionMap() {
+        return actionMap;
+    }
+
+    public FramePlugin getFramePlugin() {
+        return framePlugin;
+    }
+
+    public JMenuBar getMenuBar() {
+        return menuBar;
+    }
+
+    public JPanel getToolbarsPanel() {
+        return toolbarsPanel;
+    }
+
+    public void setActionMap(ActionMap actionMap) {
+        this.actionMap = actionMap;
+    }
+
+    public void setFramePlugin(FramePlugin framePlugin) {
+        this.framePlugin = framePlugin;
+    }
+
+    public void setMenuBar(JMenuBar menuBar) {
+        this.menuBar = menuBar;
+    }
+
+    public void setToolbarsPanel(JPanel toolbarsPanel) {
+        this.toolbarsPanel = toolbarsPanel;
     }
 
     public void addActions(Plugin plugin, String xmlPath) {
@@ -130,7 +172,16 @@
                 + Action.LONG_DESCRIPTION
                 + "$$"));
 
-        framePlugin.getActionMap().put(key, action);
+        String iconPath = plugin
+                .replaceToken("$$" + key + '.' + Action.SMALL_ICON + "$$");
+
+        if (!Util.isEmptyString(iconPath) && !iconPath.startsWith("$$")) {
+            action.putValue(Action.SMALL_ICON, new ImageIcon(plugin
+                    .getPluginClassLoader()
+                    .getResource(iconPath)));
+        }
+
+        actionMap.put(key, action);
     }
 
     protected KeyStroke processAcceleratorKey(Element acceleratorXML) {
@@ -154,17 +205,75 @@
     }
 
     /**
-     * Adds a menu contributed by plugin.
+     * Adds toolbars contributed by plugin.
      */
-    public void addMenus(Plugin plugin, String xmlPath) {
-        JFrame frame = framePlugin.getFrameController().getFrame();
+    public void addToolbars(Plugin plugin, String xmlPath) {
+
+        InputStream toolbarXML = plugin.getPluginClassLoader().getResourceAsStream(
+                xmlPath);
+        if (toolbarXML == null) {
+            throw new CayenneSwingException("No toolbar XML file found at " + xmlPath);
+        }
 
-        JMenuBar menu = frame.getJMenuBar();
-        if (menu == null) {
-            menu = new JMenuBar();
-            frame.setJMenuBar(menu);
+        Document doc;
+        try {
+            doc = XMLUtil.newBuilder().parse(toolbarXML);
+        }
+        catch (Exception e) {
+            throw new CayenneSwingException(
+                    "Error parsing toolbar XML '" + xmlPath + "'",
+                    e);
         }
 
+        List children = XMLUtil.getChildren(doc.getDocumentElement(), "toolbar");
+        Iterator it = children.iterator();
+        while (it.hasNext()) {
+            JToolBar child = processToolbar(plugin, (Element) it.next());
+            if (child != null) {
+                getToolbarsPanel().add(child);
+            }
+        }
+    }
+
+    protected JToolBar processToolbar(Plugin plugin, Element toolbarXML) {
+
+        List children = XMLUtil.getChildren(toolbarXML, "button");
+        if (children.isEmpty()) {
+            return null;
+        }
+
+        JToolBar toolbar = new JToolBar();
+        Iterator it = children.iterator();
+        while (it.hasNext()) {
+            Element buttonXML = (Element) it.next();
+
+            if ("true".equalsIgnoreCase(buttonXML.getAttribute("separator"))) {
+                toolbar.addSeparator();
+            }
+            else {
+                Action action = actionMap.get(buttonXML.getAttribute("action"));
+
+                if (action != null) {
+                    toolbar.add(action);
+                }
+                else {
+                    plugin.getPluginEngine().getLogger().log(
+                            LoggerLevel.WARNING,
+                            "Invalid button: " + buttonXML,
+                            null);
+                }
+
+            }
+        }
+
+        return toolbar;
+    }
+
+    /**
+     * Adds menus contributed by plugin.
+     */
+    public void addMenus(Plugin plugin, String xmlPath) {
+
         InputStream menuXML = plugin.getPluginClassLoader().getResourceAsStream(xmlPath);
         if (menuXML == null) {
             throw new CayenneSwingException("No menu XML file found at " + xmlPath);
@@ -183,7 +292,7 @@
         while (it.hasNext()) {
             JComponent child = processMenu(plugin, (Element) it.next(), 1);
             if (child != null) {
-                menu.add(child);
+                menuBar.add(child);
             }
         }
     }
@@ -199,7 +308,7 @@
 
         List children = XMLUtil.getChildren(menuXML, "menu");
 
-        Action action = framePlugin.getActionMap().get(menuXML.getAttribute("action"));
+        Action action = actionMap.get(menuXML.getAttribute("action"));
         String key = menuXML.getAttribute("name");
 
         JMenuItem menu = (children.isEmpty() && depth > 1)

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameBuilderExtension.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/FrameBuilderExtension.java?rev=412051&r1=412050&r2=412051&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameBuilderExtension.java
(original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FrameBuilderExtension.java
Tue Jun  6 02:13:25 2006
@@ -17,9 +17,11 @@
 
 public interface FrameBuilderExtension {
 
-    void initActions(FramePlugin plugin);
+    void initFrame(FramePlugin plugin);
 
-    void initMenus(FramePlugin plugin);
+    void initActions(FrameBuilder builder);
 
-    void initFrame(FramePlugin plugin);
+    void initMenus(FrameBuilder builder);
+
+    void initToolbars(FrameBuilder builder);
 }

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=412051&r1=412050&r2=412051&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
Tue Jun  6 02:13:25 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.cayenne.swing.plugin.frame;
 
+import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
@@ -60,6 +61,18 @@
      */
     public void startup() {
 
+        FrameBuilder builder = framePlugin.getFrameBuilder();
+        if (builder.getMenuBar() != null) {
+            frame.setJMenuBar(builder.getMenuBar());
+        }
+
+        if (builder.getToolbarsPanel() != null
+                && builder.getToolbarsPanel().getComponents().length > 0) {
+            frame.getContentPane().add(
+                    builder.getToolbarsPanel(),
+                    BorderLayout.PAGE_START);
+        }
+
         if (frame.getTitle() == null || frame.getTitle().trim().length() == 0) {
             frame.setTitle(framePlugin.getPlugin().getName());
         }
@@ -68,8 +81,11 @@
         frame.addWindowListener(new WindowAdapter() {
 
             public void windowClosing(WindowEvent e) {
-                framePlugin.getActionMap().get(FramePlugin.QUIT_ACTION).actionPerformed(
-                        new ActionEvent(this, 1, null));
+                framePlugin
+                        .getFrameBuilder()
+                        .getActionMap()
+                        .get(FramePlugin.QUIT_ACTION)
+                        .actionPerformed(new ActionEvent(this, 1, null));
             }
         });
 

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FramePlugin.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/FramePlugin.java?rev=412051&r1=412050&r2=412051&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FramePlugin.java
(original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/org/apache/cayenne/swing/plugin/frame/FramePlugin.java
Tue Jun  6 02:13:25 2006
@@ -18,13 +18,11 @@
 import java.util.Iterator;
 import java.util.List;
 
-import javax.swing.ActionMap;
-
 import org.platonos.pluginengine.Extension;
 import org.platonos.pluginengine.PluginLifecycle;
 
 /**
- * A plugin that starts an empty closeable frame intended for customization by extension.
+ * A plugin that starts an empty closeable frame intended for customization by extensions.
  * 
  * @author Andrus Adamchik
  */
@@ -36,18 +34,17 @@
 
     protected FrameBuilder frameBuilder;
     protected FrameController frameController;
-    protected ActionMap actionMap;
 
     protected void start() {
 
         frameBuilder = new FrameBuilder(this);
         frameController = new FrameController(this);
-        actionMap = new ActionMap();
 
         List extensions = getExtensionPoint(FRAME_BUILDERS_EXT).getExtensions();
 
         initActions(extensions);
         initMenus(extensions);
+        initToolbars(extensions);
         initFrame(extensions);
 
         frameController.startup();
@@ -64,7 +61,7 @@
             FrameBuilderExtension ext = (FrameBuilderExtension) extension
                     .getExtensionInstance();
 
-            ext.initActions(this);
+            ext.initActions(frameBuilder);
         }
     }
 
@@ -76,11 +73,11 @@
             FrameBuilderExtension ext = (FrameBuilderExtension) extension
                     .getExtensionInstance();
 
-            ext.initMenus(this);
+            ext.initMenus(frameBuilder);
         }
     }
 
-    protected void initFrame(List extensions) {
+    protected void initToolbars(List extensions) {
 
         Iterator it = extensions.iterator();
         while (it.hasNext()) {
@@ -88,16 +85,20 @@
             FrameBuilderExtension ext = (FrameBuilderExtension) extension
                     .getExtensionInstance();
 
-            ext.initFrame(this);
+            ext.initToolbars(frameBuilder);
         }
     }
 
-    public ActionMap getActionMap() {
-        return actionMap;
-    }
+    protected void initFrame(List extensions) {
 
-    public void setActionMap(ActionMap actionMap) {
-        this.actionMap = actionMap;
+        Iterator it = extensions.iterator();
+        while (it.hasNext()) {
+            Extension extension = (Extension) it.next();
+            FrameBuilderExtension ext = (FrameBuilderExtension) extension
+                    .getExtensionInstance();
+
+            ext.initFrame(this);
+        }
     }
 
     public FrameController getFrameController() {

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin.properties
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin.properties?rev=412051&r1=412050&r2=412051&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin.properties
(original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin.properties
Tue Jun  6 02:13:25 2006
@@ -1,2 +1,5 @@
 
-action.quit.name = Quit
+action.quit.longdescription  = Close open project and quit the application
+action.quit.name             = Quit
+action.quit.shortdescription = Close open project and quit the application
+action.quit.smallicon        = 

Modified: incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin_ru.properties
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin_ru.properties?rev=412051&r1=412050&r2=412051&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin_ru.properties
(original)
+++ incubator/cayenne/main/branches/PROTO-3.0/swing-plugin/src/main/java/plugin_ru.properties
Tue Jun  6 02:13:25 2006
@@ -1,2 +1,5 @@
 
-action.quit.name = \u0412\u044B\u0445\u043E\u0434
+action.quit.longdescription  = \u0417\u0430\u043A\u0440\u044B\u0442\u044C \u0442\u0435\u043A\u0443\u0449\u0438\u0439
\u043F\u0440\u043E\u0435\u043A\u0442 \u0438 \u0432\u044B\u0439\u0442\u0438 \u0438\u0437 \u043F\u0440\u043E\u0433\u0440\u0430\u043C\u043C\u044B
+action.quit.name             = \u0412\u044B\u0445\u043E\u0434
+action.quit.shortdescription = \u0417\u0430\u043A\u0440\u044B\u0442\u044C \u0442\u0435\u043A\u0443\u0449\u0438\u0439
\u043F\u0440\u043E\u0435\u043A\u0442 \u0438 \u0432\u044B\u0439\u0442\u0438 \u0438\u0437 \u043F\u0440\u043E\u0433\u0440\u0430\u043C\u043C\u044B
+action.quit.smallicon        = 



Mime
View raw message