001 /** 002 * Java Gui Builder - A library to build GUIs using an XML file. 003 * Copyright 2002, 2003 (C) François Beausoleil 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library; if not, write to the Free Software 017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018 */ 019 020 package jgb.handlers.swing; 021 022 import org.xml.sax.SAXException; 023 024 import javax.swing.*; 025 import javax.swing.text.JTextComponent; 026 import java.util.Map; 027 028 public class TextfieldTagHandler extends AbstractControlTagHandler { 029 /** 030 * The name of the rows attribute. 031 */ 032 protected static final String ATTR_ROWS = "rows"; 033 034 /** 035 * The name of the columns attribute. 036 */ 037 protected static final String ATTR_COLUMNS = "columns"; 038 039 protected void enterElement(Map atts) throws SAXException { 040 JTextComponent textComponent = null; 041 if (atts.containsKey(ATTR_ROWS)) { 042 int numRows = new Integer(atts.get(ATTR_ROWS).toString()).intValue(); 043 if (numRows > 1) { 044 JTextArea area = new JTextArea(); 045 textComponent = area; 046 047 area.setRows(numRows); 048 if (atts.containsKey(ATTR_COLUMNS)) { 049 area.setColumns(new Integer(atts.get(ATTR_COLUMNS).toString()).intValue()); 050 } 051 } 052 } 053 054 if (textComponent == null) { 055 JTextField field = new JTextField(); 056 textComponent = field; 057 if (atts.containsKey(ATTR_COLUMNS)) { 058 field.setColumns(new Integer(atts.get(ATTR_COLUMNS).toString()).intValue()); 059 } 060 } 061 062 if (atts.containsKey(ATTR_REFLABEL)) { 063 JLabel referrent = (JLabel)getObject(atts.get(ATTR_REFLABEL).toString()); 064 referrent.setLabelFor(textComponent); 065 } 066 067 if (atts.containsKey(ATTR_TEXT)) { 068 textComponent.setText(atts.get(ATTR_TEXT).toString()); 069 } 070 071 if (atts.containsKey(ATTR_ID)) { 072 putComponent(atts.get(ATTR_ID).toString(), textComponent); 073 } 074 075 pushCurrentControl(textComponent, (String)atts.get(ATTR_ID)); 076 } 077 078 protected void exitElement() throws SAXException { 079 popCurrentControl(); 080 } 081 082 protected String getDefaultPackagePrefix() { 083 return null; 084 } 085 }