001/* ========================================================================
002 * JCommon : a free general purpose class library for the Java(tm) platform
003 * ========================================================================
004 *
005 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006 * 
007 * Project Info:  http://www.jfree.org/jcommon/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it 
010 * under the terms of the GNU Lesser General Public License as published by 
011 * the Free Software Foundation; either version 2.1 of the License, or 
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but 
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022 * USA.  
023 *
024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025 * in the United States and other countries.]
026 * 
027 * -----------------------
028 * StrokeChooserPanel.java
029 * -----------------------
030 * (C) Copyright 2000-2004, by Object Refinery Limited.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   Dirk Zeitz;
034 *
035 * $Id: StrokeChooserPanel.java,v 1.5 2005/11/16 15:58:41 taqua Exp $
036 *
037 * Changes (from 26-Oct-2001)
038 * --------------------------
039 * 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
040 * 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
041 * 16-Mar-2004 : Fix for focus problems (DZ);
042 *
043 */
044
045package org.jfree.ui;
046
047import java.awt.BasicStroke;
048import java.awt.BorderLayout;
049import java.awt.Stroke;
050import java.awt.event.ActionEvent;
051import java.awt.event.ActionListener;
052
053import javax.swing.JComboBox;
054import javax.swing.JPanel;
055
056/**
057 * A component for choosing a stroke from a list of available strokes.  This class needs work.
058 *
059 * @author David Gilbert
060 */
061public class StrokeChooserPanel extends JPanel {
062
063    /** A combo for selecting the stroke. */
064    private JComboBox selector;
065
066    /**
067     * Creates a panel containing a combo-box that allows the user to select
068     * one stroke from a list of available strokes.
069     *
070     * @param current  the current stroke sample.
071     * @param available  an array of 'available' stroke samples.
072     */
073    public StrokeChooserPanel(final StrokeSample current, final StrokeSample[] available) {
074        setLayout(new BorderLayout());
075        this.selector = new JComboBox(available);
076        this.selector.setSelectedItem(current);
077        this.selector.setRenderer(new StrokeSample(new BasicStroke(1)));
078        add(this.selector);
079        // Changes due to focus problems!! DZ
080        this.selector.addActionListener(new ActionListener() {
081            public void actionPerformed(final ActionEvent evt) {
082                getSelector().transferFocus();
083            }
084        });
085    }
086
087    
088    /**
089     * Returns the selector component.
090     *
091     * @return Returns the selector.
092     */
093    protected final JComboBox getSelector()
094    {
095      return selector;
096    }
097    
098    /**
099     * Returns the selected stroke.
100     *
101     * @return the selected stroke.
102     */
103    public Stroke getSelectedStroke() {
104        final StrokeSample sample = (StrokeSample) this.selector.getSelectedItem();
105        return sample.getStroke();
106    }
107
108}