1. /*
  2. * @(#)MotifComboBoxRenderer.java 1.13 03/12/19
  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.motif;
  8. /**
  9. * A renderer for combo box with motif look and feel
  10. *
  11. * @version 1.13 12/19/03
  12. * @author Arnaud Weber
  13. */
  14. import javax.swing.*;
  15. import javax.swing.event.*;
  16. import javax.swing.border.*;
  17. import java.awt.Component;
  18. import java.awt.Color;
  19. import java.io.Serializable;
  20. /**
  21. * Motif rendition of the combo box renderer.
  22. * <p>
  23. * <strong>Warning:</strong>
  24. * Serialized objects of this class will not be compatible with
  25. * future Swing releases. The current serialization support is appropriate
  26. * for short term storage or RMI between applications running the same
  27. * version of Swing. A future release of Swing will provide support for
  28. * long term persistence.
  29. */
  30. public class MotifComboBoxRenderer extends JLabel
  31. implements ListCellRenderer, Serializable
  32. {
  33. protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
  34. public MotifComboBoxRenderer() {
  35. super();
  36. setOpaque(true);
  37. setBorder(noFocusBorder);
  38. }
  39. public Component getListCellRendererComponent(
  40. JList list,
  41. Object value,
  42. int index,
  43. boolean isSelected,
  44. boolean cellHasFocus)
  45. {
  46. setHorizontalAlignment(SwingConstants.LEFT);
  47. if (isSelected) {
  48. setBackground(list.getSelectionBackground());
  49. setForeground(list.getSelectionForeground());
  50. } else {
  51. setBackground(list.getBackground());
  52. setForeground(list.getForeground());
  53. }
  54. if (value instanceof Icon) {
  55. setIcon((Icon)value);
  56. }
  57. else {
  58. setText((value == null) ? "" : value.toString());
  59. }
  60. return this;
  61. }
  62. /**
  63. * A subclass of MotifComboBoxRenderer that implements UIResource.
  64. * MotifComboBoxRenderer doesn't implement UIResource
  65. * directly so that applications can safely override the
  66. * cellRenderer property with MotifListCellRenderer subclasses.
  67. * <p>
  68. * <strong>Warning:</strong>
  69. * Serialized objects of this class will not be compatible with
  70. * future Swing releases. The current serialization support is appropriate
  71. * for short term storage or RMI between applications running the same
  72. * version of Swing. A future release of Swing will provide support for
  73. * long term persistence.
  74. */
  75. public static class UIResource extends MotifComboBoxRenderer
  76. implements javax.swing.plaf.UIResource
  77. {
  78. }
  79. }