Package DisplayProject.actions

Source Code of DisplayProject.actions.ArrayColumnTitle$ActionFilter

/*
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.actions;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableModel;

import DisplayProject.ArrayColumn;
import DisplayProject.ArrayColumnModel;
import DisplayProject.ArrayFieldModel;
import DisplayProject.controls.ArrayField;
import DisplayProject.controls.TextGraphic;
import Framework.TextData;

/**
* Implements the Get and Set Colum Title methods on an ArrayField (JTable)
*
*/
public class ArrayColumnTitle extends PendingAction {
    private String title;
    private int column;
    private String name;

    private ArrayColumnTitle(Component pComponent, int column, String title) {
        super(pComponent);
        this.title = title;
        this.column = column;
    }

    private ArrayColumnTitle(Component pComponent, String columnName, String title) {
        super(pComponent);
        this.title = title;
        this.name = columnName;
    }

    private static class ActionFilter implements ActionMgr.Filter {
        private String name = null;
        private int position = -1;
        private Component component;

        private ActionFilter(Component comp, String pName) {
            this.name = pName;
            this.component = comp;
        }

        private ActionFilter(Component comp, int pPosition) {
            this.position = pPosition;
            this.component = comp;
        }

        public boolean filter(PendingAction pAction) {
            if (pAction.getComponent() == this.component && pAction instanceof ArrayColumnTitle) {
                ArrayColumnTitle act = (ArrayColumnTitle)pAction;
                if (this.name != null) {
                    return this.name.equals(act.name);
                }
                else {
                    return this.position == act.column;
                }
            }
            return false;
        }
    }

    public void performAction() {
        ArrayColumn tc;
        // TF:5/11/08:If we're search by name, do a column lookup
        if (this.name != null) {
          ArrayColumnModel columnModel = (ArrayColumnModel)((JTable)this._component).getColumnModel();
          tc = columnModel.findColumn(this.name);
          if (tc == null) {
            // Nothing to do, couldn't find the column
            return;
          }
        }
        else {
          tc = ((ArrayColumnModel)((JTable)this._component).getColumnModel()).getRealColumn(column);
        }
        tc.setHeaderValue(title);
        TableModel model = ((JTable)_component).getModel();
        if (model instanceof ArrayFieldModel) {
          ((ArrayFieldModel)model).resizeTable();
        }
        // TF:29/3/08:Added a repaint to force the new change to reflect to the screen
        ((JTable)_component).getTableHeader().repaint();
    }

    /**
     * get the Title of the column given it's name
     * @param comp
     * @param column
     * @return
     */
    public static TextData get(JTable comp, String columnName) {
        TextData title = null;
        ArrayColumnTitle action = (ArrayColumnTitle)ActionMgr.getAction(new ActionFilter(comp, columnName));
        if (action != null ) {
            title = TextData.getInstance(action.title);
        } else {
            ArrayColumn tc = ((ArrayColumnModel)comp.getColumnModel()).findColumnByName(columnName);

            title = TextData.getInstance(tc.getHeaderValue().toString());  
        }
        return title;
    }

    /**
     * get the Title of the column given it's position. The parameter must be 1-based as per forte.
     * @param comp
     * @param column
     * @return
     */
    public static TextGraphic get(JTable comp, int column){
//        TextGraphic title = null;
//        ArrayColumnTitle action = (ArrayColumnTitle)ActionMgr.getAction(new ActionFilter(comp, column));
//        if (action != null ) {
//            title = TextData.getInstance(action.title);
//        } else {
//            ArrayColumn tc = ((ArrayColumnModel)comp.getColumnModel()).getRealColumn(column);
            return ((ArrayField)comp).getColumnTitle(column-1);
//            title = TextData.getInstance(tc.getHeaderValue().toString());  
//        }
//        return title;
    }

    /**
     * set the title for the passed column on the passed table.
     * @param comp the table on which to set the title. This component must have a column
     *         model which is an ArrayColumnModel
     * @param column the 1-based index of the column to alter. This will be the real column in
     *         the model, not just the visible column
     * @param title the title to set
     */
    public static void set(JTable comp, int column, String title){
        ActionMgr.addAction(new ArrayColumnTitle(comp, column - 1, title));
    }

    /**
     * set the title for the passed column on the passed table.
     * @param comp the table on which to set the title. This component must have a column
     *         model which is an ArrayColumnModel
     * @param column the 1-based index of the column to alter. This will be the real column in
     *         the model, not just the visible column
     * @param title the title to set
     */
    public static void set(JTable comp, int column, TextData title){
      set(comp, column, title == null ? null : title.toString());
    }

    /**
     * set the title for the passed column on the passed table.
     * @param comp the table on which to set the title. This component must have a column
     *         model which is an ArrayColumnModel
     * @param column the 1-based index of the column to alter. This will be the real column in
     *         the model, not just the visible column
     * @param title a label which contains the text to set this title to
     */
    public static void set(JTable comp, int column, JLabel title) {
      set(comp, column, title == null ? null : title.getText());
    }

    /**
     * set the title for the passed column on the passed table.
     * @param comp the table on which to set the title. This component must have a column
     *         model which is an ArrayColumnModel
     * @param column the name of the column to set
     * @param title a label which contains the text to set this title to
     */
    public static void set(JTable comp, String columnName, String title){
        ActionMgr.addAction(new ArrayColumnTitle(comp, columnName, title));
    }

    /**
     * set the title for the passed column on the passed table.
     * @param comp the table on which to set the title. This component must have a column
     *         model which is an ArrayColumnModel
     * @param column the name of the column to set
     * @param title a label which contains the text to set this title to
     */
    public static void set(JTable comp, String columnName, TextData title){
      set(comp, columnName, title == null ? null : title.toString());
    }

    /**
     * set the title for the passed column on the passed table.
     * @param comp the table on which to set the title. This component must have a column
     *         model which is an ArrayColumnModel
     * @param column the name of the column to set
     * @param title a label which contains the text to set this title to
     */
    public static void set(JTable comp, String columnName, JLabel title) {
      set(comp, columnName, title == null ? null : title.getText());
    }
}
TOP

Related Classes of DisplayProject.actions.ArrayColumnTitle$ActionFilter

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.