Package DisplayProject.actions

Source Code of DisplayProject.actions.WidthPolicy

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

import java.awt.Component;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import DisplayProject.Constants;
import DisplayProject.GridCell;
import DisplayProject.GridField;
import DisplayProject.UIutils;
import DisplayProject.controls.ArrayField;
/**
* Gets and sets the Forte width policy on the target JComponent
*
*/
public class WidthPolicy extends PendingAction {

    private int policy;
    public WidthPolicy(Component pComponent, int value) {
        super(pComponent);
        this.policy = value;
    }
    public void performAction() {
        // TF:20/8/07: If we're setting this on a window form layout, just ignore this. It will be
        // dealt with by the layout manager. If we reparent the window, the policy can be set then, as per forte.
        JComponent comp = (JComponent)this._component;
       
        // TF:28/04/2008:Removed this code as we now handle this like Forte seemed to -- if it's explicitly set, use the explicit value
//        if (comp.getLayout() instanceof WindowFormLayout) {
//            return;
//        }
        //PM:4/11/07 special case for array fields
        if (this._component instanceof ArrayField){
            this.arrayFieldSpecialCase((ArrayField)this._component);
            //PM:6/03/08 LUM-1
        } else if ((this._component instanceof JScrollPane) &&
            (((JScrollPane)this._component).getViewport().getComponentCount() > 0) &&
            (((JScrollPane)this._component).getViewport().getComponent(0) instanceof ArrayField)){
          this.arrayFieldSpecialCase(((ArrayField)((JScrollPane)this._component).getViewport().getComponent(0)));
         
        }

        GridCell gbc = GridField.getConstraints((JComponent)this._component);
        gbc.setWidthPolicy(policy);
        if (comp.getParent() != null) {
            comp.getParent().invalidate();
            comp.getParent().validate();
        }
    }

    public static void set(JComponent comp, int value){
        ActionMgr.addAction(new WidthPolicy(comp, value));
    }
    public static void set(JFrame comp, int value){
        ActionMgr.addAction(new WidthPolicy(UIutils.getForm(comp), value));
    }
    public static int get(JComponent comp){
        WidthPolicy action = ActionMgr.getAction(comp, WidthPolicy.class);
        if (action != null) {
            return action.policy;
        }
        return GridField.getConstraints(comp).getWidthPolicy();
    }
    public static int get(JFrame comp){
        return get(UIutils.getForm(comp));
    }
   
    private void arrayFieldSpecialCase(ArrayField af){
        if (this.policy == Constants.SP_NATURAL)
            af.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        else
            af.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    }
}
TOP

Related Classes of DisplayProject.actions.WidthPolicy

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.