1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
  6. *
  7. * Project Info: http://www.jfree.org/jfreechart/index.html
  8. *
  9. * This library is free software; you can redistribute it and/or modify it under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * ------------------------
  25. * PaletteChooserPanel.java
  26. * ------------------------
  27. * (C) Copyright 2002-2004, by David M. O'Donnell.
  28. *
  29. * Original Author: David M. O'Donnell;
  30. * Contributor(s): David Gilbert (for Object Refinery Limited);
  31. *
  32. * $Id: PaletteChooserPanel.java,v 1.1 2004/08/31 14:54:21 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 27-Jan-2003 : Added standard header (DG);
  37. *
  38. */
  39. package org.jfree.chart.ui;
  40. import java.awt.BorderLayout;
  41. import javax.swing.JComboBox;
  42. import javax.swing.JPanel;
  43. /**
  44. * A component for choosing a palette from a list of available palettes.
  45. *
  46. * @author David M. O'Donnell.
  47. */
  48. public class PaletteChooserPanel extends JPanel {
  49. /** A combo for selecting the stroke. */
  50. private JComboBox selector;
  51. /**
  52. * Constructor.
  53. *
  54. * @param current the current palette sample.
  55. * @param available an array of 'available' palette samples.
  56. */
  57. public PaletteChooserPanel(PaletteSample current, PaletteSample[] available) {
  58. setLayout(new BorderLayout());
  59. this.selector = new JComboBox(available);
  60. this.selector.setSelectedItem(current);
  61. this.selector.setRenderer(new PaletteSample(new RainbowPalette()));
  62. add(this.selector);
  63. }
  64. /**
  65. * Returns the selected palette.
  66. *
  67. * @return The selected palette.
  68. */
  69. public ColorPalette getSelectedPalette() {
  70. PaletteSample sample = (PaletteSample) this.selector.getSelectedItem();
  71. return sample.getPalette();
  72. }
  73. }