KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > StrokeChooserPanel


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -----------------------
28  * StrokeChooserPanel.java
29  * -----------------------
30  * (C) Copyright 2000-2004, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): Dirk Zeitz;
34  *
35  * $Id: StrokeChooserPanel.java,v 1.5 2005/11/16 15:58:41 taqua Exp $
36  *
37  * Changes (from 26-Oct-2001)
38  * --------------------------
39  * 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
40  * 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
41  * 16-Mar-2004 : Fix for focus problems (DZ);
42  *
43  */

44
45 package org.jfree.ui;
46
47 import java.awt.BasicStroke JavaDoc;
48 import java.awt.BorderLayout JavaDoc;
49 import java.awt.Stroke JavaDoc;
50 import java.awt.event.ActionEvent JavaDoc;
51 import java.awt.event.ActionListener JavaDoc;
52
53 import javax.swing.JComboBox JavaDoc;
54 import javax.swing.JPanel JavaDoc;
55
56 /**
57  * A component for choosing a stroke from a list of available strokes. This class needs work.
58  *
59  * @author David Gilbert
60  */

61 public class StrokeChooserPanel extends JPanel JavaDoc {
62
63     /** A combo for selecting the stroke. */
64     private JComboBox JavaDoc selector;
65
66     /**
67      * Creates a panel containing a combo-box that allows the user to select
68      * one stroke from a list of available strokes.
69      *
70      * @param current the current stroke sample.
71      * @param available an array of 'available' stroke samples.
72      */

73     public StrokeChooserPanel(final StrokeSample current, final StrokeSample[] available) {
74         setLayout(new BorderLayout JavaDoc());
75         this.selector = new JComboBox JavaDoc(available);
76         this.selector.setSelectedItem(current);
77         this.selector.setRenderer(new StrokeSample(new BasicStroke JavaDoc(1)));
78         add(this.selector);
79         // Changes due to focus problems!! DZ
80
this.selector.addActionListener(new ActionListener JavaDoc() {
81             public void actionPerformed(final ActionEvent JavaDoc evt) {
82                 getSelector().transferFocus();
83             }
84         });
85     }
86
87     
88     /**
89      * Returns the selector component.
90      *
91      * @return Returns the selector.
92      */

93     protected final JComboBox JavaDoc getSelector()
94     {
95       return selector;
96     }
97     
98     /**
99      * Returns the selected stroke.
100      *
101      * @return the selected stroke.
102      */

103     public Stroke JavaDoc getSelectedStroke() {
104         final StrokeSample sample = (StrokeSample) this.selector.getSelectedItem();
105         return sample.getStroke();
106     }
107
108 }
109
Popular Tags