11/*
2- * Copyright (c) 1997, 2021 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1997, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2525
2626package javax .swing .plaf .basic ;
2727
28- import java .awt .*;
29- import java .awt .event .*;
28+ import java .awt .Color ;
29+ import java .awt .Component ;
30+ import java .awt .Dimension ;
31+ import java .awt .Font ;
32+ import java .awt .FontMetrics ;
33+ import java .awt .Graphics ;
34+ import java .awt .Insets ;
35+ import java .awt .Point ;
36+ import java .awt .Rectangle ;
37+ import java .awt .event .ActionEvent ;
38+ import java .awt .event .InputEvent ;
39+ import java .awt .event .MouseEvent ;
3040import java .beans .PropertyChangeEvent ;
3141import java .beans .PropertyChangeListener ;
3242
33- import javax .swing .*;
34- import javax .swing .event .*;
35- import javax .swing .plaf .*;
43+ import javax .swing .ButtonModel ;
44+ import javax .swing .Icon ;
45+ import javax .swing .InputMap ;
46+ import javax .swing .JCheckBoxMenuItem ;
47+ import javax .swing .JComponent ;
48+ import javax .swing .JMenu ;
49+ import javax .swing .JMenuItem ;
50+ import javax .swing .JRadioButtonMenuItem ;
51+ import javax .swing .KeyStroke ;
52+ import javax .swing .LookAndFeel ;
53+ import javax .swing .MenuElement ;
54+ import javax .swing .MenuSelectionManager ;
55+ import javax .swing .SwingUtilities ;
56+ import javax .swing .UIManager ;
57+ import javax .swing .event .MenuDragMouseEvent ;
58+ import javax .swing .event .MenuDragMouseListener ;
59+ import javax .swing .event .MenuKeyListener ;
60+
61+ import javax .swing .event .MouseInputListener ;
62+ import javax .swing .plaf .ComponentInputMapUIResource ;
63+ import javax .swing .plaf .ComponentUI ;
64+ import javax .swing .plaf .MenuItemUI ;
65+ import javax .swing .plaf .UIResource ;
3666import javax .swing .text .View ;
3767
38- import sun .swing .*;
68+ import com .sun .java .swing .SwingUtilities3 ;
69+ import sun .swing .MenuItemCheckIconFactory ;
70+ import sun .swing .MenuItemLayoutHelper ;
71+ import sun .swing .SwingUtilities2 ;
72+ import sun .swing .UIAction ;
73+
3974
4075/**
4176 * BasicMenuItem implementation
@@ -669,84 +704,22 @@ protected void paintMenuItem(Graphics g, JComponent c,
669704
670705 private void paintIcon (Graphics g , MenuItemLayoutHelper lh ,
671706 MenuItemLayoutHelper .LayoutResult lr , Color holdc ) {
672- if (lh .getIcon () != null ) {
673- Icon icon ;
674- ButtonModel model = lh .getMenuItem ().getModel ();
675- if (!model .isEnabled ()) {
676- icon = lh .getMenuItem ().getDisabledIcon ();
677- } else if (model .isPressed () && model .isArmed ()) {
678- icon = lh .getMenuItem ().getPressedIcon ();
679- if (icon == null ) {
680- // Use default icon
681- icon = lh .getMenuItem ().getIcon ();
682- }
683- } else {
684- icon = lh .getMenuItem ().getIcon ();
685- }
686-
687- if (icon != null ) {
688- icon .paintIcon (lh .getMenuItem (), g , lr .getIconRect ().x ,
689- lr .getIconRect ().y );
690- g .setColor (holdc );
691- }
692- }
707+ SwingUtilities3 .paintIcon (g , lh , lr , holdc );
693708 }
694709
695710 private void paintCheckIcon (Graphics g , MenuItemLayoutHelper lh ,
696711 MenuItemLayoutHelper .LayoutResult lr ,
697712 Color holdc , Color foreground ) {
698- if (lh .getCheckIcon () != null ) {
699- ButtonModel model = lh .getMenuItem ().getModel ();
700- if (model .isArmed () || (lh .getMenuItem () instanceof JMenu
701- && model .isSelected ())) {
702- g .setColor (foreground );
703- } else {
704- g .setColor (holdc );
705- }
706- if (lh .useCheckAndArrow ()) {
707- lh .getCheckIcon ().paintIcon (lh .getMenuItem (), g ,
708- lr .getCheckRect ().x , lr .getCheckRect ().y );
709- }
710- g .setColor (holdc );
711- }
713+ SwingUtilities3 .paintCheckIcon (g , lh , lr , holdc , foreground );
712714 }
713715
714716 private void paintAccText (Graphics g , MenuItemLayoutHelper lh ,
715717 MenuItemLayoutHelper .LayoutResult lr ) {
716- if (!lh .getAccText ().isEmpty ()) {
717- ButtonModel model = lh .getMenuItem ().getModel ();
718- g .setFont (lh .getAccFontMetrics ().getFont ());
719- if (!model .isEnabled ()) {
720- // *** paint the accText disabled
721- if (disabledForeground != null ) {
722- g .setColor (disabledForeground );
723- SwingUtilities2 .drawString (lh .getMenuItem (), g ,
724- lh .getAccText (), lr .getAccRect ().x ,
725- lr .getAccRect ().y + lh .getAccFontMetrics ().getAscent ());
726- } else {
727- g .setColor (lh .getMenuItem ().getBackground ().brighter ());
728- SwingUtilities2 .drawString (lh .getMenuItem (), g ,
729- lh .getAccText (), lr .getAccRect ().x ,
730- lr .getAccRect ().y + lh .getAccFontMetrics ().getAscent ());
731- g .setColor (lh .getMenuItem ().getBackground ().darker ());
732- SwingUtilities2 .drawString (lh .getMenuItem (), g ,
733- lh .getAccText (), lr .getAccRect ().x - 1 ,
734- lr .getAccRect ().y + lh .getFontMetrics ().getAscent () - 1 );
735- }
736- } else {
737- // *** paint the accText normally
738- if (model .isArmed ()
739- || (lh .getMenuItem () instanceof JMenu
740- && model .isSelected ())) {
741- g .setColor (acceleratorSelectionForeground );
742- } else {
743- g .setColor (acceleratorForeground );
744- }
745- SwingUtilities2 .drawString (lh .getMenuItem (), g , lh .getAccText (),
746- lr .getAccRect ().x , lr .getAccRect ().y +
747- lh .getAccFontMetrics ().getAscent ());
748- }
749- }
718+ SwingUtilities3 .setDisabledForeground (disabledForeground );
719+ SwingUtilities3 .setAcceleratorSelectionForeground (
720+ acceleratorSelectionForeground );
721+ SwingUtilities3 .setAcceleratorForeground (acceleratorForeground );
722+ SwingUtilities3 .paintAccText (g , lh , lr );
750723 }
751724
752725 private void paintText (Graphics g , MenuItemLayoutHelper lh ,
@@ -765,26 +738,11 @@ private void paintText(Graphics g, MenuItemLayoutHelper lh,
765738 private void paintArrowIcon (Graphics g , MenuItemLayoutHelper lh ,
766739 MenuItemLayoutHelper .LayoutResult lr ,
767740 Color foreground ) {
768- if (lh .getArrowIcon () != null ) {
769- ButtonModel model = lh .getMenuItem ().getModel ();
770- if (model .isArmed () || (lh .getMenuItem () instanceof JMenu
771- && model .isSelected ())) {
772- g .setColor (foreground );
773- }
774- if (lh .useCheckAndArrow ()) {
775- lh .getArrowIcon ().paintIcon (lh .getMenuItem (), g ,
776- lr .getArrowRect ().x , lr .getArrowRect ().y );
777- }
778- }
741+ SwingUtilities3 .paintArrowIcon (g , lh , lr , foreground );
779742 }
780743
781744 private void applyInsets (Rectangle rect , Insets insets ) {
782- if (insets != null ) {
783- rect .x += insets .left ;
784- rect .y += insets .top ;
785- rect .width -= (insets .right + rect .x );
786- rect .height -= (insets .bottom + rect .y );
787- }
745+ SwingUtilities3 .applyInsets (rect , insets );
788746 }
789747
790748 /**
0 commit comments