001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.lib.client.commands;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.jetbrains.annotations.Nullable;
018:
019: import javax.swing.*;
020: import java.awt.*;
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023: import java.awt.event.MouseAdapter;
024: import java.awt.event.MouseEvent;
025:
026: /**
027: * User: Martin
028: * Date: 21.11.2004
029: * Time: 13:21:43
030: */
031: public class CommandToolBarButton extends CommandButton {
032: @NotNull
033: private String iconKey;
034:
035: public CommandToolBarButton(@NotNull
036: final Presentation presentation, @NotNull
037: String iconKey) {
038: this (null, presentation, iconKey);
039: }
040:
041: public CommandToolBarButton(@Nullable
042: final CommandGroup commandGroup, @NotNull
043: final Presentation presentation, @NotNull
044: String iconKey) {
045: super (presentation);
046:
047: setHorizontalTextPosition(CommandButton.CENTER);
048: setVerticalTextPosition(CommandButton.BOTTOM);
049:
050: this .iconKey = iconKey;
051: setRolloverEnabled(true);
052: setMargin(new Insets(4, 4, 4, 4));
053:
054: //noinspection ConstantConditions
055: if (presentation == null) {
056: throw new IllegalArgumentException(
057: "Presentation can not be null");
058: }
059:
060: update();
061:
062: setFocusable(false);
063:
064: addMouseListener(new MouseAdapter() {
065: public void mouseEntered(@NotNull
066: MouseEvent e) {
067: presentation.getCommandApplicationRoot().setStatusText(
068: presentation.getDescription());
069: }
070:
071: public void mouseExited(@NotNull
072: MouseEvent e) {
073: presentation.getCommandApplicationRoot()
074: .clearStatusText();
075: }
076: });
077:
078: if (commandGroup != null) {
079: final CommandGroup tempCommandGroup = commandGroup;
080: addActionListener(new ActionListener() {
081: public void actionPerformed(@NotNull
082: ActionEvent e) {
083: CommandPopupMenu commandPopupMenu = CommandManager
084: .createCommandPopupMenu(presentation
085: .getCommandApplicationRoot(),
086: tempCommandGroup, CommandSettings
087: .getInstance()
088: .getToolbarIconKey());
089: JPopupMenu popupMenu = commandPopupMenu
090: .getJPopupMenu();
091: CommandToolBarButton button = CommandToolBarButton.this ;
092: popupMenu.show(button, 0, button.getHeight());
093: }
094: });
095: }
096: }
097:
098: protected void update() {
099: Presentation presentation = getPresentation();
100:
101: setIcon(presentation.getIcon(iconKey));
102: setEnabled(presentation.isEnabled());
103: setToolTipText(presentation.getText());
104: setVisible(presentation.isVisible());
105: }
106:
107: }
|