Package DisplayProject.factory

Source Code of DisplayProject.factory.GraphicFactory

/*
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.Container;
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.CompoundField;
import DisplayProject.Constants;
import DisplayProject.GridCell;
import DisplayProject.UIutils;
import DisplayProject.actions.AppData;
import DisplayProject.actions.ColourChange;
import DisplayProject.actions.Column;
import DisplayProject.actions.FrameWeight;
import DisplayProject.actions.HeightPolicy;
import DisplayProject.actions.Parent;
import DisplayProject.actions.Row;
import DisplayProject.actions.WidgetState;
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 = newTextGraphic(text);
        jl.setName(widgetName);
        return jl;
    }
   
    /**
     * 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 appData - the appData to set on the widget
     * @param text - the text of the JLabel
     * @return the newly created JLabel
     */
    public static TextGraphic newTextGraphic(Object appData, String text){
      TextGraphic jl = newTextGraphic(text);
      AppData.set(jl, appData);
      return jl;
    }
   
    /**
     * 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 appData - the appData to set on the widget
     * @param text - the text of the JLabel
     * @return the newly created JLabel
     */
    public static TextGraphic newTextGraphic(Object appData, TextData text){
      TextGraphic jl = newTextGraphic(text);
      AppData.set(jl, appData);
      return jl;
    }
   
    /**
     * 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(TextData text, String widgetName){
      return newTextGraphic(TextData.valueOf(text), widgetName);
    }
   
    public static TextGraphic newTextGraphic(Font font){
        TextGraphic jl = newTextGraphic((String)null);
        jl.setFont(font);
        return jl;
    }

    public static TextGraphic newTextGraphic(TextData text){
        TextGraphic jl = newTextGraphic(TextData.valueOf(text));
        return jl;
    }
   
    /**
     * Create a new TextGraphic with the given caption. The returned
     * TextGraphic will never obtain the focus, nor is it opaque.
     * @param text - the text of the JLabel
     * @return the newly created JLabel
     */
    public static TextGraphic newTextGraphic(String text) {
        TextGraphic jl = new TextGraphic(text);
        jl.setFocusable(false);
        // 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() {
      TextGraphic jl = new TextGraphic();
      jl.setFocusable(false);
      return jl;
    }
   
    /**
     * Create a new TextGraphic with the given caption. The returned
     * TextGraphic will never obtain the focus, nor is it opaque.
     * @param text - the text of the JLabel
     * @return the newly created JLabel
     */
    public static TextGraphic newTextGraphic(int column, int row) {
      TextGraphic jl = newTextGraphic();
      Row.set(jl, row);
      Column.set(jl, column);
      return jl;
    }
   
    // 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(font);
        Column.set(jl, column);
        FrameWeight.set(jl, frameWeight);
        HeightPolicy.set(jl, heightPolicy);
        Row.set(jl, row);
        WidthPolicy.set(jl, widthPolicy);

        return jl;
    }

    public static TextGraphic newTextGraphic(int column,
        Font font,
        int row,
        int state,
        String text) {
      TextGraphic jl = newTextGraphic(text);
      jl.setFont(font);
      Column.set(jl, column);
      Row.set(jl, row);
      WidgetState.set(jl, state);
     
      return jl;
    }
   
    public static TextGraphic newTextGraphic(int column,
        Font font,
        int row,
        int state,
        TextData text) {
      return newTextGraphic(column, font, row, state, TextData.valueOf(text));
    }
   
    public static TextGraphic newTextGraphic(int column,
        Font font,
        int row,
        String text) {
      TextGraphic jl = newTextGraphic(text);
      jl.setFont(font);
      Column.set(jl, column);
      Row.set(jl, row);
     
      return jl;
    }
   
    public static TextGraphic newTextGraphic(int column,
        Font font,
        int row,
        TextData text) {
      return newTextGraphic(column, font, row, TextData.valueOf(text));
    }
   
    public static TextGraphic newTextGraphic(int column,
        int gravity,
        Container parent,
        int penColor,
        int row,
        String text) {
      TextGraphic jl = newTextGraphic(text);
      GridCell cell = GridCell.get(jl);
      cell.setCellGravity(gravity);
      cell.setRow(row-1);
      cell.setColumn(column-1);

      Parent.set(jl, parent);
      ColourChange.setForeground(jl, penColor);
      return jl;
    }
    public static TextGraphic newTextGraphic(int column,
        int gravity,
        CompoundField parent,
        int penColor,
        int row,
        String text) {
      return newTextGraphic(column, gravity, (Container)parent, penColor, row, text);
    }   
    public static TextGraphic newTextGraphic(int column,
        int gravity,
        Container parent,
        int penColor,
        int row,
        TextData text) {
      return newTextGraphic(column, gravity, parent, penColor, row, TextData.valueOf(text));
    }   
    public static TextGraphic newTextGraphic(int column,
        int gravity,
        CompoundField parent,
        int penColor,
        int row,
        TextData text) {
      return newTextGraphic(column, gravity, (Container)parent, penColor, row, TextData.valueOf(text));
    }   
    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;
    }
}
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.