/[classpath]/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/basic/BasicMenuItemUI.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21 by trebligd, Wed Aug 31 15:23:10 2005 UTC revision 1.22 by langel, Tue Sep 6 16:22:02 2005 UTC
# Line 1  Line 1 
1  /* BasicMenuItemUI.java --  /* BasicMenuItemUI.java --
2     Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.   Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.   This file is part of GNU Classpath.
5    
6  GNU Classpath is free software; you can redistribute it and/or modify   GNU Classpath is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by   it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)   the Free Software Foundation; either version 2, or (at your option)
9  any later version.   any later version.
10    
11  GNU Classpath is distributed in the hope that it will be useful, but   GNU Classpath is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of   WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  General Public License for more details.   General Public License for more details.
15    
16  You should have received a copy of the GNU General Public License   You should have received a copy of the GNU General Public License
17  along with GNU Classpath; see the file COPYING.  If not, write to the   along with GNU Classpath; see the file COPYING.  If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301 USA.   02110-1301 USA.
20    
21  Linking this library statically or dynamically with other modules is   Linking this library statically or dynamically with other modules is
22  making a combined work based on this library.  Thus, the terms and   making a combined work based on this library.  Thus, the terms and
23  conditions of the GNU General Public License cover the whole   conditions of the GNU General Public License cover the whole
24  combination.   combination.
25    
26  As a special exception, the copyright holders of this library give you   As a special exception, the copyright holders of this library give you
27  permission to link this library with independent modules to produce an   permission to link this library with independent modules to produce an
28  executable, regardless of the license terms of these independent   executable, regardless of the license terms of these independent
29  modules, and to copy and distribute the resulting executable under   modules, and to copy and distribute the resulting executable under
30  terms of your choice, provided that you also meet, for each linked   terms of your choice, provided that you also meet, for each linked
31  independent module, the terms and conditions of the license of that   independent module, the terms and conditions of the license of that
32  module.  An independent module is a module which is not derived from   module.  An independent module is a module which is not derived from
33  or based on this library.  If you modify this library, you may extend   or based on this library.  If you modify this library, you may extend
34  this exception to your version of the library, but you are not   this exception to your version of the library, but you are not
35  obligated to do so.  If you do not wish to do so, delete this   obligated to do so.  If you do not wish to do so, delete this
36  exception statement from your version. */   exception statement from your version. */
37    
38    
39  package javax.swing.plaf.basic;  package javax.swing.plaf.basic;
# Line 178  public class BasicMenuItemUI extends Men Line 178  public class BasicMenuItemUI extends Men
178    
179    /**    /**
180     * Create MenuDragMouseListener to listen for mouse dragged events.     * Create MenuDragMouseListener to listen for mouse dragged events.
181     *     *
182     * @param c menu item to listen to     * @param c
183     *     *          menu item to listen to
184     * @return The MenuDragMouseListener     * @return The MenuDragMouseListener
185     */     */
186    protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)    protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)
# Line 189  public class BasicMenuItemUI extends Men Line 189  public class BasicMenuItemUI extends Men
189    }    }
190    
191    /**    /**
192     * Creates MenuKeyListener to listen to key events occuring when menu item     * Creates MenuKeyListener to listen to key events occuring when menu item is
193     * is visible on the screen.     * visible on the screen.
194     *     *
195     * @param c menu item to listen to     * @param c
196     *     *          menu item to listen to
197     * @return The MenuKeyListener     * @return The MenuKeyListener
198     */     */
199    protected MenuKeyListener createMenuKeyListener(JComponent c)    protected MenuKeyListener createMenuKeyListener(JComponent c)
# Line 203  public class BasicMenuItemUI extends Men Line 203  public class BasicMenuItemUI extends Men
203    
204    /**    /**
205     * Handles mouse input events occuring for this menu item     * Handles mouse input events occuring for this menu item
206     *     *
207     * @param c menu item to listen to     * @param c
208     *     *          menu item to listen to
209     * @return The MouseInputListener     * @return The MouseInputListener
210     */     */
211    protected MouseInputListener createMouseInputListener(JComponent c)    protected MouseInputListener createMouseInputListener(JComponent c)
# Line 216  public class BasicMenuItemUI extends Men Line 216  public class BasicMenuItemUI extends Men
216    /**    /**
217     * Factory method to create a BasicMenuItemUI for the given {@link     * Factory method to create a BasicMenuItemUI for the given {@link
218     * JComponent}, which should be a {@link JMenuItem}.     * JComponent}, which should be a {@link JMenuItem}.
219     *     *
220     * @param c The {@link JComponent} a UI is being created for.     * @param c
221     *     *          The {@link JComponent} a UI is being created for.
222     * @return A BasicMenuItemUI for the {@link JComponent}.     * @return A BasicMenuItemUI for the {@link JComponent}.
223     */     */
224    public static ComponentUI createUI(JComponent c)    public static ComponentUI createUI(JComponent c)
# Line 228  public class BasicMenuItemUI extends Men Line 228  public class BasicMenuItemUI extends Men
228    
229    /**    /**
230     * Programatically clicks menu item.     * Programatically clicks menu item.
231     *     *
232     * @param msm MenuSelectionManager for the menu hierarchy     * @param msm
233       *          MenuSelectionManager for the menu hierarchy
234     */     */
235    protected void doClick(MenuSelectionManager msm)    protected void doClick(MenuSelectionManager msm)
236    {    {
# Line 239  public class BasicMenuItemUI extends Men Line 240  public class BasicMenuItemUI extends Men
240    
241    /**    /**
242     * Returns maximum size for the specified menu item     * Returns maximum size for the specified menu item
243     *     *
244     * @param c component for which to get maximum size     * @param c
245     *     *          component for which to get maximum size
246     * @return Maximum size for the specified menu item.     * @return Maximum size for the specified menu item.
247     */     */
248    public Dimension getMaximumSize(JComponent c)    public Dimension getMaximumSize(JComponent c)
# Line 251  public class BasicMenuItemUI extends Men Line 252  public class BasicMenuItemUI extends Men
252    
253    /**    /**
254     * Returns minimum size for the specified menu item     * Returns minimum size for the specified menu item
255     *     *
256     * @param c component for which to get minimum size     * @param c
257     *     *          component for which to get minimum size
258     * @return Minimum size for the specified menu item.     * @return Minimum size for the specified menu item.
259     */     */
260    public Dimension getMinimumSize(JComponent c)    public Dimension getMinimumSize(JComponent c)
# Line 263  public class BasicMenuItemUI extends Men Line 264  public class BasicMenuItemUI extends Men
264    
265    /**    /**
266     * Returns path to this menu item.     * Returns path to this menu item.
267     *     *
268     * @return $MenuElement[]$ Returns array of menu elements     * @return $MenuElement[]$ Returns array of menu elements that constitute a
269     * that constitute a path to this menu item.     *         path to this menu item.
270     */     */
271    public MenuElement[] getPath()    public MenuElement[] getPath()
272    {    {
# Line 278  public class BasicMenuItemUI extends Men Line 279  public class BasicMenuItemUI extends Men
279      Component c = menuItem;      Component c = menuItem;
280      while (c instanceof MenuElement)      while (c instanceof MenuElement)
281        {        {
282          path.add(0, (MenuElement) c);          path.add(0, (MenuElement) c);
283    
284          if (c instanceof JPopupMenu)          if (c instanceof JPopupMenu)
285            c = ((JPopupMenu) c).getInvoker();            c = ((JPopupMenu) c).getInvoker();
286          else          else
287            c = c.getParent();            c = c.getParent();
288        }        }
289    
290      MenuElement[] pathArray = new MenuElement[path.size()];      MenuElement[] pathArray = new MenuElement[path.size()];
# Line 293  public class BasicMenuItemUI extends Men Line 294  public class BasicMenuItemUI extends Men
294    
295    /**    /**
296     * Returns preferred size for the given menu item.     * Returns preferred size for the given menu item.
297     *     *
298     * @param c menu item for which to get preferred size     * @param c
299     * @param checkIcon check icon displayed in the given menu item     *          menu item for which to get preferred size
300     * @param arrowIcon arrow icon displayed in the given menu item     * @param checkIcon
301     * @param defaultTextIconGap space between icon and text in the given menuItem     *          check icon displayed in the given menu item
302     *     * @param arrowIcon
303       *          arrow icon displayed in the given menu item
304       * @param defaultTextIconGap
305       *          space between icon and text in the given menuItem
306     * @return $Dimension$ preferred size for the given menu item     * @return $Dimension$ preferred size for the given menu item
307     */     */
308    protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon,    protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon,
# Line 316  public class BasicMenuItemUI extends Men Line 320  public class BasicMenuItemUI extends Men
320    
321      if (accelerator != null)      if (accelerator != null)
322        {        {
323          rect = getAcceleratorRect(accelerator,          rect = getAcceleratorRect(
324                                    m.getToolkit().getFontMetrics(acceleratorFont));                                    accelerator,
325                                      m.getToolkit().getFontMetrics(acceleratorFont));
326          // add width of accelerator's text  
327          d.width = d.width + rect.width + defaultAcceleratorLabelGap;          // add width of accelerator's text
328            d.width = d.width + rect.width + defaultAcceleratorLabelGap;
329          // adjust the heigth of the preferred size if necessary  
330          if (d.height < rect.height)          // adjust the heigth of the preferred size if necessary
331            d.height = rect.height;          if (d.height < rect.height)
332              d.height = rect.height;
333        }        }
334    
335      if (checkIcon != null)      if (checkIcon != null)
336        {        {
337          d.width = d.width + checkIcon.getIconWidth() + defaultTextIconGap;          d.width = d.width + checkIcon.getIconWidth() + defaultTextIconGap;
338    
339          if (checkIcon.getIconHeight() > d.height)          if (checkIcon.getIconHeight() > d.height)
340            d.height = checkIcon.getIconHeight();            d.height = checkIcon.getIconHeight();
341        }        }
342    
343      if (arrowIcon != null && (c instanceof JMenu))      if (arrowIcon != null && (c instanceof JMenu))
344        {        {
345          d.width = d.width + arrowIcon.getIconWidth() + defaultTextIconGap;          d.width = d.width + arrowIcon.getIconWidth() + defaultTextIconGap;
346    
347          if (arrowIcon.getIconHeight() > d.height)          if (arrowIcon.getIconHeight() > d.height)
348            d.height = arrowIcon.getIconHeight();            d.height = arrowIcon.getIconHeight();
349        }        }
350    
351      return d;      return d;
# Line 348  public class BasicMenuItemUI extends Men Line 353  public class BasicMenuItemUI extends Men
353    
354    /**    /**
355     * Returns preferred size of the given component     * Returns preferred size of the given component
356     *     *
357     * @param c component for which to return preferred size     * @param c
358     *     *          component for which to return preferred size
359     * @return $Dimension$ preferred size for the given component     * @return $Dimension$ preferred size for the given component
360     */     */
361    public Dimension getPreferredSize(JComponent c)    public Dimension getPreferredSize(JComponent c)
362    {    {
363      return getPreferredMenuItemSize(c, checkIcon, arrowIcon,      return getPreferredMenuItemSize(c, checkIcon, arrowIcon, defaultTextIconGap);
         defaultTextIconGap);  
364    }    }
365    
366    /**    /**
367     * Returns the prefix for entries in the {@link UIDefaults} table.     * Returns the prefix for entries in the {@link UIDefaults} table.
368     *     *
369     * @return "MenuItem"     * @return "MenuItem"
370     */     */
371    protected String getPropertyPrefix()    protected String getPropertyPrefix()
# Line 371  public class BasicMenuItemUI extends Men Line 375  public class BasicMenuItemUI extends Men
375    
376    /**    /**
377     * This method installs the components for this {@link JMenuItem}.     * This method installs the components for this {@link JMenuItem}.
378     *     *
379     * @param menuItem The {@link JMenuItem} to install components for.     * @param menuItem
380       *          The {@link JMenuItem} to install components for.
381     */     */
382    protected void installComponents(JMenuItem menuItem)    protected void installComponents(JMenuItem menuItem)
383    {    {
# Line 380  public class BasicMenuItemUI extends Men Line 385  public class BasicMenuItemUI extends Men
385    }    }
386    
387    /**    /**
388     * This method installs the defaults that are defined in  the Basic look and     * This method installs the defaults that are defined in the Basic look and
389     * feel for this {@link JMenuItem}.     * feel for this {@link JMenuItem}.
390     */     */
391    protected void installDefaults()    protected void installDefaults()
# Line 425  public class BasicMenuItemUI extends Men Line 430  public class BasicMenuItemUI extends Men
430    }    }
431    
432    /**    /**
433     * Installs and initializes all fields for this UI delegate. Any properties     * Installs and initializes all fields for this UI delegate. Any properties of
434     * of the UI that need to be initialized and/or set to defaults will be     * the UI that need to be initialized and/or set to defaults will be done now.
435     * done now. It will also install any listeners necessary.     * It will also install any listeners necessary.
436     *     *
437     * @param c The {@link JComponent} that is having this UI installed.     * @param c
438       *          The {@link JComponent} that is having this UI installed.
439     */     */
440    public void installUI(JComponent c)    public void installUI(JComponent c)
441    {    {
# Line 442  public class BasicMenuItemUI extends Men Line 448  public class BasicMenuItemUI extends Men
448    
449    /**    /**
450     * Paints given menu item using specified graphics context     * Paints given menu item using specified graphics context
451     *     *
452     * @param g The graphics context used to paint this menu item     * @param g
453     * @param c Menu Item to paint     *          The graphics context used to paint this menu item
454       * @param c
455       *          Menu Item to paint
456     */     */
457    public void paint(Graphics g, JComponent c)    public void paint(Graphics g, JComponent c)
458    {    {
# Line 454  public class BasicMenuItemUI extends Men Line 462  public class BasicMenuItemUI extends Men
462    
463    /**    /**
464     * Paints background of the menu item     * Paints background of the menu item
465     *     *
466     * @param g The graphics context used to paint this menu item     * @param g
467     * @param menuItem menu item to paint     *          The graphics context used to paint this menu item
468     * @param bgColor Background color to use when painting menu item     * @param menuItem
469       *          menu item to paint
470       * @param bgColor
471       *          Background color to use when painting menu item
472     */     */
473    protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)    protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
474    {    {
# Line 470  public class BasicMenuItemUI extends Men Line 481  public class BasicMenuItemUI extends Men
481    
482    /**    /**
483     * Paints specified menu item     * Paints specified menu item
484     *     *
485     * @param g The graphics context used to paint this menu item     * @param g
486     * @param c menu item to paint     *          The graphics context used to paint this menu item
487     * @param checkIcon check icon to use when painting menu item     * @param c
488     * @param arrowIcon arrow icon to use when painting menu item     *          menu item to paint
489     * @param background Background color of the menu item     * @param checkIcon
490     * @param foreground Foreground color of the menu item     *          check icon to use when painting menu item
491     * @param defaultTextIconGap space to use between icon and     * @param arrowIcon
492     *  text when painting menu item     *          arrow icon to use when painting menu item
493       * @param background
494       *          Background color of the menu item
495       * @param foreground
496       *          Foreground color of the menu item
497       * @param defaultTextIconGap
498       *          space to use between icon and text when painting menu item
499     */     */
500    protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon,    protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon,
501                                 Icon arrowIcon, Color background,                                 Icon arrowIcon, Color background,
# Line 504  public class BasicMenuItemUI extends Men Line 521  public class BasicMenuItemUI extends Men
521      SwingUtilities.calculateInsetArea(br, m.getInsets(), vr);      SwingUtilities.calculateInsetArea(br, m.getInsets(), vr);
522      paintBackground(g, m, m.getBackground());      paintBackground(g, m, m.getBackground());
523    
524      /* MenuItems insets are equal to menuItems margin, space between text and      /*
525         menuItems border. We need to paint insets region as well. */       * MenuItems insets are equal to menuItems margin, space between text and
526         * menuItems border. We need to paint insets region as well.
527         */
528      Insets insets = m.getInsets();      Insets insets = m.getInsets();
529      br.x -= insets.left;      br.x -= insets.left;
530      br.y -= insets.top;      br.y -= insets.top;
# Line 514  public class BasicMenuItemUI extends Men Line 533  public class BasicMenuItemUI extends Men
533    
534      // Menu item is considered to be highlighted when it is selected.      // Menu item is considered to be highlighted when it is selected.
535      // But we don't want to paint the background of JCheckBoxMenuItems      // But we don't want to paint the background of JCheckBoxMenuItems
536      if ((m.isSelected() && checkIcon == null) || m.getModel().isArmed() &&      if ((m.isSelected() && checkIcon == null) || m.getModel().isArmed()
537          (m.getParent() instanceof MenuElement))          && (m.getParent() instanceof MenuElement))
538        {        {
539          if (m.isContentAreaFilled())          if (m.isContentAreaFilled())
540            {            {
541              g.setColor(selectionBackground);              g.setColor(selectionBackground);
542              g.fillRect(br.x, br.y, br.width, br.height);              g.fillRect(br.x, br.y, br.width, br.height);
543            }            }
544        }        }
545      else      else
546        {        {
547          if (m.isContentAreaFilled())          if (m.isContentAreaFilled())
548            {            {
549              g.setColor(m.getBackground());              g.setColor(m.getBackground());
550              g.fillRect(br.x, br.y, br.width, br.height);              g.fillRect(br.x, br.y, br.width, br.height);
551            }            }
552        }        }
553    
554      // If this menu item is a JCheckBoxMenuItem then paint check icon      // If this menu item is a JCheckBoxMenuItem then paint check icon
555      if (checkIcon != null)      if (checkIcon != null)
556        {        {
557          SwingUtilities.layoutCompoundLabel(m, fm, null, checkIcon, vertAlign,          SwingUtilities.layoutCompoundLabel(m, fm, null, checkIcon, vertAlign,
558                                             horAlign, vertTextPos, horTextPos,                                             horAlign, vertTextPos, horTextPos,
559                                             vr, cr, tr, defaultTextIconGap);                                             vr, cr, tr, defaultTextIconGap);
560          checkIcon.paintIcon(m, g, cr.x, cr.y);          checkIcon.paintIcon(m, g, cr.x, cr.y);
561          // We need to calculate position of the menu text and position of          // We need to calculate position of the menu text and position of
562          // user menu icon if there exists one relative to the check icon.          // user menu icon if there exists one relative to the check icon.
563          // So we need to adjust view rectangle s.t. its starting point is at          // So we need to adjust view rectangle s.t. its starting point is at
564          // checkIcon.width + defaultTextIconGap.          // checkIcon.width + defaultTextIconGap.
565          vr.x = cr.x + cr.width + defaultTextIconGap;          vr.x = cr.x + cr.width + defaultTextIconGap;
566        }        }
567    
568      // if this is a submenu, then paint arrow icon to indicate it.      // if this is a submenu, then paint arrow icon to indicate it.
569      if (arrowIcon != null && (c instanceof JMenu))      if (arrowIcon != null && (c instanceof JMenu))
570        {        {
571          if (! ((JMenu) c).isTopLevelMenu())          if (!((JMenu) c).isTopLevelMenu())
572            {            {
573              int width = arrowIcon.getIconWidth();              int width = arrowIcon.getIconWidth();
574              int height = arrowIcon.getIconHeight();              int height = arrowIcon.getIconHeight();
575    
576              arrowIcon.paintIcon(m, g, vr.width - width + defaultTextIconGap,              arrowIcon.paintIcon(m, g, vr.width - width + defaultTextIconGap,
577                                  vr.y + 2);                                  vr.y + 2);
578            }            }
579        }        }
580    
581      // paint text and user menu icon if it exists                  // paint text and user menu icon if it exists
582      Icon i = m.getIcon();      Icon i = m.getIcon();
583      SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), i,      SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), i, vertAlign,
584                                         vertAlign, horAlign, vertTextPos,                                         horAlign, vertTextPos, horTextPos, vr,
585                                         horTextPos, vr, ir, tr,                                         ir, tr, defaultTextIconGap);
                                        defaultTextIconGap);  
586      if (i != null)      if (i != null)
587        i.paintIcon(c, g, ir.x, ir.y);        i.paintIcon(c, g, ir.x, ir.y);
588      paintText(g, m, tr, m.getText());      paintText(g, m, tr, m.getText());
589    
590      // paint accelerator          // paint accelerator
591      String acceleratorText = "";      String acceleratorText = "";
592    
593      if (m.getAccelerator() != null)      if (m.getAccelerator() != null)
594        {        {
595          acceleratorText = getAcceleratorText(m.getAccelerator());          acceleratorText = getAcceleratorText(m.getAccelerator());
596          fm = g.getFontMetrics(acceleratorFont);          fm = g.getFontMetrics(acceleratorFont);
597          ar.width = fm.stringWidth(acceleratorText);          ar.width = fm.stringWidth(acceleratorText);
598          ar.x = br.width - ar.width;          ar.x = br.width - ar.width;
599          vr.x = br.width - ar.width;          vr.x = br.width - ar.width;
600    
601          SwingUtilities.layoutCompoundLabel(m, fm, acceleratorText, null,          SwingUtilities.layoutCompoundLabel(m, fm, acceleratorText, null,
602                                             vertAlign, horAlign, vertTextPos,                                             vertAlign, horAlign, vertTextPos,
603                                             horTextPos, vr, ir, ar,                                             horTextPos, vr, ir, ar,
604                                             defaultTextIconGap);                                             defaultTextIconGap);
605    
606          paintAccelerator(g, m, ar, acceleratorText);          paintAccelerator(g, m, ar, acceleratorText);
607        }        }
608    }    }
609    
610    /**    /**
611     * Paints label for the given menu item     * Paints label for the given menu item
612     *     *
613     * @param g The graphics context used to paint this menu item     * @param g
614     * @param menuItem menu item for which to draw its label     *          The graphics context used to paint this menu item
615     * @param textRect rectangle specifiying position of the text relative to     * @param menuItem
616     * the given menu item     *          menu item for which to draw its label
617     * @param text label of the menu item     * @param textRect
618       *          rectangle specifiying position of the text relative to the given
619       *          menu item
620       * @param text
621       *          label of the menu item
622     */     */
623    protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect,    protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect,
624                             String text)                             String text)
# Line 605  public class BasicMenuItemUI extends Men Line 627  public class BasicMenuItemUI extends Men
627      g.setFont(f);      g.setFont(f);
628      FontMetrics fm = g.getFontMetrics(f);      FontMetrics fm = g.getFontMetrics(f);
629    
630      if (text != null && ! text.equals(""))      if (text != null && !text.equals(""))
631        {        {
632          if (menuItem.isEnabled())          if (menuItem.isEnabled())
633            {            {
634              // Menu item is considered to be highlighted when it is selected.              // Menu item is considered to be highlighted when it is selected.
635              // But not if it's a JCheckBoxMenuItem              // But not if it's a JCheckBoxMenuItem
636              if ((menuItem.isSelected() && checkIcon == null) || menuItem.getModel().isArmed() &&              if ((menuItem.isSelected() && checkIcon == null)
637                  (menuItem.getParent() instanceof MenuElement))                  || menuItem.getModel().isArmed()
638                    && (menuItem.getParent() instanceof MenuElement))
639                g.setColor(selectionForeground);                g.setColor(selectionForeground);
640              else              else
641                g.setColor(menuItem.getForeground());                g.setColor(menuItem.getForeground());
642            }            }
643          else          else
644            // FIXME: should fix this to use 'disabledForeground', but its            // FIXME: should fix this to use 'disabledForeground', but its
645            // default value in BasicLookAndFeel is null.              // default value in BasicLookAndFeel is null.
646              
647            // FIXME: should there be different foreground colours for selected            // FIXME: should there be different foreground colours for selected
648            // or deselected, when disabled?            // or deselected, when disabled?
649            g.setColor(Color.gray);            g.setColor(Color.gray);
650    
651          int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();          int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
652    
653          if (mnemonicIndex != -1)          if (mnemonicIndex != -1)
654            BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex,            BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex,
655                                                         textRect.x,                                                         textRect.x,
656                                                         textRect.y                                                         textRect.y
657                                                         + fm.getAscent());                                                             + fm.getAscent());
658          else          else
659            BasicGraphicsUtils.drawString(g, text, 0, textRect.x,            BasicGraphicsUtils.drawString(g, text, 0, textRect.x,
660                                          textRect.y + fm.getAscent());                                          textRect.y + fm.getAscent());
661        }        }
662    }    }
663    
664    /**    /**
665     * This method uninstalls the components for this {@link JMenuItem}.     * This method uninstalls the components for this {@link JMenuItem}.
666     *     *
667     * @param menuItem The {@link JMenuItem} to uninstall components for.     * @param menuItem
668       *          The {@link JMenuItem} to uninstall components for.
669     */     */
670    protected void uninstallComponents(JMenuItem menuItem)    protected void uninstallComponents(JMenuItem menuItem)
671    {    {
# Line 693  public class BasicMenuItemUI extends Men Line 717  public class BasicMenuItemUI extends Men
717    
718    /**    /**
719     * Performs the opposite of installUI. Any properties or resources that need     * Performs the opposite of installUI. Any properties or resources that need
720     * to be cleaned up will be done now. It will also uninstall any listeners     * to be cleaned up will be done now. It will also uninstall any listeners it
721     * it has. In addition, any properties of this UI will be nulled.     * has. In addition, any properties of this UI will be nulled.
722     *     *
723     * @param c The {@link JComponent} that is having this UI uninstalled.     * @param c
724       *          The {@link JComponent} that is having this UI uninstalled.
725     */     */
726    public void uninstallUI(JComponent c)    public void uninstallUI(JComponent c)
727    {    {
# Line 708  public class BasicMenuItemUI extends Men Line 733  public class BasicMenuItemUI extends Men
733    
734    /**    /**
735     * This method calls paint.     * This method calls paint.
736     *     *
737     * @param g The graphics context used to paint this menu item     * @param g
738     * @param c The menu item to paint     *          The graphics context used to paint this menu item
739       * @param c
740       *          The menu item to paint
741     */     */
742    public void update(Graphics g, JComponent c)    public void update(Graphics g, JComponent c)
743    {    {
# Line 719  public class BasicMenuItemUI extends Men Line 746  public class BasicMenuItemUI extends Men
746    
747    /**    /**
748     * Return text representation of the specified accelerator     * Return text representation of the specified accelerator
749     *     *
750     * @param accelerator Accelerator for which to return string representation     * @param accelerator
751     *     *          Accelerator for which to return string representation
752     * @return $String$ Text representation of the given accelerator     * @return $String$ Text representation of the given accelerator
753     */     */
754    private String getAcceleratorText(KeyStroke accelerator)    private String getAcceleratorText(KeyStroke accelerator)
# Line 744  public class BasicMenuItemUI extends Men Line 771  public class BasicMenuItemUI extends Men
771    
772    /**    /**
773     * Calculates and return rectange in which accelerator should be displayed     * Calculates and return rectange in which accelerator should be displayed
774     *     *
775     * @param accelerator accelerator for which to return the display rectangle     * @param accelerator
776     * @param fm The font metrics used to measure the text     *          accelerator for which to return the display rectangle
777     *     * @param fm
778       *          The font metrics used to measure the text
779     * @return $Rectangle$ reactangle which will be used to display accelerator     * @return $Rectangle$ reactangle which will be used to display accelerator
780     */     */
781    private Rectangle getAcceleratorRect(KeyStroke accelerator, FontMetrics fm)    private Rectangle getAcceleratorRect(KeyStroke accelerator, FontMetrics fm)
# Line 759  public class BasicMenuItemUI extends Men Line 787  public class BasicMenuItemUI extends Men
787    
788    /**    /**
789     * Paints accelerator inside menu item     * Paints accelerator inside menu item
790     *     *
791     * @param g The graphics context used to paint the border     * @param g
792     * @param menuItem Menu item for which to draw accelerator     *          The graphics context used to paint the border
793     * @param acceleratorRect rectangle representing position     * @param menuItem
794     * of the accelerator relative to the menu item     *          Menu item for which to draw accelerator
795     * @param acceleratorText accelerator's text     * @param acceleratorRect
796       *          rectangle representing position of the accelerator relative to the
797       *          menu item
798       * @param acceleratorText
799       *          accelerator's text
800     */     */
801    private void paintAccelerator(Graphics g, JMenuItem menuItem,    private void paintAccelerator(Graphics g, JMenuItem menuItem,
802                                  Rectangle acceleratorRect,                                  Rectangle acceleratorRect,
# Line 785  public class BasicMenuItemUI extends Men Line 817  public class BasicMenuItemUI extends Men
817    }    }
818    
819    /**    /**
820     * This class handles mouse events occuring inside the menu item.     * This class handles mouse events occuring inside the menu item. Most of the
821     * Most of the events are forwarded for processing to MenuSelectionManager     * events are forwarded for processing to MenuSelectionManager of the current
822     * of the current menu hierarchy.     * menu hierarchy.
    *  
823     */     */
824    protected class MouseInputHandler implements MouseInputListener    protected class MouseInputHandler implements MouseInputListener
825    {    {
# Line 800  public class BasicMenuItemUI extends Men Line 831  public class BasicMenuItemUI extends Men
831      }      }
832    
833      /**      /**
834       * This method is called when mouse is clicked on the menu item.       * This method is called when mouse is clicked on the menu item. It forwards
835       * It forwards this event to MenuSelectionManager.       * this event to MenuSelectionManager.
836       *       *
837       * @param e A {@link MouseEvent}.       * @param e
838         *          A {@link MouseEvent}.
839       */       */
840      public void mouseClicked(MouseEvent e)      public void mouseClicked(MouseEvent e)
841      {      {
# Line 812  public class BasicMenuItemUI extends Men Line 844  public class BasicMenuItemUI extends Men
844      }      }
845    
846      /**      /**
847       * This method is called when mouse is dragged inside the menu item.       * This method is called when mouse is dragged inside the menu item. It
848       * It forwards this event to MenuSelectionManager.       * forwards this event to MenuSelectionManager.
849       *       *
850       * @param e A {@link MouseEvent}.       * @param e
851         *          A {@link MouseEvent}.
852       */       */
853      public void mouseDragged(MouseEvent e)      public void mouseDragged(MouseEvent e)
854      {      {
# Line 824  public class BasicMenuItemUI extends Men Line 857  public class BasicMenuItemUI extends Men
857      }      }
858    
859      /**      /**
860       * This method is called when mouse enters menu item.       * This method is called when mouse enters menu item. When this happens menu
861       * When this happens menu item is considered to be selected and selection path       * item is considered to be selected and selection path in
862       * in MenuSelectionManager is set. This event is also forwarded to MenuSelection       * MenuSelectionManager is set. This event is also forwarded to
863       * Manager for further processing.       * MenuSelection Manager for further processing.
864       *       *
865       * @param e A {@link MouseEvent}.       * @param e
866         *          A {@link MouseEvent}.
867       */       */
868      public void mouseEntered(MouseEvent e)      public void mouseEntered(MouseEvent e)
869      {      {
870        Component source = (Component) e.getSource();        Component source = (Component) e.getSource();
871        if (source.getParent() instanceof MenuElement)        if (source.getParent() instanceof MenuElement)
872          {          {
873            MenuSelectionManager manager = MenuSelectionManager.defaultManager();            MenuSelectionManager manager = MenuSelectionManager.defaultManager();
874            manager.setSelectedPath(getPath());            manager.setSelectedPath(getPath());
875            manager.processMouseEvent(e);            manager.processMouseEvent(e);
876          }          }
877      }      }
878    
879      /**      /**
880       * This method is called when mouse exits menu item. The event is       * This method is called when mouse exits menu item. The event is forwarded
881       * forwarded to MenuSelectionManager for processing.       * to MenuSelectionManager for processing.
882       *       *
883       * @param e A {@link MouseEvent}.       * @param e
884         *          A {@link MouseEvent}.
885       */       */
886      public void mouseExited(MouseEvent e)      public void mouseExited(MouseEvent e)
887      {      {
# Line 855  public class BasicMenuItemUI extends Men Line 890  public class BasicMenuItemUI extends Men
890      }      }
891    
892      /**      /**
893       * This method is called when mouse is inside the menu item.       * This method is called when mouse is inside the menu item. This event is
894       * This event is forwarder to MenuSelectionManager for further processing.       * forwarder to MenuSelectionManager for further processing.
895       *       *
896       * @param e A {@link MouseEvent}.       * @param e
897         *          A {@link MouseEvent}.
898       */       */
899      public void mouseMoved(MouseEvent e)      public void mouseMoved(MouseEvent e)
900      {      {
# Line 869  public class BasicMenuItemUI extends Men Line 905  public class BasicMenuItemUI extends Men
905      /**      /**
906       * This method is called when mouse is pressed. This event is forwarded to       * This method is called when mouse is pressed. This event is forwarded to
907       * MenuSelectionManager for further processing.       * MenuSelectionManager for further processing.
908       *       *
909       * @param e A {@link MouseEvent}.       * @param e
910         *          A {@link MouseEvent}.
911       */       */
912      public void mousePressed(MouseEvent e)      public void mousePressed(MouseEvent e)
913      {      {
# Line 882  public class BasicMenuItemUI extends Men Line 919  public class BasicMenuItemUI extends Men
919       * This method is called when mouse is released. If the mouse is released       * This method is called when mouse is released. If the mouse is released
920       * inside this menuItem, then this menu item is considered to be chosen and       * inside this menuItem, then this menu item is considered to be chosen and
921       * the menu hierarchy should be closed.       * the menu hierarchy should be closed.
922       *       *
923       * @param e A {@link MouseEvent}.       * @param e
924         *          A {@link MouseEvent}.
925       */       */
926      public void mouseReleased(MouseEvent e)      public void mouseReleased(MouseEvent e)
927      {      {
# Line 892  public class BasicMenuItemUI extends Men Line 930  public class BasicMenuItemUI extends Men
930        if (e.getX() > 0 && e.getX() < size.width && e.getY() > 0        if (e.getX() > 0 && e.getX() < size.width && e.getY() > 0
931            && e.getY() < size.height)            && e.getY() < size.height)
932          {          {
933            manager.clearSelectedPath();            manager.clearSelectedPath();
934            menuItem.doClick();            menuItem.doClick();
935          }          }
936    
937        else        else
938          manager.processMouseEvent(e);          manager.processMouseEvent(e);
939      }      }
940    }    }
941    
# Line 908  public class BasicMenuItemUI extends Men Line 946  public class BasicMenuItemUI extends Men
946    {    {
947      /**      /**
948       * Tbis method is invoked when mouse is dragged over the menu item.       * Tbis method is invoked when mouse is dragged over the menu item.
949       *       *
950       * @param e The MenuDragMouseEvent       * @param e
951         *          The MenuDragMouseEvent
952       */       */
953      public void menuDragMouseDragged(MenuDragMouseEvent e)      public void menuDragMouseDragged(MenuDragMouseEvent e)
954      {      {
# Line 918  public class BasicMenuItemUI extends Men Line 957  public class BasicMenuItemUI extends Men
957      }      }
958    
959      /**      /**
960       * Tbis method is invoked when mouse enters the menu item while it is       * Tbis method is invoked when mouse enters the menu item while it is being
961       * being dragged.       * dragged.
962       *       *
963       * @param e The MenuDragMouseEvent       * @param e
964         *          The MenuDragMouseEvent
965       */       */
966      public void menuDragMouseEntered(MenuDragMouseEvent e)      public void menuDragMouseEntered(MenuDragMouseEvent e)
967      {      {
# Line 930  public class BasicMenuItemUI extends Men Line 970  public class BasicMenuItemUI extends Men
970      }      }
971    
972      /**      /**
973       * Tbis method is invoked when mouse exits the menu item while       * Tbis method is invoked when mouse exits the menu item while it is being
974       * it is being dragged       * dragged
975       *       *
976       * @param e The MenuDragMouseEvent       * @param e
977         *          The MenuDragMouseEvent
978       */       */
979      public void menuDragMouseExited(MenuDragMouseEvent e)      public void menuDragMouseExited(MenuDragMouseEvent e)
980      {      {
981      }      }
982    
983      /**      /**
984       * Tbis method is invoked when mouse was dragged and released       * Tbis method is invoked when mouse was dragged and released inside the
985       * inside the menu item.       * menu item.
986       *       *
987       * @param e The MenuDragMouseEvent       * @param e
988         *          The MenuDragMouseEvent
989       */       */
990      public void menuDragMouseReleased(MenuDragMouseEvent e)      public void menuDragMouseReleased(MenuDragMouseEvent e)
991      {      {
992        MenuElement[] path = e.getPath();        MenuElement[] path = e.getPath();
993    
994        if (path[path.length - 1] instanceof JMenuItem)        if (path[path.length - 1] instanceof JMenuItem)
995          ((JMenuItem) path[path.length - 1]).doClick();          ((JMenuItem) path[path.length - 1]).doClick();
996    
997        MenuSelectionManager manager = MenuSelectionManager.defaultManager();        MenuSelectionManager manager = MenuSelectionManager.defaultManager();
998        manager.clearSelectedPath();        manager.clearSelectedPath();
# Line 965  public class BasicMenuItemUI extends Men Line 1007  public class BasicMenuItemUI extends Men
1007    {    {
1008      /**      /**
1009       * This method is invoked when key has been pressed       * This method is invoked when key has been pressed
1010       *       *
1011       * @param e A {@link MenuKeyEvent}.       * @param e
1012         *          A {@link MenuKeyEvent}.
1013       */       */
1014      public void menuKeyPressed(MenuKeyEvent e)      public void menuKeyPressed(MenuKeyEvent e)
1015      {      {
# Line 974  public class BasicMenuItemUI extends Men Line 1017  public class BasicMenuItemUI extends Men
1017    
1018      /**      /**
1019       * This method is invoked when key has been pressed       * This method is invoked when key has been pressed
1020       *       *
1021       * @param e A {@link MenuKeyEvent}.       * @param e
1022         *          A {@link MenuKeyEvent}.
1023       */       */
1024      public void menuKeyReleased(MenuKeyEvent e)      public void menuKeyReleased(MenuKeyEvent e)
1025      {      {
1026      }      }
1027    
1028      /**      /**
1029       * This method is invoked when key has been typed       * This method is invoked when key has been typed It handles the mnemonic
1030       * It handles the mnemonic key for the menu item.       * key for the menu item.
1031       *       *
1032       * @param e A {@link MenuKeyEvent}.       * @param e
1033         *          A {@link MenuKeyEvent}.
1034       */       */
1035      public void menuKeyTyped(MenuKeyEvent e)      public void menuKeyTyped(MenuKeyEvent e)
1036      {      {

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26