Frames | No Frames |
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: * InsetsTextField.java 29: * -------------------- 30: * (C) Copyright 2000-2004, by Andrzej Porebski. 31: * 32: * Original Author: Andrzej Porebski; 33: * Contributor(s): Arnaud Lelievre; 34: * 35: * $Id: InsetsTextField.java,v 1.2 2005/10/18 13:18:34 mungady Exp $ 36: * 37: * Changes (from 7-Nov-2001) 38: * ------------------------- 39: * 07-Nov-2001 : Added to com.jrefinery.ui package (DG); 40: * 08-Sep-2003 : Added internationalization via use of properties resourceBundle (RFE 690236) (AL); 41: * 42: */ 43: 44: package org.jfree.ui; 45: 46: import java.awt.Insets; 47: import java.util.ResourceBundle; 48: 49: import javax.swing.JTextField; 50: 51: /** 52: * A JTextField for displaying insets. 53: * 54: * @author Andrzej Porebski 55: */ 56: public class InsetsTextField extends JTextField { 57: 58: /** The resourceBundle for the localization. */ 59: protected static ResourceBundle localizationResources = 60: ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle"); 61: 62: /** 63: * Default constructor. Initializes this text field with formatted string describing 64: * provided insets. 65: * 66: * @param insets the insets. 67: */ 68: public InsetsTextField(final Insets insets) { 69: super(); 70: setInsets(insets); 71: setEnabled(false); 72: } 73: 74: /** 75: * Returns a formatted string describing provided insets. 76: * 77: * @param insets the insets. 78: * 79: * @return the string. 80: */ 81: public String formatInsetsString(Insets insets) { 82: insets = (insets == null) ? new Insets(0, 0, 0, 0) : insets; 83: return 84: localizationResources.getString("T") + insets.top + ", " 85: + localizationResources.getString("L") + insets.left + ", " 86: + localizationResources.getString("B") + insets.bottom + ", " 87: + localizationResources.getString("R") + insets.right; 88: } 89: 90: /** 91: * Sets the text of this text field to the formatted string 92: * describing provided insets. If insets is null, empty insets 93: * (0,0,0,0) are used. 94: * 95: * @param insets the insets. 96: */ 97: public void setInsets(final Insets insets) { 98: setText(formatInsetsString(insets)); 99: } 100: 101: }