//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
*
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
package com.nexirius.framework.swing;
import com.nexirius.framework.onlinehelp.OnlineHelp;
import com.nexirius.util.XString;
import com.nexirius.util.assertion.Assert;
import com.nexirius.util.resource.ClientResource;
import com.nexirius.util.resource.ResourceChangeEvent;
import javax.swing.*;
import java.awt.*;
/**
* A JTextField which responds to changes in client resources.
* Changes can include Tool tip text
* <p/>
* Property name Component Property
* ------------- ------------------
* resourceKey.tip tooltiptext
* <p/>
*
* @author Marcel Baumann
* Date Author Changes/Enhancements
* 1999.02.19 MB Created
*/
public class CFJTextField
extends JTextField
implements CFJItem {
private static Insets defaultInsets = new Insets(1, 3, 1, 3);
// The key used to look up specific resources
private String resourceKey;
/**
* Construct a CFJTextField (Client Framework JTextField)
* Need a null constructor so we can use this class in a GUI builder
*/
public CFJTextField() {
super();
setMargin(defaultInsets);
}
/**
* Construct a CFJTextField
*
* @param resource The resource to be used to establish basic attributes
* of the JTextField
* @param resourceKey The key to be used in establishing resources
*/
public CFJTextField(ClientResource resource, String resourceKey) {
super(resourceKey);
Assert.pre(resource != null, "Parameter resource is not null");
Assert.pre(resourceKey != null, "Parameter resourceKey is not null");
this.resourceKey = resourceKey;
OnlineHelp.set(this, resourceKey);
update(resource);
resource.addResourceChangeListener(this);
setMargin(defaultInsets);
}
/**
* Get the resource key
*
* @return the resource key
*/
public String getResourceKey() {
return this.resourceKey;
}
/**
* Set the resource key
*
* @param resourceKey the resource key
*/
public void setResourceKey(String resourceKey) {
Assert.pre(resourceKey != null, "Parameter resourceKey is not null");
this.resourceKey = resourceKey;
OnlineHelp.set(this, resourceKey);
}
/**
* @see import com.nexirius.util.resource.ResourceChangeListener;
*/
public void resourceChange(ResourceChangeEvent event) {
update(event.getClientResource());
}
/**
* Update properties based on client resource
*
* @param clientResource the resource to be used to establish properties
*/
public void update(ClientResource clientResource) {
if (resourceKey == null) {
return;
}
String tip = clientResource.getToolTipText(resourceKey);
if (tip != null) {
XString xs = new XString(tip);
xs.replace("\\n", "\n");
setToolTipText(xs.toString());
}
}
}