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.components.tabbedpane;
015:
016: import org.jetbrains.annotations.NotNull;
017:
018: import javax.swing.*;
019: import javax.swing.plaf.ComponentUI;
020: import javax.swing.plaf.UIResource;
021: import javax.swing.plaf.basic.BasicGraphicsUtils;
022: import javax.swing.plaf.basic.BasicToggleButtonUI;
023: import java.awt.*;
024:
025: /**
026: * User: Martin
027: * Date: 17.03.2005
028: * Time: 19:33:04
029: */
030: public class HoverToggleButtonUI extends BasicToggleButtonUI {
031: @NotNull
032: private static final HoverToggleButtonUI metalToggleButtonUI = new HoverToggleButtonUI();
033:
034: @NotNull
035: protected Color focusColor;
036: @NotNull
037: protected Color selectColor;
038: @NotNull
039: private Color selectForegroundColor;
040: @NotNull
041: private Color fgColor;
042:
043: @NotNull
044: protected Color disabledTextColor;
045:
046: private boolean defaults_initialized;
047:
048: @NotNull
049: @SuppressWarnings({"UnusedDeclaration"})
050: public static ComponentUI createUI(@NotNull
051: JComponent b) {
052: return metalToggleButtonUI;
053: }
054:
055: public void installDefaults(@NotNull
056: AbstractButton b) {
057: super .installDefaults(b);
058: if (!defaults_initialized) {
059: focusColor = UIManager.getColor(getPropertyPrefix()
060: + "focus");//NON-NLS
061: selectColor = UIManager
062: .getColor("List.selectionBackground");//NON-NLS
063: selectForegroundColor = UIManager
064: .getColor("List.selectionForeground");//NON-NLS
065: fgColor = b.getForeground();
066: disabledTextColor = UIManager.getColor(getPropertyPrefix()
067: + "disabledText");//NON-NLS
068: defaults_initialized = true;
069: }
070: }
071:
072: protected void uninstallDefaults(@NotNull
073: AbstractButton b) {
074: super .uninstallDefaults(b);
075: defaults_initialized = false;
076: }
077:
078: public void update(@NotNull
079: Graphics g, @NotNull
080: JComponent c) {
081:
082: AbstractButton button = (AbstractButton) c;
083:
084: Color background = c.getBackground();
085: if ((background instanceof UIResource)
086: && button.isContentAreaFilled() && c.isEnabled()) {
087: ButtonModel model = button.getModel();
088: g.setColor(background);
089: g.fillRect(0, 0, c.getWidth(), c.getHeight());
090: g.setColor(selectColor/*.brighter()*/);
091: g.drawRect(0, 0, c.getWidth() - 1, c.getHeight() - 1);
092: if (model.isSelected() || model.isPressed()) {
093: c.setForeground(selectForegroundColor);
094: paint(g, c);
095: return;
096: } else if (model.isRollover()) {
097: c.setForeground(fgColor);
098: paint(g, c);
099: return;
100: } else {
101: c.setForeground(fgColor);
102: }
103: }
104: super .update(g, c);
105: }
106:
107: protected void paintButtonPressed(@NotNull
108: Graphics g, @NotNull
109: AbstractButton b) {
110: if (b.isContentAreaFilled()) {
111: g.setColor(selectColor/*.brighter()*/);
112: g.fillRect(0, 0, b.getWidth(), b.getHeight());
113: g.setColor(selectColor.darker());
114: g.drawRect(0, 0, b.getWidth() - 1, b.getHeight() - 1);
115: }
116: }
117:
118: protected void paintFocus(@NotNull
119: Graphics g, @NotNull
120: AbstractButton b, @NotNull
121: Rectangle viewRect, @NotNull
122: Rectangle textRect, @NotNull
123: Rectangle iconRect) {
124: }
125:
126: @NotNull
127: public Dimension getPreferredSize(@NotNull
128: JComponent c) {
129: AbstractButton b = (AbstractButton) c;
130: Dimension preferredButtonSize = BasicGraphicsUtils
131: .getPreferredButtonSize(b, b.getIconTextGap());
132: return new Dimension(preferredButtonSize.width + 10,
133: preferredButtonSize.height + 10);
134: }
135:
136: }
|