use of com.servoy.j2db.util.gui.SpecialMatteBorder in project servoy-client by Servoy.
the class BorderPropertyType method fromJSON.
@Override
public Border fromJSON(Object newValue, Border previousValue, PropertyDescription pd, IBrowserConverterContext dataConverterContext, ValueReference<Boolean> returnValueAdjustedIncommingValue) {
if (newValue == null)
return null;
JSONObject object = (JSONObject) newValue;
String type = object.optString(TYPE);
if (type == null)
return null;
JSONObject borderStyle = object.optJSONObject(BORDER_STYLE);
switch(type) {
case ComponentFactoryHelper.BEVEL_BORDER:
{
int borderType = "outset".equals(borderStyle.optString(BORDER_STYLE)) ? BevelBorder.RAISED : BevelBorder.LOWERED;
String borderColor = borderStyle.optString(BORDER_COLOR);
StringTokenizer st = new StringTokenizer(borderColor, " ");
Color hiOut = null;
Color hiin = null;
Color shOut = null;
Color shIn = null;
if (st.hasMoreTokens())
hiOut = PersistHelper.createColor(st.nextToken());
if (st.hasMoreTokens())
shOut = PersistHelper.createColor(st.nextToken());
if (st.hasMoreTokens())
shIn = PersistHelper.createColor(st.nextToken());
if (st.hasMoreTokens())
hiin = PersistHelper.createColor(st.nextToken());
return BorderFactory.createBevelBorder(borderType, hiOut, hiin, shOut, shIn);
}
case ComponentFactoryHelper.EMPTY_BORDER:
{
Insets insets = PersistHelper.createInsets(borderStyle.optString(BORDER_WIDTH).replaceAll("px ", ","));
return BorderFactory.createEmptyBorder(insets.top, insets.right, insets.bottom, insets.left);
}
case ComponentFactoryHelper.ETCHED_BORDER:
{
StringTokenizer st = new StringTokenizer(borderStyle.optString(BORDER_COLOR), " ");
Color hi = null;
Color sh = null;
if (st.hasMoreTokens())
hi = PersistHelper.createColor(st.nextToken());
if (st.hasMoreTokens())
sh = PersistHelper.createColor(st.nextToken());
int t = borderStyle.optString(BORDER_STYLE).equals("ridge") ? EtchedBorder.RAISED : EtchedBorder.LOWERED;
return BorderFactory.createEtchedBorder(t, hi, sh);
}
case ComponentFactoryHelper.LINE_BORDER:
{
Color borderColor = PersistHelper.createColor(borderStyle.optString(BORDER_COLOR));
String width = borderStyle.optString(BORDER_WIDTH);
if (width != null)
width = width.substring(0, width.length() - 2);
return BorderFactory.createLineBorder(borderColor, Utils.getAsInteger(width));
}
case ComponentFactoryHelper.MATTE_BORDER:
{
Insets insets = PersistHelper.createInsets(borderStyle.optString(BORDER_WIDTH).replaceAll("px ", ","));
Color borderColor = PersistHelper.createColor(borderStyle.optString(BORDER_COLOR));
return BorderFactory.createMatteBorder(insets.top, insets.right, insets.bottom, insets.left, borderColor);
}
case ComponentFactoryHelper.ROUNDED_BORDER:
{
float top = Utils.getAsFloat(borderStyle.optString(BORDER_TOP_WIDTH).replace("px", ""));
float left = Utils.getAsFloat(borderStyle.optString(BORDER_LEFT_WIDTH).replace("px", ""));
float bottom = Utils.getAsFloat(borderStyle.optString(BORDER_BOTTOM_WIDTH).replace("px", ""));
float right = Utils.getAsFloat(borderStyle.optString(BORDER_RIGHT_WIDTH).replace("px", ""));
Color topColor = PersistHelper.createColor(borderStyle.optString(BORDER_TOP_COLOR));
Color bottomColor = PersistHelper.createColor(borderStyle.optString(BORDER_BOTTOM_COLOR));
Color leftColor = PersistHelper.createColor(borderStyle.optString(BORDER_LEFT_COLOR));
Color rightColor = PersistHelper.createColor(borderStyle.optString(BORDER_RIGHT_COLOR));
RoundedBorder border = new RoundedBorder(top, left, bottom, right, topColor, leftColor, bottomColor, rightColor);
border.setBorderStyles(borderStyle.optString(BORDER_STYLE).replaceAll(" ", ";"));
border.setRoundingRadius(borderStyle.optString(BORDER_RADIUS).replaceAll("px", ";").replaceAll(" ", "").replaceAll("/", ""));
return border;
}
case ComponentFactoryHelper.SPECIAL_MATTE_BORDER:
{
float top = Utils.getAsFloat(borderStyle.optString(BORDER_TOP_WIDTH).replace("px", ""));
float left = Utils.getAsFloat(borderStyle.optString(BORDER_LEFT_WIDTH).replace("px", ""));
float bottom = Utils.getAsFloat(borderStyle.optString(BORDER_BOTTOM_WIDTH).replace("px", ""));
float right = Utils.getAsFloat(borderStyle.optString(BORDER_RIGHT_WIDTH).replace("px", ""));
Color topColor = PersistHelper.createColor(borderStyle.optString(BORDER_TOP_COLOR));
Color bottomColor = PersistHelper.createColor(borderStyle.optString(BORDER_BOTTOM_COLOR));
Color leftColor = PersistHelper.createColor(borderStyle.optString(BORDER_LEFT_COLOR));
Color rightColor = PersistHelper.createColor(borderStyle.optString(BORDER_RIGHT_COLOR));
return new SpecialMatteBorder(top, left, bottom, right, topColor, leftColor, bottomColor, rightColor);
}
case ComponentFactoryHelper.TITLED_BORDER:
{
String borderTitle = object.optString(TITLE);
int titleJustification = TitledBorder.DEFAULT_JUSTIFICATION;
switch(object.optString(TITLE_JUSTIFICATION)) {
case "left":
titleJustification = TitledBorder.LEFT;
break;
case "right":
titleJustification = TitledBorder.RIGHT;
break;
case "center":
titleJustification = TitledBorder.CENTER;
break;
case "leading":
titleJustification = TitledBorder.LEADING;
break;
case "trailing":
titleJustification = TitledBorder.TRAILING;
}
int titlePosition = TitledBorder.DEFAULT_POSITION;
switch(object.optString(TITLE_POSITION)) {
case "Above top":
titlePosition = TitledBorder.ABOVE_TOP;
break;
case "Top":
titlePosition = TitledBorder.TOP;
break;
case "Below top":
titlePosition = TitledBorder.BELOW_TOP;
break;
case "Above bottom":
titlePosition = TitledBorder.ABOVE_BOTTOM;
break;
case "Below bottom":
titlePosition = TitledBorder.BELOW_BOTTOM;
break;
case "Bottom":
titlePosition = TitledBorder.BOTTOM;
break;
}
// TODO previous value
Font titleFont = FontPropertyType.INSTANCE.fromJSON(object.optJSONObject("font"), null, null, dataConverterContext, null);
Color titleColor = PersistHelper.createColor(object.optString("color"));
return BorderFactory.createTitledBorder(null, borderTitle, titleJustification, titlePosition, titleFont, titleColor);
}
}
return null;
}
use of com.servoy.j2db.util.gui.SpecialMatteBorder in project servoy-client by Servoy.
the class BorderPropertyType method writeBorderToJson.
public static Map<String, Object> writeBorderToJson(Border value) {
Map<String, Object> map = new HashMap<>();
if (value instanceof SpecialMatteBorder) {
SpecialMatteBorder border = (SpecialMatteBorder) value;
map.put(TYPE, ((border instanceof RoundedBorder) ? ComponentFactoryHelper.ROUNDED_BORDER : ComponentFactoryHelper.SPECIAL_MATTE_BORDER));
Map<String, Object> borderStyle = new HashMap<>();
map.put(BORDER_STYLE, borderStyle);
borderStyle.put(BORDER_TOP_WIDTH, border.getTop() + "px");
borderStyle.put(BORDER_RIGHT_WIDTH, border.getRight() + "px");
borderStyle.put(BORDER_BOTTOM_WIDTH, border.getBottom() + "px");
borderStyle.put(BORDER_LEFT_WIDTH, border.getLeft() + "px");
borderStyle.put(BORDER_TOP_COLOR, border.getTopColor());
borderStyle.put(BORDER_RIGHT_COLOR, border.getRightColor());
borderStyle.put(BORDER_BOTTOM_COLOR, border.getBottomColor());
borderStyle.put(BORDER_LEFT_COLOR, border.getLeftColor());
if (border instanceof RoundedBorder) {
float[] radius = ((RoundedBorder) border).getRadius();
borderStyle.put(BORDER_RADIUS, radius[0] + "px " + radius[2] + "px " + radius[4] + "px " + radius[6] + "px /" + radius[1] + "px " + radius[3] + "px " + radius[5] + "px " + radius[7] + "px");
String[] styles = ((RoundedBorder) border).getBorderStyles();
borderStyle.put(BORDER_STYLE, styles[0] + " " + styles[1] + " " + styles[2] + " " + styles[3]);
} else {
// $NON-NLS-1$
borderStyle.put(BORDER_RADIUS, border.getRoundingRadius() + "px");
// retval += "," + SpecialMatteBorder.createDashString(border.getDashPattern()); //$NON-NLS-1$
if (border.getDashPattern() != null) {
borderStyle.put(BORDER_STYLE, "dashed");
} else {
borderStyle.put(BORDER_STYLE, "solid");
}
}
} else if (value instanceof EtchedBorder) {
EtchedBorder border = (EtchedBorder) value;
map.put(TYPE, ComponentFactoryHelper.ETCHED_BORDER);
Map<String, Object> borderStyle = new HashMap<>();
map.put(BORDER_STYLE, borderStyle);
String hi = PersistHelper.createColorString(border.getHighlightColor());
String sh = PersistHelper.createColorString(border.getShadowColor());
if (border.getEtchType() != EtchedBorder.RAISED) {
String tmp = hi;
hi = sh;
sh = tmp;
}
borderStyle.put(BORDER_COLOR, hi + " " + sh + " " + sh + " " + hi);
borderStyle.put(BORDER_STYLE, border.getEtchType() == EtchedBorder.RAISED ? "ridge" : "groove");
borderStyle.put(BORDER_WIDTH, "2px");
} else if (value instanceof BevelBorder) {
BevelBorder border = (BevelBorder) value;
map.put(TYPE, ComponentFactoryHelper.BEVEL_BORDER);
Map<String, Object> borderStyle = new HashMap<>();
map.put(BORDER_STYLE, borderStyle);
borderStyle.put(BORDER_STYLE, border.getBevelType() == BevelBorder.RAISED ? "outset" : "inset");
String hiOut = PersistHelper.createColorString(border.getHighlightOuterColor());
String hiin = PersistHelper.createColorString(border.getHighlightInnerColor());
String shOut = PersistHelper.createColorString(border.getShadowOuterColor());
String shIn = PersistHelper.createColorString(border.getShadowInnerColor());
if (border.getBevelType() == BevelBorder.LOWERED) {
// swap 1-3
String temp = hiOut;
hiOut = shOut;
shOut = temp;
// swap 2-4
temp = hiin;
hiin = shIn;
shIn = temp;
}
borderStyle.put(BORDER_COLOR, hiOut + " " + shOut + " " + shIn + " " + hiin);
borderStyle.put(BORDER_WIDTH, "2px");
} else if (value instanceof LineBorder) {
LineBorder border = (LineBorder) value;
map.put(TYPE, ComponentFactoryHelper.LINE_BORDER);
Map<String, Object> borderStyle = new HashMap<>();
map.put(BORDER_STYLE, borderStyle);
int thick = border.getThickness();
borderStyle.put(BORDER_COLOR, border.getLineColor());
borderStyle.put(BORDER_STYLE, "solid");
borderStyle.put(BORDER_WIDTH, thick + "px");
} else if (value instanceof MatteBorder) {
MatteBorder border = (MatteBorder) value;
map.put(TYPE, ComponentFactoryHelper.MATTE_BORDER);
Map<String, Object> borderStyle = new HashMap<>();
map.put(BORDER_STYLE, borderStyle);
Insets in = border.getBorderInsets();
borderStyle.put(BORDER_WIDTH, in.top + "px " + in.right + "px " + in.bottom + "px " + in.left + "px ");
borderStyle.put(BORDER_COLOR, border.getMatteColor());
borderStyle.put(BORDER_STYLE, "solid");
} else if (value instanceof EmptyBorder) {
EmptyBorder border = (EmptyBorder) value;
map.put(TYPE, ComponentFactoryHelper.EMPTY_BORDER);
Map<String, Object> borderStyle = new HashMap<>();
map.put(BORDER_STYLE, borderStyle);
Insets in = border.getBorderInsets();
borderStyle.put(BORDER_WIDTH, in.top + "px " + in.right + "px " + in.bottom + "px " + in.left + "px ");
borderStyle.put(BORDER_COLOR, "rgba(0,0,0,0)");
} else if (value instanceof TitledBorder) {
TitledBorder border = (TitledBorder) value;
map.put(TYPE, ComponentFactoryHelper.TITLED_BORDER);
map.put(TITLE, border.getTitle());
map.put("font", border.getTitleFont());
map.put("color", border.getTitleColor());
int just = border.getTitleJustification();
String titleJust = "left";
switch(just) {
case TitledBorder.LEFT:
titleJust = "left";
break;
case TitledBorder.RIGHT:
titleJust = "right";
break;
case TitledBorder.CENTER:
titleJust = "center";
break;
case TitledBorder.LEADING:
titleJust = "leading";
break;
case TitledBorder.TRAILING:
titleJust = "trailing";
break;
}
map.put(TITLE_JUSTIFICATION, titleJust);
String titlePosition = "Top";
switch(border.getTitlePosition()) {
case TitledBorder.ABOVE_TOP:
titlePosition = "Above top";
break;
case TitledBorder.BELOW_TOP:
titlePosition = "Below top";
break;
case TitledBorder.ABOVE_BOTTOM:
titlePosition = "Above bottom";
break;
case TitledBorder.BELOW_BOTTOM:
titlePosition = "Below bottom";
break;
case TitledBorder.BOTTOM:
titlePosition = "Bottom";
break;
}
map.put(TITLE_POSITION, titlePosition);
}
return map;
}
use of com.servoy.j2db.util.gui.SpecialMatteBorder in project servoy-client by Servoy.
the class ComponentFactoryHelper method createBorder.
public static Border createBorder(String s, boolean design) {
Border currentBorder = null;
if (s != null) {
// $NON-NLS-1$
StringTokenizer tk = new StringTokenizer(s, ",");
if (tk.hasMoreTokens()) {
try {
String type = tk.nextToken().trim();
if (type.equals(COMPOUND_BORDER)) {
// $NON-NLS-1$
StringTokenizer tk2 = new StringTokenizer(s, ";");
// skip 'CompoundBorder,' token
tk2.nextToken().trim();
String s_oborder = tk2.nextToken().trim();
Border oborder = createBorder(s_oborder);
String s_iborder = tk2.nextToken().trim();
Border iborder = createBorder(s_iborder);
currentBorder = BorderFactory.createCompoundBorder(oborder, iborder);
} else if (type.equals(EMPTY_BORDER)) {
int top = Utils.getAsInteger(tk.nextToken().trim());
int right = Utils.getAsInteger(tk.nextToken().trim());
int bottom = Utils.getAsInteger(tk.nextToken().trim());
int left = Utils.getAsInteger(tk.nextToken().trim());
currentBorder = BorderFactory.createEmptyBorder(top, left, bottom, right);
} else if (type.equals(BEVEL_BORDER)) {
int beveltype = Utils.getAsInteger(tk.nextToken().trim());
if (tk.hasMoreTokens()) {
Color highlightO = PersistHelper.createColor(tk.nextToken().trim());
Color highlightI = PersistHelper.createColor(tk.nextToken().trim());
Color shadowO = PersistHelper.createColor(tk.nextToken().trim());
Color shadowI = PersistHelper.createColor(tk.nextToken().trim());
currentBorder = BorderFactory.createBevelBorder(beveltype, highlightO, highlightI, shadowO, shadowI);
} else {
currentBorder = BorderFactory.createBevelBorder(beveltype);
}
} else if (type.equals(ETCHED_BORDER)) {
int beveltype = Utils.getAsInteger(tk.nextToken().trim());
Color highlight = PersistHelper.createColor(tk.nextToken().trim());
Color shadow = PersistHelper.createColor(tk.nextToken().trim());
currentBorder = BorderFactory.createEtchedBorder(beveltype, highlight, shadow);
} else if (type.equals(LINE_BORDER)) {
int thick = Utils.getAsInteger(tk.nextToken().trim());
currentBorder = BorderFactory.createLineBorder(PersistHelper.createColor(tk.nextToken().trim()), thick);
} else if (type.equals(TITLED_BORDER)) {
String title = tk.nextToken().trim();
// unescape //$NON-NLS-1$ //$NON-NLS-2$
title = Utils.stringReplace(title, "|", ",");
int justification = 0;
int position = 0;
Font font = null;
Color color = null;
if (tk.hasMoreTokens()) {
justification = Utils.getAsInteger(tk.nextToken().trim());
position = Utils.getAsInteger(tk.nextToken().trim());
if (tk.hasMoreTokens()) {
// we know a font has 3 parameters ALSO separated with ',' //$NON-NLS-1$ //$NON-NLS-2$
font = PersistHelper.createFont(tk.nextToken().trim() + "," + tk.nextToken().trim() + "," + tk.nextToken().trim());
if (tk.hasMoreTokens()) {
color = PersistHelper.createColor(tk.nextToken().trim());
}
}
}
if (design) {
currentBorder = BorderFactory.createTitledBorder(title);
} else {
currentBorder = BorderFactory.createTitledBorder(J2DBGlobals.getServiceProvider() != null ? J2DBGlobals.getServiceProvider().getI18NMessageIfPrefixed(title) : title);
}
((TitledBorder) currentBorder).setTitleJustification(justification);
((TitledBorder) currentBorder).setTitlePosition(position);
if (font != null)
((TitledBorder) currentBorder).setTitleFont(font);
if (color != null)
((TitledBorder) currentBorder).setTitleColor(color);
// if (font == null)
// {
// currentBorder = BorderFactory.createTitledBorder(null,title,justification,position);
// }
// else
// {
// if (font != null && color != null)
// {
// currentBorder = BorderFactory.createTitledBorder(null,title,justification,position,font,color);
// }
// else
// {
// currentBorder = BorderFactory.createTitledBorder(null,title,justification,position,font);
// }
// }
} else if (type.equals(MATTE_BORDER)) {
int top = Utils.getAsInteger(tk.nextToken().trim());
int right = Utils.getAsInteger(tk.nextToken().trim());
int bottom = Utils.getAsInteger(tk.nextToken().trim());
int left = Utils.getAsInteger(tk.nextToken().trim());
Color color = Color.black;
if (tk.hasMoreElements())
color = PersistHelper.createColor(tk.nextToken().trim());
currentBorder = BorderFactory.createMatteBorder(top, left, bottom, right, color);
} else if (type.equals(SPECIAL_MATTE_BORDER) || type.equals(ROUNDED_BORDER)) {
float top = Utils.getAsFloat(tk.nextToken().trim());
float right = Utils.getAsFloat(tk.nextToken().trim());
float bottom = Utils.getAsFloat(tk.nextToken().trim());
float left = Utils.getAsFloat(tk.nextToken().trim());
Color topColor = PersistHelper.createColor(tk.nextToken().trim());
Color rightColor = PersistHelper.createColor(tk.nextToken().trim());
Color bottomColor = PersistHelper.createColor(tk.nextToken().trim());
Color leftColor = PersistHelper.createColor(tk.nextToken().trim());
if (type.equals(SPECIAL_MATTE_BORDER)) {
currentBorder = new SpecialMatteBorder(top, left, bottom, right, topColor, leftColor, bottomColor, rightColor);
} else {
currentBorder = new RoundedBorder(top, left, bottom, right, topColor, leftColor, bottomColor, rightColor);
}
if (tk.hasMoreTokens()) {
if (type.equals(SPECIAL_MATTE_BORDER)) {
((SpecialMatteBorder) currentBorder).setRoundingRadius(Utils.getAsFloat(tk.nextToken().trim()));
} else {
((RoundedBorder) currentBorder).setRoundingRadius(tk.nextToken().trim());
}
}
if (tk.hasMoreTokens()) {
if (type.equals(SPECIAL_MATTE_BORDER)) {
((SpecialMatteBorder) currentBorder).setDashPattern(SpecialMatteBorder.createDash(tk.nextToken().trim()));
} else {
((RoundedBorder) currentBorder).setBorderStyles(tk.nextToken().trim());
}
}
} else {
currentBorder = BorderFactory.createEtchedBorder();
}
} catch (Exception ex) {
Debug.error(ex);
return null;
}
} else {
currentBorder = BorderFactory.createEtchedBorder();
}
}
return currentBorder;
}
use of com.servoy.j2db.util.gui.SpecialMatteBorder in project servoy-client by Servoy.
the class ComponentFactoryHelper method createBorderString.
public static String createBorderString(Object currentBorder) {
String retval = null;
if (currentBorder != null) {
if (currentBorder instanceof CompoundBorder) {
Border oborder = ((CompoundBorder) currentBorder).getOutsideBorder();
Border iborder = ((CompoundBorder) currentBorder).getInsideBorder();
// $NON-NLS-1$
retval = COMPOUND_BORDER + ",";
// $NON-NLS-1$
retval += ";" + createBorderString(oborder);
// $NON-NLS-1$ //$NON-NLS-2$
retval += ";" + createBorderString(iborder) + ";";
} else if (currentBorder instanceof BevelBorder) {
BevelBorder border = (BevelBorder) currentBorder;
int type = border.getBevelType();
// $NON-NLS-1$
retval = BEVEL_BORDER + "," + type;
if (border.getHighlightInnerColor() != null || border.getHighlightOuterColor() != null || border.getShadowInnerColor() != null || border.getShadowOuterColor() != null) {
// $NON-NLS-1$
retval += "," + PersistHelper.createColorString(border.getHighlightOuterColor());
// $NON-NLS-1$
retval += "," + PersistHelper.createColorString(border.getHighlightInnerColor());
// $NON-NLS-1$
retval += "," + PersistHelper.createColorString(border.getShadowOuterColor());
// $NON-NLS-1$
retval += "," + PersistHelper.createColorString(border.getShadowInnerColor());
}
} else if (currentBorder instanceof EtchedBorder) {
EtchedBorder border = (EtchedBorder) currentBorder;
int type = border.getEtchType();
Color hi = border.getHighlightColor();
Color sh = border.getShadowColor();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
retval = ETCHED_BORDER + "," + type + "," + PersistHelper.createColorString(hi) + "," + PersistHelper.createColorString(sh);
} else if (currentBorder instanceof LineBorder) {
LineBorder border = (LineBorder) currentBorder;
int thick = border.getThickness();
Color lineColor = border.getLineColor();
// $NON-NLS-1$ //$NON-NLS-2$
retval = LINE_BORDER + "," + thick + "," + PersistHelper.createColorString(lineColor);
} else if (currentBorder instanceof TitledBorder) {
TitledBorder border = (TitledBorder) currentBorder;
String s = border.getTitle();
// escape //$NON-NLS-1$ //$NON-NLS-2$
s = Utils.stringReplace(s, ",", "|");
Font f = border.getTitleFont();
Color c = border.getTitleColor();
// $NON-NLS-1$
retval = TITLED_BORDER + "," + s;
int justification = border.getTitleJustification();
int position = border.getTitlePosition();
if (justification != 0 || position != 0 || f != null || c != null) {
// $NON-NLS-1$ //$NON-NLS-2$
retval += "," + justification + "," + position;
if (f != null) {
// $NON-NLS-1$
retval += "," + PersistHelper.createFontString(f);
if (c != null) {
// $NON-NLS-1$
retval += "," + PersistHelper.createColorString(c);
}
}
}
} else if (currentBorder instanceof SpecialMatteBorder) {
SpecialMatteBorder border = (SpecialMatteBorder) currentBorder;
retval = // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
((border instanceof RoundedBorder) ? ROUNDED_BORDER : SPECIAL_MATTE_BORDER) + "," + border.getTop() + "," + border.getRight() + "," + border.getBottom() + "," + // $NON-NLS-1$
border.getLeft();
// $NON-NLS-1$
retval += "," + PersistHelper.createColorString(border.getTopColor());
// $NON-NLS-1$
retval += "," + PersistHelper.createColorString(border.getRightColor());
// $NON-NLS-1$
retval += "," + PersistHelper.createColorString(border.getBottomColor());
// $NON-NLS-1$
retval += "," + PersistHelper.createColorString(border.getLeftColor());
if (border instanceof RoundedBorder) {
// $NON-NLS-1$
retval += "," + ((RoundedBorder) border).getRoundingRadiusString();
// $NON-NLS-1$
retval += "," + ((RoundedBorder) border).getBorderStylesString();
} else {
// $NON-NLS-1$
retval += "," + border.getRoundingRadius();
// $NON-NLS-1$
retval += "," + SpecialMatteBorder.createDashString(border.getDashPattern());
}
} else if (currentBorder instanceof MatteBorder) {
MatteBorder border = (MatteBorder) currentBorder;
Insets i = ComponentFactoryHelper.getBorderInsetsForNoComponent(border);
Color lineColor = border.getMatteColor();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
retval = MATTE_BORDER + "," + i.top + "," + i.right + "," + i.bottom + "," + i.left + "," + PersistHelper.createColorString(lineColor);
} else if (currentBorder instanceof EmptyBorder) {
EmptyBorder border = (EmptyBorder) currentBorder;
Insets i = ComponentFactoryHelper.getBorderInsetsForNoComponent(border);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
retval = EMPTY_BORDER + "," + i.top + "," + i.right + "," + i.bottom + "," + i.left;
} else {
// $NON-NLS-1$
retval = "<select>";
}
}
return retval;
}
use of com.servoy.j2db.util.gui.SpecialMatteBorder in project servoy-client by Servoy.
the class FixedStyleSheet method getBorder.
public Border getBorder(AttributeSet a) {
Border b = null;
// Initial values.
Object borderStyle = null;
Object borderColor = null;
float top = getLength(null);
float right = getLength(null);
float bottom = getLength(null);
float left = getLength(null);
// Try to use the unexpanded "border" attribute, if any.
Object unexpandedBorder = a.getAttribute(CSS.Attribute.BORDER);
if (unexpandedBorder != null) {
StringTokenizer st = new StringTokenizer(unexpandedBorder.toString());
// general case.
while (st.hasMoreTokens()) {
String tok = st.nextToken();
// If we got digits in the token, then it refers to border size.
if (// $NON-NLS-1$
tok.matches("^[0-9]+.*")) {
top = right = bottom = left = getLength(tok);
} else // If it is a border style keyword, use it accordingly.
if (Arrays.asList(IStyleSheet.BORDER_STYLES).contains(tok)) {
borderStyle = tok;
} else // If "transparent" then transparent.
if (tok.equals(IStyleSheet.COLOR_TRANSPARENT)) {
borderColor = IStyleSheet.COLOR_TRANSPARENT;
} else // Otherwise assume it is a color.
{
Color c = PersistHelper.createColor(tok);
if (c != null)
borderColor = tok;
}
}
}
// extracted from the unexpanded "border" attribute.
if (a.isDefined(CSS.Attribute.BORDER_STYLE))
borderStyle = a.getAttribute(CSS.Attribute.BORDER_STYLE);
if (a.isDefined(CSS.Attribute.BORDER_COLOR))
borderColor = a.getAttribute(CSS.Attribute.BORDER_COLOR);
if (a.isDefined(CSS.Attribute.BORDER_TOP_WIDTH))
top = getLength(a.getAttribute(CSS.Attribute.BORDER_TOP_WIDTH));
if (a.isDefined(CSS.Attribute.BORDER_RIGHT_WIDTH))
right = getLength(a.getAttribute(CSS.Attribute.BORDER_RIGHT_WIDTH));
if (a.isDefined(CSS.Attribute.BORDER_BOTTOM_WIDTH))
bottom = getLength(a.getAttribute(CSS.Attribute.BORDER_BOTTOM_WIDTH));
if (a.isDefined(CSS.Attribute.BORDER_LEFT_WIDTH))
left = getLength(a.getAttribute(CSS.Attribute.BORDER_LEFT_WIDTH));
if (borderStyle == null) {
// TODO this should be fixed when we compile against java 7.
// java 7 expands the complete border:
Enumeration<?> attributes = a.getAttributeNames();
while (attributes.hasMoreElements()) {
Object element = attributes.nextElement();
if (element != null && element.toString().startsWith("border-top-style")) {
borderStyle = a.getAttribute(element);
break;
}
}
}
if (borderStyle == null && (borderColor != null || top >= 0 || right >= 0 || bottom >= 0 || left >= 0)) {
borderStyle = IStyleSheet.BORDER_STYLE_SOLID;
}
if (borderStyle != null) {
Color[] colors = getBorderColor(borderColor, a);
String bstyle = borderStyle.toString();
if (a.isDefined(CSSName.BORDER_TOP_LEFT_RADIUS.toString())) {
top = makeSizeSave(top);
right = makeSizeSave(right);
bottom = makeSizeSave(bottom);
left = makeSizeSave(left);
colors = expandColors(colors);
b = new RoundedBorder(top, left, bottom, right, colors[0], colors[3], colors[2], colors[1]);
float[] radius = new float[8];
parseCornerBorderRadius(a, radius, 0, CSSName.BORDER_TOP_LEFT_RADIUS.toString());
parseCornerBorderRadius(a, radius, 1, CSSName.BORDER_TOP_RIGHT_RADIUS.toString());
parseCornerBorderRadius(a, radius, 2, CSSName.BORDER_BOTTOM_RIGHT_RADIUS.toString());
parseCornerBorderRadius(a, radius, 3, CSSName.BORDER_BOTTOM_LEFT_RADIUS.toString());
((RoundedBorder) b).setRoundingRadius(radius);
((RoundedBorder) b).setBorderStyles(new String[] { (String) a.getAttribute(CSSName.BORDER_TOP_STYLE.toString()), (String) a.getAttribute(CSSName.BORDER_LEFT_STYLE.toString()), (String) a.getAttribute(CSSName.BORDER_BOTTOM_STYLE.toString()), (String) a.getAttribute(CSSName.BORDER_RIGHT_STYLE.toString()) });
} else if (bstyle.equals(IStyleSheet.BORDER_STYLE_INSET) || bstyle.equals(IStyleSheet.BORDER_STYLE_OUTSET)) {
int style = BevelBorder.LOWERED;
if (bstyle.equals(IStyleSheet.BORDER_STYLE_OUTSET))
style = BevelBorder.RAISED;
Insets customBorderInsets = null;
if (top != -1.0 || right != -1.0 || bottom != -1.0 || left != -1.0) {
top = makeSizeSave(top);
right = makeSizeSave(right);
bottom = makeSizeSave(bottom);
left = makeSizeSave(left);
customBorderInsets = new Insets((int) top, (int) left, (int) bottom, (int) right);
}
if (colors != null && colors.length > 0) {
if (colors.length == 1 || (colors.length == 4 && Utils.equalObjects(colors[0], colors[1]) && Utils.equalObjects(colors[0], colors[2]) && Utils.equalObjects(colors[0], colors[3]))) {
// this tries to do the same thing as the web does..
b = new CustomBevelBorder(style, colors[0], customBorderInsets);
} else if (colors.length == 2) {
b = new CustomBevelBorder(style, colors[0], colors[1], customBorderInsets);
} else if (colors.length > 3) {
b = new CustomBevelBorder(style, colors[0], colors[1], colors[2], colors[3], customBorderInsets);
}
} else {
b = new CustomBevelBorder(style, customBorderInsets);
}
} else if (bstyle.equals(IStyleSheet.BORDER_STYLE_NONE)) {
b = BorderFactory.createEmptyBorder();
} else if (bstyle.equals(IStyleSheet.BORDER_STYLE_DOUBLE)) {
top = makeSizeSave(top);
right = makeSizeSave(right);
bottom = makeSizeSave(bottom);
left = makeSizeSave(left);
b = BorderFactory.createEmptyBorder((int) top, (int) left, (int) bottom, (int) right);
} else if (bstyle.equals(IStyleSheet.BORDER_STYLE_GROOVE) || bstyle.equals(IStyleSheet.BORDER_STYLE_RIDGE)) {
int style = EtchedBorder.LOWERED;
if (bstyle.equals(IStyleSheet.BORDER_STYLE_RIDGE))
style = EtchedBorder.RAISED;
Insets customBorderInsets = null;
if (top != -1.0 || right != -1.0 || bottom != -1.0 || left != -1.0) {
top = makeSizeSave(top);
right = makeSizeSave(right);
bottom = makeSizeSave(bottom);
left = makeSizeSave(left);
customBorderInsets = new Insets((int) top, (int) left, (int) bottom, (int) right);
}
if (colors != null && colors.length > 0) {
if (colors.length == 1 || (colors.length == 4 && Utils.equalObjects(colors[0], colors[1]) && Utils.equalObjects(colors[0], colors[2]) && Utils.equalObjects(colors[0], colors[3]))) {
// this tries to do the same thing as the web does..
b = new CustomEtchedBorder(style, colors[0], customBorderInsets);
} else if (colors.length >= 2) {
b = new CustomEtchedBorder(style, colors[0], colors[1], customBorderInsets);
}
} else {
b = new CustomEtchedBorder(style, customBorderInsets);
}
} else if (bstyle.equals(IStyleSheet.BORDER_STYLE_SOLID) || bstyle.equals(IStyleSheet.BORDER_STYLE_DOTTED) || bstyle.equals(IStyleSheet.BORDER_STYLE_DASHED)) {
// int bw = (int) getLength(CSS.Attribute.BORDER_WIDTH, a);
// int colorCount = (colors == null ? 0 : colors.length);
colors = expandColors(colors);
// Object obj = a.getAttribute(CSS.Attribute.BORDER_WIDTH);
if (bstyle.equals(IStyleSheet.BORDER_STYLE_SOLID)) {
if (borderColor != null && IStyleSheet.COLOR_TRANSPARENT.equals(borderColor.toString())) {
top = makeSizeSave(top);
right = makeSizeSave(right);
bottom = makeSizeSave(bottom);
left = makeSizeSave(left);
b = BorderFactory.createEmptyBorder((int) top, (int) left, (int) bottom, (int) right);
} else if (colors != null) {
if (// is undefined, make 1 px
top == -1f && right == -1f && bottom == -1f && left == -1f) {
b = BorderFactory.createLineBorder(colors[0]);
} else if (// is contradiction solid but width 0 make empty border
top == 0f && right == 0f && bottom == 0f && left == 0f) {
b = BorderFactory.createEmptyBorder();
} else {
top = makeSizeSave(top);
right = makeSizeSave(right);
bottom = makeSizeSave(bottom);
left = makeSizeSave(left);
b = new SpecialMatteBorder(top, left, bottom, right, colors[0], colors[3], colors[2], colors[1]);
}
}
} else if (bstyle.equals(IStyleSheet.BORDER_STYLE_DASHED)) {
if (top <= 0 && left <= 0 && bottom <= 0 && right <= 0) {
top = left = bottom = right = 1;
}
b = new SpecialMatteBorder(top, left, bottom, right, colors[0], colors[3], colors[2], colors[1]);
((SpecialMatteBorder) b).setDashPattern(new float[] { 3, 3 });
} else if (bstyle.equals(IStyleSheet.BORDER_STYLE_DOTTED)) {
if (top <= 0 && left <= 0 && bottom <= 0 && right <= 0) {
top = left = bottom = right = 1;
}
b = new SpecialMatteBorder(top, left, bottom, right, colors[0], colors[3], colors[2], colors[1]);
((SpecialMatteBorder) b).setDashPattern(new float[] { 1, 1 });
}
}
}
return b;
}
Aggregations