ch.randelshofer.quaqua.QuaquaMenuItemUI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Quaqua Show documentation
Show all versions of Quaqua Show documentation
A Mavenisation of the Quaqua Mac OSX Swing Look and Feel (Java library)
Quaqua Look and Feel (C) 2003-2010, Werner Randelshofer.
Mavenisation by Matt Gumbley, DevZendo.org - for problems with
Mavenisation, see Matt; for issues with Quaqua, see the Quaqua home page.
For full license details, see http://randelshofer.ch/quaqua/license.html
The newest version!
/*
* @(#)QuaquaMenuItemUI.java
*
* Copyright (c) 2003-2010 Werner Randelshofer, Immensee, Switzerland.
* All rights reserved.
*
* You may not use, copy or modify this file, except in compliance with the
* license agreement you entered into with Werner Randelshofer.
* For details see accompanying license terms.
*/
package ch.randelshofer.quaqua;
import ch.randelshofer.quaqua.border.BackgroundBorder;
import ch.randelshofer.quaqua.color.PaintableColor;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
/**
* A replacement for the AquaMenuItemUI.
*
* This class provides the following workarounds for issues in Apple's
* implementation of the Aqua Look and Feel in Java 1.4.1:
*
* - MenuItems are highlighted with a blue background color and white text and
* accelerator instead of higlighting with a striped background, white text and black
* accelerator.
*
* - Menu item accelerators use character symbols instead of writing "Meta",
* "Delete" or "Backspace".
*
*
*
* @author Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland
* @version $Id: QuaquaMenuItemUI.java 361 2010-11-21 11:19:20Z wrandelshofer $
*/
public class QuaquaMenuItemUI extends BasicMenuItemUI
implements QuaquaMenuPainterClient {
boolean fIsScreenMenuItem = false;
int fType;
static final int kPlain = 0;
static final int kCheckBox = 1;
static final int kRadioButton = 2;
static final String[] sPropertyPrefixes = {"MenuItem", "CheckBoxMenuItem", "RadioButtonMenuItem"};
// BasicMenuUI also uses this.
//Handler handler;
QuaquaMenuItemUI(int type) {
fType = type;
}
public static ComponentUI createUI(JComponent jcomponent) {
int i = 0;
if (jcomponent instanceof JCheckBoxMenuItem) {
i = 1;
} else if (jcomponent instanceof JRadioButtonMenuItem) {
i = 2;
}
return new QuaquaMenuItemUI(i);
}
protected String getPropertyPrefix() {
return sPropertyPrefixes[fType];
}
/*
protected void installListeners() {
if ((mouseInputListener = createMouseInputListener(menuItem)) != null) {
menuItem.addMouseListener(mouseInputListener);
menuItem.addMouseMotionListener(mouseInputListener);
}
if ((menuDragMouseListener = createMenuDragMouseListener(menuItem)) != null) {
menuItem.addMenuDragMouseListener(menuDragMouseListener);
}
if ((menuKeyListener = createMenuKeyListener(menuItem)) != null) {
menuItem.addMenuKeyListener(menuKeyListener);
if (menuKeyListener instanceof PropertyChangeListener) {
menuItem.addPropertyChangeListener((PropertyChangeListener) menuKeyListener);
}
}
}*/
protected void updateListenersForScreenMenuItem() {
setIsScreenMenu(true);
}
protected void setIsScreenMenu(boolean bool) {
if (fIsScreenMenuItem != bool) {
fIsScreenMenuItem = bool;
if (fIsScreenMenuItem) {
removeListeners();
} else {
addListeners();
}
}
}
protected void removeListeners() {
//menuItem.removeMouseListener(getHandler());
//menuItem.removeMouseMotionListener(getHandler());
//menuItem.removeMenuDragMouseListener(getHandler());
menuItem.removeMouseListener(mouseInputListener);
menuItem.removeMouseMotionListener(mouseInputListener);
menuItem.removeMenuDragMouseListener(menuDragMouseListener);
}
protected void addListeners() {
menuItem.addMouseListener(mouseInputListener);
menuItem.addMouseMotionListener(mouseInputListener);
menuItem.addMenuDragMouseListener(menuDragMouseListener);
}
protected void paintMenuItem(Graphics g, JComponent c,
Icon checkIcon, Icon arrowIcon, Color background,
Color foreground, int defaultTextIconGap) {
QuaquaMenuPainter.getInstance().paintMenuItem(this, g, c, checkIcon,
arrowIcon, background, foreground,
disabledForeground,
selectionForeground, defaultTextIconGap,
acceleratorFont);
}
protected Dimension getPreferredMenuItemSize(JComponent c,
Icon checkIcon,
Icon arrowIcon,
int defaultTextIconGap) {
return QuaquaMenuPainter.getInstance().getPreferredMenuItemSize(c, checkIcon, arrowIcon, defaultTextIconGap, acceleratorFont);
}
public void update(Graphics graphics, JComponent jcomponent) {
this.paint(graphics, jcomponent);
}
public void paintBackground(Graphics g, JComponent component, int menuWidth, int menuHeight) {
Color bgColor = selectionBackground;
AbstractButton menuItem = (AbstractButton) component;
ButtonModel model = menuItem.getModel();
Color oldColor = g.getColor();
if (menuItem.isOpaque()) {
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
//g.setColor(bgColor);
((Graphics2D) g).setPaint(PaintableColor.getPaint(bgColor, component));
g.fillRect(0, 0, menuWidth, menuHeight);
} else {
//g.setColor(menuItem.getBackground());
((Graphics2D) g).setPaint(PaintableColor.getPaint(menuItem.getBackground(), component));
g.fillRect(0, 0, menuWidth, menuHeight);
}
g.setColor(oldColor);
}
/*
if (component.getBorder() instanceof BackgroundBorder) {
Border b = ((BackgroundBorder) component.getBorder()).getBackgroundBorder();
b.paintBorder(component, g, 0, 0, component.getWidth(), component.getHeight());
}*/
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy