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:
045: package org.jfree.ui;
046:
047: import java.awt.BasicStroke;
048: import java.awt.BorderLayout;
049: import java.awt.Stroke;
050: import java.awt.event.ActionEvent;
051: import java.awt.event.ActionListener;
052:
053: import javax.swing.JComboBox;
054: import 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: */
061: public 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,
074: final StrokeSample[] available) {
075: setLayout(new BorderLayout());
076: this .selector = new JComboBox(available);
077: this .selector.setSelectedItem(current);
078: this .selector.setRenderer(new StrokeSample(new BasicStroke(1)));
079: add(this .selector);
080: // Changes due to focus problems!! DZ
081: this .selector.addActionListener(new ActionListener() {
082: public void actionPerformed(final ActionEvent evt) {
083: getSelector().transferFocus();
084: }
085: });
086: }
087:
088: /**
089: * Returns the selector component.
090: *
091: * @return Returns the selector.
092: */
093: protected final JComboBox getSelector() {
094: return selector;
095: }
096:
097: /**
098: * Returns the selected stroke.
099: *
100: * @return the selected stroke.
101: */
102: public Stroke getSelectedStroke() {
103: final StrokeSample sample = (StrokeSample) this.selector
104: .getSelectedItem();
105: return sample.getStroke();
106: }
107:
108: }
|