01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.lib.client.commands;
15:
16: import org.jetbrains.annotations.NotNull;
17:
18: import javax.swing.*;
19: import java.awt.event.MouseAdapter;
20: import java.awt.event.MouseEvent;
21: import java.beans.PropertyChangeEvent;
22: import java.beans.PropertyChangeListener;
23:
24: /**
25: * User: Martin
26: * Date: 19.11.2004
27: * Time: 14:17:34
28: */
29: public class CommandMenu extends JMenu implements CommandComponent {
30: @NotNull
31: private Presentation presentation;
32: private boolean showIcon;
33: @NotNull
34: private String iconKey;
35:
36: public CommandMenu(@NotNull
37: final Presentation presentation, boolean showIcon, @NotNull
38: String iconKey) {
39: this .presentation = presentation;
40: this .showIcon = showIcon;
41: this .iconKey = iconKey;
42: update();
43:
44: presentation
45: .addPropertyChangeListener(new PropertyChangeListener() {
46: public void propertyChange(@NotNull
47: PropertyChangeEvent evt) {
48: update();
49: }
50: });
51:
52: addMouseListener(new MouseAdapter() {
53: public void mouseEntered(@NotNull
54: MouseEvent e) {
55: presentation.getCommandApplicationRoot().setStatusText(
56: presentation.getDescription());
57: }
58:
59: public void mouseExited(@NotNull
60: MouseEvent e) {
61: presentation.getCommandApplicationRoot()
62: .clearStatusText();
63: }
64: });
65:
66: }
67:
68: private void update() {
69: setText(presentation.getText());
70: if (showIcon) {
71: setIcon(presentation.getIcon(iconKey));
72: }
73: setEnabled(presentation.isEnabled());
74: setVisible(presentation.isVisible());
75: setMnemonic(presentation.getMnemonic());
76: setDisplayedMnemonicIndex(presentation
77: .getDisplayedMnemonicIndex());
78: }
79:
80: }
|