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