Package DisplayProject.actions

Source Code of DisplayProject.actions.FrameColor

/*
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.BorderFactory;
import javax.swing.JComponent;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import DisplayProject.CompoundField;
import DisplayProject.Constants;
import DisplayProject.GridField;
import DisplayProject.GridTitledBorder;
import DisplayProject.LineBorderWithColour;
import DisplayProject.UIutils;
import DisplayProject.controls.Panel;
/**
* This pending action implements the behaviour of the FrameColor attribute
* of a FieldWidget in Forte.
*/
public class FrameColor extends PendingAction {

    /**
     * Set up the width of the border by default
     */
    public static final int cDEFAULT_THICKNESS = 2;
    private int color;
    private FrameColor(Component pComponent, int value) {
        super(pComponent);
        this.color = value;
    }
   
    public void performAction() {
        if (this._component != null) {
            JComponent c = (JComponent)this._component;
            Border border = c.getBorder();
            if ((border == null) || (border instanceof EmptyBorder)) {
              // TF:18/09/2009:Corrected this to use a GridTitledBorder, which better understands
              // how to handle frame weights and frame colours
              GridTitledBorder gtb = new GridTitledBorder();
              gtb.setFrameWeight(Constants.W_NONE);
              gtb.setFrameColor(UIutils.forteToJavaColor(color));
              c.setBorder(gtb);
//                c.setBorder(new LineBorderWithColour(UIutils.forteToJavaColor(color)));
            }
            else if ((border != null) && (border instanceof GridTitledBorder)) {
                // TF:6/9/07:Added the functionality to use the GridTitledBorder for proper behaviour
                GridTitledBorder gridBorder = (GridTitledBorder)border;
                gridBorder.setFrameColor(UIutils.forteToJavaColor(color));
                c.repaint();
            }
            else if ((border != null) && (border instanceof TitledBorder))
            {
                TitledBorder titledBorder = (TitledBorder)border;
                Border innerBorder = titledBorder.getBorder();
                String title = titledBorder.getTitle();
                Border newBorder;
                if (innerBorder instanceof LineBorder) {
                    newBorder = new LineBorderWithColour(UIutils.forteToJavaColor(color),((LineBorder)innerBorder).getThickness());
                    c.setBorder(BorderFactory.createTitledBorder(newBorder, title));
                }
            }
            else if (border != null && (border instanceof LineBorder)) {
                c.setBorder(new LineBorderWithColour(UIutils.forteToJavaColor(color),((LineBorder)border).getThickness()));
            }
            else if (border != null) {
                c.setBorder(new LineBorderWithColour(UIutils.forteToJavaColor(color),cDEFAULT_THICKNESS));
            }
        }
    }
   
    public int getColor() {
        return color;
    }
    public void setColor(int row) {
        color = row;
    }
    public static void set(CompoundField comp, int value){
        if (comp instanceof JComponent)
            ActionMgr.addAction(new FrameColor((JComponent)comp, value));
    }
    public static void set(Panel comp, int value){
            ActionMgr.addAction(new FrameColor((JComponent)comp, value));
    }
    public static void set(GridField comp, int value){
        ActionMgr.addAction(new FrameColor(comp, value));
    }

    public static void set(JComponent comp, int value){
        ActionMgr.addAction(new FrameColor(comp, value));
    }
    public static int get(JComponent comp){
        FrameColor action = ActionMgr.getAction(comp, FrameColor.class);
        if (action != null) {
            return action.getColor();
        }
        Border border = comp.getBorder();
        if (border != null)
        {
            if (border instanceof GridTitledBorder) {
                return UIutils.javaToForteColor(((GridTitledBorder)border).getFrameColor());
            }
            else if (border instanceof LineBorder){
                return UIutils.javaToForteColor(((LineBorder)border).getLineColor());
            }
            else
                return Constants.C_INHERIT;
        }
        else
            return Constants.C_INHERIT;
    }
}
TOP

Related Classes of DisplayProject.actions.FrameColor

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.