Package DisplayProject.actions

Source Code of DisplayProject.actions.FrameWeight

/*
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.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.plaf.basic.BasicBorders;
import javax.swing.plaf.basic.BasicBorders.FieldBorder;
import javax.swing.text.JTextComponent;

import DisplayProject.CompoundField;
import DisplayProject.Constants;
import DisplayProject.GridField;
import DisplayProject.GridTitledBorder;
import DisplayProject.LineBorderWithColour;
import DisplayProject.UIutils;
import DisplayProject.controls.Panel;
import DisplayProject.controls.TextGraphic;

/**
* This class manages the frame weight associated with the container. Note that most of this
* functionality is now encapsulated in the GridTitledBorder class which closely follows the
* forte semantics and layouts, and large portions of this class are only needed for
* backward compatibility.
*
*/
public class FrameWeight extends PendingAction {
    public static final int TOP_PAD = 1;
    public static final int LEFT_PAD = 3; //PM:29/4/08 changed from 1 to 3
    private int weight;
    public FrameWeight(Component pComponent, int value) {
        super(pComponent);
        this.weight = value;
    }
    public void performAction() {
        JComponent jc = (JComponent)this._component;
        // TF:6/9/07:Added functionality to use GridTitledBorder
        if (jc.getBorder() instanceof GridTitledBorder) {
            // Grid Titled Borders know how to adjust themselves properly
            ((GridTitledBorder)jc.getBorder()).setFrameWeight(this.weight);
            jc.revalidate();
            jc.repaint();
        }
        else if (jc instanceof TextGraphic) {
            Border newBorder = null;
            switch (this.weight){
            case Constants.W_DEFAULT:
                newBorder = BasicBorders.getTextFieldBorder();
                break;
            case Constants.W_NONE:
                newBorder = null;
                break;
            default:
                // The lineWeightInPixels handles all the values.  CraigM: 28/01/2008.
                newBorder = new LineBorderWithColour(jc.getForeground(), UIutils.getLineWeightInPixels(this.weight));
                break;
            }
            jc.setBorder(newBorder);
        } else if (jc instanceof JLabel || jc instanceof JTextComponent){
            //PM:12/10/07
            /*
             * the borders for JLabels to match forte
             * TF:14/11/07:Extended this for JTextComponents and handled the default case
             * TF:22/11/07:TextGraphics now know how to pad themselves properly, so we no longer
             * need the padding border.
             */
            Border outsideBorder = null;
            Border newBorder = null;
            switch (this.weight){
            case Constants.W_DEFAULT:
                newBorder = BasicBorders.getTextFieldBorder();
                break;
            case Constants.W_NONE:
                newBorder = BorderFactory.createEmptyBorder(TOP_PAD, LEFT_PAD, 0, 0);
                break;
            case Constants.W_HEAVY:
            case Constants.W_MEDIUM:
            case Constants.W_ONEPIXEL:
            case Constants.W_THIN:
            case Constants.W_THREEPIXELS:
            case Constants.W_TWOPIXELS:
            case Constants.W_VERYHEAVY:
            case Constants.W_VERYTHIN:
                outsideBorder = new LineBorderWithColour(jc.getForeground(), UIutils.getLineWeightInPixels(this.weight));
                newBorder = BorderFactory.createCompoundBorder(outsideBorder, new EmptyBorder(TOP_PAD, LEFT_PAD, 0, 0));
                break;
            default:
                newBorder = BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), new EmptyBorder(TOP_PAD, LEFT_PAD, 0, 0));
                break;
            }
            jc.setBorder(newBorder);
        } else {
            String caption = (String)jc.getClientProperty("qq_caption");
            GridTitledBorder gtb = new GridTitledBorder(null, caption);
            gtb.setFrameWeight(weight);
            jc.setBorder(gtb);
        }
    }

    public static void set(JComponent comp, int value){
        ActionMgr.addAction(new FrameWeight(comp, value));
    }
    public static void set(GridField comp, int value){
        ActionMgr.addAction(new FrameWeight(comp, value));
    }
    public static void set(Panel comp, int value){
        ActionMgr.addAction(new FrameWeight(comp, value));
    }
    public static void set(CompoundField comp, int value){
        if (comp instanceof JComponent)
            ActionMgr.addAction(new FrameWeight((JComponent)comp, value));
    }
   
    private static final int[] FRAME_WEIGHTS = new int[] {
      Constants.W_HEAVY,
      Constants.W_MEDIUM,
      Constants.W_ONEPIXEL,
      Constants.W_THIN,
      Constants.W_THREEPIXELS,
      Constants.W_TWOPIXELS,
      Constants.W_VERYHEAVY,
      Constants.W_VERYTHIN
    };
   
    public static int get(JComponent comp){
        FrameWeight action = ActionMgr.getAction(comp, FrameWeight.class);
        if (action != null) {
            return action.weight;
        }
        // TF:6/9/07:Added functionality to GridTitledBorder
        if (comp.getBorder() instanceof GridTitledBorder) {
            return ((GridTitledBorder)comp.getBorder()).getFrameWeight();
        }
        else {
            Border border = comp.getBorder();
            if (border == null)
                return Constants.W_NONE;
            else if (border instanceof EtchedBorder || border instanceof FieldBorder)
                return Constants.W_DEFAULT;
            else if (border instanceof LineBorder) {
              int thickness = ((LineBorder)border).getThickness();
              for (int thisFrame : FRAME_WEIGHTS) {
                if (thickness == UIutils.getLineWeightInPixels(thisFrame)) {
                  return thisFrame;
                }
              }
            }
            return Constants.W_NONE;
        }
    }

}
TOP

Related Classes of DisplayProject.actions.FrameWeight

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.