use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.
the class Resources method readTimeline.
Timeline readTimeline(DataInputStream input) throws IOException {
int duration = input.readInt();
int width = input.readInt();
int height = input.readInt();
AnimationObject[] animations = new AnimationObject[input.readShort()];
int alen = animations.length;
for (int iter = 0; iter < alen; iter++) {
String name = input.readUTF();
int startTime = input.readInt();
int animDuration = input.readInt();
int x = input.readInt();
int y = input.readInt();
Image i = getImage(name);
if (i == null) {
animations[iter] = AnimationObject.createAnimationImage(name, this, x, y);
} else {
animations[iter] = AnimationObject.createAnimationImage(i, x, y);
}
animations[iter].setStartTime(startTime);
animations[iter].setEndTime(startTime + animDuration);
int frameDelay = input.readInt();
if (frameDelay > -1) {
int frameWidth = input.readInt();
int frameHeight = input.readInt();
animations[iter].defineFrames(frameWidth, frameHeight, frameDelay);
}
if (input.readBoolean()) {
animations[iter].defineMotionX(input.readInt(), startTime, animDuration, x, input.readInt());
}
if (input.readBoolean()) {
animations[iter].defineMotionY(input.readInt(), startTime, animDuration, y, input.readInt());
}
if (input.readBoolean()) {
animations[iter].defineWidth(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
}
if (input.readBoolean()) {
animations[iter].defineHeight(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
}
if (input.readBoolean()) {
animations[iter].defineOpacity(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
}
if (input.readBoolean()) {
animations[iter].defineOrientation(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
}
}
Timeline tl = Timeline.createTimeline(duration, animations, new Dimension(width, height));
return tl;
}
use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.
the class EditableResources method getResourceEditor.
public JComponent getResourceEditor(String name, ResourceEditorView view) {
byte magic = getResourceType(name);
switch(magic) {
case MAGIC_IMAGE:
case MAGIC_IMAGE_LEGACY:
Image i = getImage(name);
if (getResourceObject(name) instanceof MultiImage) {
ImageMultiEditor tl = new ImageMultiEditor(this, name, view);
tl.setImage((MultiImage) getResourceObject(name));
return tl;
}
if (i instanceof Timeline) {
TimelineEditor tl = new TimelineEditor(this, name, view);
tl.setImage((Timeline) i);
return tl;
}
if (i.isSVG()) {
MultiImageSVGEditor img = new MultiImageSVGEditor(this, name);
img.setImage(i);
return img;
}
ImageRGBEditor img = new ImageRGBEditor(this, name, view);
img.setImage(i);
return img;
case MAGIC_TIMELINE:
TimelineEditor tl = new TimelineEditor(this, name, view);
tl.setImage((Timeline) getImage(name));
return tl;
case MAGIC_THEME:
case MAGIC_THEME_LEGACY:
ThemeEditor theme = new ThemeEditor(this, name, getTheme(name), view);
return theme;
case MAGIC_FONT:
case MAGIC_FONT_LEGACY:
case MAGIC_INDEXED_FONT_LEGACY:
FontEditor fonts = new FontEditor(this, getFont(name), name);
return fonts;
case MAGIC_DATA:
DataEditor data = new DataEditor(this, name);
return data;
case MAGIC_UI:
UserInterfaceEditor uie = new UserInterfaceEditor(name, this, view.getProjectGeneratorSettings(), view);
return uie;
case MAGIC_L10N:
// we are cheating this isn't a theme but it should work since
// this is a hashtable that will include the nested locales
L10nEditor l10n = new L10nEditor(this, name);
return l10n;
default:
throw new IllegalArgumentException("Unrecognized magic number: " + Integer.toHexString(magic & 0xff));
}
}
use of com.codename1.ui.animations.Timeline 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);
}
}
}
}
}
}
use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.
the class EditableResources method saveXMLFile.
private void saveXMLFile(File xml, File resourcesDir) throws IOException {
// disable override for the duration of the save so stuff from the override doesn't
// get into the main resource file
File overrideFileBackup = overrideFile;
EditableResources overrideResourceBackup = overrideResource;
overrideResource = null;
overrideFile = null;
try {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xml), "UTF-8"));
String[] resourceNames = getResourceNames();
Arrays.sort(resourceNames, String.CASE_INSENSITIVE_ORDER);
bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
bw.write("<resource majorVersion=\"" + MAJOR_VERSION + "\" minorVersion=\"" + MINOR_VERSION + "\" useXmlUI=\"" + xmlUI + "\">\n");
for (int iter = 0; iter < resourceNames.length; iter++) {
String xResourceName = xmlize(resourceNames[iter]);
// write the magic number
byte magic = getResourceType(resourceNames[iter]);
switch(magic) {
case MAGIC_TIMELINE:
case MAGIC_ANIMATION_LEGACY:
case MAGIC_IMAGE_LEGACY:
case MAGIC_INDEXED_IMAGE_LEGACY:
magic = MAGIC_IMAGE;
break;
case MAGIC_THEME_LEGACY:
magic = MAGIC_THEME;
break;
case MAGIC_FONT_LEGACY:
magic = MAGIC_FONT;
break;
}
switch(magic) {
case MAGIC_IMAGE:
Object o = getResourceObject(resourceNames[iter]);
if (!(o instanceof MultiImage)) {
o = null;
}
bw.write(" <image name=\"" + xResourceName + "\" ");
com.codename1.ui.Image image = getImage(resourceNames[iter]);
MultiImage mi = (MultiImage) o;
int rType = getImageType(image, mi);
switch(rType) {
// PNG file
case 0xf1:
// JPEG File
case 0xf2:
if (image instanceof EncodedImage) {
byte[] data = ((EncodedImage) image).getImageData();
writeToFile(data, new File(resourcesDir, normalizeFileName(resourceNames[iter])));
} else {
FileOutputStream fo = new FileOutputStream(new File(resourcesDir, normalizeFileName(resourceNames[iter])));
BufferedImage buffer = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
buffer.setRGB(0, 0, image.getWidth(), image.getHeight(), image.getRGB(), 0, image.getWidth());
ImageIO.write(buffer, "png", fo);
fo.close();
}
break;
// SVG
case 0xf5:
// multiimage with SVG
case 0xf7:
SVG s = (SVG) image.getSVGDocument();
writeToFile(s.getSvgData(), new File(resourcesDir, normalizeFileName(resourceNames[iter])));
if (s.getBaseURL() != null && s.getBaseURL().length() > 0) {
bw.write("baseUrl=\"" + s.getBaseURL() + "\" ");
}
bw.write("type=\"svg\" ");
break;
case 0xF6:
File multiImageDir = new File(resourcesDir, normalizeFileName(resourceNames[iter]));
multiImageDir.mkdirs();
for (int imageIter = 0; imageIter < mi.getDpi().length; imageIter++) {
File f = null;
switch(mi.getDpi()[imageIter]) {
case Display.DENSITY_4K:
f = new File(multiImageDir, "4k.png");
break;
case Display.DENSITY_2HD:
f = new File(multiImageDir, "2hd.png");
break;
case Display.DENSITY_560:
f = new File(multiImageDir, "560.png");
break;
case Display.DENSITY_HD:
f = new File(multiImageDir, "hd.png");
break;
case Display.DENSITY_VERY_HIGH:
f = new File(multiImageDir, "veryhigh.png");
break;
case Display.DENSITY_HIGH:
f = new File(multiImageDir, "high.png");
break;
case Display.DENSITY_MEDIUM:
f = new File(multiImageDir, "medium.png");
break;
case Display.DENSITY_LOW:
f = new File(multiImageDir, "low.png");
break;
case Display.DENSITY_VERY_LOW:
f = new File(multiImageDir, "verylow.png");
break;
}
writeToFile(mi.getInternalImages()[imageIter].getImageData(), f);
}
bw.write("type=\"multi\" ");
break;
// Timeline
case MAGIC_TIMELINE:
File timeline = new File(resourcesDir, normalizeFileName(resourceNames[iter]));
DataOutputStream timelineOut = new DataOutputStream(new FileOutputStream(timeline));
writeTimeline(timelineOut, (Timeline) image);
timelineOut.close();
bw.write("type=\"timeline\" ");
break;
// Fail this is the wrong data type
default:
throw new IOException("Illegal type while creating image: " + Integer.toHexString(rType));
}
bw.write(" />\n");
continue;
case MAGIC_THEME:
Hashtable<String, Object> theme = getTheme(resourceNames[iter]);
theme.remove("name");
bw.write(" <theme name=\"" + xResourceName + "\">\n");
ArrayList<String> setOfKeys = new ArrayList<String>(theme.keySet());
Collections.sort(setOfKeys);
for (String key : setOfKeys) {
if (key.startsWith("@")) {
if (key.endsWith("Image")) {
bw.write(" <val key=\"" + key + "\" value=\"" + findId(theme.get(key), true) + "\" />\n");
} else {
bw.write(" <val key=\"" + key + "\" value=\"" + theme.get(key) + "\" />\n");
}
continue;
}
// if this is a simple numeric value
if (key.endsWith("Color")) {
bw.write(" <val key=\"" + key + "\" value=\"" + theme.get(key) + "\" />\n");
continue;
}
if (key.endsWith("align") || key.endsWith("textDecoration")) {
bw.write(" <val key=\"" + key + "\" value=\"" + ((Number) theme.get(key)).shortValue() + "\" />\n");
continue;
}
// if this is a short numeric value
if (key.endsWith("transparency")) {
bw.write(" <val key=\"" + key + "\" value=\"" + theme.get(key) + "\" />\n");
continue;
}
if (key.endsWith("opacity")) {
bw.write(" <val key=\"" + key + "\" value=\"" + theme.get(key) + "\" />\n");
continue;
}
// if this is a padding or margin then we will have the 4 values as bytes
if (key.endsWith("padding") || key.endsWith("margin")) {
bw.write(" <val key=\"" + key + "\" value=\"" + theme.get(key) + "\" />\n");
continue;
}
// padding and or margin type
if (key.endsWith("Unit")) {
byte[] b = (byte[]) theme.get(key);
bw.write(" <val key=\"" + key + "\" value=\"" + b[0] + "," + b[1] + "," + b[2] + "," + b[3] + "\" />\n");
continue;
}
if (key.endsWith("border")) {
Border border = (Border) theme.get(key);
if (border instanceof RoundBorder) {
RoundBorder rb = (RoundBorder) border;
bw.write(" <border key=\"" + key + "\" type=\"round\" " + "roundBorderColor=\"" + rb.getColor() + "\" " + "opacity=\"" + rb.getOpacity() + "\" " + "strokeColor=\"" + rb.getStrokeColor() + "\" " + "strokeOpacity=\"" + rb.getStrokeOpacity() + "\" " + "strokeThickness=\"" + rb.getStrokeThickness() + "\" " + "strokeMM=\"" + rb.isStrokeMM() + "\" " + "shadowSpread=\"" + rb.getShadowSpread() + "\" " + "shadowOpacity=\"" + rb.getShadowOpacity() + "\" " + "shadowX=\"" + rb.getShadowX() + "\" " + "shadowY=\"" + rb.getShadowY() + "\" " + "shadowBlur=\"" + rb.getShadowBlur() + "\" " + "shadowMM=\"" + rb.isShadowMM() + "\" " + "rectangle=\"" + rb.isRectangle() + "\" />\n");
continue;
}
if (border instanceof RoundRectBorder) {
RoundRectBorder rb = (RoundRectBorder) border;
bw.write(" <border key=\"" + key + "\" type=\"roundRect\" " + "strokeColor=\"" + rb.getStrokeColor() + "\" " + "strokeOpacity=\"" + rb.getStrokeOpacity() + "\" " + "strokeThickness=\"" + rb.getStrokeThickness() + "\" " + "strokeMM=\"" + rb.isStrokeMM() + "\" " + "shadowSpread=\"" + rb.getShadowSpread() + "\" " + "shadowOpacity=\"" + rb.getShadowOpacity() + "\" " + "shadowX=\"" + rb.getShadowX() + "\" " + "shadowY=\"" + rb.getShadowY() + "\" " + "shadowBlur=\"" + rb.getShadowBlur() + "\" " + "topOnlyMode=\"" + rb.isTopOnlyMode() + "\" " + "bottomOnlyMode=\"" + rb.isBottomOnlyMode() + "\" " + "cornerRadius=\"" + rb.getCornerRadius() + "\" " + "bezierCorners=\"" + rb.isBezierCorners() + "\" />\n");
continue;
}
int type = Accessor.getType(border);
switch(type) {
case BORDER_TYPE_EMPTY:
bw.write(" <border key=\"" + key + "\" type=\"empty\" />\n");
continue;
case BORDER_TYPE_LINE:
// use theme colors?
if (Accessor.isThemeColors(border)) {
bw.write(" <border key=\"" + key + "\" type=\"line\" millimeters=\"" + Accessor.isMillimeters(border) + "\" thickness=\"" + Accessor.getThickness(border) + "\" />\n");
} else {
bw.write(" <border key=\"" + key + "\" type=\"line\" millimeters=\"" + Accessor.isMillimeters(border) + "\" thickness=\"" + Accessor.getThickness(border) + "\" color=\"" + Accessor.getColorA(border) + "\" />\n");
}
continue;
case BORDER_TYPE_UNDERLINE:
// use theme colors?
if (Accessor.isThemeColors(border)) {
bw.write(" <border key=\"" + key + "\" type=\"underline\" millimeters=\"" + Accessor.isMillimeters(border) + "\" thickness=\"" + Accessor.getThickness(border) + "\" />\n");
} else {
bw.write(" <border key=\"" + key + "\" type=\"underline\" millimeters=\"" + Accessor.isMillimeters(border) + "\" thickness=\"" + Accessor.getThickness(border) + "\" color=\"" + Accessor.getColorA(border) + "\" />\n");
}
continue;
case BORDER_TYPE_ROUNDED:
if (Accessor.isThemeColors(border)) {
bw.write(" <border key=\"" + key + "\" type=\"rounded\" " + "thickness=\"" + Accessor.getThickness(border) + "\" arcW=\"" + Accessor.getArcWidth(border) + "\" arcH=\"" + Accessor.getArcHeight(border) + "\" />\n");
} else {
bw.write(" <border key=\"" + key + "\" type=\"rounded\" " + "thickness=\"" + Accessor.getThickness(border) + "\" arcW=\"" + Accessor.getArcWidth(border) + "\" arcH=\"" + Accessor.getArcHeight(border) + "\" color=\"" + Accessor.getColorA(border) + "\" />\n");
}
continue;
case BORDER_TYPE_ETCHED_RAISED:
// use theme colors?
if (Accessor.isThemeColors(border)) {
bw.write(" <border key=\"" + key + "\" type=\"etchedRaised\" " + "thickness=\"" + Accessor.getThickness(border) + "\" />\n");
} else {
bw.write(" <border key=\"" + key + "\" type=\"etchedRaised\" " + "thickness=\"" + Accessor.getThickness(border) + "\" color=\"" + Accessor.getColorA(border) + "\" colorB=\"" + Accessor.getColorB(border) + "\" />\n");
}
continue;
case BORDER_TYPE_ETCHED_LOWERED:
// use theme colors?
if (Accessor.isThemeColors(border)) {
bw.write(" <border key=\"" + key + "\" type=\"etchedLowered\" " + "thickness=\"" + Accessor.getThickness(border) + "\" />\n");
} else {
bw.write(" <border key=\"" + key + "\" type=\"etchedLowered\" " + "thickness=\"" + Accessor.getThickness(border) + "\" color=\"" + Accessor.getColorA(border) + "\" colorB=\"" + Accessor.getColorB(border) + "\" />\n");
}
continue;
case BORDER_TYPE_BEVEL_LOWERED:
// use theme colors?
if (Accessor.isThemeColors(border)) {
bw.write(" <border key=\"" + key + "\" type=\"bevelLowered\" " + "thickness=\"" + Accessor.getThickness(border) + "\" />\n");
} else {
bw.write(" <border key=\"" + key + "\" type=\"bevelLowered\" " + "thickness=\"" + Accessor.getThickness(border) + "\" color=\"" + Accessor.getColorA(border) + "\" colorB=\"" + Accessor.getColorB(border) + "\" colorC=\"" + Accessor.getColorC(border) + "\" colorD=\"" + Accessor.getColorD(border) + "\" />\n");
}
continue;
case BORDER_TYPE_BEVEL_RAISED:
if (Accessor.isThemeColors(border)) {
bw.write(" <border key=\"" + key + "\" type=\"bevelRaised\" " + "thickness=\"" + Accessor.getThickness(border) + "\" />\n");
} else {
bw.write(" <border key=\"" + key + "\" type=\"bevelRaised\" " + "thickness=\"" + Accessor.getThickness(border) + "\" color=\"" + Accessor.getColorA(border) + "\" colorB=\"" + Accessor.getColorB(border) + "\" colorC=\"" + Accessor.getColorC(border) + "\" colorD=\"" + Accessor.getColorD(border) + "\" />\n");
}
continue;
// case BORDER_TYPE_IMAGE_SCALED:
case BORDER_TYPE_IMAGE:
{
Image[] images = Accessor.getImages(border);
int resourceCount = 0;
for (int counter = 0; counter < images.length; counter++) {
if (images[counter] != null && findId(images[counter], true) != null) {
resourceCount++;
}
}
if (resourceCount != 2 && resourceCount != 3 && resourceCount != 8 && resourceCount != 9) {
System.out.println("Odd resource count for image border: " + resourceCount);
resourceCount = 2;
}
switch(resourceCount) {
case 2:
bw.write(" <border key=\"" + key + "\" type=\"image\" " + "i1=\"" + findId(images[0], true) + "\" " + "i2=\"" + findId(images[4], true) + "\" />\n");
break;
case 3:
bw.write(" <border key=\"" + key + "\" type=\"image\" " + "i1=\"" + findId(images[0], true) + "\" " + "i2=\"" + findId(images[4], true) + "\" " + "i3=\"" + findId(images[8], true) + "\" />\n");
break;
case 8:
bw.write(" <border key=\"" + key + "\" type=\"image\" " + "i1=\"" + findId(images[0], true) + "\" " + "i2=\"" + findId(images[1], true) + "\" " + "i3=\"" + findId(images[2], true) + "\" " + "i4=\"" + findId(images[3], true) + "\" " + "i5=\"" + findId(images[4], true) + "\" " + "i6=\"" + findId(images[5], true) + "\" " + "i7=\"" + findId(images[6], true) + "\" " + "i8=\"" + findId(images[7], true) + "\" />\n");
break;
case 9:
bw.write(" <border key=\"" + key + "\" type=\"image\" " + "i1=\"" + findId(images[0], true) + "\" " + "i2=\"" + findId(images[1], true) + "\" " + "i3=\"" + findId(images[2], true) + "\" " + "i4=\"" + findId(images[3], true) + "\" " + "i5=\"" + findId(images[4], true) + "\" " + "i6=\"" + findId(images[5], true) + "\" " + "i7=\"" + findId(images[6], true) + "\" " + "i8=\"" + findId(images[7], true) + "\" " + "i9=\"" + findId(images[8], true) + "\" />\n");
break;
}
continue;
}
case BORDER_TYPE_IMAGE_HORIZONTAL:
{
Image[] images = Accessor.getImages(border);
bw.write(" <border key=\"" + key + "\" type=\"imageH\" " + "i1=\"" + findId(images[0], true) + "\" " + "i2=\"" + findId(images[1], true) + "\" " + "i3=\"" + findId(images[2], true) + "\" />\n");
continue;
}
case BORDER_TYPE_IMAGE_VERTICAL:
{
Image[] images = Accessor.getImages(border);
bw.write(" <border key=\"" + key + "\" type=\"imageV\" " + "i1=\"" + findId(images[0], true) + "\" " + "i2=\"" + findId(images[1], true) + "\" " + "i3=\"" + findId(images[2], true) + "\" />\n");
continue;
}
}
continue;
}
// if this is a font
if (key.endsWith("font")) {
com.codename1.ui.Font f = (com.codename1.ui.Font) theme.get(key);
// is this a new font?
boolean newFont = f instanceof EditorFont;
if (newFont) {
bw.write(" <font key=\"" + key + "\" type=\"named\" " + "name=\"" + findId(f) + "\" />\n");
} else {
if (f instanceof EditorTTFFont && (((EditorTTFFont) f).getFontFile() != null || ((EditorTTFFont) f).getNativeFontName() != null)) {
EditorTTFFont ed = (EditorTTFFont) f;
String fname;
String ffName;
if (((EditorTTFFont) f).getNativeFontName() != null) {
fname = ((EditorTTFFont) f).getNativeFontName();
ffName = fname;
} else {
fname = ed.getFontFile().getName();
ffName = ((java.awt.Font) ed.getNativeFont()).getPSName();
}
bw.write(" <font key=\"" + key + "\" type=\"ttf\" " + "face=\"" + f.getFace() + "\" " + "style=\"" + f.getStyle() + "\" " + "size=\"" + f.getSize() + "\" " + "name=\"" + fname + "\" " + "family=\"" + ffName + "\" " + "sizeSettings=\"" + ed.getSizeSetting() + "\" " + "actualSize=\"" + ed.getActualSize() + "\" />\n");
} else {
bw.write(" <font key=\"" + key + "\" type=\"system\" " + "face=\"" + f.getFace() + "\" " + "style=\"" + f.getStyle() + "\" " + "size=\"" + f.getSize() + "\" />\n");
}
}
continue;
}
// if this is a background image
if (key.endsWith("bgImage")) {
bw.write(" <val key=\"" + key + "\" value=\"" + findId(theme.get(key), true) + "\" />\n");
continue;
}
if (key.endsWith("scaledImage")) {
bw.write(" <val key=\"" + key + "\" value=\"" + theme.get(key) + "\" />\n");
continue;
}
if (key.endsWith("derive")) {
bw.write(" <val key=\"" + key + "\" value=\"" + theme.get(key) + "\" />\n");
continue;
}
// if this is a background gradient
if (key.endsWith("bgGradient")) {
Object[] gradient = (Object[]) theme.get(key);
bw.write(" <gradient key=\"" + key + "\" color1=\"" + gradient[0] + "\"" + " color2=\"" + gradient[1] + "\"" + " posX=\"" + gradient[2] + "\"" + " posY=\"" + gradient[3] + "\"" + " radius=\"" + gradient[4] + "\" />\n");
continue;
}
if (key.endsWith(Style.BACKGROUND_TYPE) || key.endsWith(Style.BACKGROUND_ALIGNMENT)) {
bw.write(" <val key=\"" + key + "\" value=\"" + theme.get(key) + "\" />\n");
continue;
}
// thow an exception no idea what this is
throw new IOException("Error while trying to read theme property: " + key);
}
bw.write(" </theme>\n");
continue;
case MAGIC_FONT:
File legacyFont = new File(resourcesDir, normalizeFileName(resourceNames[iter]));
DataOutputStream legacyFontOut = new DataOutputStream(new FileOutputStream(legacyFont));
saveFont(legacyFontOut, false, resourceNames[iter]);
legacyFontOut.close();
bw.write(" <legacyFont name=\"" + xResourceName + "\" />\n");
continue;
case MAGIC_DATA:
{
File dataFile = new File(resourcesDir, normalizeFileName(resourceNames[iter]));
DataOutputStream dataFileOut = new DataOutputStream(new FileOutputStream(dataFile));
InputStream i = getData(resourceNames[iter]);
ByteArrayOutputStream outArray = new ByteArrayOutputStream();
int val = i.read();
while (val != -1) {
outArray.write(val);
val = i.read();
}
byte[] data = outArray.toByteArray();
dataFileOut.write(data);
dataFileOut.close();
bw.write(" <data name=\"" + xResourceName + "\" />\n");
continue;
}
case MAGIC_UI:
{
File uiXML = new File(resourcesDir, resourceNames[iter] + ".ui");
UIBuilderOverride u = new UIBuilderOverride();
com.codename1.ui.Container cnt = u.createContainer(this, resourceNames[iter]);
FileOutputStream fos = new FileOutputStream(uiXML);
writeUIXml(cnt, fos);
fos.close();
File ui = new File(resourcesDir, resourceNames[iter]);
DataOutputStream uiOut = new DataOutputStream(new FileOutputStream(ui));
InputStream i = getUi(resourceNames[iter]);
ByteArrayOutputStream outArray = new ByteArrayOutputStream();
int val = i.read();
while (val != -1) {
outArray.write(val);
val = i.read();
}
byte[] data = outArray.toByteArray();
uiOut.write(data);
uiOut.close();
bw.write(" <ui name=\"" + xResourceName + "\" />\n");
continue;
}
case MAGIC_L10N:
// we are getting the theme which allows us to acces the l10n data
bw.write(" <l10n name=\"" + xResourceName + "\">\n");
Hashtable<String, Object> l10n = getTheme(resourceNames[iter]);
for (String locale : l10n.keySet()) {
bw.write(" <lang name=\"" + locale + "\">\n");
Hashtable<String, String> current = (Hashtable<String, String>) l10n.get(locale);
for (String key : current.keySet()) {
String val = current.get(key);
bw.write(" <entry key=\"" + xmlize(key) + "\" value=\"" + xmlize(val) + "\" />\n");
}
bw.write(" </lang>\n");
}
bw.write(" </l10n>\n");
continue;
default:
throw new IOException("Corrupt theme file unrecognized magic number: " + Integer.toHexString(magic & 0xff));
}
}
bw.write("</resource>\n");
bw.close();
} finally {
overrideFile = overrideFileBackup;
overrideResource = overrideResourceBackup;
}
}
use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.
the class EditableResources method setImage.
public void setImage(final String name, final com.codename1.ui.Image value) {
if (overrideResource != null) {
overrideResource.setImage(name, value);
return;
}
// we need to replace the image in all the themes...
final com.codename1.ui.Image oldValue = getImage(name);
byte type;
if (value instanceof Timeline) {
type = MAGIC_TIMELINE;
} else {
type = MAGIC_IMAGE;
}
final byte finalType = type;
pushUndoable(new UndoableEdit() {
@Override
protected String performAction() {
replaceThemeValue(oldValue, value);
setResource(name, finalType, value);
return name;
}
@Override
protected String performUndo() {
replaceThemeValue(value, oldValue);
setResource(name, finalType, oldValue);
return name;
}
});
}
Aggregations