Java Code Examples for javax.swing.plaf.ButtonUI

The following examples show how to use javax.swing.plaf.ButtonUI. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk1.8-source-analysis   Source File: WindowsIconFactory.java    License: Apache License 2.0 6 votes vote down vote up
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 2
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 3
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 4
Source Project: jdk8u60   Source File: WindowsIconFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 5
Source Project: JDKSourceCode1.8   Source File: WindowsIconFactory.java    License: MIT License 6 votes vote down vote up
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 6
/**
 * Uninstalls the specified menu item.
 *
 * @param menuItem Menu item.
 */
public static void uninstallMenu(JMenuItem menuItem) {
    if (menuItem instanceof JMenu) {
        JMenu menu = (JMenu) menuItem;
        for (Component comp : menu.getMenuComponents())
            if (comp instanceof JMenuItem)
                SubstanceCoreUtilities.uninstallMenu((JMenuItem) comp);
    }

    ButtonUI menuItemUI = menuItem.getUI();
    if (menuItemUI instanceof SubstanceMenu) {
        SubstanceMenu sMenu = (SubstanceMenu) menuItemUI;
        if (sMenu.getAssociatedMenuItem() != null) {
            menuItemUI.uninstallUI(menuItem);
        }
    }

    for (ActionListener actionListener : menuItem.getActionListeners())
        menuItem.removeActionListener(actionListener);

    menuItem.removeAll();
}
 
Example 7
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 8
Source Project: netbeans   Source File: ThemeValue.java    License: Apache License 2.0 6 votes vote down vote up
private static SynthContext getSynthContext () {
    try {
        JButton dummyButton = getDummyButton();
        
        ButtonUI bui = dummyButton.getUI();
        if (bui instanceof SynthUI) {
            return ((SynthUI) bui).getContext(dummyButton);
        } else {
           throw new IllegalStateException ("I don't have a SynthButtonUI to play with"); //NOI18N
        }
    } catch (Exception e) {
        functioning = Boolean.FALSE;
        if (log) {
            e.printStackTrace();
        }
        return null;
    }
}
 
Example 9
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 10
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 11
Source Project: jdk8u-jdk   Source File: WindowsIconFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 12
Source Project: hottub   Source File: WindowsIconFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 13
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 14
Source Project: openjdk-8   Source File: WindowsIconFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 15
Source Project: jdk8u_jdk   Source File: WindowsIconFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 16
Source Project: jdk8u-jdk   Source File: WindowsIconFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 17
private static WindowsMenuItemUIAccessor getAccessor(
        JMenuItem menuItem) {
    WindowsMenuItemUIAccessor rv = null;
    ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
            : null;
    if (uiObject instanceof WindowsMenuItemUI) {
        rv = ((WindowsMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsMenuUI) {
        rv = ((WindowsMenuUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
        rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
    } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
        rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
    }
    return rv;
}
 
Example 18
Source Project: consulo   Source File: StripeTabPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredUIAccess
public TabInfo addTab(@Nonnull String tabName, @Nonnull JComponent component, @Nullable JComponent preferredFocusableComponent) {
  StaticAnchoredButton button = new StaticAnchoredButton(tabName, ToolWindowAnchor.LEFT);

  button.addItemListener(myItemListener);
  button.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
  button.setBackground(new Color(247, 243, 239));
  button.setUI((ButtonUI)DesktopStripeButtonUI.createUI(button));

  myTabPanel.add(button);

  TabInfo tabInfo = new TabInfo(button, component, preferredFocusableComponent);
  button.putClientProperty(TabInfo.class, tabInfo);

  myButtonGroup.add(button);
  myContentPanel.add(component, tabName);
  if(myButtonGroup.getSelection() == null) {
    tabInfo.select();
  }
  return tabInfo;
}
 
Example 19
/**
 * Returns the layout metrics of the specified popup menu.
 * 
 * @param popupMenu
 *            Popup menu.
 * @return Layout metrics of the specified popup menu.
 */
public static MenuLayoutMetrics getMetrics(JPopupMenu popupMenu, boolean forPainting) {
    MenuLayoutMetrics metrics = new MenuLayoutMetrics();
    for (int i = 0; i < popupMenu.getComponentCount(); i++) {
        Component comp = popupMenu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem childMenuItem = (JMenuItem) comp;
            ButtonUI bui = childMenuItem.getUI();
            if (!(bui instanceof SubstanceMenu))
                continue;
            SubstanceMenu ui = (SubstanceMenu) bui;
            MenuLayoutInfo mli = MenuUtilities.getMenuLayoutInfo(forPainting, childMenuItem,
                    ui.getAcceleratorFont(), ui.getCheckIcon(), ui.getArrowIcon(),
                    ui.getDefaultTextIconGap());
            metrics.maxIconWidth = Math.max(metrics.maxIconWidth, mli.iconRect.width);
            metrics.maxCheckIconWidth = Math.max(metrics.maxCheckIconWidth,
                    mli.checkIconRect.width);
            metrics.maxTextWidth = Math.max(metrics.maxTextWidth, mli.textRect.width);
            metrics.maxAcceleratorWidth = Math.max(metrics.maxAcceleratorWidth,
                    mli.acceleratorRect.width);
            metrics.maxArrowIconWidth = Math.max(metrics.maxArrowIconWidth,
                    mli.arrowIconRect.width);
            metrics.maxIconTextGap = Math.max(metrics.maxIconTextGap,
                    ui.getDefaultTextIconGap());
        }
    }
    return metrics;
}
 
Example 20
/**
 * Returns the layout metrics of the popup menu of the specified menu item.
 * 
 * @param menuItem
 *            Menu item.
 * @return Layout metrics of the popup menu of the specified menu item.
 */
public static MenuLayoutMetrics getPopupLayoutMetrics(JMenuItem menuItem, boolean forPainting) {
    Component comp = menuItem.getParent();
    if (comp instanceof JPopupMenu) {
        JPopupMenu popupMenu = (JPopupMenu) comp;
        return getPopupLayoutMetrics(popupMenu, forPainting);
    }
    // fix for issue 347 - menu item in menu bar is not
    // covered by the code above
    if (!(comp instanceof JMenu)) {
        ButtonUI bui = menuItem.getUI();
        if (bui instanceof SubstanceMenu) {
            SubstanceMenu ui = (SubstanceMenu) bui;

            MenuLayoutInfo mli = MenuUtilities.getMenuLayoutInfo(forPainting, menuItem,
                    ui.getAcceleratorFont(), ui.getCheckIcon(), ui.getArrowIcon(),
                    ui.getDefaultTextIconGap());
            MenuLayoutMetrics metrics = new MenuLayoutMetrics();
            metrics.maxIconWidth = mli.iconRect.width;
            metrics.maxCheckIconWidth = mli.checkIconRect.width;
            metrics.maxTextWidth = mli.textRect.width;
            metrics.maxAcceleratorWidth = mli.acceleratorRect.width;
            metrics.maxArrowIconWidth = mli.arrowIconRect.width;
            metrics.maxIconTextGap = ui.getDefaultTextIconGap();
            return metrics;
        }
    }

    // If here, the parent is not popup menu - this is a top-level menu
    // in a menu bar. No need to align the different rectangles
    return null;
}
 
Example 21
Source Project: netbeans   Source File: BasicSlidingTabDisplayerUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void updateUI () {
    SlidingTabDisplayerButtonUI ui = null;
    try {
        ui = (SlidingTabDisplayerButtonUI) UIManager.getUI(this);
        setUI (ui);
        return;
    } catch (Error e) {
        System.err.println ("Error getting sliding button UI: " + e.getMessage());
    } catch (Exception ex) {
        System.err.println ("Exception getting button UI: " + ex.getMessage());
    }
    setUI ((ButtonUI) SlidingTabDisplayerButtonUI.createUI(this));
}
 
Example 22
/**
 * Maps {@code AbstractButton.getUI()} through queue
 */
public ButtonUI getUI() {
    return (runMapping(new MapAction<ButtonUI>("getUI") {
        @Override
        public ButtonUI map() {
            return ((AbstractButton) getSource()).getUI();
        }
    }));
}
 
Example 23
/**
 * Maps {@code AbstractButton.setUI(ButtonUI)} through queue
 */
public void setUI(final ButtonUI buttonUI) {
    runMapping(new MapVoidAction("setUI") {
        @Override
        public void map() {
            ((AbstractButton) getSource()).setUI(buttonUI);
        }
    });
}
 
Example 24
void addTab(JOutlookBar tabs, String title) {
  JPanel panel = new JPanel();
  panel.setLayout(new PercentLayout(PercentLayout.VERTICAL, 0));
  panel.setOpaque(false);

  String[] buttons = new String[] {"Inbox", "icons/outlook-inbox.gif",
    "Outbox", "icons/outlook-outbox.gif", "Drafts", "icons/outlook-inbox.gif",
    "Templates", "icons/outlook-inbox.gif", "Deleted Items",
    "icons/outlook-trash.gif",};

  for (int i = 0, c = buttons.length; i < c; i += 2) {
    JButton button = new JButton(buttons[i]);
    try {
      button.setUI((ButtonUI)Class.forName(
        (String)UIManager.get("OutlookButtonUI")).newInstance());
    } catch (Exception e) {
      e.printStackTrace();
    }
    button.setIcon(new ImageIcon(OutlookBarMain.class
      .getResource(buttons[i + 1])));
    panel.add(button);
  }

  JScrollPane scroll = tabs.makeScrollPane(panel);
  tabs.addTab("", scroll);

  // this to test the UI gets notified of changes
  int index = tabs.indexOfComponent(scroll);
  tabs.setTitleAt(index, title);
  tabs.setToolTipTextAt(index, title + " Tooltip");
}
 
Example 25
Source Project: pumpernickel   Source File: TextSearchBar.java    License: MIT License 5 votes vote down vote up
/**
 * Sets the ButtonUI for all the non-checkbox buttons in this search bar.
 * 
 * @param ui
 *            the button UI to use for all non-checkbox buttons.
 */
public void setButtonUI(ButtonUI ui) {
	for (int a = 0; a < getComponentCount(); a++) {
		if (getComponent(a) instanceof JButton) {
			((JButton) getComponent(a)).setUI(ui);
		} else if (getComponent(a) instanceof JCheckBox) {
			// do nothing
		} else if (getComponent(a) instanceof JToggleButton) {
			((JToggleButton) getComponent(a)).setUI(ui);
		}
	}
	updateLayout(); // must update the UI of the close button correctly
}
 
Example 26
public void setUI( final ButtonUI ui ) {
  super.setUI( ui );

  if ( alignment != null ) {
    setAlignmentX( alignment );
  }
}
 
Example 27
Source Project: consulo   Source File: JBCheckBox.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets given icon to display between checkbox icon and text.
 *
 * @return true in case of success and false otherwise
 */
public boolean setTextIcon(@Nonnull Icon icon) {
  ButtonUI ui = getUI();
  if (ui instanceof BasicRadioButtonUI) {
    Icon defaultIcon = ((BasicRadioButtonUI) ui).getDefaultIcon();
    if (defaultIcon != null) {
      MergedIcon mergedIcon = new MergedIcon(defaultIcon, 10, icon);
      setIcon(mergedIcon);
      return true;
    }
  }
  return false;
}
 
Example 28
Source Project: consulo   Source File: StickyButton.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setUI(ButtonUI ui) {
  if (ui instanceof StickyButtonUI) {
    super.setUI(ui);
  } else {
    super.setUI(createUI());
  }
}
 
Example 29
public void addNotify() {
    super.addNotify();

    // Avoid the Auto toggle behavior of AWT CheckBoxMenuItem
    CCheckboxMenuItem ccb = (CCheckboxMenuItem) getPeer();
    ccb.setAutoToggle(false);

    fMenuItem.addComponentListener(this);
    fPropertyListener = new ScreenMenuPropertyListener(this);
    fMenuItem.addPropertyChangeListener(fPropertyListener);
    addActionListener(this);
    addItemListener(this);
    fMenuItem.addItemListener(this);
    setIndeterminate(IndeterminateListener.isIndeterminate(fMenuItem));

    // can't setState or setAccelerator or setIcon till we have a peer
    setAccelerator(fMenuItem.getAccelerator());

    final Icon icon = fMenuItem.getIcon();
    if (icon != null) {
        this.setIcon(icon);
    }

    final String tooltipText = fMenuItem.getToolTipText();
    if (tooltipText != null) {
        this.setToolTipText(tooltipText);
    }

    // sja fix is this needed?
    fMenuItem.addItemListener(this);

    final ButtonUI ui = fMenuItem.getUI();
    if (ui instanceof ScreenMenuItemUI) {
        ((ScreenMenuItemUI)ui).updateListenersForScreenMenuItem();
    }

    if (fMenuItem instanceof JCheckBoxMenuItem) {
        forceSetState(fMenuItem.isSelected());
    } else {
        forceSetState(fMenuItem.getModel().isSelected());
    }
}
 
Example 30
public void addNotify() {
    super.addNotify();

    // Avoid the Auto toggle behavior of AWT CheckBoxMenuItem
    CCheckboxMenuItem ccb = (CCheckboxMenuItem) getPeer();
    ccb.setAutoToggle(false);

    fMenuItem.addComponentListener(this);
    fPropertyListener = new ScreenMenuPropertyListener(this);
    fMenuItem.addPropertyChangeListener(fPropertyListener);
    addActionListener(this);
    addItemListener(this);
    fMenuItem.addItemListener(this);
    setIndeterminate(IndeterminateListener.isIndeterminate(fMenuItem));

    // can't setState or setAccelerator or setIcon till we have a peer
    setAccelerator(fMenuItem.getAccelerator());

    final Icon icon = fMenuItem.getIcon();
    if (icon != null) {
        this.setIcon(icon);
    }

    final String tooltipText = fMenuItem.getToolTipText();
    if (tooltipText != null) {
        this.setToolTipText(tooltipText);
    }

    // sja fix is this needed?
    fMenuItem.addItemListener(this);

    final ButtonUI ui = fMenuItem.getUI();
    if (ui instanceof ScreenMenuItemUI) {
        ((ScreenMenuItemUI)ui).updateListenersForScreenMenuItem();
    }

    if (fMenuItem instanceof JCheckBoxMenuItem) {
        forceSetState(fMenuItem.isSelected());
    } else {
        forceSetState(fMenuItem.getModel().isSelected());
    }
}