001    /* ========================================================================
002     * JCommon : a free general purpose class library for the Java(tm) platform
003     * ========================================================================
004     *
005     * (C) Copyright 2000-2008, 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     * InsetsTextField.java
029     * --------------------
030     * (C) Copyright 2000-2008, by Andrzej Porebski.
031     *
032     * Original Author:  Andrzej Porebski;
033     * Contributor(s):   Arnaud Lelievre;
034     *
035     * $Id: InsetsTextField.java,v 1.4 2008/12/18 09:57:32 mungady Exp $
036     *
037     * Changes (from 7-Nov-2001)
038     * -------------------------
039     * 07-Nov-2001 : Added to com.jrefinery.ui package (DG);
040     * 08-Sep-2003 : Added internationalization via use of properties
041     *               resourceBundle (RFE 690236) (AL);
042     * 18-Dec-2008 : Use ResourceBundleWrapper - see JFreeChart patch 1607918 by
043     *               Jess Thrysoee (DG);
044     *
045     */
046    
047    package org.jfree.ui;
048    
049    import java.awt.Insets;
050    import java.util.ResourceBundle;
051    
052    import javax.swing.JTextField;
053    
054    import org.jfree.util.ResourceBundleWrapper;
055    
056    /**
057     * A JTextField for displaying insets.
058     *
059     * @author Andrzej Porebski
060     */
061    public class InsetsTextField extends JTextField {
062    
063        /** The resourceBundle for the localization. */
064        protected static ResourceBundle localizationResources
065                = ResourceBundleWrapper.getBundle(
066                        "org.jfree.ui.LocalizationBundle");
067    
068        /**
069         * Default constructor. Initializes this text field with formatted string
070         * describing provided insets.
071         *
072         * @param insets  the insets.
073         */
074        public InsetsTextField(final Insets insets) {
075            super();
076            setInsets(insets);
077            setEnabled(false);
078        }
079    
080        /**
081         * Returns a formatted string describing provided insets.
082         *
083         * @param insets  the insets.
084         *
085         * @return the string.
086         */
087        public String formatInsetsString(Insets insets) {
088            insets = (insets == null) ? new Insets(0, 0, 0, 0) : insets;
089            return
090                localizationResources.getString("T") + insets.top + ", "
091                 + localizationResources.getString("L") + insets.left + ", "
092                 + localizationResources.getString("B") + insets.bottom + ", "
093                 + localizationResources.getString("R") + insets.right;
094        }
095    
096        /**
097         * Sets the text of this text field to the formatted string
098         * describing provided insets. If insets is null, empty insets
099         * (0,0,0,0) are used.
100         *
101         * @param insets  the insets.
102         */
103        public void setInsets(final Insets insets) {
104            setText(formatInsetsString(insets));
105        }
106    
107    }