11/*
2- * Copyright (c) 1997, 2022 , 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
@@ -670,84 +705,22 @@ protected void paintMenuItem(Graphics g, JComponent c,
670705
671706 private void paintIcon (Graphics g , MenuItemLayoutHelper lh ,
672707 MenuItemLayoutHelper .LayoutResult lr , Color holdc ) {
673- if (lh .getIcon () != null ) {
674- Icon icon ;
675- ButtonModel model = lh .getMenuItem ().getModel ();
676- if (!model .isEnabled ()) {
677- icon = lh .getMenuItem ().getDisabledIcon ();
678- } else if (model .isPressed () && model .isArmed ()) {
679- icon = lh .getMenuItem ().getPressedIcon ();
680- if (icon == null ) {
681- // Use default icon
682- icon = lh .getMenuItem ().getIcon ();
683- }
684- } else {
685- icon = lh .getMenuItem ().getIcon ();
686- }
687-
688- if (icon != null ) {
689- icon .paintIcon (lh .getMenuItem (), g , lr .getIconRect ().x ,
690- lr .getIconRect ().y );
691- g .setColor (holdc );
692- }
693- }
708+ SwingUtilities3 .paintIcon (g , lh , lr , holdc );
694709 }
695710
696711 private void paintCheckIcon (Graphics g , MenuItemLayoutHelper lh ,
697712 MenuItemLayoutHelper .LayoutResult lr ,
698713 Color holdc , Color foreground ) {
699- if (lh .getCheckIcon () != null ) {
700- ButtonModel model = lh .getMenuItem ().getModel ();
701- if (model .isArmed () || (lh .getMenuItem () instanceof JMenu
702- && model .isSelected ())) {
703- g .setColor (foreground );
704- } else {
705- g .setColor (holdc );
706- }
707- if (lh .useCheckAndArrow ()) {
708- lh .getCheckIcon ().paintIcon (lh .getMenuItem (), g ,
709- lr .getCheckRect ().x , lr .getCheckRect ().y );
710- }
711- g .setColor (holdc );
712- }
714+ SwingUtilities3 .paintCheckIcon (g , lh , lr , holdc , foreground );
713715 }
714716
715717 private void paintAccText (Graphics g , MenuItemLayoutHelper lh ,
716718 MenuItemLayoutHelper .LayoutResult lr ) {
717- if (!lh .getAccText ().isEmpty ()) {
718- ButtonModel model = lh .getMenuItem ().getModel ();
719- g .setFont (lh .getAccFontMetrics ().getFont ());
720- if (!model .isEnabled ()) {
721- // *** paint the accText disabled
722- if (disabledForeground != null ) {
723- g .setColor (disabledForeground );
724- SwingUtilities2 .drawString (lh .getMenuItem (), g ,
725- lh .getAccText (), lr .getAccRect ().x ,
726- lr .getAccRect ().y + lh .getAccFontMetrics ().getAscent ());
727- } else {
728- g .setColor (lh .getMenuItem ().getBackground ().brighter ());
729- SwingUtilities2 .drawString (lh .getMenuItem (), g ,
730- lh .getAccText (), lr .getAccRect ().x ,
731- lr .getAccRect ().y + lh .getAccFontMetrics ().getAscent ());
732- g .setColor (lh .getMenuItem ().getBackground ().darker ());
733- SwingUtilities2 .drawString (lh .getMenuItem (), g ,
734- lh .getAccText (), lr .getAccRect ().x - 1 ,
735- lr .getAccRect ().y + lh .getFontMetrics ().getAscent () - 1 );
736- }
737- } else {
738- // *** paint the accText normally
739- if (model .isArmed ()
740- || (lh .getMenuItem () instanceof JMenu
741- && model .isSelected ())) {
742- g .setColor (acceleratorSelectionForeground );
743- } else {
744- g .setColor (acceleratorForeground );
745- }
746- SwingUtilities2 .drawString (lh .getMenuItem (), g , lh .getAccText (),
747- lr .getAccRect ().x , lr .getAccRect ().y +
748- lh .getAccFontMetrics ().getAscent ());
749- }
750- }
719+ SwingUtilities3 .setDisabledForeground (disabledForeground );
720+ SwingUtilities3 .setAcceleratorSelectionForeground (
721+ acceleratorSelectionForeground );
722+ SwingUtilities3 .setAcceleratorForeground (acceleratorForeground );
723+ SwingUtilities3 .paintAccText (g , lh , lr );
751724 }
752725
753726 private void paintText (Graphics g , MenuItemLayoutHelper lh ,
@@ -766,26 +739,11 @@ private void paintText(Graphics g, MenuItemLayoutHelper lh,
766739 private void paintArrowIcon (Graphics g , MenuItemLayoutHelper lh ,
767740 MenuItemLayoutHelper .LayoutResult lr ,
768741 Color foreground ) {
769- if (lh .getArrowIcon () != null ) {
770- ButtonModel model = lh .getMenuItem ().getModel ();
771- if (model .isArmed () || (lh .getMenuItem () instanceof JMenu
772- && model .isSelected ())) {
773- g .setColor (foreground );
774- }
775- if (lh .useCheckAndArrow ()) {
776- lh .getArrowIcon ().paintIcon (lh .getMenuItem (), g ,
777- lr .getArrowRect ().x , lr .getArrowRect ().y );
778- }
779- }
742+ SwingUtilities3 .paintArrowIcon (g , lh , lr , foreground );
780743 }
781744
782745 private void applyInsets (Rectangle rect , Insets insets ) {
783- if (insets != null ) {
784- rect .x += insets .left ;
785- rect .y += insets .top ;
786- rect .width -= (insets .right + rect .x );
787- rect .height -= (insets .bottom + rect .y );
788- }
746+ SwingUtilities3 .applyInsets (rect , insets );
789747 }
790748
791749 /**
0 commit comments