use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.
the class Border method getMinimumWidth.
/**
* Returns the minimum size required to properly display this border, normally this
* is 0 but a border might deem itself undisplayable with too small a size e.g. for
* the case of an image border the minimum height would be top + bottom and the minimum
* width would be left+right
*
* @return 0 if not applicable or a dimension if it is.
*/
public int getMinimumWidth() {
if (images != null) {
if (images.length < 4) {
if (type == TYPE_IMAGE_HORIZONTAL) {
return images[0].getWidth() + images[1].getWidth();
} else {
return images[0].getWidth();
}
}
Image topLeft = images[4];
Image topRight = images[5];
return topLeft.getWidth() + topRight.getWidth();
}
return 0;
}
use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.
the class Border method paint.
void paint(Graphics g, int x, int y, int width, int height, Component c) {
int originalColor = g.getColor();
if (!themeColors) {
g.setColor(colorA);
}
int ac = 1;
if (thickness > 0) {
if (millimeters) {
ac = Display.getInstance().convertToPixels(thickness);
} else {
ac = (int) thickness;
}
}
switch(type) {
case TYPE_LINE:
if (borderTitle == null) {
if (millimeters) {
g.drawRect(x, y, width, height, ac);
} else {
g.drawRect(x, y, width, height, ac);
}
} else {
Font f = c.getStyle().getFont();
int titleW = f.stringWidth(borderTitle);
int topPad = c.getStyle().getPaddingTop();
int topY = y + (topPad - ac) / 2;
if (c.isRTL()) {
// top (segment before the title)
g.fillRect(x + width - TITLE_MARGIN, topY, TITLE_MARGIN, ac);
// top (segment after the title)
g.fillRect(x, topY, width - (TITLE_MARGIN + titleW + TITLE_SPACE * 2), ac);
g.drawString(borderTitle, x + width - (TITLE_MARGIN + titleW + TITLE_SPACE), y + (topPad - f.getHeight()) / 2);
} else {
// top (segment before the title)
g.fillRect(x, topY, TITLE_MARGIN, ac);
// top (segment after the title)
g.fillRect(x + TITLE_MARGIN + titleW + TITLE_SPACE * 2, topY, width - (TITLE_MARGIN + titleW + TITLE_SPACE * 2), ac);
g.drawString(borderTitle, x + TITLE_MARGIN + TITLE_SPACE, y + (topPad - f.getHeight()) / 2);
}
// bottom
g.fillRect(x, y + height - ac, width, ac);
// left
g.fillRect(x, topY, ac, height);
// right
g.fillRect(x + width - ac, topY, ac, height);
}
break;
case TYPE_DASHED:
case TYPE_DOTTED:
int segWidth = ac;
if (type == TYPE_DASHED) {
segWidth = ac * 3;
}
int ix = x;
for (; ix < x + width; ix += segWidth * 2) {
g.fillRect(ix, y, segWidth, ac);
g.fillRect(ix, y + height - ac, segWidth, ac);
}
if (ix - segWidth < x + width) {
// fill in the gap if any
g.fillRect(ix - segWidth, y, x + width - ix + segWidth, ac);
g.fillRect(ix - segWidth, y + height - ac, x + width - ix + segWidth, ac);
}
int iy = y;
for (; iy < y + height; iy += segWidth * 2) {
g.fillRect(x, iy, ac, segWidth);
g.fillRect(x + width - ac, iy, ac, segWidth);
}
if (iy - segWidth < y + height) {
// fill in the gap if any
g.fillRect(x, iy - segWidth, ac, y + height - iy + segWidth);
g.fillRect(x + width - ac, iy - segWidth, ac, y + height - iy + segWidth);
}
break;
case TYPE_DOUBLE:
width--;
height--;
for (int iter = 0; iter < ac; iter++) {
if ((iter * 100 / ac <= 33) || (iter * 100 / ac >= 66)) {
g.drawRect(x + iter, y + iter, width, height);
}
width -= 2;
height -= 2;
}
break;
case TYPE_INSET:
case TYPE_OUTSET:
for (int i = 0; i < ac; i++) {
g.drawLine(x + i, y + i, x + i, y + height - i);
g.drawLine(x + i, y + i, x + width - i, y + i);
}
if (type == TYPE_INSET) {
g.lighterColor(50);
} else {
g.darkerColor(50);
}
for (int i = 0; i < ac; i++) {
g.drawLine(x + i, y + height - i, x + width - i, y + height - i);
g.drawLine(x + width - i, y + i, x + width - i, y + height - i);
}
break;
case TYPE_GROOVE:
case TYPE_RIDGE:
for (int i = 0; i < ac / 2; i++) {
g.drawLine(x + i, y + i, x + i, y + height - i);
g.drawLine(x + i, y + i, x + width - i, y + i);
}
for (int i = ac / 2; i < ac; i++) {
g.drawLine(x + i, y + height - i, x + width - i, y + height - i);
g.drawLine(x + width - i, y + i, x + width - i, y + height - i);
}
if (type == TYPE_GROOVE) {
g.lighterColor(50);
} else {
g.darkerColor(50);
}
for (int i = 0; i < ac / 2; i++) {
g.drawLine(x + i, y + height - i, x + width - i, y + height - i);
g.drawLine(x + width - i, y + i, x + width - i, y + height - i);
}
for (int i = ac / 2; i < ac; i++) {
g.drawLine(x + i, y + i, x + i, y + height - i);
g.drawLine(x + i, y + i, x + width - i, y + i);
}
break;
case TYPE_ROUNDED_PRESSED:
x++;
y++;
width -= 2;
height -= 2;
case TYPE_ROUNDED:
width--;
height--;
if (outline) {
g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
}
break;
case TYPE_ETCHED_LOWERED:
case TYPE_ETCHED_RAISED:
g.drawRect(x, y, width - 2, height - 2);
if (themeColors) {
if (type == TYPE_ETCHED_LOWERED) {
g.lighterColor(40);
} else {
g.darkerColor(40);
}
} else {
g.setColor(colorB);
}
g.drawLine(x + 1, y + height - 3, x + 1, y + 1);
g.drawLine(x + 1, y + 1, x + width - 3, y + 1);
g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
g.drawLine(x + width - 1, y + height - 1, x + width - 1, y);
break;
case TYPE_BEVEL_RAISED:
if (themeColors) {
g.setColor(getBackgroundColor(c));
g.lighterColor(50);
} else {
g.setColor(colorA);
}
g.drawLine(x, y, x, y + height - 2);
g.drawLine(x + 1, y, x + width - 2, y);
if (themeColors) {
g.darkerColor(25);
} else {
g.setColor(colorB);
}
g.drawLine(x + 1, y + 1, x + 1, y + height - 3);
g.drawLine(x + 2, y + 1, x + width - 3, y + 1);
if (themeColors) {
g.darkerColor(50);
} else {
g.setColor(colorC);
}
g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
g.drawLine(x + width - 1, y, x + width - 1, y + height - 2);
if (themeColors) {
g.darkerColor(25);
} else {
g.setColor(colorD);
}
g.drawLine(x + 1, y + height - 2, x + width - 2, y + height - 2);
g.drawLine(x + width - 2, y + 1, x + width - 2, y + height - 3);
break;
case TYPE_UNDERLINE:
g.fillRect(x, y + height - ac - 1, width, ac);
break;
case TYPE_BEVEL_LOWERED:
if (themeColors) {
g.setColor(getBackgroundColor(c));
g.darkerColor(50);
} else {
g.setColor(colorD);
}
g.drawLine(x, y, x, y + height - 1);
g.drawLine(x + 1, y, x + width - 1, y);
if (themeColors) {
g.lighterColor(25);
} else {
g.setColor(colorC);
}
g.drawLine(x + 1, y + 1, x + 1, y + height - 2);
g.drawLine(x + 2, y + 1, x + width - 2, y + 1);
if (themeColors) {
g.lighterColor(50);
} else {
g.setColor(colorC);
}
g.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
g.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 2);
if (themeColors) {
g.lighterColor(25);
} else {
g.setColor(colorA);
}
g.drawLine(x + 2, y + height - 2, x + width - 2, y + height - 2);
g.drawLine(x + width - 2, y + 2, x + width - 2, y + height - 3);
break;
case TYPE_COMPOUND:
Style style = c.getStyle();
boolean drawLeft = true;
boolean drawRight = true;
if (c.getUIManager().getLookAndFeel().isRTL()) {
boolean temp = drawLeft;
drawLeft = drawRight;
drawRight = temp;
}
Border top = compoundBorders[Component.TOP];
Border bottom = compoundBorders[Component.BOTTOM];
Border left = compoundBorders[Component.LEFT];
Border right = compoundBorders[Component.RIGHT];
int topThickness = 0;
int bottomThickness = 0;
if (top != null) {
Rectangle clip = saveClip(g);
// g.pushClip();
topThickness = (int) top.thickness;
g.clipRect(x, y, width, topThickness);
// top.paint(g, c);
top.paint(g, x, y, width, height, c);
restoreClip(g, clip);
// g.popClip();
}
if (bottom != null) {
Rectangle clip = saveClip(g);
// g.pushClip();
bottomThickness = (int) bottom.thickness;
g.clipRect(x, y + height - bottomThickness, width, bottomThickness);
// bottom.paint(g, c);
bottom.paint(g, x, y, width, height, c);
restoreClip(g, clip);
// g.popClip();
}
if ((drawLeft) && (left != null)) {
Rectangle clip = saveClip(g);
// g.pushClip();
g.clipRect(x, y + topThickness, (int) left.thickness, height - topThickness - bottomThickness);
// left.paint(g, c);
left.paint(g, x, y, width, height, c);
restoreClip(g, clip);
// g.popClip();
}
if ((drawRight) && (right != null)) {
Rectangle clip = saveClip(g);
// g.pushClip();
g.clipRect(x + width - (int) right.thickness, y + topThickness, (int) right.thickness, height - topThickness - bottomThickness);
// right.paint(g, c);
right.paint(g, x, y, width, height, c);
restoreClip(g, clip);
// g.popClip();
}
break;
case TYPE_IMAGE:
case TYPE_IMAGE_SCALED:
case TYPE_IMAGE_HORIZONTAL:
case TYPE_IMAGE_VERTICAL:
break;
}
g.setColor(originalColor);
}
use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.
the class Border method getMinimumHeight.
/**
* Returns the minimum size required to properly display this border, normally this
* is 0 but a border might deem itself undisplayable with too small a size e.g. for
* the case of an image border the minimum height would be top + bottom and the minimum
* width would be left+right
*
* @return 0 if not applicable or a dimension if it is.
*/
public int getMinimumHeight() {
if (images != null) {
if (images.length < 4) {
if (type == TYPE_IMAGE_HORIZONTAL) {
return images[0].getHeight();
} else {
return images[0].getHeight() + images[1].getHeight();
}
}
Image topLeft = images[4];
Image bottomRight = images[7];
return topLeft.getHeight() + bottomRight.getHeight();
}
return 0;
}
use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.
the class EditableResources method writeBorder.
private void writeBorder(DataOutputStream output, Border border, boolean newVersion) throws IOException {
if (border instanceof RoundBorder) {
output.writeShort(0xff12);
RoundBorder rb = (RoundBorder) border;
output.writeBoolean(rb.isRectangle());
output.writeInt(rb.getColor());
output.writeInt(rb.getOpacity());
output.writeFloat(rb.getStrokeThickness());
output.writeBoolean(rb.isStrokeMM());
output.writeInt(rb.getStrokeColor());
output.writeInt(rb.getStrokeOpacity());
output.writeFloat(rb.getShadowBlur());
output.writeInt(rb.getShadowOpacity());
output.writeInt(rb.getShadowSpread());
output.writeBoolean(rb.isShadowMM());
output.writeFloat(rb.getShadowX());
output.writeFloat(rb.getShadowY());
return;
}
if (border instanceof RoundRectBorder) {
output.writeShort(0xff13);
RoundRectBorder rb = (RoundRectBorder) border;
output.writeFloat(rb.getStrokeThickness());
output.writeBoolean(rb.isStrokeMM());
output.writeInt(rb.getStrokeColor());
output.writeInt(rb.getStrokeOpacity());
output.writeFloat(rb.getShadowBlur());
output.writeInt(rb.getShadowOpacity());
output.writeFloat(rb.getShadowSpread());
output.writeFloat(rb.getShadowX());
output.writeFloat(rb.getShadowY());
output.writeFloat(rb.getCornerRadius());
output.writeBoolean(rb.isBezierCorners());
output.writeBoolean(rb.isTopOnlyMode());
output.writeBoolean(rb.isBottomOnlyMode());
return;
}
int type = Accessor.getType(border);
switch(type) {
case BORDER_TYPE_EMPTY:
output.writeShort(0xff01);
return;
case BORDER_TYPE_LINE:
output.writeShort(0xff02);
// use theme colors?
if (Accessor.isThemeColors(border)) {
output.writeBoolean(true);
output.writeBoolean(Accessor.isMillimeters(border));
output.writeFloat(Accessor.getThickness(border));
} else {
output.writeBoolean(false);
output.writeBoolean(Accessor.isMillimeters(border));
output.writeFloat(Accessor.getThickness(border));
output.writeInt(Accessor.getColorA(border));
}
return;
case BORDER_TYPE_UNDERLINE:
output.writeShort(0xff14);
// use theme colors?
if (Accessor.isThemeColors(border)) {
output.writeBoolean(true);
output.writeBoolean(Accessor.isMillimeters(border));
output.writeFloat(Accessor.getThickness(border));
} else {
output.writeBoolean(false);
output.writeBoolean(Accessor.isMillimeters(border));
output.writeFloat(Accessor.getThickness(border));
output.writeInt(Accessor.getColorA(border));
}
return;
case BORDER_TYPE_ROUNDED:
output.writeShort(0xff03);
// use theme colors?
if (Accessor.isThemeColors(border)) {
output.writeBoolean(true);
output.writeByte(Accessor.getArcWidth(border));
output.writeByte(Accessor.getArcHeight(border));
} else {
output.writeBoolean(false);
output.writeByte(Accessor.getArcWidth(border));
output.writeByte(Accessor.getArcHeight(border));
output.writeInt(Accessor.getColorA(border));
}
return;
case BORDER_TYPE_ETCHED_RAISED:
output.writeShort(0xff05);
writeEtchedBorder(output, border);
return;
case BORDER_TYPE_ETCHED_LOWERED:
output.writeShort(0xff04);
writeEtchedBorder(output, border);
return;
case BORDER_TYPE_BEVEL_LOWERED:
output.writeShort(0xff06);
writeBevelBorder(output, border);
return;
case BORDER_TYPE_BEVEL_RAISED:
output.writeShort(0xff07);
writeBevelBorder(output, border);
return;
case BORDER_TYPE_IMAGE:
output.writeShort(0xff08);
writeImageBorder(output, border);
return;
case BORDER_TYPE_IMAGE_HORIZONTAL:
output.writeShort(0xff09);
writeImageHVBorder(output, border);
return;
case BORDER_TYPE_IMAGE_VERTICAL:
output.writeShort(0xff10);
writeImageHVBorder(output, border);
return;
case BORDER_TYPE_IMAGE_SCALED:
output.writeShort(0xff11);
writeImageBorder(output, border);
return;
}
}
use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.
the class EditableResources method replaceThemeValue.
/**
* Used when changing a font or an image to update the theme
*/
private void replaceThemeValue(Object oldValue, Object value) {
if (oldValue != null && value != null) {
if (oldValue instanceof MultiImage) {
MultiImage m = (MultiImage) oldValue;
Object newValue = value;
if (newValue instanceof MultiImage) {
newValue = ((MultiImage) newValue).getBest();
}
for (com.codename1.ui.EncodedImage e : m.getInternalImages()) {
replaceThemeValue(e, newValue);
}
}
for (String themeName : getThemeResourceNames()) {
Hashtable theme = getTheme(themeName);
for (Object key : theme.keySet()) {
Object currentValue = theme.get(key);
if (currentValue == oldValue) {
theme.put(key, value);
}
}
}
// we need to check the existance of image borders to replace images there...
if (value instanceof Image) {
for (String themeName : getThemeResourceNames()) {
Hashtable theme = getTheme(themeName);
for (Object v : theme.values()) {
if (v instanceof Border) {
Border b = (Border) v;
if (Accessor.getType(b) == BORDER_TYPE_IMAGE || Accessor.getType(b) == BORDER_TYPE_IMAGE_VERTICAL || Accessor.getType(b) == BORDER_TYPE_IMAGE_HORIZONTAL) {
Image[] images = Accessor.getImages(b);
for (int i = 0; i < images.length; i++) {
if (images[i] == oldValue) {
images[i] = (Image) value;
}
}
}
}
}
}
}
// check if a timeline is making use of said image and replace it
for (String image : getImageResourceNames()) {
com.codename1.ui.Image current = getImage(image);
if (current instanceof com.codename1.ui.animations.Timeline) {
com.codename1.ui.animations.Timeline time = (com.codename1.ui.animations.Timeline) current;
for (int iter = 0; iter < time.getAnimationCount(); iter++) {
com.codename1.ui.animations.AnimationObject o = time.getAnimation(iter);
if (AnimationAccessor.getImage(o) == oldValue) {
AnimationAccessor.setImage(o, (com.codename1.ui.Image) value);
}
}
}
}
}
}
Aggregations