Package net.helipilot50.stocktrade.displayproject.factory

Source Code of net.helipilot50.stocktrade.displayproject.factory.CompoundFieldFactory

/*
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 net.helipilot50.stocktrade.displayproject.factory;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;

import net.helipilot50.stocktrade.displayproject.ArrayFieldModel;
import net.helipilot50.stocktrade.displayproject.CompoundField;
import net.helipilot50.stocktrade.displayproject.Constants;
import net.helipilot50.stocktrade.displayproject.GridField;
import net.helipilot50.stocktrade.displayproject.PanelLayoutManager;
import net.helipilot50.stocktrade.displayproject.PopupListener;
import net.helipilot50.stocktrade.displayproject.UIutils;
import net.helipilot50.stocktrade.displayproject.WindowFormLayout;
import net.helipilot50.stocktrade.displayproject.actions.ActionMgr;
import net.helipilot50.stocktrade.displayproject.actions.Caption;
import net.helipilot50.stocktrade.displayproject.actions.Column;
import net.helipilot50.stocktrade.displayproject.actions.FieldWidgetGravity;
import net.helipilot50.stocktrade.displayproject.actions.FrameWeight;
import net.helipilot50.stocktrade.displayproject.actions.HeightPolicy;
import net.helipilot50.stocktrade.displayproject.actions.Parent;
import net.helipilot50.stocktrade.displayproject.actions.Row;
import net.helipilot50.stocktrade.displayproject.actions.Widget;
import net.helipilot50.stocktrade.displayproject.actions.WidgetState;
import net.helipilot50.stocktrade.displayproject.actions.WidthPolicy;
import net.helipilot50.stocktrade.displayproject.controls.CompoundGraphic;
import net.helipilot50.stocktrade.displayproject.controls.Panel;
import net.helipilot50.stocktrade.displayproject.controls.ScrollList;
import net.helipilot50.stocktrade.displayproject.controls.TabFolder;
import net.helipilot50.stocktrade.displayproject.events.ClientEventManager;
import net.helipilot50.stocktrade.displayproject.plaf.ForteLayoutFocusTraversalPolicy;
import net.helipilot50.stocktrade.framework.ListElement;
import net.helipilot50.stocktrade.framework.TextData;


/**
* This factory construct the Forte CompoundFields
*
* @author Peter
*/
public class CompoundFieldFactory {

  /**
   * Default constructor
   */
  private CompoundFieldFactory() {
    super();
  }

  /**
   * Factory method for creating the main Form that all UI components on a
   * Frame are contained within. This is the equivalent of the Form field in
   * Forte.
   *
   * @return A <code>Panel</code> which represents the Form
   */
  public static Panel newForm() {
    Panel gf = new Panel();
    gf.setName("Form");
    gf.setDoubleBuffered(true);
    gf.setFocusable(false);
    gf.setBackground(null);
    // TF:19/06/2008:Added the instantiation of the layout manager here
    gf.setLayout(new WindowFormLayout());

    gf.setFocusTraversalPolicyProvider(true);
    gf.setFocusTraversalPolicy(new ForteLayoutFocusTraversalPolicy()); // CraigM:01/09/2008 - Moved code into special class.

    return gf;
  }

  /**
   * Factory method for creating a ScrollPane
   *
   * @return The created <code>JScrollPane</code>
   */
  @SuppressWarnings("serial")
  public static JScrollPane newScrollPane() {
    JScrollPane sp = new JScrollPane() {
      // TF:06/11/2008:When our minimum size changes, we may need to layout our
      // parent again, particularly when it's a panel. Thus we force a layout.
      @Override
      public void setMinimumSize(Dimension minimumSize) {
        super.setMinimumSize(minimumSize);
        if (this.getParent() != null) {
          this.getParent().invalidate();
          this.getParent().validate();
        }
      }
     
      @Override
      public Dimension getMinimumSize() {
       
        // CraigM:08/01/2009 - ScrollPanes will size their width to their contents (unless Explicit size)
        // TF:19/07/2009:Cleaned this up for better code style and to be able to reduce the size down to smaller
        // than the preset minimum, as per DET-103
        Component underlyingComponent = this.getViewport() != null ? this.getViewport().getView() : null;
        if (underlyingComponent instanceof ScrollList) {
//          if (this.getComponentCount() > 0
//              && this.getComponent(0) instanceof JViewport
//              && ((JViewport)this.getComponent(0)).getComponentCount() > 0
//              && ((JViewport)this.getComponent(0)).getComponent(0) instanceof ScrollList) {
            if (WidthPolicy.get(this) == Constants.SP_EXPLICIT) {
              return super.getMinimumSize();
            }
              Dimension minimum = super.getMinimumSize();
             
              if (minimum == null) {
                minimum = new Dimension(10,10);
              }
              ScrollList scrollList = (ScrollList)underlyingComponent;
              List<ListElement> items = scrollList.getElementList();
             
              // TF:19/07/2009:The size for an empty list or a null list is 80 pixels in Forte, including the scrollbar
              if (items == null || items.size() == 0) {
                minimum.width = 80;
              }
              else {
                minimum.width = scrollList.getWidthForData();
                if (this.verticalScrollBar.isVisible()) {
                  minimum.width += this.verticalScrollBar.getWidth();
                }
              }
//              minimum.width = Math.max(minimum.width, ((ScrollList)((JViewport)this.getComponent(0)).getComponent(0)).getWidthForModel());
             
              return minimum;
          }
          return super.getMinimumSize();
      }
     
      @Override
      public void setViewportView(Component view) {
        super.setViewportView(view);
        if (view instanceof ScrollList) {
          this.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        }
      }
     
      @Override
      public void setVerticalScrollBarPolicy(int policy) {
        if (this.getViewport() != null && this.getViewport().getView() instanceof ScrollList) {
          super.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        }
        else {
          super.setVerticalScrollBarPolicy(policy);
        }
      }
    };
    sp.getHorizontalScrollBar().setVisible(false);
    sp.getVerticalScrollBar().setVisible(false);
    sp.setInheritsPopupMenu(true);
    sp.getViewport().setInheritsPopupMenu(true);
    return sp;
  }

  /**
   * Factory method for creating a ScrollPane that contains a
   * <code>JTable</code>.
   *
   * @param view
   *            The view that will be contained in the ScrollPane
   * @return The created <code>JScrollPane</code>
   */
  public static JScrollPane newScrollPane(final JTable view) {
    JScrollPane sp = newScrollPane();

    // If the table allows append then ensure there is sufficient space in
    // the viewport to allow append click
    if (((ArrayFieldModel) view.getModel()).allowsAppend()) {
      sp.setOpaque(false);
      sp.setViewport(new JViewport() {

        private static final long serialVersionUID = 1198452025480683030L;

        public Dimension getViewSize() {
          Dimension d = super.getViewSize();

          if (((JTable) getView()) != null
              && ((ArrayFieldModel) ((JTable) getView())
                  .getModel()).allowsAppend()) {
            d.height = d.height
                + ((JTable) getView()).getRowHeight();
          }
          return d;
        }
      });
      sp.setViewportView(view);
    } else
      sp.setViewportView(view);

    // Change background to white as default color. add mouselistener to
    // deligate event to jtable.
    sp.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        if (SwingUtilities.isRightMouseButton(e)) {
          MouseEvent me = new MouseEvent(view,
              MouseEvent.MOUSE_CLICKED, e.getWhen(), e
                  .getModifiers(), e.getX(), e.getY(), 1,
              true, 1);
          MouseListener[] ms = view.getMouseListeners();
          for (int i = 0; i < ms.length; i++) {
            if (ms[i] instanceof PopupListener)
              ((PopupListener) ms[i]).mousePressed(me);
          }
        } else {
          ClientEventManager.postEvent(view, "ChildClick");
        }
      }
    });

    return sp;
  }

  /**
   * Factory method for creating a Forte ViewPort
   *
   * @param name
   *            The name of the ViewPort
   * @return JScrollpane as the implementation of a ViewPort
   */
  public static JScrollPane newViewPort(String name) {
    JScrollPane sp = new JScrollPane();
    sp.setName(name);
    sp.getHorizontalScrollBar().setVisible(false);
    sp.getVerticalScrollBar().setVisible(false);
    // TF:9/11/07:Refactored this method to initialise the state properly
    // for coded widgets, instead of declared widgets
    WidgetState.set(sp, Constants.FS_UPDATE);
    return sp;
  }

  /**
   * Factory Method to create a GridField
   *
   * @param name
   *            Name of the GridField
   * @return The created GridField
   */
  public static GridField newGridField(String name) {
    GridField gf = new GridField(name);
    return gf;
  }

  /**
   * Factory Method to create a GridField
   *
   * @param name
   *            Name of the GridField
   * @param generatedName
   *            Specifies whether the name is a generated name or the
   *            Component Name. If true it is the generated name if false then
   *            the component name
   * @return The created GridField
   */
  public static GridField newGridField(String name, boolean generatedName) {
    GridField gf = new GridField(name, generatedName);
    return gf;
  }

  /**
   * Factory Method to create a GridField
   *
   * @return The created GridField
   */
  public static GridField newGridField() {
    // TF:9/11/07:Refactored this method to initialise the state properly
    // for coded widgets, instead of declared widgets
    GridField gf = new GridField();
    WidgetState.set(gf, Constants.FS_UPDATE);
    return gf;
  }

  /**
   * Factory Method to create a GridField
   *
   * @param name
   *            Name of the GridField
   * @param generatedName
   *            Specifies whether the name is a generated name or the
   *            Component Name. If true it is the generated name if false then
   *            the component name
   * @return The created GridField
   */
  public static GridField newGridField(TextData name) {
    return newGridField(name.toString());

  }

  /**
   * Factory Method to create a GridField
   *
   * @param name
   *            Name of the GridField
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param caption
   *            The Caption to use.
   * @param bc
   *            The Background colour.
   * @return The created GridField
   */
  public static GridField newGridField(String name, int frameWeight,
      String caption, Color bc) {
    GridField gf = new GridField(name);
    FrameWeight.set(gf, frameWeight);
    Caption.set(gf, caption);
    return gf;
  }

  /**
   * Factory Method to create a GridField
   *
   * ISSUE 35 - Allow font style to be added to grid title
   *
   * @param name
   *            Name of the GridField
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param caption
   *            The Caption to use.
   * @param bc
   *            The Background colour.
   * @param fontStyle
   *            The fontStyle to use for the caption, but gets ignored and is
   *            not translated at this stage
   * @return The created GridField
   */
  public static GridField newGridField(String name, int frameWeight,
      String caption, Color bc, int fontStyle) {
    GridField gf = new GridField(name);
    FrameWeight.set(gf, frameWeight);
    Caption.set(gf, caption);

    return gf;
  }

  /**
   * Factory Method to create a GridField
   *
   * ISSUE 35 - Allow font style to be added to grid title
   *
   * @param name
   *            Name of the GridField
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param caption
   *            The Caption to use.
   * @param bc
   *            The Background colour.
   * @param fontStyle
   *            The fontStyle to use for the caption, but gets ignored and is
   *            not translated at this stage
   * @return The created GridField
   */
  public static GridField newGridField(
      int cellLeftMargin,
      int cellRightMargin,
      int column,
      int frameWeight,
      int gravity,
      int heightPolicy,
      int horzDividerWeight,
      int minWidthInPixels,
      Container parent,
      int row,
      int vertDividerWeight,
      int widthPolicy) {
   
    GridField gf = new GridField();
    gf.setCellLeftMargin(cellLeftMargin);
    gf.setCellRightMargin(cellRightMargin);
    gf.setHorzDividerWeight(horzDividerWeight);
    gf.setVertDividerWeight(vertDividerWeight);
    gf.setMinWidth(minWidthInPixels);

    Column.set(gf, column);
    Row.set(gf, row);
    FrameWeight.set(gf, frameWeight);
    FieldWidgetGravity.set(gf, gravity);
    HeightPolicy.set(gf, heightPolicy);
    WidthPolicy.set(gf, widthPolicy);
    Parent.set(gf, parent);
   
    return gf;
  }
 
  /**
   * Factory Method to create a GridField
   *
   * ISSUE 35 - Allow font style to be added to grid title
   *
   * @param name
   *            Name of the GridField
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param caption
   *            The Caption to use.
   * @param bc
   *            The Background colour.
   * @param fontStyle
   *            The fontStyle to use for the caption, but gets ignored and is
   *            not translated at this stage
   * @return The created GridField
   */
  public static GridField newGridField(
      int cellLeftMargin,
      int cellRightMargin,
      int column,
      int frameWeight,
      int gravity,
      int heightPolicy,
      int horzDividerWeight,
      int minWidthInPixels,
      CompoundField parent,
      int row,
      int vertDividerWeight,
      int widthPolicy) {
    return newGridField(cellLeftMargin, cellRightMargin, column, frameWeight, gravity, heightPolicy, horzDividerWeight, minWidthInPixels, (Container)parent, row, vertDividerWeight, widthPolicy);
  }
 
  /**
   * Factory Method to create a <code>Panel</code>
   *
   * ISSUE 35 - Allow font style to be added to Panel title
   *
   * @param name
   *            Name of the Panel
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param caption
   *            The caption to use in the title.
   * @param bc
   *            The Background colour.
   * @param fontStyle
   *            The fontStyle to use for the caption, but gets ignored and is
   *            not translated at this stage
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(String name, int frameWeight, String caption,
      Color bc, int fontStyle) {
    Panel gf = newPanel(name);
    FrameWeight.set(gf, frameWeight);
    Caption.set(gf, caption);

    gf.setOpaque(true);
    gf.setBackground(null);

    return gf;
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param name
   *            Name of the Panel
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param caption
   *            The caption to use in the title.
   * @param bc
   *            The Background colour.
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(String name, int frameWeight, String caption,
      Color bc) {
    Panel gf = newPanel(name);
    FrameWeight.set(gf, frameWeight);
    Caption.set(gf, caption);
    gf.setOpaque(true);
    gf.setBackground(null);
    // TF:21/8/07:When we add components to the panel we have to cater for
    // the border offsets. However,
    // because this component isn't always created on the GUI thread the
    // border may not be set prior to
    // us adding the components because it's in the pending action queue.
    // Hence we process this queue first.
    // PM:15/11/07 change processGUIActions to be specific to this object
    ActionMgr.processGUIActions(gf);
    return gf;
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel() {
    // TF:9/11/07:Refactored this method to initialise the state properly
    // for coded widgets, instead of declared widgets
    Panel result = newPanel((String) null);
    WidgetState.set(result, Constants.FS_UPDATE);
    return result;
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param height
   *            The height parameter (int) specifies the height of the
   *            <code>Panel</code>, including its frame, in mils.
   * @param parent
   *            The parent parameter (CompoundField) specifies the immediate
   *            parent widget. The parent widget must be one of the compound
   *            fields, such as a panel or an array field.
   * @param width
   *            The width parameter (int) specifies the width of the
   *            <code>Panel</code>, including its border, in mils.
   * @param x
   *            The x parameter (int) specifies the x (horizontal) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. X is measured in mils, from left to right.
   * @param y
   *            The y parameter (int) specifies the y (vertical) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. Y is measured in mils from top to bottom.
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(int frameWeight, int height, Container parent,
      int width, int x, int y) {
    return newPanel(x, y, height, width, frameWeight, parent);
  }


  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param height
   *            The height parameter (int) specifies the height of the
   *            <code>Panel</code>, including its frame, in mils.
   * @param parent
   *            The parent parameter (CompoundField) specifies the immediate
   *            parent widget. The parent widget must be one of the compound
   *            fields, such as a panel or an array field.
   * @param width
   *            The width parameter (int) specifies the width of the
   *            <code>Panel</code>, including its border, in mils.
   * @param x
   *            The x parameter (int) specifies the x (horizontal) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. X is measured in mils, from left to right.
   * @param y
   *            The y parameter (int) specifies the y (vertical) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. Y is measured in mils from top to bottom.
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(int frameWeight, int height, CompoundField parent,
      int width, int x, int y) {
    return newPanel(x, y, height, width, frameWeight, (Container)parent);
  }
 
  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param height
   *            The height parameter (int) specifies the height of the
   *            <code>Panel</code>, including its frame, in mils.
   * @param parent
   *            The parent parameter (CompoundField) specifies the immediate
   *            parent widget. The parent widget must be one of the compound
   *            fields, such as a panel or an array field.
   * @param width
   *            The width parameter (int) specifies the width of the
   *            <code>Panel</code>, including its border, in mils.
   * @param x
   *            The x parameter (int) specifies the x (horizontal) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. X is measured in mils, from left to right.
   * @param y
   *            The y parameter (int) specifies the y (vertical) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. Y is measured in mils from top to bottom.
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(int frameWeight, int height, Panel parent,
      int width, int x, int y) {
    return newPanel(x, y, height, width, frameWeight, parent);
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param parent
   *            The parent parameter (CompoundField) specifies the immediate
   *            parent widget. The parent widget must be one of the compound
   *            fields, such as a panel or an array field.
   * @param x
   *            The x parameter (int) specifies the x (horizontal) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. X is measured in mils, from left to right.
   * @param y
   *            The y parameter (int) specifies the y (vertical) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. Y is measured in mils from top to bottom.
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(int frameWeight, CompoundField parent, int x, int y) {
    return CompoundFieldFactory.newPanel(frameWeight, (Container)parent, x, y);
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param parent
   *            The parent parameter (Panel) specifies the immediate
   *            parent widget. The parent widget must be one of the compound
   *            fields, such as a panel or an array field.
   * @param x
   *            The x parameter (int) specifies the x (horizontal) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. X is measured in mils, from left to right.
   * @param y
   *            The y parameter (int) specifies the y (vertical) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. Y is measured in mils from top to bottom.
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(int frameWeight, Panel parent, int x, int y) {
    return CompoundFieldFactory.newPanel(frameWeight, (Container)parent, x, y);
  }
 
  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param height
   *            The height parameter (int) specifies the height of the
   *            <code>Panel</code>, including its frame, in mils.
   * @param parent
   *            The parent parameter (CompoundField) specifies the immediate
   *            parent widget. The parent widget must be one of the compound
   *            fields, such as a panel or an array field.
   * @param width
   *            The width parameter (int) specifies the width of the
   *            <code>Panel</code>, including its border, in mils.
   * @param x
   *            The x parameter (int) specifies the x (horizontal) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. X is measured in mils, from left to right.
   * @param y
   *            The y parameter (int) specifies the y (vertical) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. Y is measured in mils from top to bottom.
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(int x, int y, int height, int width,
      int frameWeight, Container parent) {
    Panel jp = newPanel((String) null);
    Widget.configure(jp, x, y, width, height);
    FrameWeight.set(jp, frameWeight);
    Parent.set(jp, parent);
    jp.setBackground(null);
    return jp;
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param parent
   *            The parent parameter (CompoundField) specifies the immediate
   *            parent widget. The parent widget must be one of the compound
   *            fields, such as a panel or an array field.
   * @param x
   *            The x parameter (int) specifies the x (horizontal) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. X is measured in mils, from left to right.
   * @param y
   *            The y parameter (int) specifies the y (vertical) position of
   *            the <code>Panel</code> and its border relative to its parent
   *            widget. Y is measured in mils from top to bottom.
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(int frameWeight, Container parent, int x, int y) {
    Panel jp = newPanel((String) null);
    FrameWeight.set(jp, frameWeight);
    Parent.set(jp, parent);
    jp.setLocation(UIutils.milsToPixels(x), UIutils.milsToPixels(y));
    jp.setBackground(null);
    return jp;
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param caption
   *       The caption displayed on the panel
   * @param heightPolicy
   *       The height policy of the panel. This should be one of the SP_ constants
   * @param name
   *       The name of the panel
   * @param widthPolicy
   *       The width policy of the panel. This should be one of the SP_ constants
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(String caption, int heightPolicy, String name, int widthPolicy) {
    Panel panel = newPanel(name);
    HeightPolicy.set(panel, heightPolicy);
    WidthPolicy.set(panel, widthPolicy);
    Caption.set(panel, caption);
    return panel;
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param caption
   *       The caption displayed on the panel
   * @param heightPolicy
   *       The height policy of the panel. This should be one of the SP_ constants
   * @param name
   *       The name of the panel
   * @param widthPolicy
   *       The width policy of the panel. This should be one of the SP_ constants
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(TextData caption, int heightPolicy, String name, int widthPolicy) {
    Panel panel = newPanel(name);
    HeightPolicy.set(panel, heightPolicy);
    WidthPolicy.set(panel, widthPolicy);
    Caption.set(panel, caption);
    return panel;
  }
 
  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param caption
   *       The caption displayed on the panel
   * @param heightPolicy
   *       The height policy of the panel. This should be one of the SP_ constants
   * @param name
   *       The name of the panel
   * @param widthPolicy
   *       The width policy of the panel. This should be one of the SP_ constants
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(String caption, int heightPolicy, TextData name, int widthPolicy) {
    Panel panel = newPanel(name);
    HeightPolicy.set(panel, heightPolicy);
    WidthPolicy.set(panel, widthPolicy);
    Caption.set(panel, caption);
    return panel;
  }
 
  /**
   * Factory Method to create a <code>Panel</code>
   *
   *
   * @param caption
   *       The caption displayed on the panel
   * @param heightPolicy
   *       The height policy of the panel. This should be one of the SP_ constants
   * @param name
   *       The name of the panel
   * @param widthPolicy
   *       The width policy of the panel. This should be one of the SP_ constants
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(TextData caption, int heightPolicy, TextData name, int widthPolicy) {
    Panel panel = newPanel(name);
    HeightPolicy.set(panel, heightPolicy);
    WidthPolicy.set(panel, widthPolicy);
    Caption.set(panel, caption);
    return panel;
  }
 
  /**
   * Factory Method to create a <code>Panel</code>
   *
   * @param name
   *            Name of the Panel
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(TextData name) {
    return newPanel(name.toString());
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   * @param name
   *            Name of the Panel
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(String name) {
    Panel panel = new Panel();
    int size = UIutils.milsToPixels(5000);
    panel.setSize(size, size);
    // panel.setMinimumSize(panel.getSize());
    panel.setName(name);
    panel.setFocusable(false);
    panel.setOpaque(true);
    panel.setLayout(new PanelLayoutManager());
    panel.setBackground(null);
    return panel;
  }

  /**
   * Factory Method to create a <code>Panel</code>
   *
   * @param name
   *            Name of the Panel
   * @param margin
   *            The margin parameter (int) defines a margin, in mils, between
   *            a panel�s boundaries and its child widgets as a group.
   * @return The created <code>Panel</code>
   */
  public static Panel newPanel(String name, int margin) {
    Panel gf = newPanel(name);
    int gap = UIutils.milsToPixels(margin);
    gf.getInsets().left = gap;
    gf.getInsets().right = gap;
    gf.getInsets().top = gap;
    gf.getInsets().bottom = gap;
    gf.setBackground(null);
    return gf;
  }

  /**
   * Factory method to create a new Tab Folder as a <code>JTabbedPane</code>
   *
   * @param name
   *            Name of the TabFolder
   * @param tabLayoutPolicy
   *            the policy used to layout the tabs
   * @return The created <code>JTabbedPane</code> like a Forte TabFolder
   */
  public static TabFolder newTabFolder(String name, int tabLayoutPolicy) {
    TabFolder tp = new TabFolder();
    tp.setName(name);
    tp.setTabLayoutPolicy(tabLayoutPolicy);
    // PM 9/7/07 allows inhert background colour
    tp.setBackground(null);
    // TF:9/11/07:Refactored this method to initialise the state properly
    // for coded widgets, instead of declared widgets
    WidgetState.set(tp, Constants.FS_UPDATE);

    return tp;
  }

  /**
   * Factory method to create a new CompoundGraphic
   *
   * @param name
   *            Name of the TabFolder
   * @param frameWeight
   *            The Frame Weight in mils if over 5 or
   *            DisplayProjects.Constants.W_ constants
   * @param caption The caption parameter provides a caption for the matrix field. The caption is displayed as part of the CompoundGraphic upper border.
   * @param bc
   *            The Background colour.
   * @return The created <code>CompoundGraphic</code>
   */
  public static CompoundGraphic newCompoundGraphic(String name, int frameWeight,
      String caption, Color bc) {
    CompoundGraphic gf = newCompoundGraphic(name);
    FrameWeight.set(gf, frameWeight);
    Caption.set(gf, caption);
    gf.setOpaque(true);
    // gf.setLayout(null);
    return gf;
  }

  /**
   * Factory method to create a new CompoundGraphic
   *
   * @return The created <code>CompoundGraphic</code>
   */
  public static CompoundGraphic newCompoundGraphic() {
    return newCompoundGraphic(null);
  }

  /**
   * Factory method to create a new CompoundGraphic
   *
   * @param name
   *            Name of the TabFolder
   * @return The created <code>CompoundGraphic</code>
   */
  public static CompoundGraphic newCompoundGraphic(String name) {
    CompoundGraphic gf = new CompoundGraphic(name);

    return gf;
  }
}
TOP

Related Classes of net.helipilot50.stocktrade.displayproject.factory.CompoundFieldFactory

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.