606 } // End class MenuItemCheckIcon
607
608 @SuppressWarnings("serial") // Same-version serialization only
609 private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
610 public void paintIcon(Component c, Graphics g, int x, int y) {
611 /* For debugging:
612 Color oldColor = g.getColor();
613 g.setColor(Color.green);
614 g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
615 g.setColor(oldColor);
616 */
617 }
618 public int getIconWidth() { return 4; }
619 public int getIconHeight() { return 8; }
620
621 } // End class MenuItemArrowIcon
622
623 @SuppressWarnings("serial") // Same-version serialization only
624 private static class MenuArrowIcon implements Icon, UIResource, Serializable {
625 public void paintIcon(Component c, Graphics g, int x, int y) {
626 if (WindowsMenuItemUI.isVistaPainting()) {
627 XPStyle xp = XPStyle.getXP();
628 State state = State.NORMAL;
629 if (c instanceof JMenuItem) {
630 state = ((JMenuItem) c).getModel().isEnabled()
631 ? State.NORMAL : State.DISABLED;
632 }
633 Skin skin = xp.getSkin(c, Part.MP_POPUPSUBMENU);
634 if (WindowsGraphicsUtils.isLeftToRight(c)) {
635 skin.paintSkin(g, x, y, state);
636 } else {
637 Graphics2D g2d = (Graphics2D)g.create();
638 g2d.translate(x + skin.getWidth(), y);
639 g2d.scale(-1, 1);
640 skin.paintSkin(g2d, 0, 0, state);
641 g2d.dispose();
642 }
643 } else {
644 g.translate(x,y);
645 if( WindowsGraphicsUtils.isLeftToRight(c) ) {
646 g.drawLine( 0, 0, 0, 7 );
647 g.drawLine( 1, 1, 1, 6 );
648 g.drawLine( 2, 2, 2, 5 );
649 g.drawLine( 3, 3, 3, 4 );
650 } else {
651 g.drawLine( 4, 0, 4, 7 );
652 g.drawLine( 3, 1, 3, 6 );
653 g.drawLine( 2, 2, 2, 5 );
654 g.drawLine( 1, 3, 1, 4 );
655 }
656 g.translate(-x,-y);
657 }
658 }
659 public int getIconWidth() {
660 if (WindowsMenuItemUI.isVistaPainting()) {
661 Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPSUBMENU);
662 return skin.getWidth();
663 } else {
664 return 4;
665 }
666 }
667 public int getIconHeight() {
668 if (WindowsMenuItemUI.isVistaPainting()) {
669 Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPSUBMENU);
670 return skin.getHeight();
671 } else {
672 return 8;
673 }
674 }
675 } // End class MenuArrowIcon
676
677 static class VistaMenuItemCheckIconFactory
678 implements MenuItemCheckIconFactory {
679 private static final int OFFSET = 3;
680
681 public Icon getIcon(JMenuItem component) {
682 return new VistaMenuItemCheckIcon(component);
683 }
684
685 public boolean isCompatible(Object icon, String prefix) {
686 return icon instanceof VistaMenuItemCheckIcon
687 && ((VistaMenuItemCheckIcon) icon).type == getType(prefix);
688 }
689
690 public Icon getIcon(String type) {
691 return new VistaMenuItemCheckIcon(type);
692 }
693
694 static int getIconWidth() {
695 return XPStyle.getXP().getSkin(null, Part.MP_POPUPCHECK).getWidth()
696 + 2 * OFFSET;
697 }
698
699 private static Class<? extends JMenuItem> getType(Component c) {
700 Class<? extends JMenuItem> rv = null;
701 if (c instanceof JCheckBoxMenuItem) {
702 rv = JCheckBoxMenuItem.class;
703 } else if (c instanceof JRadioButtonMenuItem) {
704 rv = JRadioButtonMenuItem.class;
705 } else if (c instanceof JMenu) {
706 rv = JMenu.class;
707 } else if (c instanceof JMenuItem) {
708 rv = JMenuItem.class;
709 }
710 return rv;
711 }
712
713 private static Class<? extends JMenuItem> getType(String type) {
714 Class<? extends JMenuItem> rv = null;
715 if (type == "CheckBoxMenuItem") {
739 private final JMenuItem menuItem;
740 private final Class<? extends JMenuItem> type;
741
742 VistaMenuItemCheckIcon(JMenuItem menuItem) {
743 this.type = getType(menuItem);
744 this.menuItem = menuItem;
745 }
746 VistaMenuItemCheckIcon(String type) {
747 this.type = getType(type);
748 this.menuItem = null;
749 }
750
751 public int getIconHeight() {
752 Icon lafIcon = getLaFIcon();
753 if (lafIcon != null) {
754 return lafIcon.getIconHeight();
755 }
756 Icon icon = getIcon();
757 int height = 0;
758 if (icon != null) {
759 height = icon.getIconHeight() + 2 * OFFSET;
760 } else {
761 Skin skin =
762 XPStyle.getXP().getSkin(null, Part.MP_POPUPCHECK);
763 height = skin.getHeight() + 2 * OFFSET;
764 }
765 return height;
766 }
767
768 public int getIconWidth() {
769 Icon lafIcon = getLaFIcon();
770 if (lafIcon != null) {
771 return lafIcon.getIconWidth();
772 }
773 Icon icon = getIcon();
774 int width = 0;
775 if (icon != null) {
776 width = icon.getIconWidth() + 2 * OFFSET;
777 } else {
778 width = VistaMenuItemCheckIconFactory.getIconWidth();
779 }
780 return width;
781 }
782
783 public void paintIcon(Component c, Graphics g, int x, int y) {
784 Icon lafIcon = getLaFIcon();
792 || type == JRadioButtonMenuItem.class) {
793 AbstractButton b = (AbstractButton) c;
794 if (b.isSelected()) {
795 Part backgroundPart = Part.MP_POPUPCHECKBACKGROUND;
796 Part part = Part.MP_POPUPCHECK;
797 State backgroundState;
798 State state;
799 if (isEnabled(c, null)) {
800 backgroundState =
801 (icon != null) ? State.BITMAP : State.NORMAL;
802 state = (type == JRadioButtonMenuItem.class)
803 ? State.BULLETNORMAL
804 : State.CHECKMARKNORMAL;
805 } else {
806 backgroundState = State.DISABLEDPUSHED;
807 state =
808 (type == JRadioButtonMenuItem.class)
809 ? State.BULLETDISABLED
810 : State.CHECKMARKDISABLED;
811 }
812 Skin skin;
813 XPStyle xp = XPStyle.getXP();
814 skin = xp.getSkin(c, backgroundPart);
815 skin.paintSkin(g, x, y,
816 getIconWidth(), getIconHeight(), backgroundState);
817 if (icon == null) {
818 skin = xp.getSkin(c, part);
819 skin.paintSkin(g, x + OFFSET, y + OFFSET, state);
820 }
821 }
822 }
823 if (icon != null) {
824 icon.paintIcon(c, g, x + OFFSET, y + OFFSET);
825 }
826 }
827 private static WindowsMenuItemUIAccessor getAccessor(
828 JMenuItem menuItem) {
829 WindowsMenuItemUIAccessor rv = null;
830 ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
831 : null;
832 if (uiObject instanceof WindowsMenuItemUI) {
833 rv = ((WindowsMenuItemUI) uiObject).accessor;
834 } else if (uiObject instanceof WindowsMenuUI) {
835 rv = ((WindowsMenuUI) uiObject).accessor;
836 } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
837 rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
838 } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
839 rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
|
606 } // End class MenuItemCheckIcon
607
608 @SuppressWarnings("serial") // Same-version serialization only
609 private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
610 public void paintIcon(Component c, Graphics g, int x, int y) {
611 /* For debugging:
612 Color oldColor = g.getColor();
613 g.setColor(Color.green);
614 g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
615 g.setColor(oldColor);
616 */
617 }
618 public int getIconWidth() { return 4; }
619 public int getIconHeight() { return 8; }
620
621 } // End class MenuItemArrowIcon
622
623 @SuppressWarnings("serial") // Same-version serialization only
624 private static class MenuArrowIcon implements Icon, UIResource, Serializable {
625 public void paintIcon(Component c, Graphics g, int x, int y) {
626 XPStyle xp = XPStyle.getXP();
627 if (xp != null && WindowsMenuItemUI.isVistaPainting()) {
628 State state = State.NORMAL;
629 if (c instanceof JMenuItem) {
630 state = ((JMenuItem) c).getModel().isEnabled()
631 ? State.NORMAL : State.DISABLED;
632 }
633 Skin skin = xp.getSkin(c, Part.MP_POPUPSUBMENU);
634 if (WindowsGraphicsUtils.isLeftToRight(c)) {
635 skin.paintSkin(g, x, y, state);
636 } else {
637 Graphics2D g2d = (Graphics2D)g.create();
638 g2d.translate(x + skin.getWidth(), y);
639 g2d.scale(-1, 1);
640 skin.paintSkin(g2d, 0, 0, state);
641 g2d.dispose();
642 }
643 } else {
644 g.translate(x,y);
645 if( WindowsGraphicsUtils.isLeftToRight(c) ) {
646 g.drawLine( 0, 0, 0, 7 );
647 g.drawLine( 1, 1, 1, 6 );
648 g.drawLine( 2, 2, 2, 5 );
649 g.drawLine( 3, 3, 3, 4 );
650 } else {
651 g.drawLine( 4, 0, 4, 7 );
652 g.drawLine( 3, 1, 3, 6 );
653 g.drawLine( 2, 2, 2, 5 );
654 g.drawLine( 1, 3, 1, 4 );
655 }
656 g.translate(-x,-y);
657 }
658 }
659 public int getIconWidth() {
660 XPStyle xp = XPStyle.getXP();
661 if (xp != null && WindowsMenuItemUI.isVistaPainting()) {
662 Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU);
663 return skin.getWidth();
664 } else {
665 return 4;
666 }
667 }
668 public int getIconHeight() {
669 XPStyle xp = XPStyle.getXP();
670 if (xp != null && WindowsMenuItemUI.isVistaPainting()) {
671 Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU);
672 return skin.getHeight();
673 } else {
674 return 8;
675 }
676 }
677 } // End class MenuArrowIcon
678
679 static class VistaMenuItemCheckIconFactory
680 implements MenuItemCheckIconFactory {
681 private static final int OFFSET = 3;
682
683 public Icon getIcon(JMenuItem component) {
684 return new VistaMenuItemCheckIcon(component);
685 }
686
687 public boolean isCompatible(Object icon, String prefix) {
688 return icon instanceof VistaMenuItemCheckIcon
689 && ((VistaMenuItemCheckIcon) icon).type == getType(prefix);
690 }
691
692 public Icon getIcon(String type) {
693 return new VistaMenuItemCheckIcon(type);
694 }
695
696 static int getIconWidth() {
697 XPStyle xp = XPStyle.getXP();
698 return ((xp != null) ? xp.getSkin(null, Part.MP_POPUPCHECK).getWidth() : 16)
699 + 2 * OFFSET;
700 }
701
702 private static Class<? extends JMenuItem> getType(Component c) {
703 Class<? extends JMenuItem> rv = null;
704 if (c instanceof JCheckBoxMenuItem) {
705 rv = JCheckBoxMenuItem.class;
706 } else if (c instanceof JRadioButtonMenuItem) {
707 rv = JRadioButtonMenuItem.class;
708 } else if (c instanceof JMenu) {
709 rv = JMenu.class;
710 } else if (c instanceof JMenuItem) {
711 rv = JMenuItem.class;
712 }
713 return rv;
714 }
715
716 private static Class<? extends JMenuItem> getType(String type) {
717 Class<? extends JMenuItem> rv = null;
718 if (type == "CheckBoxMenuItem") {
742 private final JMenuItem menuItem;
743 private final Class<? extends JMenuItem> type;
744
745 VistaMenuItemCheckIcon(JMenuItem menuItem) {
746 this.type = getType(menuItem);
747 this.menuItem = menuItem;
748 }
749 VistaMenuItemCheckIcon(String type) {
750 this.type = getType(type);
751 this.menuItem = null;
752 }
753
754 public int getIconHeight() {
755 Icon lafIcon = getLaFIcon();
756 if (lafIcon != null) {
757 return lafIcon.getIconHeight();
758 }
759 Icon icon = getIcon();
760 int height = 0;
761 if (icon != null) {
762 height = icon.getIconHeight();
763 } else {
764 XPStyle xp = XPStyle.getXP();
765 if (xp != null) {
766 Skin skin = xp.getSkin(null, Part.MP_POPUPCHECK);
767 height = skin.getHeight();
768 } else {
769 height = 16;
770 }
771 }
772 height += 2 * OFFSET;
773 return height;
774 }
775
776 public int getIconWidth() {
777 Icon lafIcon = getLaFIcon();
778 if (lafIcon != null) {
779 return lafIcon.getIconWidth();
780 }
781 Icon icon = getIcon();
782 int width = 0;
783 if (icon != null) {
784 width = icon.getIconWidth() + 2 * OFFSET;
785 } else {
786 width = VistaMenuItemCheckIconFactory.getIconWidth();
787 }
788 return width;
789 }
790
791 public void paintIcon(Component c, Graphics g, int x, int y) {
792 Icon lafIcon = getLaFIcon();
800 || type == JRadioButtonMenuItem.class) {
801 AbstractButton b = (AbstractButton) c;
802 if (b.isSelected()) {
803 Part backgroundPart = Part.MP_POPUPCHECKBACKGROUND;
804 Part part = Part.MP_POPUPCHECK;
805 State backgroundState;
806 State state;
807 if (isEnabled(c, null)) {
808 backgroundState =
809 (icon != null) ? State.BITMAP : State.NORMAL;
810 state = (type == JRadioButtonMenuItem.class)
811 ? State.BULLETNORMAL
812 : State.CHECKMARKNORMAL;
813 } else {
814 backgroundState = State.DISABLEDPUSHED;
815 state =
816 (type == JRadioButtonMenuItem.class)
817 ? State.BULLETDISABLED
818 : State.CHECKMARKDISABLED;
819 }
820 XPStyle xp = XPStyle.getXP();
821 if (xp != null) {
822 Skin skin;
823 skin = xp.getSkin(c, backgroundPart);
824 skin.paintSkin(g, x, y,
825 getIconWidth(), getIconHeight(), backgroundState);
826 if (icon == null) {
827 skin = xp.getSkin(c, part);
828 skin.paintSkin(g, x + OFFSET, y + OFFSET, state);
829 }
830 }
831 }
832 }
833 if (icon != null) {
834 icon.paintIcon(c, g, x + OFFSET, y + OFFSET);
835 }
836 }
837 private static WindowsMenuItemUIAccessor getAccessor(
838 JMenuItem menuItem) {
839 WindowsMenuItemUIAccessor rv = null;
840 ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
841 : null;
842 if (uiObject instanceof WindowsMenuItemUI) {
843 rv = ((WindowsMenuItemUI) uiObject).accessor;
844 } else if (uiObject instanceof WindowsMenuUI) {
845 rv = ((WindowsMenuUI) uiObject).accessor;
846 } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
847 rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
848 } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
849 rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
|