001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.channel.ho.client.swing;
032:
033: import java.awt.event.*;
034: import java.util.*;
035:
036: import javax.swing.*;
037:
038: import de.ug2t.kernel.*;
039: import de.ug2t.unifiedGui.interfaces.*;
040: import de.ug2t.unifiedGui.views.*;
041:
042: public final class HoSwingMenu extends HoSwingComponent implements
043: IUnMenu {
044: private JMenuBar pem_swingObj = null;
045: private KeTreeNode pem_rootNode = null;
046:
047: public HoSwingMenu(String xName, KeTreeNode xRoot,
048: IUnApplication xAppl) throws Exception {
049: super (xName, xAppl);
050:
051: if (xRoot == null)
052: pem_rootNode = this ;
053: else
054: pem_rootNode = xRoot;
055:
056: this .pem_swingObj = new JMenuBar();
057: super .pdm_realSwingCmp = this .pem_swingObj;
058: this .pcmf_setEventOnChange(true);
059:
060: this .pcmf_setLocalValue(pem_rootNode.pcmf_getValue());
061:
062: // Aufbau des Menus
063: this .pcmf_commitMenu();
064:
065: return;
066: };
067:
068: private void pcmf_buildMenuItems(KeTreeNode xNode, JMenu xMenu) {
069: KeTreeNode l_node = null;
070: Iterator l_it = xNode.pcmf_getAllSubs().iterator();
071:
072: while (l_it.hasNext()) {
073: l_node = (KeTreeNode) l_it.next();
074: if (l_node.pcmf_getAllSubs().size() == 0) {
075: String l_string = l_node.pcmf_getValue().toString();
076: if (l_string.equals("--") || l_string.equals("|"))
077: xMenu.addSeparator();
078: else {
079: HoSwingEnhJMenuItem l_item = new HoSwingEnhJMenuItem(
080: l_node.pcmf_getValue().toString(), l_node,
081: this );
082: Object l_key = l_node.pcmf_getAdditionalInfo();
083: if (l_key != null)
084: l_item.setAccelerator(KeyStroke.getKeyStroke(
085: l_key.toString().charAt(0),
086: InputEvent.ALT_MASK));
087:
088: xMenu.add(l_item);
089: }
090: } else {
091: JMenu l_menu = new JMenu(l_node.pcmf_getValue()
092: .toString());
093: if (l_node.pcmf_getValue() instanceof HoSwingImage)
094: l_menu.setIcon(((JLabel) ((HoSwingImage) l_node
095: .pcmf_getValue()).pcmf_getRealSwingObj())
096: .getIcon());
097: else {
098: UnIconValueView l_view = (UnIconValueView) l_node
099: .pcmf_getView();
100: if (l_view != null)
101: l_view.pcmf_applyStdView(l_menu);
102: }
103: this .pcmf_buildMenuItems(l_node, l_menu);
104: xMenu.add(l_menu);
105: }
106: ;
107: }
108: ;
109: return;
110: };
111:
112: public void pcmf_commitMenu() {
113: this .pem_swingObj.removeAll();
114: this .pcmf_setLocalValue(pem_rootNode.pcmf_getValue());
115:
116: // Aufbau des Menus
117: KeTreeNode l_node = null;
118: Iterator l_it = pem_rootNode.pcmf_getAllSubs().iterator();
119: JMenu l_menu = null;
120: while (l_it.hasNext()) {
121: l_node = (KeTreeNode) l_it.next();
122: if (l_node.pcmf_getAllSubs().size() == 0) {
123: String l_string = l_node.pcmf_getValue().toString();
124:
125: if (l_string.equals("--")) {
126: l_menu = new JMenu("|");
127: l_menu.setEnabled(false);
128: } else
129: l_menu = new JMenu(l_string);
130:
131: this .pem_swingObj.add(l_menu);
132: } else {
133: l_menu = new JMenu(l_node.pcmf_getValue().toString());
134: this .pcmf_buildMenuItems(l_node, l_menu);
135: this .pem_swingObj.add(l_menu);
136: }
137: ;
138: if (l_node.pcmf_getValue() instanceof HoSwingImage)
139: l_menu.setIcon(((JLabel) ((HoSwingImage) l_node
140: .pcmf_getValue()).pcmf_getRealSwingObj())
141: .getIcon());
142: else {
143: UnIconValueView l_view = (UnIconValueView) l_node
144: .pcmf_getView();
145: if (l_view != null)
146: l_view.pcmf_applyStdView(l_menu);
147: }
148: if (l_node.pcmf_isDisabled() == true)
149: l_menu.setEnabled(false);
150: }
151: ;
152:
153: return;
154: };
155:
156: public KeTreeNode pcmf_setRoot(KeTreeNode xRoot) {
157: KeTreeNode l_node = this .pem_rootNode;
158:
159: if (xRoot == null)
160: pem_rootNode = this ;
161: else
162: pem_rootNode = xRoot;
163:
164: this .pcmf_commitMenu();
165:
166: return (l_node);
167: };
168:
169: public void pcmf_setMenuWidth(int xWi) {
170: // Does nothing
171: KeLog.pcmf_log("ug2t", "pcmf_setMenuWidth is not implemented",
172: this, KeLog.DEBUG);
173: }
174: }
|