use of com.codename1.ui.EditorTTFFont 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.EditorTTFFont in project CodenameOne by codenameone.
the class EditableResources method refreshThemeMultiImages.
public void refreshThemeMultiImages() {
EditableResources ed = (EditableResources) JavaSEPortWithSVGSupport.getNativeTheme();
if (ed != null && ed != this) {
ed.refreshThemeMultiImages();
}
for (String themeName : getThemeResourceNames()) {
Hashtable theme = getTheme(themeName);
for (Object key : theme.keySet()) {
Object currentValue = theme.get(key);
if (currentValue instanceof EditorTTFFont) {
((EditorTTFFont) currentValue).refresh();
}
if (currentValue instanceof com.codename1.ui.Image) {
String id = findId(currentValue);
if (isMultiImage(id)) {
theme.put(key, ((MultiImage) getResourceObject(id)).getBest());
}
}
if (currentValue instanceof com.codename1.ui.plaf.Border) {
com.codename1.ui.Image[] images = Accessor.getImages((com.codename1.ui.plaf.Border) currentValue);
if (images != null) {
for (int iter = 0; iter < images.length; iter++) {
com.codename1.ui.Image img = images[iter];
if (img != null) {
String id = findId(img);
if (id == null) {
JOptionPane.showMessageDialog(java.awt.Frame.getFrames()[0], "Missing image from border: " + key, "Error", JOptionPane.ERROR_MESSAGE);
continue;
}
if (isMultiImage(id)) {
images[iter] = ((MultiImage) getResourceObject(id)).getBest();
}
}
}
}
}
}
}
com.codename1.ui.Form f = Display.getInstance().getCurrent();
if (f != null) {
f.revalidate();
}
}
use of com.codename1.ui.EditorTTFFont in project CodenameOne by codenameone.
the class ResourceEditorApp method generateResourceFile.
private static void generateResourceFile(File f, String themeName, String ui) throws Exception {
System.out.println("Generating resource file " + f + " theme " + themeName + " template " + ui);
EditableResources res = new EditableResources();
// "native", "leather", "tzone", "tipster", "blank"
String template = "Native_Theme";
if (themeName.equalsIgnoreCase("leather")) {
template = "Leather";
}
if (themeName.equalsIgnoreCase("chrome")) {
template = "Chrome";
}
if (themeName.equalsIgnoreCase("tzone")) {
template = "tzone_theme";
}
if (themeName.equalsIgnoreCase("tipster")) {
template = "tipster_theme";
}
if (themeName.equalsIgnoreCase("socialboo")) {
template = "socialboo";
}
if (themeName.equalsIgnoreCase("mapper")) {
template = "mapper";
}
if (themeName.equalsIgnoreCase("flatblue")) {
template = "FlatBlueTheme";
}
if (themeName.equalsIgnoreCase("flatred")) {
template = "FlatRedTheme";
}
if (themeName.equalsIgnoreCase("flatorange")) {
template = "FlatOrangeTheme";
}
if (themeName.equalsIgnoreCase("business")) {
template = "BusinessTheme";
}
res.setTheme("Theme", importRes(res, template));
if ("HiWorld".equalsIgnoreCase(ui)) {
importRes(res, "HiWorldTemplate");
generate(res, f);
} else {
if ("Tabs".equalsIgnoreCase(ui)) {
importRes(res, "Tabs");
generate(res, f);
} else {
if ("List".equalsIgnoreCase(ui)) {
importRes(res, "ListOfItems");
generate(res, f);
} else {
if ("NewHi".equalsIgnoreCase(ui)) {
importImage("android-icon.png", res);
importImage("apple-icon.png", res);
importImage("windows-icon.png", res);
importImage("duke-no-logos.png", res);
Map m = res.getTheme("Theme");
m.put("GetStarted.fgColor", "ffffff");
m.put("GetStarted.sel#fgColor", "ffffff");
m.put("GetStarted.press#fgColor", "ffffff");
m.put("GetStarted.bgColor", "339900");
m.put("GetStarted.sel#bgColor", "339900");
m.put("GetStarted.press#bgColor", "339900");
m.put("GetStarted.transparency", "255");
m.put("GetStarted.sel#transparency", "255");
m.put("GetStarted.press#transparency", "255");
Integer centerAlign = new Integer(4);
m.put("GetStarted.align", centerAlign);
m.put("GetStarted.sel#align", centerAlign);
m.put("GetStarted.press#align", centerAlign);
m.put("GetStarted.padding", "1,1,1,1");
m.put("GetStarted.padUnit", new byte[] { Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS });
m.put("GetStarted.sel#padding", "1,1,1,1");
m.put("GetStarted.sel#padUnit", new byte[] { Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS });
m.put("GetStarted.press#padding", "1,1,1,1");
m.put("GetStarted.press#padUnit", new byte[] { Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS });
m.put("GetStarted.font", new EditorTTFFont("native:MainLight", 3, 2.5f, Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM)));
}
}
}
}
FileOutputStream os = new FileOutputStream(f);
res.save(os);
os.close();
}
use of com.codename1.ui.EditorTTFFont in project CodenameOne by codenameone.
the class AddThemeEntry method updateThemeHashtable.
/**
* Updates the theme hash with the values from this editor
*/
public void updateThemeHashtable(Hashtable themeRes) {
if (disableRefresh) {
return;
}
String uiid = prefix;
String item = (String) componentName.getSelectedItem();
if (item != null && item.length() > 0) {
uiid = item + "." + prefix;
}
removeKeys(themeRes, uiid);
if (!defineAttribute.isSelected()) {
String val = (String) baseStyle.getSelectedItem();
if (val != null && val.length() > 0) {
switch(baseStyleType.getSelectedIndex()) {
case 0:
themeRes.put(uiid + "derive", val);
break;
case 1:
themeRes.put(uiid + "derive", val + ".sel");
break;
case 2:
themeRes.put(uiid + "derive", val + ".press");
break;
case 3:
themeRes.put(uiid + "derive", val + ".dis");
break;
}
}
}
if (!deriveAlignment.isSelected()) {
switch(alignmentCombo.getSelectedIndex()) {
case 0:
themeRes.put(uiid + "align", new Integer(com.codename1.ui.Component.LEFT));
break;
case 1:
themeRes.put(uiid + "align", new Integer(com.codename1.ui.Component.RIGHT));
break;
default:
themeRes.put(uiid + "align", new Integer(com.codename1.ui.Component.CENTER));
break;
}
}
if (!deriveBackground.isSelected()) {
int index = backgroundType.getSelectedIndex();
themeRes.put(uiid + "bgType", new Byte(BACKGROUND_VALUES[index]));
if (backgroundType.getSelectedIndex() >= BACKGROUND_VALUES_GRADIENT_ARRAY_OFFSET) {
// this is a gradient related type
themeRes.put(uiid + "bgGradient", new Object[] { Integer.valueOf(gradientStartColor.getText(), 16), Integer.valueOf(gradientEndColor.getText(), 16), new Float(((Number) gradientX.getValue()).floatValue()), new Float(((Number) gradientY.getValue()).floatValue()), new Float(((Number) gradientSize.getValue()).floatValue()) });
} else {
// this is an image related type
if (imagesCombo.getSelectedItem() != null && imagesCombo.getSelectedItem().toString().length() > 0) {
themeRes.put(uiid + "bgImage", resources.getImage((String) imagesCombo.getSelectedItem()));
} else {
brokenImage = true;
themeRes.put(uiid + "bgImage", com.codename1.ui.Image.createImage(5, 5));
}
}
}
if (!deriveBackgroundColor.isSelected()) {
themeRes.put(uiid + "bgColor", colorValueBG.getText());
}
if (!deriveBorder.isSelected()) {
if (currentBorder == null) {
themeRes.remove(uiid + "border");
} else {
themeRes.put(uiid + "border", currentBorder);
}
}
if (!deriveFont.isSelected()) {
Object v;
if (bitmapFont.isSelected()) {
String val = (String) bitmapFontValue.getSelectedItem();
if (val != null) {
v = resources.getFont(val);
} else {
v = Font.getDefaultFont();
}
} else {
if (trueTypeFont.getSelectedIndex() > 0) {
Font sys = Font.createSystemFont(FONT_FACE_VALUES[fontFace.getSelectedIndex()], FONT_STYLE_VALUES[fontStyle.getSelectedIndex()], FONT_SIZE_VALUES[fontSize.getSelectedIndex()]);
String selectedItem = (String) trueTypeFont.getSelectedItem();
if (selectedItem.startsWith("native:")) {
v = new EditorTTFFont(selectedItem, trueTypeFontSizeOption.getSelectedIndex(), ((Number) trueTypeFontSizeValue.getValue()).floatValue(), sys);
} else {
v = new EditorTTFFont(new File(ResourceEditorView.getLoadedFile().getParentFile(), selectedItem), trueTypeFontSizeOption.getSelectedIndex(), ((Number) trueTypeFontSizeValue.getValue()).floatValue(), sys);
}
} else {
v = Font.createSystemFont(FONT_FACE_VALUES[fontFace.getSelectedIndex()], FONT_STYLE_VALUES[fontStyle.getSelectedIndex()], FONT_SIZE_VALUES[fontSize.getSelectedIndex()]);
}
}
themeRes.put(uiid + "font", v);
}
if (!deriveForegroundColor.isSelected()) {
themeRes.put(uiid + "fgColor", colorValueFG.getText());
}
if (!deriveMargin.isSelected()) {
themeRes.put(uiid + "margin", marginTop.getValue() + "," + marginBottom.getValue() + "," + marginLeft.getValue() + "," + marginRight.getValue());
byte[] padUnit = new byte[4];
padUnit[com.codename1.ui.Component.BOTTOM] = (byte) marginBottomUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.TOP] = (byte) marginTopUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.LEFT] = (byte) marginLeftUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.RIGHT] = (byte) marginRightUnit.getSelectedIndex();
updateThemeRes(padUnit, themeRes, uiid + "marUnit");
}
if (!derivePadding.isSelected()) {
themeRes.put(uiid + "padding", paddingTop.getValue() + "," + paddingBottom.getValue() + "," + paddingLeft.getValue() + "," + paddingRight.getValue());
byte[] padUnit = new byte[4];
padUnit[com.codename1.ui.Component.BOTTOM] = (byte) paddingBottomUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.TOP] = (byte) paddingTopUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.LEFT] = (byte) paddingLeftUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.RIGHT] = (byte) paddingRightUnit.getSelectedIndex();
updateThemeRes(padUnit, themeRes, uiid + "padUnit");
}
if (!deriveTextDecoration.isSelected()) {
Object v;
switch(textDecorationCombo.getSelectedIndex()) {
case 1:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_UNDERLINE);
break;
case 2:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_STRIKETHRU);
break;
case 3:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_3D);
break;
case 4:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_3D_LOWERED);
break;
case 5:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_3D_SHADOW_NORTH);
break;
default:
v = new Integer(0);
break;
}
themeRes.put(uiid + "textDecoration", v);
}
if (!deriveTransparency.isSelected()) {
themeRes.put(uiid + "transparency", "" + transparencyValue.getValue());
}
}
use of com.codename1.ui.EditorTTFFont in project CodenameOne by codenameone.
the class AddThemeEntry method setKeyValue.
private void setKeyValue(String key, Object value) {
int pos = key.indexOf(".");
String attr;
if (pos > -1) {
componentName.setSelectedItem(key.substring(0, pos));
attr = key.substring(pos + 1, key.length());
} else {
componentName.setSelectedIndex(0);
attr = key;
}
pos = attr.indexOf('#');
if (pos > -1) {
attr = attr.substring(pos + 1);
}
if (attr.indexOf("fgColor") > -1) {
deriveForegroundColor.setSelected(false);
highlightTab(1);
changeColorButtonFG.setEnabled(true);
colorValueFG.setEnabled(true);
if (value instanceof String) {
colorValueFG.setText((String) value);
} else {
colorValueFG.setText(Integer.toHexString(((Number) value).intValue()));
}
return;
}
if (attr.indexOf("bgColor") > -1) {
deriveBackgroundColor.setSelected(false);
highlightTab(1);
changeColorButtonBG.setEnabled(true);
colorValueBG.setEnabled(true);
if (value instanceof String) {
colorValueBG.setText((String) value);
} else {
colorValueBG.setText(Integer.toHexString(((Number) value).intValue()));
}
return;
}
if (attr.indexOf("derive") > -1) {
highlightTab(6);
baseStyle.setEnabled(true);
baseStyleType.setEnabled(true);
defineAttribute.setSelected(false);
String baseItemValue = (String) value;
int keyPos = baseItemValue.indexOf('.');
if (keyPos < 0) {
baseStyle.setSelectedItem(baseItemValue);
} else {
String b = baseItemValue.substring(0, keyPos);
String k = baseItemValue.substring(keyPos + 1);
baseStyle.setSelectedItem(b);
if (k.equals("sel")) {
baseStyleType.setSelectedIndex(1);
return;
}
if (k.equals("press")) {
baseStyleType.setSelectedIndex(2);
return;
}
if (k.equals("dis")) {
baseStyleType.setSelectedIndex(3);
return;
}
}
return;
}
if (attr.indexOf("align") > -1) {
highlightTab(2);
deriveAlignment.setSelected(false);
alignmentCombo.setEnabled(true);
switch(((Number) value).intValue()) {
case com.codename1.ui.Component.LEFT:
alignmentCombo.setSelectedIndex(0);
break;
case com.codename1.ui.Component.RIGHT:
alignmentCombo.setSelectedIndex(1);
break;
case com.codename1.ui.Component.CENTER:
alignmentCombo.setSelectedIndex(2);
break;
}
return;
}
if (attr.indexOf("textDecoration") > -1) {
highlightTab(7);
deriveTextDecoration.setSelected(false);
textDecorationCombo.setEnabled(true);
switch(((Number) value).intValue()) {
case com.codename1.ui.plaf.Style.TEXT_DECORATION_UNDERLINE:
textDecorationCombo.setSelectedIndex(1);
break;
case com.codename1.ui.plaf.Style.TEXT_DECORATION_STRIKETHRU:
textDecorationCombo.setSelectedIndex(2);
break;
case com.codename1.ui.plaf.Style.TEXT_DECORATION_3D:
textDecorationCombo.setSelectedIndex(3);
break;
case com.codename1.ui.plaf.Style.TEXT_DECORATION_3D_LOWERED:
textDecorationCombo.setSelectedIndex(4);
break;
default:
textDecorationCombo.setSelectedIndex(0);
break;
}
return;
}
if (attr.indexOf("border") > -1) {
highlightTab(5);
customizeBorder.setEnabled(true);
deriveBorder.setSelected(false);
borderLabel.setText(Accessor.toString((Border) value));
((CodenameOneComponentWrapper) borderLabel).getCodenameOneComponent().getStyle().setBorder((Border) value);
borderLabel.repaint();
if (value != null && value instanceof Border) {
currentBorder = (Border) value;
} else {
currentBorder = Border.getDefaultBorder();
}
return;
}
if (attr.indexOf("font") > -1) {
highlightTab(7);
Font font = (Font) value;
deriveFont.setSelected(false);
systemFont.setEnabled(true);
bitmapFont.setEnabled(true);
if (resources.getFontResourceNames() != null) {
for (String fontName : resources.getFontResourceNames()) {
if (font == resources.getFont(fontName)) {
// this is a bitmap font
bitmapFont.setSelected(true);
bitmapFontValue.setEnabled(true);
addNewBitmapFont.setEnabled(true);
bitmapFontValue.setSelectedItem(fontName);
return;
}
}
}
// this is a system font
systemFont.setSelected(true);
fontFace.setEnabled(true);
fontSize.setEnabled(true);
fontStyle.setEnabled(true);
trueTypeFont.setEnabled(trueTypeFont.getModel().getSize() > 0);
trueTypeFontSizeOption.setEnabled(trueTypeFont.getModel().getSize() > 0);
trueTypeFontSizeValue.setEnabled(trueTypeFont.getModel().getSize() > 0);
fontFace.setSelectedIndex(getSystemFontOffset(font.getFace(), FONT_FACE_VALUES));
fontSize.setSelectedIndex(getSystemFontOffset(font.getSize(), FONT_SIZE_VALUES));
fontStyle.setSelectedIndex(getSystemFontOffset(font.getStyle(), FONT_STYLE_VALUES));
if (font instanceof EditorTTFFont) {
EditorTTFFont ed = (EditorTTFFont) font;
if (ed.getFontFile() != null) {
trueTypeFont.setSelectedItem(ed.getFontFile().getName());
trueTypeFontSizeOption.setSelectedIndex(ed.getSizeSetting());
trueTypeFontSizeValue.setValue(new Double(ed.getActualSize()));
} else {
if (ed.getNativeFontName() != null) {
trueTypeFont.setSelectedItem(ed.getNativeFontName());
trueTypeFontSizeOption.setSelectedIndex(ed.getSizeSetting());
trueTypeFontSizeValue.setValue(new Double(ed.getActualSize()));
}
}
}
return;
}
if (attr.indexOf("bgImage") > -1) {
highlightTab(0);
updateBackgroundAttribute();
for (int iter = 0; iter < imagesCombo.getModel().getSize(); iter++) {
String name = (String) imagesCombo.getModel().getElementAt(iter);
if (value == resources.getImage(name)) {
imagesCombo.setSelectedItem(name);
return;
}
}
return;
}
if (attr.indexOf("transparency") > -1) {
highlightTab(1);
deriveTransparency.setSelected(false);
transparencyValue.setEnabled(true);
transparencyValue.setValue(Integer.valueOf((String) value));
return;
}
if (attr.indexOf("padding") > -1) {
highlightTab(3);
derivePadding.setSelected(false);
paddingBottom.setEnabled(true);
paddingTop.setEnabled(true);
paddingLeft.setEnabled(true);
paddingRight.setEnabled(true);
paddingBottomUnit.setEnabled(true);
paddingTopUnit.setEnabled(true);
paddingLeftUnit.setEnabled(true);
paddingRightUnit.setEnabled(true);
StringTokenizer tokenizer = new StringTokenizer((String) value, ", ");
paddingTop.setValue(Float.parseFloat(tokenizer.nextToken()));
paddingBottom.setValue(Float.parseFloat(tokenizer.nextToken()));
paddingLeft.setValue(Float.parseFloat(tokenizer.nextToken()));
paddingRight.setValue(Float.parseFloat(tokenizer.nextToken()));
return;
}
if (attr.indexOf("padUnit") > -1) {
byte[] padUnit = (byte[]) value;
paddingBottomUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.BOTTOM]);
paddingTopUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.TOP]);
paddingLeftUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.LEFT]);
paddingRightUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.RIGHT]);
return;
}
if (attr.indexOf("margin") > -1) {
highlightTab(4);
deriveMargin.setSelected(false);
marginBottom.setEnabled(true);
marginTop.setEnabled(true);
marginLeft.setEnabled(true);
marginRight.setEnabled(true);
marginBottomUnit.setEnabled(true);
marginTopUnit.setEnabled(true);
marginLeftUnit.setEnabled(true);
marginRightUnit.setEnabled(true);
StringTokenizer tokenizer = new StringTokenizer((String) value, ", ");
marginTop.setValue(Float.parseFloat(tokenizer.nextToken()));
marginBottom.setValue(Float.parseFloat(tokenizer.nextToken()));
marginLeft.setValue(Float.parseFloat(tokenizer.nextToken()));
marginRight.setValue(Float.parseFloat(tokenizer.nextToken()));
return;
}
if (attr.indexOf("marUnit") > -1) {
byte[] padUnit = (byte[]) value;
marginBottomUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.BOTTOM]);
marginTopUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.TOP]);
marginLeftUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.LEFT]);
marginRightUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.RIGHT]);
return;
}
if (attr.indexOf("bgType") > -1) {
highlightTab(0);
updateBackgroundAttribute();
byte bgType = ((Byte) value).byteValue();
for (int iter = 0; iter < BACKGROUND_VALUES.length; iter++) {
if (bgType == BACKGROUND_VALUES[iter]) {
backgroundType.setSelectedIndex(iter);
break;
}
}
return;
}
if (attr.indexOf("bgGradient") > -1) {
highlightTab(0);
updateBackgroundAttribute();
Object[] gradient = (Object[]) value;
gradientStartColor.setText(Integer.toHexString(((Number) gradient[0]).intValue()));
gradientEndColor.setText(Integer.toHexString(((Number) gradient[1]).intValue()));
if (gradient.length > 2) {
gradientX.setValue(new Double(((Number) gradient[2]).doubleValue()));
gradientY.setValue(new Double(((Number) gradient[3]).doubleValue()));
if (gradient.length > 4) {
gradientSize.setValue(new Double(((Number) gradient[4]).doubleValue()));
}
}
return;
}
}
Aggregations