001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance.combo;
031:
032: import java.awt.Graphics;
033: import java.awt.Insets;
034:
035: import javax.swing.*;
036:
037: import org.jvnet.lafwidget.animation.FadeConfigurationManager;
038: import org.jvnet.lafwidget.animation.FadeKind;
039: import org.jvnet.substance.SubstanceImageCreator;
040: import org.jvnet.substance.SubstanceLookAndFeel;
041: import org.jvnet.substance.utils.SubstanceCoreUtilities;
042: import org.jvnet.substance.utils.SubstanceSizeUtils;
043:
044: /**
045: * Combo box button in <b>Substance</b> look and feel.
046: *
047: * @author Kirill Grouchnikov
048: */
049: public final class SubstanceComboBoxButton extends JButton {
050: static {
051: FadeConfigurationManager.getInstance().disallowFades(
052: FadeKind.GHOSTING_BUTTON_PRESS,
053: SubstanceComboBoxButton.class);
054: FadeConfigurationManager.getInstance().disallowFades(
055: FadeKind.GHOSTING_ICON_ROLLOVER,
056: SubstanceComboBoxButton.class);
057: }
058:
059: /**
060: * Simple constructor.
061: *
062: * @param comboBox
063: * The owner combo box.
064: * @param comboIcon
065: * The button icon (down arrow).
066: */
067: public SubstanceComboBoxButton(JComboBox comboBox) {
068: super ("");
069: this .setModel(new DefaultButtonModel() {
070: @Override
071: public void setArmed(boolean armed) {
072: super .setArmed(this .isPressed() || armed);
073: }
074: });
075: this .setEnabled(comboBox.isEnabled());
076: this .setFocusable(false);
077: this .setRequestFocusEnabled(comboBox.isEnabled());
078:
079: int fontSize = SubstanceSizeUtils
080: .getComponentFontSize(comboBox);
081: int tbrInset = SubstanceSizeUtils.getAdjustedSize(fontSize, 1,
082: 2, 1, false);
083: int lInset = SubstanceSizeUtils.getAdjustedSize(fontSize, 0, 2,
084: 1, false);
085: this
086: .setMargin(new Insets(tbrInset, lInset, tbrInset,
087: tbrInset));
088: this .putClientProperty(
089: SubstanceLookAndFeel.USE_THEMED_DEFAULT_ICONS,
090: Boolean.FALSE);
091: this .putClientProperty(
092: SubstanceCoreUtilities.DO_NOT_FILL_BACKGROUND,
093: Boolean.TRUE);
094: }
095:
096: /**
097: * Sets the icon for this button.
098: *
099: * @param comboBox
100: * Combobox.
101: * @param comboIcon
102: * Combo icon.
103: */
104: public void setIcon(JComboBox comboBox, Icon comboIcon) {
105: this .setIcon(comboIcon);
106: // this.setDisabledIcon(SubstanceImageCreator.makeTransparent(comboBox,
107: // comboIcon, 0.4));
108: }
109:
110: @Override
111: public void paint(Graphics g) {
112: super.paint(g);
113:
114: }
115: }
|