/*
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.JFrame;
import javax.swing.JPanel;
import DisplayProject.Constants;
import DisplayProject.LineBorderWithColour;
import DisplayProject.UIutils;
/**
* this pending action implements the frame weight or border on a Window, based on the Forte constant
*
*/
public class WindowFrameWeight extends PendingAction {
private int value;
public WindowFrameWeight(Component pComponent, int pValue) {
super(pComponent);
this.value = pValue;
}
public int getValue() {
return this.value;
}
public void performAction() {
JPanel form = UIutils.getForm(((JFrame)this._component));
if (form!=null){
switch (this.value){
case Constants.W_DEFAULT :
form.setBorder(BorderFactory.createEtchedBorder());
break;
case Constants.W_NONE :
form.setBorder(null);
break;
case Constants.W_ONEPIXEL :
form.setBorder(new LineBorderWithColour(form.getForeground(), 1));
break;
case Constants.W_TWOPIXELS :
form.setBorder(new LineBorderWithColour(form.getForeground(), 2));
break;
case Constants.W_THREEPIXELS :
form.setBorder(new LineBorderWithColour(form.getForeground(), 3));
break;
case Constants.W_MEDIUM :
form.setBorder(new LineBorderWithColour(form.getForeground(), 3));
break;
case Constants.W_HEAVY :
form.setBorder(new LineBorderWithColour(form.getForeground(), 4));
break;
case Constants.W_THIN :
form.setBorder(new LineBorderWithColour(form.getForeground(), 2));
break;
case Constants.W_VERYTHIN :
form.setBorder(new LineBorderWithColour(form.getForeground(), 1));
break;
case Constants.W_VERYHEAVY :
form.setBorder(new LineBorderWithColour(form.getForeground(), 5));
break;
}
}
}
public static void set(Component comp, int value){
ActionMgr.addAction(new WindowFrameWeight(comp, value));
}
public static int get(Component comp){
WindowFrameWeight action = ActionMgr.getAction(comp, WindowFrameWeight.class);
if (action != null) {
return action.getValue();
}
JPanel form = UIutils.getForm(((JFrame)comp));
int value = Constants.W_NONE;
if (form!=null){
if (form.getBorder().equals(BorderFactory.createEtchedBorder()))
value = Constants.W_DEFAULT ;
else if (form.getBorder().equals(null))
value = Constants.W_NONE ;
else if (form.getBorder().equals(new LineBorderWithColour(form.getForeground(), 1)))
value = Constants.W_ONEPIXEL ;
else if (form.getBorder().equals(new LineBorderWithColour(form.getForeground(), 2)))
value = Constants.W_TWOPIXELS ;
else if (form.getBorder().equals(new LineBorderWithColour(form.getForeground(), 3)))
value = Constants.W_THREEPIXELS ;
else if (form.getBorder().equals(new LineBorderWithColour(form.getForeground(), 3)))
value = Constants.W_MEDIUM ;
else if (form.getBorder().equals(new LineBorderWithColour(form.getForeground(), 4)))
value = Constants.W_HEAVY ;
else if (form.getBorder().equals(new LineBorderWithColour(form.getForeground(), 2)))
value = Constants.W_THIN ;
else if (form.getBorder().equals(new LineBorderWithColour(form.getForeground(), 1)))
value = Constants.W_VERYTHIN ;
else if (form.getBorder().equals(new LineBorderWithColour(form.getForeground(), 5)))
value = Constants.W_VERYHEAVY ;
}
return value;
}
}