1. /*
  2. * @(#)WindowsUtils.java 1.9 04/04/16
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.windows;
  8. import javax.swing.plaf.*;
  9. import javax.swing.*;
  10. import java.awt.*;
  11. /**
  12. * This is a collection of utility methods needed by the Windows L&F
  13. *
  14. * @version 1.9 04/16/04
  15. * @author Brian Beck
  16. */
  17. class WindowsUtils {
  18. /*
  19. * Convenience function for determining ComponentOrientation. Helps us
  20. * avoid having Munge directives throughout the code.
  21. */
  22. static boolean isLeftToRight( Component c ) {
  23. return c.getComponentOrientation().isLeftToRight();
  24. }
  25. /*
  26. * Repaints all the components with the mnemonics in the given window and
  27. * all its owned windows.
  28. */
  29. static void repaintMnemonicsInWindow(Window w) {
  30. if(w == null || !w.isShowing()) {
  31. return;
  32. }
  33. Window[] ownedWindows = w.getOwnedWindows();
  34. for(int i=0;i<ownedWindows.length;i++) {
  35. repaintMnemonicsInWindow(ownedWindows[i]);
  36. }
  37. repaintMnemonicsInContainer(w);
  38. }
  39. /*
  40. * Repaints all the components with the mnemonics in container.
  41. * Recursively searches for all the subcomponents.
  42. */
  43. static void repaintMnemonicsInContainer(Container cont) {
  44. Component c;
  45. for(int i=0; i<cont.getComponentCount(); i++) {
  46. c = cont.getComponent(i);
  47. if(c == null || !c.isVisible()) {
  48. continue;
  49. }
  50. if(c instanceof AbstractButton
  51. && ((AbstractButton)c).getMnemonic() != '\0') {
  52. c.repaint();
  53. continue;
  54. } else if(c instanceof JLabel
  55. && ((JLabel)c).getDisplayedMnemonic() != '\0') {
  56. c.repaint();
  57. continue;
  58. }
  59. if(c instanceof Container) {
  60. repaintMnemonicsInContainer((Container)c);
  61. }
  62. }
  63. }
  64. }