Package DisplayProject.factory

Source Code of DisplayProject.factory.DropFillinFactory$ForteSizedListElementCellRenderer

/*
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.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.util.Arrays;

import javax.swing.DefaultCellEditor;
import javax.swing.JComponent;
import javax.swing.JList;

import DisplayProject.CompoundField;
import DisplayProject.DropListModel;
import DisplayProject.actions.AppData;
import DisplayProject.actions.Column;
import DisplayProject.actions.FieldWidgetGravity;
import DisplayProject.actions.Parent;
import DisplayProject.actions.Row;
import DisplayProject.actions.TextValue;
import DisplayProject.actions.WidthPolicy;
import DisplayProject.controls.AutoResizingComboBox;
import DisplayProject.controls.DropList;
import DisplayProject.controls.FillInField;
import DisplayProject.table.ListElementCellEditor;
import DisplayProject.table.ListElementCellRenderer;
import Framework.Array_Of_ListElement;
import Framework.ListElement;
import Framework.TextData;

/**
* Factory method that creates a cell renderer to set the height
* of the rows within the droplist to match the font size of the
* elements within the droplist - in line with the Forte sizing
*/
public class DropFillinFactory {
    @SuppressWarnings("serial")
  protected static class ForteSizedListElementCellRenderer extends ListElementCellRenderer {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (index == -1)
                return c;
            else {
                FontMetrics fm = list.getFontMetrics(list.getFont());
                Dimension size = new Dimension(c.getWidth(), fm.getHeight());
                c.setSize(size);
                if (c instanceof JComponent)
                    ((JComponent)c).setPreferredSize(size);
                return c;
            }
        }
    }
    private DropFillinFactory()
    {
        super();
    }
   
  public static FillInField newFillinField() {
      // CraigM:01/05/2008:Override the enabled, focusable, and paint methods, so we can draw the text as black if we are disabled but focusable
        FillInField cb = new FillInField();
        cb.setModel(new DropListModel(new Array_Of_ListElement<ListElement>(),cb));
        cb.setEditable(true);
        return cb;
    }

    @SuppressWarnings("unchecked")
  public static FillInField newFillinField(ListElement[] elements) {
        FillInField cb = DropFillinFactory.newFillinField();
        cb.setElementList(new Array_Of_ListElement(Arrays.asList(elements)));

        return cb;
    }

    @SuppressWarnings("unchecked")
    public static FillInField newFillinField(Array_Of_ListElement<ListElement> elements) {
      FillInField cb = DropFillinFactory.newFillinField();
      cb.setElementList(new Array_Of_ListElement(Arrays.asList(elements)));
     
      return cb;
    }
   
  public static DropList newDropList()
    {
        final DropList cb = new DropList();
        cb.setEditable(false);
        cb.setRenderer(new ForteSizedListElementCellRenderer());
        cb.setModel(new DropListModel(new Array_Of_ListElement<ListElement>(),cb));
        return cb;
    }

    @SuppressWarnings("unchecked")
  public static DropList newDropList(ListElement[] elements) {
        DropList cb = DropFillinFactory.newDropList();
        DropListModel model = new DropListModel(new Array_Of_ListElement(Arrays.asList(elements)),cb);
        cb.setModel(model);
        //cb.addActionListener(model);
        //cb.setModel(new DefaultComboBoxModel(elements));
        cb.setMaximumRowCount(elements.length);
        return cb;
    }

    @SuppressWarnings("unchecked")
    public static DropList newDropList(Array_Of_ListElement<ListElement> elements) {
      DropList cb = DropFillinFactory.newDropList();
      DropListModel model = new DropListModel(new Array_Of_ListElement(Arrays.asList(elements)),cb);
      cb.setModel(model);
      //cb.addActionListener(model);
      //cb.setModel(new DefaultComboBoxModel(elements));
      cb.setMaximumRowCount(elements.size());
      return cb;
    }

    public static DropList newDropList(Object appData, int column, int gravity, int maxCharacters, int minWidth, Container parent, int row, TextData textValue, int widthPolicy) {
      DropList cb = DropFillinFactory.newDropList();
      AppData.set(cb, appData);
      Column.set(cb, column);
      FieldWidgetGravity.set(cb, gravity);
      // Drop lists are non editable, so the max characters is not needed
//      MaxCharacters.set(cb, maxCharacters);
      cb.setMinimumSize(new Dimension(minWidth, cb.getMinimumSize().height));
      Parent.set(cb, parent);
      Row.set(cb, row);
      TextValue.set(cb, textValue);
      WidthPolicy.set(cb, widthPolicy);
      return cb;
    }

    public static DropList newDropList(Object appData, int column, int gravity, int maxCharacters, int minWidth, CompoundField parent, int row, TextData textValue, int widthPolicy) {
      return DropFillinFactory.newDropList(appData, column, gravity, maxCharacters, minWidth, (Container)parent, row, textValue, widthPolicy);
    }
    public static DropList newDropList(Object appData, int column, int gravity, int maxCharacters, int minWidth, Container parent, int row, String textValue, int widthPolicy) {
      return DropFillinFactory.newDropList(appData, column, gravity, maxCharacters, minWidth, parent, row, TextData.getInstance(textValue), widthPolicy);
    }
   
    public static DropList newDropList(Object appData, int column, int gravity, int maxCharacters, int minWidth, CompoundField parent, int row, String textValue, int widthPolicy) {
      return DropFillinFactory.newDropList(appData, column, gravity, maxCharacters, minWidth, (Container)parent, row, TextData.getInstance(textValue), widthPolicy);
    }
   
    public static DropList newDropList(Object appData, int column, int gravity, int minWidth, Container parent, int row, int widthPolicy) {
      DropList cb = DropFillinFactory.newDropList();
      AppData.set(cb, appData);
      Column.set(cb, column);
      FieldWidgetGravity.set(cb, gravity);
      cb.setMinimumSize(new Dimension(minWidth, cb.getMinimumSize().height));
      Parent.set(cb, parent);
      Row.set(cb, row);
      WidthPolicy.set(cb, widthPolicy);
      return cb;
    }
   
    public static DropList newDropList(Object appData, int column, int gravity, int minWidth, CompoundField parent, int row, int widthPolicy) {
      return newDropList(appData, column, gravity, minWidth, (Container)parent, row, widthPolicy);
    }
   
    /**
     * Factory method that creates a default cell editor based on a AutoResizingComboBox
     * from the supplied array of list elements. The table models getColumnClass
     * method will be used to determine whether the list elements integer or
     * text value is used as the cell editors value.
     *
     * @param elements the list elements
     * @return An editor that can be used in a table
     */
    public static DefaultCellEditor newDropListEditor(ListElement[] elements)
    {
        return new ListElementCellEditor(newDropList(elements));
    }

    /**
     * Creates a new cell editor using the supplied combox box
     * It is assumed the items in the combo boxes model are ListElements
     * AD:26/6/2008 Change JComboBox to AutoResizingComboBox to reduce casting later
     * @param comboBox
     * @return A cell editor
     */
    public static ListElementCellEditor newDropListEditor(AutoResizingComboBox comboBox)
    {
        return new ListElementCellEditor(comboBox);
    }

}
TOP

Related Classes of DisplayProject.factory.DropFillinFactory$ForteSizedListElementCellRenderer

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.