Package DisplayProject.factory

Source Code of DisplayProject.factory.GraphicFactory

/*
Copyright (c) 2003-2008 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.Font;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;

import DisplayProject.Constants;
import DisplayProject.UIutils;
import DisplayProject.actions.Column;
import DisplayProject.actions.FrameWeight;
import DisplayProject.actions.HeightPolicy;
import DisplayProject.actions.Row;
import DisplayProject.actions.WidthPolicy;
import DisplayProject.controls.CompoundGraphic;
import DisplayProject.controls.Line;
import DisplayProject.controls.PictureGraphic;
import DisplayProject.controls.PolyLine;
import DisplayProject.controls.TextGraphic;
import Framework.ImageData;
import Framework.TextData;

/**
* This factory creates all the all the Forte graphic subclasses
*
*/
public class GraphicFactory {
    private GraphicFactory() {
        super();
    }
    public static CompoundGraphic newCompoundGraphic(){
        CompoundGraphic cg = new CompoundGraphic(null);
        cg.setLayout(null);
        cg.setBackground(null);
        return cg;
    }
   
    public static CompoundGraphic newCompoundGraphic(String name){
        CompoundGraphic gf = new CompoundGraphic(name);
        return gf;
    }
   
    public static CompoundGraphic newCompoundGraphic(TextData name){
        return newCompoundGraphic(TextData.valueOf(name));
    }
    /**
     * Create a new TextGraphic with the given caption and the given widget name. The returned
     * TextGraphic will never obtain the focus, nor is it opaque.
     * @param text - the text of the JLabel
     * @param widgetName - the name of the JLabel widget.
     * @return the newly created JLabel
     */
    public static TextGraphic newTextGraphic(String text, String widgetName){
        TextGraphic jl = new TextGraphic(text);
        jl.setFocusable(false);
        // jl.setOpaque(false);    // TF:25/07/2008:Moved this into the object constructor
        jl.setName(widgetName);
        // TF:21/11/07:removed the margin from here and added it to the GraphicFactory itself.
        //UIutils.labelWidth(jl);
        return jl;
    }
   
    public static TextGraphic newTextGraphic(Font font){
        TextGraphic jl = newTextGraphic(null, null);
        jl.setFont(font);
        return jl;
    }

    public static TextGraphic newTextGraphic(TextData text){
        TextGraphic jl = newTextGraphic(text.toString(), null);
        return jl;
    }

    public static PictureGraphic newPictureGraphic(String name, ImageData icon){
        return GraphicFactory.newPictureGraphic(name, icon.asIconImage());
    }
    public static PictureGraphic newPictureGraphic(String name, ImageIcon icon){
        return newPictureGraphic(name, icon, Constants.CG_CENTER);
    }

    public static PictureGraphic newPictureGraphic(String name, String resource, int imageGravity, Class<?> sourceClass){
        return newPictureGraphic(name, new ImageIcon(sourceClass.getClassLoader().getResource(resource)), imageGravity);//PM:2 oct. 2008:corrected to load the image
    }

    public static PictureGraphic newPictureGraphic() {
        return newPictureGraphic(null, Constants.CG_DEFAULT);
    }

    public static PictureGraphic newPictureGraphic(TextData name){ //PM:12/9/07
        return newPictureGraphic(name.toString(), Constants.CG_DEFAULT);
    }
    public static PictureGraphic newPictureGraphic(String name){ //PM:5/11/07
        return newPictureGraphic(name, Constants.CG_DEFAULT);
    }
    public static PictureGraphic newPictureGraphic(String name, int imageGravity){
        PictureGraphic jl = new PictureGraphic();
        jl.setBackground(null);
        jl.setName(name);
        jl.setFocusable(false);
        switch (imageGravity) {
            case Constants.CG_TOPLEFT:
                jl.setHorizontalAlignment(SwingConstants.LEFT);
                jl.setVerticalAlignment(SwingConstants.TOP);

            case Constants.CG_TOPCENTER:
                jl.setHorizontalAlignment(SwingConstants.CENTER);
                jl.setVerticalAlignment(SwingConstants.TOP);

            case Constants.CG_TOPRIGHT:
                jl.setHorizontalAlignment(SwingConstants.RIGHT);
                jl.setVerticalAlignment(SwingConstants.TOP);

            case Constants.CG_MIDDLELEFT:
                jl.setHorizontalAlignment(SwingConstants.LEFT);
                jl.setVerticalAlignment(SwingConstants.CENTER);

            case Constants.CG_MIDDLERIGHT:
                jl.setHorizontalAlignment(SwingConstants.RIGHT);
                jl.setVerticalAlignment(SwingConstants.CENTER);

            case Constants.CG_BOTTOMLEFT:
                jl.setHorizontalAlignment(SwingConstants.LEFT);
                jl.setVerticalAlignment(SwingConstants.BOTTOM);

            case Constants.CG_BOTTOMCENTER:
                jl.setHorizontalAlignment(SwingConstants.CENTER);
                jl.setVerticalAlignment(SwingConstants.BOTTOM);

            case Constants.CG_BOTTOMRIGHT:
                jl.setHorizontalAlignment(SwingConstants.RIGHT);
                jl.setVerticalAlignment(SwingConstants.BOTTOM);

            default:
                jl.setHorizontalAlignment(SwingConstants.CENTER);
                jl.setVerticalAlignment(SwingConstants.CENTER);

        }
        return jl;
    }
    public static PictureGraphic newPictureGraphic(String name, ImageIcon icon, int imageGravity){
        PictureGraphic jl = newPictureGraphic(name, imageGravity);
        jl.setIcon(icon);
        return jl;
    }
    public static PictureGraphic newPictureGraphic(String name, URL resource, int imageGravity){
        PictureGraphic label = null;
        if (resource != null) {
            try {
                BufferedImage image = ImageIO.read(resource);
                if (image != null) {
                    ImageIcon icon = new ImageIcon(image);
                    label = newPictureGraphic(name, icon, imageGravity);
                }
                else
                    label = newPictureGraphic(name, Constants.CG_TOPLEFT);
                    label.setText("<" + resource + ">");
            } catch (IOException e) {
                label = newPictureGraphic(name, Constants.CG_TOPLEFT);
                label.setText("<" + resource + ">");
            }
        }
        else{
            label = newPictureGraphic(name, Constants.CG_TOPLEFT);
            label.setText("< unknown resource >");
        }
        return label;
    }

    public static Line newLine(int startX, int startY, int endX, int endY){
        Line l = new Line(startX, startY, endX, endY);
        l.setFocusable(false);
        l.setOpaque(false);
        return l;
    }
    public static PolyLine newPolyLine(int x, int y){
        PolyLine l = new PolyLine();
        l.setFocusable(false);
        l.setOpaque(false);
        l.setLocation(x, y);
        return l;
    }

    // TF:18/05/2010:Changed the result of these methods to be TextGraphics not JLabels, otherwise the
    // results must be downcast to TextGraphics upon assignment
    public static TextGraphic newTextGraphic(Object appData,
            int column,
            Font font,
            int frameWeight,
            int heightPolicy,
            int row,
            int state,
            int widthPolicy ){
      TextGraphic jl = newTextGraphic(column, font, frameWeight, heightPolicy, row, widthPolicy);
        UIutils.setState(jl, state);
        // TF:15/02/2010:Corrected this name to qq_AppData from aa_AppData
        jl.putClientProperty("qq_AppData", appData);


        return jl;
    }
    public static TextGraphic newTextGraphic(int column,
            Font font,
            int frameWeight,
            int heightPolicy,
            int row,
            int widthPolicy ){
      TextGraphic jl = newTextGraphic(null, null);
        Column.set(jl, column);
        jl.setFont(font);
        FrameWeight.set(jl, frameWeight);
        HeightPolicy.set(jl, heightPolicy);
        Row.set(jl, row);
        WidthPolicy.set(jl, widthPolicy);

        return jl;
    }
}
TOP

Related Classes of DisplayProject.factory.GraphicFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.