1 /*
2 * Copyright (c) 1997, 2018, 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
699 MenuItemLayoutHelper.LayoutResult lr,
700 Color holdc, Color foreground) {
701 if (lh.getCheckIcon() != null) {
702 ButtonModel model = lh.getMenuItem().getModel();
703 if (model.isArmed() || (lh.getMenuItem() instanceof JMenu
704 && model.isSelected())) {
705 g.setColor(foreground);
706 } else {
707 g.setColor(holdc);
708 }
709 if (lh.useCheckAndArrow()) {
710 lh.getCheckIcon().paintIcon(lh.getMenuItem(), g,
711 lr.getCheckRect().x, lr.getCheckRect().y);
712 }
713 g.setColor(holdc);
714 }
715 }
716
717 private void paintAccText(Graphics g, MenuItemLayoutHelper lh,
718 MenuItemLayoutHelper.LayoutResult lr) {
719 if (!lh.getAccText().equals("")) {
720 ButtonModel model = lh.getMenuItem().getModel();
721 g.setFont(lh.getAccFontMetrics().getFont());
722 if (!model.isEnabled()) {
723 // *** paint the accText disabled
724 if (disabledForeground != null) {
725 g.setColor(disabledForeground);
726 SwingUtilities2.drawString(lh.getMenuItem(), g,
727 lh.getAccText(), lr.getAccRect().x,
728 lr.getAccRect().y + lh.getAccFontMetrics().getAscent());
729 } else {
730 g.setColor(lh.getMenuItem().getBackground().brighter());
731 SwingUtilities2.drawString(lh.getMenuItem(), g,
732 lh.getAccText(), lr.getAccRect().x,
733 lr.getAccRect().y + lh.getAccFontMetrics().getAscent());
734 g.setColor(lh.getMenuItem().getBackground().darker());
735 SwingUtilities2.drawString(lh.getMenuItem(), g,
736 lh.getAccText(), lr.getAccRect().x - 1,
737 lr.getAccRect().y + lh.getFontMetrics().getAscent() - 1);
738 }
739 } else {
740 // *** paint the accText normally
741 if (model.isArmed()
742 || (lh.getMenuItem() instanceof JMenu
743 && model.isSelected())) {
744 g.setColor(acceleratorSelectionForeground);
745 } else {
746 g.setColor(acceleratorForeground);
747 }
748 SwingUtilities2.drawString(lh.getMenuItem(), g, lh.getAccText(),
749 lr.getAccRect().x, lr.getAccRect().y +
750 lh.getAccFontMetrics().getAscent());
751 }
752 }
753 }
754
755 private void paintText(Graphics g, MenuItemLayoutHelper lh,
756 MenuItemLayoutHelper.LayoutResult lr) {
757 if (!lh.getText().equals("")) {
758 if (lh.getHtmlView() != null) {
759 // Text is HTML
760 lh.getHtmlView().paint(g, lr.getTextRect());
761 } else {
762 // Text isn't HTML
763 paintText(g, lh.getMenuItem(), lr.getTextRect(), lh.getText());
764 }
765 }
766 }
767
768 private void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh,
769 MenuItemLayoutHelper.LayoutResult lr,
770 Color foreground) {
771 if (lh.getArrowIcon() != null) {
772 ButtonModel model = lh.getMenuItem().getModel();
773 if (model.isArmed() || (lh.getMenuItem() instanceof JMenu
774 && model.isSelected())) {
775 g.setColor(foreground);
776 }
777 if (lh.useCheckAndArrow()) {
|
1 /*
2 * Copyright (c) 1997, 2019, 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
699 MenuItemLayoutHelper.LayoutResult lr,
700 Color holdc, Color foreground) {
701 if (lh.getCheckIcon() != null) {
702 ButtonModel model = lh.getMenuItem().getModel();
703 if (model.isArmed() || (lh.getMenuItem() instanceof JMenu
704 && model.isSelected())) {
705 g.setColor(foreground);
706 } else {
707 g.setColor(holdc);
708 }
709 if (lh.useCheckAndArrow()) {
710 lh.getCheckIcon().paintIcon(lh.getMenuItem(), g,
711 lr.getCheckRect().x, lr.getCheckRect().y);
712 }
713 g.setColor(holdc);
714 }
715 }
716
717 private void paintAccText(Graphics g, MenuItemLayoutHelper lh,
718 MenuItemLayoutHelper.LayoutResult lr) {
719 if (!lh.getAccText().isEmpty()) {
720 ButtonModel model = lh.getMenuItem().getModel();
721 g.setFont(lh.getAccFontMetrics().getFont());
722 if (!model.isEnabled()) {
723 // *** paint the accText disabled
724 if (disabledForeground != null) {
725 g.setColor(disabledForeground);
726 SwingUtilities2.drawString(lh.getMenuItem(), g,
727 lh.getAccText(), lr.getAccRect().x,
728 lr.getAccRect().y + lh.getAccFontMetrics().getAscent());
729 } else {
730 g.setColor(lh.getMenuItem().getBackground().brighter());
731 SwingUtilities2.drawString(lh.getMenuItem(), g,
732 lh.getAccText(), lr.getAccRect().x,
733 lr.getAccRect().y + lh.getAccFontMetrics().getAscent());
734 g.setColor(lh.getMenuItem().getBackground().darker());
735 SwingUtilities2.drawString(lh.getMenuItem(), g,
736 lh.getAccText(), lr.getAccRect().x - 1,
737 lr.getAccRect().y + lh.getFontMetrics().getAscent() - 1);
738 }
739 } else {
740 // *** paint the accText normally
741 if (model.isArmed()
742 || (lh.getMenuItem() instanceof JMenu
743 && model.isSelected())) {
744 g.setColor(acceleratorSelectionForeground);
745 } else {
746 g.setColor(acceleratorForeground);
747 }
748 SwingUtilities2.drawString(lh.getMenuItem(), g, lh.getAccText(),
749 lr.getAccRect().x, lr.getAccRect().y +
750 lh.getAccFontMetrics().getAscent());
751 }
752 }
753 }
754
755 private void paintText(Graphics g, MenuItemLayoutHelper lh,
756 MenuItemLayoutHelper.LayoutResult lr) {
757 if (!lh.getText().isEmpty()) {
758 if (lh.getHtmlView() != null) {
759 // Text is HTML
760 lh.getHtmlView().paint(g, lr.getTextRect());
761 } else {
762 // Text isn't HTML
763 paintText(g, lh.getMenuItem(), lr.getTextRect(), lh.getText());
764 }
765 }
766 }
767
768 private void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh,
769 MenuItemLayoutHelper.LayoutResult lr,
770 Color foreground) {
771 if (lh.getArrowIcon() != null) {
772 ButtonModel model = lh.getMenuItem().getModel();
773 if (model.isArmed() || (lh.getMenuItem() instanceof JMenu
774 && model.isSelected())) {
775 g.setColor(foreground);
776 }
777 if (lh.useCheckAndArrow()) {
|