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.*;
034: import java.awt.event.*;
035: import java.util.*;
036:
037: import javax.swing.*;
038: import javax.swing.table.*;
039:
040: import de.ug2t.kernel.*;
041: import de.ug2t.unifiedGui.interfaces.*;
042: import de.ug2t.unifiedGui.views.*;
043:
044: public final class HoSwingContextMenu extends HoSwingComponent
045: implements IUnContextMenu {
046: private JPopupMenu pem_swingObj = null;
047: private KeTreeNode pem_rootNode = null;
048: private MouseListener pem_myListener = null;
049: private boolean pem_autoShow = false;
050:
051: final class MyPopUp_li extends HoMouseAdapter {
052: private JPopupMenu pem_menu = null;
053: private Component pem_parent = null;
054:
055: public MyPopUp_li(JPopupMenu xMenu, Component xComp) {
056: this .pem_menu = xMenu;
057: this .pem_parent = xComp;
058:
059: return;
060: };
061:
062: public void mouseClicked(MouseEvent e) {
063: this .mousePressed(e);
064: }
065:
066: public void mouseReleased(MouseEvent e) {
067: this .mousePressed(e);
068: }
069:
070: public void mousePressed(MouseEvent e) {
071: if (e.isPopupTrigger()
072: || e.getButton() == MouseEvent.BUTTON2
073: || e.getButton() == MouseEvent.BUTTON3) {
074: if (e.getSource() instanceof JTableHeader)
075: e.translatePoint(0, -e.getY());
076: else if (e.getSource() instanceof JScrollPane)
077: e.translatePoint(0, -(e.getY() / 2));
078:
079: if (HoSwingContextMenu.this .pcmf_getAutoShow())
080: this .pem_menu.show(pem_parent, e.getX(), e.getY());
081: else {
082: try {
083: String l_objName = HoSwingContextMenu.this
084: .pcmf_getObjName();
085:
086: // Lokale Listener aufrufen
087: HoSwingContextMenu.this
088: .pcmf_setValue(IUnContextMenu.CTX_MENU_OPENED
089: + ":"
090: + e.getX()
091: + "px,"
092: + e.getY() + "px");
093: HoSwingContextMenu.this .pcmf_setRefresh();
094: HoSwingContextMenu.this .pcmf_dispatchEvent();
095:
096: // Werte setzen um diese zum Server zu übertragen
097: ((HoSwingPage) HoSwingContextMenu.this
098: .pcmf_getAppl().pcmf_getActive())
099: .pcmf_setSubmitValue(l_objName,
100: HoSwingContextMenu.this
101: .pcmf_getValue()
102: .toString());
103: if (HoSwingContextMenu.this .pcmf_isSubmit() == true)
104: ((HoSwingPage) HoSwingContextMenu.this
105: .pcmf_getAppl().pcmf_getActive())
106: .pcmf_submit();
107: } catch (Exception ex) {
108: KeLog.pcmf_logException("ug2t", this , ex);
109: }
110: }
111: }
112: return;
113: }
114: }
115:
116: public HoSwingContextMenu(String xName, KeTreeNode xRoot,
117: IUnApplication xAppl) throws Exception {
118: super (xName, xAppl);
119:
120: if (xRoot == null)
121: pem_rootNode = this ;
122: else
123: pem_rootNode = xRoot;
124:
125: this .pem_swingObj = new JPopupMenu();
126: super .pdm_realSwingCmp = this .pem_swingObj;
127: this .pcmf_setEventOnChange(true);
128:
129: this .pcmf_setLocalValue(pem_rootNode.pcmf_getValue());
130:
131: // Aufbau des Menus
132: this .pcmf_commitMenu();
133:
134: return;
135: };
136:
137: private void pcmf_buildMenuItems(KeTreeNode xNode, JMenu xMenu) {
138: KeTreeNode l_node = null;
139: Iterator l_it = xNode.pcmf_getAllSubs().iterator();
140:
141: while (l_it.hasNext()) {
142: l_node = (KeTreeNode) l_it.next();
143: if (l_node.pcmf_getAllSubs().size() == 0) {
144: String l_string = l_node.pcmf_getValue().toString();
145: if (l_string.equals("--") || l_string.equals("|"))
146: xMenu.addSeparator();
147: else {
148: HoSwingEnhJMenuItem l_item = new HoSwingEnhJMenuItem(
149: l_node.pcmf_getValue().toString(), l_node,
150: this );
151: Object l_key = l_node.pcmf_getAdditionalInfo();
152: if (l_key != null)
153: l_item.setAccelerator(KeyStroke.getKeyStroke(
154: l_key.toString().charAt(0),
155: InputEvent.ALT_MASK));
156:
157: xMenu.add(l_item);
158: }
159: } else {
160: JMenu l_menu = new JMenu(l_node.pcmf_getValue()
161: .toString());
162: if (l_node.pcmf_getValue() instanceof HoSwingImage)
163: l_menu.setIcon(((JLabel) ((HoSwingImage) l_node
164: .pcmf_getValue()).pcmf_getRealSwingObj())
165: .getIcon());
166: else {
167: UnIconValueView l_view = (UnIconValueView) l_node
168: .pcmf_getView();
169: if (l_view != null)
170: l_view.pcmf_applyStdView(l_menu);
171: }
172: this .pcmf_buildMenuItems(l_node, l_menu);
173: xMenu.add(l_menu);
174: }
175: ;
176: }
177: ;
178: return;
179: };
180:
181: public void pcmf_commitMenu() {
182: this .pem_swingObj = new JPopupMenu();
183: super .pdm_realSwingCmp = this .pem_swingObj;
184:
185: this .pcmf_setLocalValue(pem_rootNode.pcmf_getValue());
186:
187: // Aufbau des Menus
188: KeTreeNode l_node = null;
189: Iterator l_it = pem_rootNode.pcmf_getAllSubs().iterator();
190: while (l_it.hasNext()) {
191: l_node = (KeTreeNode) l_it.next();
192: if (l_node.pcmf_getAllSubs().size() == 0) {
193: String l_string = l_node.pcmf_getValue().toString();
194: if (l_string.equals("--"))
195: this .pem_swingObj.addSeparator();
196: else {
197: HoSwingEnhJMenuItem l_menuItem = new HoSwingEnhJMenuItem(
198: l_node.pcmf_getValue().toString(), l_node,
199: this );
200:
201: Object l_key = l_node.pcmf_getAdditionalInfo();
202: if (l_key != null)
203: l_menuItem
204: .setAccelerator(KeyStroke.getKeyStroke(
205: l_key.toString().charAt(0),
206: InputEvent.ALT_MASK));
207:
208: this .pem_swingObj.add(l_menuItem);
209: if (l_node.pcmf_getValue() instanceof HoSwingImage)
210: l_menuItem
211: .setIcon(((JLabel) ((HoSwingImage) l_node
212: .pcmf_getValue())
213: .pcmf_getRealSwingObj())
214: .getIcon());
215: else {
216: UnIconValueView l_view = (UnIconValueView) l_node
217: .pcmf_getView();
218: if (l_view != null)
219: l_view.pcmf_applyStdView(l_menuItem);
220: }
221: }
222: } else {
223: JMenu l_menu = new JMenu(l_node.pcmf_getValue()
224: .toString());
225: this .pcmf_buildMenuItems(l_node, l_menu);
226: this .pem_swingObj.add(l_menu);
227: if (l_node.pcmf_getValue() instanceof HoSwingImage)
228: l_menu.setIcon(((JLabel) ((HoSwingImage) l_node
229: .pcmf_getValue()).pcmf_getRealSwingObj())
230: .getIcon());
231: else {
232: UnIconValueView l_view = (UnIconValueView) l_node
233: .pcmf_getView();
234: if (l_view != null)
235: l_view.pcmf_applyStdView(l_menu);
236: }
237: if (l_node.pcmf_isDisabled() == true)
238: l_menu.setEnabled(false);
239: }
240: ;
241: }
242: ;
243:
244: KeTreeNode l_parent = this .pcmf_getParentNode();
245: if (l_parent != null) {
246: if (this .pem_myListener != null)
247: ((HoSwingComponent) l_parent).pcmf_getSwingWidget()
248: .removeMouseListener(this .pem_myListener);
249:
250: this .pem_myListener = new MyPopUp_li(this .pem_swingObj,
251: ((HoSwingComponent) this .pcmf_getParentNode())
252: .pcmf_getSwingWidget());
253: ((HoSwingComponent) l_parent).pcmf_getSwingWidget()
254: .addMouseListener(this .pem_myListener);
255: }
256:
257: return;
258: };
259:
260: public KeTreeNode pcmf_setRoot(KeTreeNode xRoot) {
261: KeTreeNode l_node = this .pem_rootNode;
262:
263: if (xRoot == null)
264: pem_rootNode = this ;
265: else
266: pem_rootNode = xRoot;
267:
268: this .pcmf_commitMenu();
269:
270: return (l_node);
271: };
272:
273: public void pcmf_setMenuWidth(int xWi) {
274: // Does nothing
275: KeLog.pcmf_log("ug2t", "pcmf_setMenuWidth is not implemented",
276: this , KeLog.DEBUG);
277: }
278:
279: public void pcmf_setAutoShow(boolean xAS) {
280: this .pem_autoShow = xAS;
281: }
282:
283: public boolean pcmf_getAutoShow() {
284: return this .pem_autoShow;
285: }
286:
287: public void pcmf_show(int x, int y) {
288: this .pem_swingObj.show(((HoSwingComponent) this
289: .pcmf_getParentNode()).pcmf_getSwingWidget(), x, y);
290: }
291: }
|