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 ToggleCommandMenuItem extends JCheckBoxMenuItem implements
30: CommandComponent {
31: @NotNull
32: private Presentation presentation;
33: @NotNull
34: private String iconKey;
35:
36: public ToggleCommandMenuItem(@NotNull
37: final Presentation presentation, @NotNull
38: String iconKey) {
39: this .presentation = presentation;
40: this .iconKey = iconKey;
41: update();
42:
43: presentation
44: .addPropertyChangeListener(new PropertyChangeListener() {
45: public void propertyChange(@NotNull
46: PropertyChangeEvent evt) {
47: update();
48: }
49: });
50:
51: addMouseListener(new MouseAdapter() {
52: public void mouseEntered(@NotNull
53: MouseEvent e) {
54: presentation.getCommandApplicationRoot().setStatusText(
55: presentation.getDescription());
56: }
57:
58: public void mouseExited(@NotNull
59: MouseEvent e) {
60: presentation.getCommandApplicationRoot()
61: .clearStatusText();
62: }
63: });
64:
65: }
66:
67: private void update() {
68: setText(presentation.getText());
69: setIcon(presentation.getIcon(iconKey));
70: setEnabled(presentation.isEnabled());
71: setVisible(presentation.isVisible());
72:
73: Object selectedProperty = presentation
74: .getClientProperty("selected");//NON-NLS
75: setSelected(Boolean.TRUE.equals(selectedProperty));
76: }
77:
78: }
|