1. /*
  2. * @(#)MotifOptionPaneUI.java 1.16 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.motif;
  8. import javax.swing.*;
  9. import javax.swing.plaf.basic.BasicOptionPaneUI;
  10. import javax.swing.plaf.ComponentUI;
  11. import java.awt.Color;
  12. import java.awt.Component;
  13. import java.awt.Container;
  14. import java.awt.Dimension;
  15. import java.awt.Graphics;
  16. import java.awt.Insets;
  17. import java.awt.Rectangle;
  18. /**
  19. * Provides the CDE/Motif look and feel for a JOptionPane.
  20. * <p>
  21. * <strong>Warning:</strong>
  22. * Serialized objects of this class will not be compatible with
  23. * future Swing releases. The current serialization support is appropriate
  24. * for short term storage or RMI between applications running the same
  25. * version of Swing. A future release of Swing will provide support for
  26. * long term persistence.
  27. *
  28. * @version 1.16 01/23/03
  29. * @author Scott Violet
  30. */
  31. public class MotifOptionPaneUI extends BasicOptionPaneUI
  32. {
  33. /**
  34. * Creates a new MotifOptionPaneUI instance.
  35. */
  36. public static ComponentUI createUI(JComponent x) {
  37. return new MotifOptionPaneUI();
  38. }
  39. /**
  40. * Creates and returns a Container containin the buttons. The buttons
  41. * are created by calling <code>getButtons</code>.
  42. */
  43. protected Container createButtonArea() {
  44. Container b = super.createButtonArea();
  45. if(b != null && b.getLayout() instanceof ButtonAreaLayout) {
  46. ((ButtonAreaLayout)b.getLayout()).setCentersChildren(false);
  47. }
  48. return b;
  49. }
  50. /**
  51. * Returns null, CDE/Motif does not impose a minimum size.
  52. */
  53. public Dimension getMinimumOptionPaneSize() {
  54. return null;
  55. }
  56. protected Container createSeparator() {
  57. return new JPanel() {
  58. public Dimension getPreferredSize() {
  59. return new Dimension(10, 2);
  60. }
  61. public void paint(Graphics g) {
  62. int width = getWidth();
  63. g.setColor(Color.darkGray);
  64. g.drawLine(0, 0, width, 0);
  65. g.setColor(Color.white);
  66. g.drawLine(0, 1, width, 1);
  67. }
  68. };
  69. }
  70. /**
  71. * Creates and adds a JLabel representing the icon returned from
  72. * <code>getIcon</code> to <code>top</code>. This is messaged from
  73. * <code>createMessageArea</code>
  74. */
  75. protected void addIcon(Container top) {
  76. /* Create the icon. */
  77. Icon sideIcon = getIcon();
  78. if (sideIcon != null) {
  79. JLabel iconLabel = new JLabel(sideIcon);
  80. iconLabel.setVerticalAlignment(SwingConstants.CENTER);
  81. top.add(iconLabel, "West");
  82. }
  83. }
  84. }