protected void initComponent() { setModel(new DefaultSplitButtonModel()); if (getAction() != null) { configurePropertiesFromAction(getAction()); } setFocusable(true); setRequestFocusEnabled(false); }
@Override protected void configurePropertiesFromAction(Action action) { super.configurePropertiesFromAction(action); setButtonEnabled(isSplitButtonEnabled(action)); setIconFromAction(action); }
/** * If the property is true, the split button doesn't have default action. It always drops down the menu when mouse * clicks. By default, this value is false. * * @param alwaysDropdown true or false. */ public void setAlwaysDropdown(boolean alwaysDropdown) { if (_alwaysDropdown != alwaysDropdown) { boolean old = _alwaysDropdown; _alwaysDropdown = alwaysDropdown; firePropertyChange(PROPERTY_ALWAYS_DROPDOWN, old, alwaysDropdown); } }
/** * Gets the background for different states. The states are defined in ThemePainter as constants. Not all states are * supported by all components. If the state is not supported or background is never set, it will return null. * <p/> * Please note, each L&F will have its own way to paint the different backgrounds. This method allows you to * customize it for each component to use a different background. So if you want the background to be used, don't * use a ColorUIResource because UIResource is considered as a setting set by the L&F and any L&F can choose to * ignore it. * * @param state the button state. Please refer to {@link com.jidesoft.plaf.basic.ThemePainter} to see the list of * available states. * @return the background for different states. */ public Color getBackgroundOfState(int state) { switch (state) { case ThemePainter.STATE_DEFAULT: return getBackground(); case ThemePainter.STATE_ROLLOVER: return getRolloverBackground(); case ThemePainter.STATE_SELECTED: return getSelectedBackground(); case ThemePainter.STATE_PRESSED: return getPressedBackground(); } return null; }
/** * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) */ public void valueChanged(ListSelectionEvent e) { if (e != null && e.getValueIsAdjusting()) return; TokenInitiative ti = (TokenInitiative) displayList.getSelectedValue(); boolean enabled = (ti != null && hasOwnerPermission(ti.getToken())) ? true : false; CLEAR_INIT_STATE_VALUE.setEnabled(enabled); SET_INIT_STATE_VALUE.setEnabled(enabled); if (menuButton.getAction() == TOGGLE_HOLD_ACTION) { menuButton.setButtonEnabled(enabled); } else { TOGGLE_HOLD_ACTION.setEnabled(enabled); } // endif MAKE_CURRENT_ACTION.setEnabled(enabled && ti != list.getTokenInitiative(list.getCurrent())); REMOVE_TOKEN_ACTION.setEnabled(enabled); ti = (list.getCurrent() >= 0) ? list.getTokenInitiative(list.getCurrent()) : null; if (hasGMPermission() || (ti != null && hasOwnerPermission(ti.getToken()))) { menuButton.setButtonEnabled(true); } else { if (menuButton.getAction() == NEXT_ACTION) menuButton.setButtonEnabled(false); } }
menuButton.setAction(NEXT_ACTION); } else { TOGGLE_HOLD_ACTION.setEnabled(true); menuButton.setAction(TOGGLE_HOLD_ACTION); menuButton.removeAll(); if (hasGMPermission()) { menuButton.add(new JMenuItem(PREV_ACTION)); menuButton.add(new JMenuItem(SORT_LIST_ACTION)); menuButton.addSeparator(); menuButton.add(new JMenuItem(MAKE_CURRENT_ACTION)); menuButton.add(new JMenuItem(TOGGLE_HOLD_ACTION)); menuButton.add(new JMenuItem(SET_INIT_STATE_VALUE)); menuButton.add(new JMenuItem(CLEAR_INIT_STATE_VALUE)); menuButton.addSeparator(); JCheckBoxMenuItem item = new JCheckBoxMenuItem(SHOW_TOKENS_ACTION); item.setSelected(showTokens); menuButton.add(item); item = new JCheckBoxMenuItem(SHOW_TOKEN_STATES_ACTION); item.setSelected(showTokenStates); menuButton.add(item); item = new JCheckBoxMenuItem(SHOW_INIT_STATE); item.setSelected(showInitState); menuButton.add(item); item = new JCheckBoxMenuItem(INIT_STATE_SECOND_LINE); item.setSelected(initStateSecondLine); menuButton.add(item);
JPanel panel = new JPanel(new FormLayout("2px pref 8dlu pref 4dlu fill:30px 0px:grow 2px", "4dlu fill:pref 7px fill:0px:grow 4dlu")); add(panel, SwingConstants.CENTER); menuButton = new JideSplitButton(I18N.getText("initPanel.menuButton")); panel.add(menuButton, new CellConstraints(2, 2)); JideButton rButton = new JideButton(RESET_COUNTER_ACTION);
/** * Clicks on the button part of the <code>JideSplitButton</code>. */ @Override public void doClick() { Action action = getActionMap().get("pressed"); if (action != null) { action.actionPerformed(new ActionEvent(this, 0, "")); } }
@Override protected void actionPropertyChanged(Action action, String propertyName) { super.actionPropertyChanged(action, propertyName); if (Action.SELECTED_KEY.equals(propertyName)) { ((ToggleSplitButtonModel) getModel()).setButtonSelected((Boolean) action.getValue(propertyName)); } }
@Override protected void configurePropertiesFromAction(Action action) { super.configurePropertiesFromAction(action); boolean selected = false; if (action != null) { selected = Boolean.TRUE.equals(action.getValue(Action.SELECTED_KEY)); } if (selected != isSelected()) { // This won't notify ActionListeners, but that should be // ok as the change is coming from the Action. setSelected(selected); // Make sure the change actually took effect if (!selected && isSelected()) { if (getModel() instanceof DefaultButtonModel) { ButtonGroup group = (ButtonGroup) ((DefaultButtonModel) getModel()).getGroup(); if (group != null) { group.clearSelection(); } } } } }
public void run() { model.setList(list); if (menuButton != null && menuButton.getAction() == NEXT_ACTION) menuButton.setButtonEnabled(hasGMPermission() || list.getCurrent() >= 0 && hasOwnerPermission(list.getToken(list.getCurrent()))); if (list.getCurrent() >= 0) { int index = model.getDisplayIndex(list.getCurrent()); if (index >= 0) displayList.ensureIndexIsVisible(index); } } });
/** * Clicks on the drop down menu part of the <code>JideSplitButton</code>. */ public void doClickOnMenu() { Action action = getActionMap().get("downPressed"); if (action != null) { action.actionPerformed(new ActionEvent(this, 0, "")); } }
/** * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(InitiativeList.ROUND_PROP)) { String text = list.getRound() < 0 ? "" : Integer.toString(list.getRound()); round.setText(text); } else if (evt.getPropertyName().equals(InitiativeList.CURRENT_PROP)) { if (list.getCurrent() < 0) return; Token t = list.getTokenInitiative(list.getCurrent()).getToken(); if (t == null) return; String s = I18N.getText("initPanel.displayMessage", t.getName()); if (InitiativeListModel.isTokenVisible(t, list.isHideNPC()) && t.getType() != Type.NPC && AppPreferences.isShowInitGainMessage()) MapTool.addMessage(TextMessage.say(null, s)); displayList.ensureIndexIsVisible(model.getDisplayIndex(list.getCurrent())); if (menuButton.getAction() == NEXT_ACTION) menuButton.setButtonEnabled(list.getCurrent() >= 0 && hasOwnerPermission(list.getToken(list.getCurrent()))); } else if (evt.getPropertyName().equals(InitiativeList.TOKENS_PROP)) { if ((evt.getOldValue() == null && evt.getNewValue() instanceof TokenInitiative) || (evt.getNewValue() == null & evt.getOldValue() instanceof TokenInitiative)) displayList.getSelectionModel().clearSelection(); } else if (evt.getPropertyName().equals(InitiativeList.HIDE_NPCS_PROP)) { displayList.getSelectionModel().clearSelection(); } else if (evt.getPropertyName().equals(InitiativeList.OWNER_PERMISSIONS_PROP)) { updateView(); } // endif }
@Override protected void actionPropertyChanged(Action action, String propertyName) { super.actionPropertyChanged(action, propertyName); if (ACTION_PROPERTY_SPLIT_BUTTON_ENABLED.equals(propertyName) || "enabled".equals(propertyName)) { setButtonEnabled(isSplitButtonEnabled(action)); } else if (Action.SMALL_ICON.equals(propertyName)) { setIconFromAction(action); } else if (SystemInfo.isJdk6Above() && Action.LARGE_ICON_KEY.equals(propertyName)) { setIconFromAction(action); } }
/** * Sets the button style. * * @param buttonStyle the new button style. */ public void setButtonStyle(int buttonStyle) { if (buttonStyle < 0 || buttonStyle > FLAT_STYLE) { throw new IllegalArgumentException("Only TOOLBAR_STYLE, TOOLBOX_STYLE, and FLAT_STYLE are supported"); } if (buttonStyle == _buttonStyle) return; int oldStyle = _buttonStyle; _buttonStyle = buttonStyle; firePropertyChange(BUTTON_STYLE_PROPERTY, oldStyle, _buttonStyle); }