001: /*
002: * @(#)DefaultSplitButtonModel.java 2/17/2005
003: *
004: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.swing;
007:
008: import javax.swing.*;
009: import java.awt.event.ItemEvent;
010:
011: /**
012: */
013: public class DefaultSplitButtonModel extends DefaultButtonModel
014: implements SplitButtonModel {
015: /**
016: * Indicates that the button part of the split button has been selected.
017: */
018: public final static int BUTTON_SELECTED = 1 << 6;
019:
020: /**
021: * Indicates that the button part of the split button is enabled or disabled.
022: */
023: public final static int BUTTON_ENABLED = 1 << 7;
024:
025: /**
026: * Indicates that the button part of the split button is rollover.
027: */
028: public final static int BUTTON_ROLLOVER = 1 << 8;
029:
030: public DefaultSplitButtonModel() {
031: setButtonEnabled(true);
032: }
033:
034: /**
035: * Selects or deselects the button part of the JideSplitButton.
036: *
037: * @param b true selects the button,
038: * false deselects the button
039: */
040: public void setButtonSelected(boolean b) {
041: if (this .isButtonSelected() == b) {
042: return;
043: }
044:
045: if (b) {
046: stateMask |= BUTTON_SELECTED;
047: } else {
048: stateMask &= ~BUTTON_SELECTED;
049: }
050:
051: fireItemStateChanged(new ItemEvent(this ,
052: ItemEvent.ITEM_STATE_CHANGED, this ,
053: b ? ItemEvent.SELECTED : ItemEvent.DESELECTED));
054:
055: fireStateChanged();
056:
057: }
058:
059: /**
060: * Indicates if the button part of the JideSplitButton has been selected.
061: *
062: * @return true if the button is selected
063: */
064: public boolean isButtonSelected() {
065: return (stateMask & BUTTON_SELECTED) != 0;
066: }
067:
068: /**
069: * Selects or deselects the button part of the JideSplitButton.
070: *
071: * @param b true selects the button,
072: * false deselects the button
073: */
074: public void setButtonEnabled(boolean b) {
075: if (this .isButtonEnabled() == b) {
076: return;
077: }
078:
079: if (b) {
080: stateMask |= BUTTON_ENABLED;
081: } else {
082: stateMask &= ~BUTTON_ENABLED;
083: }
084:
085: fireStateChanged();
086:
087: }
088:
089: /**
090: * Indicates if the button part of the JideSplitButton has been enabled.
091: *
092: * @return true if the button is enabled
093: */
094: public boolean isButtonEnabled() {
095: return (stateMask & BUTTON_ENABLED) != 0;
096: }
097:
098: /**
099: * Sets the button part of the JideSplitButton as rollover.
100: *
101: * @param b true set the button as rollover,
102: * false set the button as not rollover
103: */
104: public void setButtonRollover(boolean b) {
105: if (this .isButtonRollover() == b) {
106: return;
107: }
108:
109: if (b) {
110: stateMask |= BUTTON_ROLLOVER;
111: } else {
112: stateMask &= ~BUTTON_ROLLOVER;
113: }
114:
115: fireStateChanged();
116: }
117:
118: /**
119: * Indicates if the button part of the JideSplitButton is rollover.
120: *
121: * @return true if the button is rollover
122: */
123: public boolean isButtonRollover() {
124: return (stateMask & BUTTON_ROLLOVER) != 0;
125: }
126:
127: @Override
128: public void setRollover(boolean b) {
129: super .setRollover(b);
130: if (!b) {
131: setButtonRollover(false);
132: }
133: }
134: }
|