001: //WebOnSwing - Web Application Framework
002: //Copyright (C) 2003 Fernando Damian Petrola
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: package net.ar.webonswing.swing.layouts;
019:
020: import java.awt.*;
021: import java.io.*;
022:
023: import javax.swing.*;
024:
025: import net.ar.webonswing.*;
026: import net.ar.webonswing.render.templates.*;
027:
028: /**
029: * Este LayoutManager propaga el contenido de una plantilla tipo "menu" a todos los subcomponentes de un JMenuBar.
030: * Va recorriendo recursivamente todos los subcomponentes y segun el tipo de elemento de menu que sea le
031: * copia la subplantilla correspondiente extraida del template proporcionado en la construccion.
032: *
033: * @author Fernando Damian Petrola
034: */
035: public class PropagateMenuTemplateLayout implements LayoutManager,
036: Serializable {
037: protected KeyPositionTemplate theTemplate;
038:
039: public PropagateMenuTemplateLayout(KeyPositionTemplate aTemplate) {
040: theTemplate = aTemplate;
041: }
042:
043: public void addLayoutComponent(String name, Component comp) {
044: }
045:
046: public void removeLayoutComponent(Component comp) {
047: }
048:
049: public Dimension preferredLayoutSize(Container parent) {
050: return null;
051: }
052:
053: public Dimension minimumLayoutSize(Container parent) {
054: return null;
055: }
056:
057: public void layoutContainer(Container parent) {
058: JMenuBar theMenuBar = (JMenuBar) parent;
059: theMenuBar
060: .setLayout(new TemplateLayout(WosFramework
061: .getInstance().getTemplateManager()
062: .getKeyPositionTemplateForSubTemplate(
063: theTemplate, "")));
064:
065: Component[] theMenus = theMenuBar.getComponents();
066: for (int i = 0; i < theMenus.length; i++)
067: propagateToMenu((JMenu) theMenus[i]);
068: }
069:
070: private void propagateToMenu(JMenu aMenu) {
071: aMenu.setLayout(new TemplateLayout(WosFramework.getInstance()
072: .getTemplateManager()
073: .getKeyPositionTemplateForSubTemplate(theTemplate,
074: "theItems")));
075: propagateToPopupMenu(aMenu.getPopupMenu());
076: }
077:
078: private void propagateToPopupMenu(JPopupMenu aPopupMenu) {
079: aPopupMenu.setLayout(new TemplateLayout(WosFramework
080: .getInstance().getTemplateManager()
081: .getKeyPositionTemplateForSubTemplate(theTemplate,
082: "theItems.JPopupMenu")));
083:
084: Component[] theMenuItems = aPopupMenu.getComponents();
085: for (int i = 0; i < theMenuItems.length; i++)
086: propagateToMenuItem((JComponent) theMenuItems[i]);
087: }
088:
089: private void propagateToMenuItem(JComponent aItem) {
090: if (aItem instanceof JMenu) {
091: JMenu theMenu = (JMenu) aItem;
092: theMenu
093: .setLayout(new TemplateLayout(
094: WosFramework
095: .getInstance()
096: .getTemplateManager()
097: .getKeyPositionTemplateForSubTemplate(
098: theTemplate,
099: "theItems.JPopupMenu.thePopupMenu.theMenuItem.MenuWithChilds")));
100: propagateToPopupMenu(theMenu.getPopupMenu());
101: } else {
102: aItem
103: .setLayout(new TemplateLayout(
104: WosFramework
105: .getInstance()
106: .getTemplateManager()
107: .getKeyPositionTemplateForSubTemplate(
108: theTemplate,
109: "theItems.JPopupMenu.thePopupMenu.theMenuItem")));
110: }
111: }
112: }
|