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.*;
20: import java.awt.event.MouseAdapter;
21: import java.awt.event.MouseEvent;
22: import java.beans.PropertyChangeEvent;
23: import java.beans.PropertyChangeListener;
24:
25: /**
26: * User: Martin
27: * Date: 21.11.2004
28: * Time: 13:21:43
29: */
30: public class ToggleCommandToolBarButton extends JToggleButton implements
31: CommandComponent {
32: @NotNull
33: private Presentation presentation;
34: @NotNull
35: private String iconKey;
36:
37: public ToggleCommandToolBarButton(@NotNull
38: final Presentation presentation, @NotNull
39: String iconKey) {
40: this .iconKey = iconKey;
41: //setRolloverEnabled(true);
42:
43: setHorizontalTextPosition(CommandButton.CENTER);
44: setVerticalTextPosition(CommandButton.BOTTOM);
45: setMargin(new Insets(4, 4, 4, 4));
46:
47: //noinspection ConstantConditions
48: if (presentation == null) {
49: throw new IllegalArgumentException(
50: "Presentation can not be null");
51: }
52:
53: this .presentation = presentation;
54:
55: update();
56:
57: presentation
58: .addPropertyChangeListener(new PropertyChangeListener() {
59: public void propertyChange(@NotNull
60: PropertyChangeEvent evt) {
61: update();
62: }
63: });
64:
65: setFocusable(false);
66:
67: addMouseListener(new MouseAdapter() {
68: public void mouseEntered(@NotNull
69: MouseEvent e) {
70: presentation.getCommandApplicationRoot().setStatusText(
71: presentation.getDescription());
72: }
73:
74: public void mouseExited(@NotNull
75: MouseEvent e) {
76: presentation.getCommandApplicationRoot()
77: .clearStatusText();
78: }
79: });
80: }
81:
82: private void update() {
83: setIcon(presentation.getIcon(iconKey));
84: setEnabled(presentation.isEnabled());
85: setToolTipText(presentation.getText());
86: setVisible(presentation.isVisible());
87:
88: Object selectedProperty = presentation
89: .getClientProperty("selected");//NON-NLS
90: setSelected(Boolean.TRUE.equals(selectedProperty));
91: }
92:
93: }
|