/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package DisplayProject.factory;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import DisplayProject.GridCell;
import DisplayProject.TableJButton;
import Framework.TextData;
/**
* This class is a factory for JButton (PuchButton)
* @author Peter & Tim
*
*/
public class PushButtonFactory {
public class qq_Resolver {
public static final int cNAME = 1;
public static final int cLABEL = 2;
public static final int cNAME_LABEL = 3;
public static final int cLABEL_NAME = 4;
public static final int cCOLUMN_ROW = 5;
}
private PushButtonFactory() {
super();
}
/**
* Create a new JButton with the given name and text. Note that the returned value will be a
* TableJButton (ie can be used as a table cell renderer if needed) to ensure that proper
* click behaviour is implemented.
* @see TableJButton
* @param name the name of the button
* @param text the text to be displayed on the button
* @return the newly created button instance
*/
public static TableJButton newInstance(String name, String text){
return newTableInstance(name, text);
}
public static TableJButton newInstance(String first, String second, int resolver){
switch (resolver){
case qq_Resolver.cNAME_LABEL:
return newTableInstance(first, second);
case qq_Resolver.cLABEL_NAME:
return newTableInstance(second, first);
}
return null;
}
public static TableJButton newInstance(int first, int second, int resolver){
switch (resolver){
case qq_Resolver.cCOLUMN_ROW:
TableJButton result = newInstance();
GridCell.get(result).setColumn(first);
GridCell.get(result).setRow(second);
return result;
}
return null;
}
public static TableJButton newInstance(TextData first, TextData second, int resolver){
return newInstance(first.toString(), second.toString(), resolver);
}
public static TableJButton newInstance(String value, int resolver){
switch (resolver){
case qq_Resolver.cNAME:
return newInstance(value);
case qq_Resolver.cLABEL:
TableJButton jb = newInstance("");
jb.setText(value);
return jb;
}
return null;
}
public static TableJButton newInstance(TextData value, int resolver){
switch (resolver){
case qq_Resolver.cNAME:
return newInstance(value);
case qq_Resolver.cLABEL:
TableJButton jb = newInstance("");
jb.setText(TextData.valueOf(value));
return jb;
}
return null;
}
/**
* Create a new JButton with the given name and icon. Note that the returned value will be a
* TableJButton (ie can be used as a table cell renderer if needed) to ensure that proper
* click behaviour is implemented.
* @see TableJButton
* @param name the name of the button
* @param icon the text to be displayed on the button
* @return the newly created button instance
*/
public static TableJButton newInstance(String name, Icon icon){
return newTableInstance(name, icon);
}
public static TableJButton newInstance(){
return _newInstance(new TableJButton(), null);
}
public static TableJButton newInstance(String name){
return _newInstance(new TableJButton(), name);
}
public static TableJButton newInstance(TextData name){
return newInstance(name.toString());
}
public static TableJButton newInstance(String name, URL resource){
if (resource != null) {
try {
BufferedImage image = ImageIO.read(resource);
if (image != null) {
ImageIcon icon = new ImageIcon(image);
return newInstance(name, icon);
}
else
return newInstance(name, "<" + resource + ">");
} catch (IOException e) {
return newInstance(name, "<" + resource + ">");
}
}
else
return newInstance(name, "<unknown resource>");
}
public static TableJButton newTableInstance(String name, String text){
TableJButton jb = _newInstance(new TableJButton(), name);
jb.setText( text );
return (TableJButton)jb;
}
public static TableJButton newTableInstance(String name, Icon icon){
TableJButton jb = _newInstance(new TableJButton(), name);
jb.setIcon( icon );
return (TableJButton)jb;
}
protected static TableJButton _newInstance(TableJButton jb, String name){
jb.setName( name );
jb.setMargin( new Insets(0, 0, 0, 0) );
// TF:17 Sep 2009:Moved this to the actual control
// jb.addMouseListener(StatusTextListener.sharedInstance()); // implements status line text
return jb;
}
}