1 /*
2 * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
596 public int getIconHeight() { return 9; }
597
598 } // End class MenuItemCheckIcon
599
600 private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
601 public void paintIcon(Component c, Graphics g, int x, int y) {
602 /* For debugging:
603 Color oldColor = g.getColor();
604 g.setColor(Color.green);
605 g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
606 g.setColor(oldColor);
607 */
608 }
609 public int getIconWidth() { return 4; }
610 public int getIconHeight() { return 8; }
611
612 } // End class MenuItemArrowIcon
613
614 private static class MenuArrowIcon implements Icon, UIResource, Serializable {
615 public void paintIcon(Component c, Graphics g, int x, int y) {
616 if (WindowsMenuItemUI.isVistaPainting()) {
617 XPStyle xp = XPStyle.getXP();
618 State state = State.NORMAL;
619 if (c instanceof JMenuItem) {
620 state = ((JMenuItem) c).getModel().isEnabled()
621 ? State.NORMAL : State.DISABLED;
622 }
623 Skin skin = xp.getSkin(c, Part.MP_POPUPSUBMENU);
624 if (WindowsGraphicsUtils.isLeftToRight(c)) {
625 skin.paintSkin(g, x, y, state);
626 } else {
627 Graphics2D g2d = (Graphics2D)g.create();
628 g2d.translate(x + skin.getWidth(), y);
629 g2d.scale(-1, 1);
630 skin.paintSkin(g2d, 0, 0, state);
631 g2d.dispose();
632 }
633 } else {
634 g.translate(x,y);
635 if( WindowsGraphicsUtils.isLeftToRight(c) ) {
636 g.drawLine( 0, 0, 0, 7 );
637 g.drawLine( 1, 1, 1, 6 );
638 g.drawLine( 2, 2, 2, 5 );
639 g.drawLine( 3, 3, 3, 4 );
640 } else {
641 g.drawLine( 4, 0, 4, 7 );
642 g.drawLine( 3, 1, 3, 6 );
643 g.drawLine( 2, 2, 2, 5 );
644 g.drawLine( 1, 3, 1, 4 );
645 }
646 g.translate(-x,-y);
647 }
648 }
649 public int getIconWidth() {
650 if (WindowsMenuItemUI.isVistaPainting()) {
651 Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPSUBMENU);
652 return skin.getWidth();
653 } else {
654 return 4;
655 }
656 }
657 public int getIconHeight() {
658 if (WindowsMenuItemUI.isVistaPainting()) {
659 Skin skin = XPStyle.getXP().getSkin(null, Part.MP_POPUPSUBMENU);
660 return skin.getHeight();
661 } else {
662 return 8;
663 }
664 }
665 } // End class MenuArrowIcon
666
667 static class VistaMenuItemCheckIconFactory
668 implements MenuItemCheckIconFactory {
669 private static final int OFFSET = 3;
670
671 public Icon getIcon(JMenuItem component) {
672 return new VistaMenuItemCheckIcon(component);
673 }
674
675 public boolean isCompatible(Object icon, String prefix) {
676 return icon instanceof VistaMenuItemCheckIcon
677 && ((VistaMenuItemCheckIcon) icon).type == getType(prefix);
678 }
679
680 public Icon getIcon(String type) {
681 return new VistaMenuItemCheckIcon(type);
682 }
683
684 static int getIconWidth() {
685 return XPStyle.getXP().getSkin(null, Part.MP_POPUPCHECK).getWidth()
686 + 2 * OFFSET;
687 }
688
689 private static Class<? extends JMenuItem> getType(Component c) {
690 Class<? extends JMenuItem> rv = null;
691 if (c instanceof JCheckBoxMenuItem) {
692 rv = JCheckBoxMenuItem.class;
693 } else if (c instanceof JRadioButtonMenuItem) {
694 rv = JRadioButtonMenuItem.class;
695 } else if (c instanceof JMenu) {
696 rv = JMenu.class;
697 } else if (c instanceof JMenuItem) {
698 rv = JMenuItem.class;
699 }
700 return rv;
701 }
702
703 private static Class<? extends JMenuItem> getType(String type) {
704 Class<? extends JMenuItem> rv = null;
705 if (type == "CheckBoxMenuItem") {
728 private final JMenuItem menuItem;
729 private final Class<? extends JMenuItem> type;
730
731 VistaMenuItemCheckIcon(JMenuItem menuItem) {
732 this.type = getType(menuItem);
733 this.menuItem = menuItem;
734 }
735 VistaMenuItemCheckIcon(String type) {
736 this.type = getType(type);
737 this.menuItem = null;
738 }
739
740 public int getIconHeight() {
741 Icon lafIcon = getLaFIcon();
742 if (lafIcon != null) {
743 return lafIcon.getIconHeight();
744 }
745 Icon icon = getIcon();
746 int height = 0;
747 if (icon != null) {
748 height = icon.getIconHeight() + 2 * OFFSET;
749 } else {
750 Skin skin =
751 XPStyle.getXP().getSkin(null, Part.MP_POPUPCHECK);
752 height = skin.getHeight() + 2 * OFFSET;
753 }
754 return height;
755 }
756
757 public int getIconWidth() {
758 Icon lafIcon = getLaFIcon();
759 if (lafIcon != null) {
760 return lafIcon.getIconWidth();
761 }
762 Icon icon = getIcon();
763 int width = 0;
764 if (icon != null) {
765 width = icon.getIconWidth() + 2 * OFFSET;
766 } else {
767 width = VistaMenuItemCheckIconFactory.getIconWidth();
768 }
769 return width;
770 }
771
772 public void paintIcon(Component c, Graphics g, int x, int y) {
773 Icon lafIcon = getLaFIcon();
781 || type == JRadioButtonMenuItem.class) {
782 AbstractButton b = (AbstractButton) c;
783 if (b.isSelected()) {
784 Part backgroundPart = Part.MP_POPUPCHECKBACKGROUND;
785 Part part = Part.MP_POPUPCHECK;
786 State backgroundState;
787 State state;
788 if (isEnabled(c, null)) {
789 backgroundState =
790 (icon != null) ? State.BITMAP : State.NORMAL;
791 state = (type == JRadioButtonMenuItem.class)
792 ? State.BULLETNORMAL
793 : State.CHECKMARKNORMAL;
794 } else {
795 backgroundState = State.DISABLEDPUSHED;
796 state =
797 (type == JRadioButtonMenuItem.class)
798 ? State.BULLETDISABLED
799 : State.CHECKMARKDISABLED;
800 }
801 Skin skin;
802 XPStyle xp = XPStyle.getXP();
803 skin = xp.getSkin(c, backgroundPart);
804 skin.paintSkin(g, x, y,
805 getIconWidth(), getIconHeight(), backgroundState);
806 if (icon == null) {
807 skin = xp.getSkin(c, part);
808 skin.paintSkin(g, x + OFFSET, y + OFFSET, state);
809 }
810 }
811 }
812 if (icon != null) {
813 icon.paintIcon(c, g, x + OFFSET, y + OFFSET);
814 }
815 }
816 private static WindowsMenuItemUIAccessor getAccessor(
817 JMenuItem menuItem) {
818 WindowsMenuItemUIAccessor rv = null;
819 ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
820 : null;
821 if (uiObject instanceof WindowsMenuItemUI) {
822 rv = ((WindowsMenuItemUI) uiObject).accessor;
823 } else if (uiObject instanceof WindowsMenuUI) {
824 rv = ((WindowsMenuUI) uiObject).accessor;
825 } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
826 rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
827 } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
828 rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
|
1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
596 public int getIconHeight() { return 9; }
597
598 } // End class MenuItemCheckIcon
599
600 private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
601 public void paintIcon(Component c, Graphics g, int x, int y) {
602 /* For debugging:
603 Color oldColor = g.getColor();
604 g.setColor(Color.green);
605 g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
606 g.setColor(oldColor);
607 */
608 }
609 public int getIconWidth() { return 4; }
610 public int getIconHeight() { return 8; }
611
612 } // End class MenuItemArrowIcon
613
614 private static class MenuArrowIcon implements Icon, UIResource, Serializable {
615 public void paintIcon(Component c, Graphics g, int x, int y) {
616 XPStyle xp = XPStyle.getXP();
617 if (WindowsMenuItemUI.isVistaPainting(xp)) {
618 State state = State.NORMAL;
619 if (c instanceof JMenuItem) {
620 state = ((JMenuItem) c).getModel().isEnabled()
621 ? State.NORMAL : State.DISABLED;
622 }
623 Skin skin = xp.getSkin(c, Part.MP_POPUPSUBMENU);
624 if (WindowsGraphicsUtils.isLeftToRight(c)) {
625 skin.paintSkin(g, x, y, state);
626 } else {
627 Graphics2D g2d = (Graphics2D)g.create();
628 g2d.translate(x + skin.getWidth(), y);
629 g2d.scale(-1, 1);
630 skin.paintSkin(g2d, 0, 0, state);
631 g2d.dispose();
632 }
633 } else {
634 g.translate(x,y);
635 if( WindowsGraphicsUtils.isLeftToRight(c) ) {
636 g.drawLine( 0, 0, 0, 7 );
637 g.drawLine( 1, 1, 1, 6 );
638 g.drawLine( 2, 2, 2, 5 );
639 g.drawLine( 3, 3, 3, 4 );
640 } else {
641 g.drawLine( 4, 0, 4, 7 );
642 g.drawLine( 3, 1, 3, 6 );
643 g.drawLine( 2, 2, 2, 5 );
644 g.drawLine( 1, 3, 1, 4 );
645 }
646 g.translate(-x,-y);
647 }
648 }
649 public int getIconWidth() {
650 XPStyle xp = XPStyle.getXP();
651 if (WindowsMenuItemUI.isVistaPainting(xp)) {
652 Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU);
653 return skin.getWidth();
654 } else {
655 return 4;
656 }
657 }
658 public int getIconHeight() {
659 XPStyle xp = XPStyle.getXP();
660 if (WindowsMenuItemUI.isVistaPainting(xp)) {
661 Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU);
662 return skin.getHeight();
663 } else {
664 return 8;
665 }
666 }
667 } // End class MenuArrowIcon
668
669 static class VistaMenuItemCheckIconFactory
670 implements MenuItemCheckIconFactory {
671 private static final int OFFSET = 3;
672
673 public Icon getIcon(JMenuItem component) {
674 return new VistaMenuItemCheckIcon(component);
675 }
676
677 public boolean isCompatible(Object icon, String prefix) {
678 return icon instanceof VistaMenuItemCheckIcon
679 && ((VistaMenuItemCheckIcon) icon).type == getType(prefix);
680 }
681
682 public Icon getIcon(String type) {
683 return new VistaMenuItemCheckIcon(type);
684 }
685
686 static int getIconWidth() {
687 XPStyle xp = XPStyle.getXP();
688 return ((xp != null) ? xp.getSkin(null, Part.MP_POPUPCHECK).getWidth() : 16)
689 + 2 * OFFSET;
690 }
691
692 private static Class<? extends JMenuItem> getType(Component c) {
693 Class<? extends JMenuItem> rv = null;
694 if (c instanceof JCheckBoxMenuItem) {
695 rv = JCheckBoxMenuItem.class;
696 } else if (c instanceof JRadioButtonMenuItem) {
697 rv = JRadioButtonMenuItem.class;
698 } else if (c instanceof JMenu) {
699 rv = JMenu.class;
700 } else if (c instanceof JMenuItem) {
701 rv = JMenuItem.class;
702 }
703 return rv;
704 }
705
706 private static Class<? extends JMenuItem> getType(String type) {
707 Class<? extends JMenuItem> rv = null;
708 if (type == "CheckBoxMenuItem") {
731 private final JMenuItem menuItem;
732 private final Class<? extends JMenuItem> type;
733
734 VistaMenuItemCheckIcon(JMenuItem menuItem) {
735 this.type = getType(menuItem);
736 this.menuItem = menuItem;
737 }
738 VistaMenuItemCheckIcon(String type) {
739 this.type = getType(type);
740 this.menuItem = null;
741 }
742
743 public int getIconHeight() {
744 Icon lafIcon = getLaFIcon();
745 if (lafIcon != null) {
746 return lafIcon.getIconHeight();
747 }
748 Icon icon = getIcon();
749 int height = 0;
750 if (icon != null) {
751 height = icon.getIconHeight();
752 } else {
753 XPStyle xp = XPStyle.getXP();
754 if (xp != null) {
755 Skin skin = xp.getSkin(null, Part.MP_POPUPCHECK);
756 height = skin.getHeight();
757 } else {
758 height = 16;
759 }
760 }
761 height += 2 * OFFSET;
762 return height;
763 }
764
765 public int getIconWidth() {
766 Icon lafIcon = getLaFIcon();
767 if (lafIcon != null) {
768 return lafIcon.getIconWidth();
769 }
770 Icon icon = getIcon();
771 int width = 0;
772 if (icon != null) {
773 width = icon.getIconWidth() + 2 * OFFSET;
774 } else {
775 width = VistaMenuItemCheckIconFactory.getIconWidth();
776 }
777 return width;
778 }
779
780 public void paintIcon(Component c, Graphics g, int x, int y) {
781 Icon lafIcon = getLaFIcon();
789 || type == JRadioButtonMenuItem.class) {
790 AbstractButton b = (AbstractButton) c;
791 if (b.isSelected()) {
792 Part backgroundPart = Part.MP_POPUPCHECKBACKGROUND;
793 Part part = Part.MP_POPUPCHECK;
794 State backgroundState;
795 State state;
796 if (isEnabled(c, null)) {
797 backgroundState =
798 (icon != null) ? State.BITMAP : State.NORMAL;
799 state = (type == JRadioButtonMenuItem.class)
800 ? State.BULLETNORMAL
801 : State.CHECKMARKNORMAL;
802 } else {
803 backgroundState = State.DISABLEDPUSHED;
804 state =
805 (type == JRadioButtonMenuItem.class)
806 ? State.BULLETDISABLED
807 : State.CHECKMARKDISABLED;
808 }
809 XPStyle xp = XPStyle.getXP();
810 if (xp != null) {
811 Skin skin;
812 skin = xp.getSkin(c, backgroundPart);
813 skin.paintSkin(g, x, y,
814 getIconWidth(), getIconHeight(), backgroundState);
815 if (icon == null) {
816 skin = xp.getSkin(c, part);
817 skin.paintSkin(g, x + OFFSET, y + OFFSET, state);
818 }
819 }
820 }
821 }
822 if (icon != null) {
823 icon.paintIcon(c, g, x + OFFSET, y + OFFSET);
824 }
825 }
826 private static WindowsMenuItemUIAccessor getAccessor(
827 JMenuItem menuItem) {
828 WindowsMenuItemUIAccessor rv = null;
829 ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
830 : null;
831 if (uiObject instanceof WindowsMenuItemUI) {
832 rv = ((WindowsMenuItemUI) uiObject).accessor;
833 } else if (uiObject instanceof WindowsMenuUI) {
834 rv = ((WindowsMenuUI) uiObject).accessor;
835 } else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
836 rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
837 } else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
838 rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
|