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.utils;
031:
032: import java.awt.Insets;
033:
034: import javax.swing.*;
035:
036: import org.jvnet.lafwidget.animation.FadeConfigurationManager;
037: import org.jvnet.lafwidget.animation.FadeKind;
038: import org.jvnet.substance.SubstanceImageCreator;
039: import org.jvnet.substance.SubstanceLookAndFeel;
040:
041: /**
042: * Spinner button in <b>Substance</b> look and feel.
043: *
044: * @author Kirill Grouchnikov
045: */
046: public class SubstanceSpinnerButton extends JButton implements Sideable {
047: static {
048: FadeConfigurationManager.getInstance().disallowFades(
049: FadeKind.GHOSTING_BUTTON_PRESS,
050: SubstanceSpinnerButton.class);
051: FadeConfigurationManager.getInstance().disallowFades(
052: FadeKind.GHOSTING_ICON_ROLLOVER,
053: SubstanceSpinnerButton.class);
054: }
055:
056: /**
057: * Button orientation.
058: */
059: private int orientation;
060:
061: /**
062: * Simple constructor.
063: *
064: * @param spinner
065: * The owner spinner.
066: * @param orientation
067: * The orientation of the spinner icon arrow.
068: */
069: public SubstanceSpinnerButton(JSpinner spinner, int orientation) {
070: // super(0, 0, false);
071: super ();
072: // setModel(new DefaultButtonModel() {
073: // @Override
074: // public void setArmed(boolean armed) {
075: // super.setArmed(isPressed() || armed);
076: // }
077: // });
078: this .setEnabled(spinner.isEnabled());
079: this .setFocusable(false);
080: this .setRequestFocusEnabled(false);
081: this .setMargin(new Insets(0, 0, 0, 2));
082: this .setBorder(null);
083: this .orientation = orientation;
084: this .putClientProperty(
085: SubstanceLookAndFeel.USE_THEMED_DEFAULT_ICONS,
086: Boolean.FALSE);
087: }
088:
089: /**
090: * Sets the icon for this button.
091: *
092: * @param spinner
093: * Spinner.
094: * @param defaultIcon
095: * Spinner icon.
096: */
097: public void setIcon(JSpinner spinner, Icon defaultIcon) {
098: super .setIcon(defaultIcon);
099: // super.setDisabledIcon(SubstanceImageCreator.makeTransparent(spinner,
100: // defaultIcon, 0.4));
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see java.awt.Component#isFocusable()
107: */
108: @Override
109: public boolean isFocusable() {
110: return false;
111: }
112:
113: /*
114: * (non-Javadoc)
115: *
116: * @see org.jvnet.substance.utils.Sideable#getSide()
117: */
118: public SubstanceConstants.Side getSide() {
119: switch (this.orientation) {
120: case SwingConstants.NORTH:
121: return SubstanceConstants.Side.BOTTOM;
122: case SwingConstants.WEST:
123: return SubstanceConstants.Side.RIGHT;
124: case SwingConstants.SOUTH:
125: return SubstanceConstants.Side.TOP;
126: case SwingConstants.EAST:
127: return SubstanceConstants.Side.LEFT;
128: default:
129: return null;
130: }
131: }
132: }
|