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.7 2008/09/10 09:26:11 mungady 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 import javax.swing.JComboBox; 053 import javax.swing.JPanel; 054 055 /** 056 * A component for choosing a stroke from a list of available strokes. This class needs work. 057 * 058 * @author David Gilbert 059 */ 060 public class StrokeChooserPanel extends JPanel { 061 062 /** A combo for selecting the stroke. */ 063 private JComboBox selector; 064 065 /** 066 * Creates a panel containing a combo-box that allows the user to select 067 * one stroke from a list of available strokes. 068 * 069 * @param current the current stroke sample. 070 * @param available an array of 'available' stroke samples. 071 */ 072 public StrokeChooserPanel(final StrokeSample current, final StrokeSample[] available) { 073 setLayout(new BorderLayout()); 074 this.selector = new JComboBox(available); 075 this.selector.setSelectedItem(current); 076 this.selector.setRenderer(new StrokeSample(new BasicStroke(1))); 077 add(this.selector); 078 // Changes due to focus problems!! DZ 079 this.selector.addActionListener(new ActionListener() { 080 public void actionPerformed(final ActionEvent evt) { 081 getSelector().transferFocus(); 082 } 083 }); 084 } 085 086 087 /** 088 * Returns the selector component. 089 * 090 * @return Returns the selector. 091 */ 092 protected final JComboBox getSelector() 093 { 094 return this.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.getSelectedItem(); 104 return sample.getStroke(); 105 } 106 107 }