use of com.codename1.rad.models.Property in project CodenameOne by codenameone.
the class SQLMap method selectImpl.
/**
* Fetches the components from the database matching the given cmp description, the fields that aren't
* null within the cmp will match the where clause
* @param where the where statement
* @param propertyClass the class of the property business object
* @param params the parameters to use in the where statement
* @param orderBy the column to order by, can be null to ignore order
* @param ascending true to indicate ascending order
* @param maxElements the maximum number of elements returned can be 0 or lower to ignore
* @param page the page within the query to match the max elements value
* @return the result of the query
*/
private java.util.List<PropertyBusinessObject> selectImpl(PropertyBusinessObject cmp, String where, Class propertyClass, Object[] params, Property orderBy, boolean ascending, int maxElements, int page) throws IOException, InstantiationException {
String tableName = getTableName(cmp);
StringBuilder createStatement = new StringBuilder("SELECT * FROM ");
createStatement.append(tableName);
if (where != null && where.length() > 0) {
if (!where.toUpperCase().startsWith(" WHERE ")) {
createStatement.append(" WHERE ");
}
createStatement.append(where);
}
if (orderBy != null) {
createStatement.append(" ORDER BY ");
createStatement.append(getColumnName(orderBy));
if (!ascending) {
createStatement.append(" DESC");
}
}
if (maxElements > 0) {
createStatement.append(" LIMIT ");
createStatement.append(maxElements);
if (page > 0) {
createStatement.append(" OFFSET ");
createStatement.append(page * maxElements);
}
}
Cursor c = null;
try {
ArrayList<PropertyBusinessObject> response = new ArrayList<PropertyBusinessObject>();
c = executeQuery(createStatement.toString(), params);
while (c.next()) {
PropertyBusinessObject pb = (PropertyBusinessObject) propertyClass.newInstance();
for (PropertyBase p : pb.getPropertyIndex()) {
Row currentRow = c.getRow();
SqlType t = getSqlType(p);
if (t == SqlType.SQL_EXCLUDE) {
continue;
}
Object value = t.getValue(currentRow, c.getColumnIndex(getColumnName(p)), p);
if (p instanceof Property) {
((Property) p).set(value);
}
}
response.add(pb);
}
c.close();
return response;
} catch (Throwable t) {
Log.e(t);
if (c != null) {
c.close();
}
if (t instanceof IOException) {
throw ((IOException) t);
} else {
throw new IOException(t.toString());
}
}
}
use of com.codename1.rad.models.Property in project CodenameOne by codenameone.
the class InstantUI method createEntryForProperty.
private void createEntryForProperty(PropertyBase b, Container cnt, ArrayList<UiBinding.Binding> allBindings, UiBinding uib) throws RuntimeException {
if (isExcludedProperty(b)) {
return;
}
Class cls = (Class) b.getClientProperty("cn1$cmpCls");
if (cls != null) {
try {
Component cmp = (Component) cls.newInstance();
cmp.setName(b.getName());
cnt.add(b.getLabel()).add(cmp);
allBindings.add(uib.bind(b, cmp));
} catch (Exception err) {
Log.e(err);
throw new RuntimeException("Custom property instant UI failed for " + b.getName() + " " + err);
}
return;
}
String[] multiLabels = (String[]) b.getClientProperty("cn1$multiChceLbl");
if (multiLabels != null) {
// multi choice component
final Object[] multiValues = (Object[]) b.getClientProperty("cn1$multiChceVal");
if (multiLabels.length < 5) {
// toggle buttons
ButtonGroup bg = new ButtonGroup();
RadioButton[] rbs = new RadioButton[multiLabels.length];
cnt.add(b.getLabel());
Container radioBox = new Container(new GridLayout(multiLabels.length));
for (int iter = 0; iter < multiLabels.length; iter++) {
rbs[iter] = RadioButton.createToggle(multiLabels[iter], bg);
radioBox.add(rbs[iter]);
}
cnt.add(radioBox);
allBindings.add(uib.bindGroup(b, multiValues, rbs));
} else {
Picker stringPicker = new Picker();
stringPicker.setStrings(multiLabels);
Map<Object, Object> m1 = new HashMap<Object, Object>();
Map<Object, Object> m2 = new HashMap<Object, Object>();
for (int iter = 0; iter < multiLabels.length; iter++) {
m1.put(multiLabels[iter], multiValues[iter]);
m2.put(multiValues[iter], multiLabels[iter]);
}
cnt.add(b.getLabel()).add(stringPicker);
allBindings.add(uib.bind(b, stringPicker, new UiBinding.PickerAdapter<Object>(new UiBinding.MappingConverter(m1), new UiBinding.MappingConverter(m2))));
}
return;
}
Class t = b.getGenericType();
if (t != null) {
if (t == Boolean.class) {
CheckBox cb = new CheckBox();
uib.bind(b, cb);
cnt.add(b.getLabel()).add(cb);
return;
}
if (t == Date.class) {
Picker dp = new Picker();
dp.setType(Display.PICKER_TYPE_DATE);
uib.bind(b, dp);
cnt.add(b.getLabel()).add(dp);
return;
}
}
TextField tf = new TextField();
tf.setConstraint(getTextFieldConstraint(b));
uib.bind(b, tf);
cnt.add(b.getLabel()).add(tf);
}
use of com.codename1.rad.models.Property in project CodenameOne by codenameone.
the class ThemeEditor method findFlushingPropertyContrust.
/**
* Returns a "contrasting" value for the property to flash, e.g. for a font,
* return a differnet font or for a color return a ligher/darker color...
*/
private Object findFlushingPropertyContrust() {
if (flashingProperty.indexOf("Color") > -1) {
// flash to white or black depending on whether the color is closer to white
int val = Integer.decode("0x" + originalFlashingPropertyValue);
if (val > 0xf0f0f0) {
return "000000";
} else {
return "ffffff";
}
}
if (flashingProperty.indexOf("derive") > -1) {
return "NoPropertyUIIDExists";
}
if (flashingProperty.indexOf("font") > -1) {
// if this is not a bold font then just return a system bold font
if ((((com.codename1.ui.Font) originalFlashingPropertyValue).getStyle() & com.codename1.ui.Font.STYLE_BOLD) != 0) {
return com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_LARGE);
}
return com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_BOLD, com.codename1.ui.Font.SIZE_LARGE);
}
if (flashingProperty.indexOf("bgImage") > -1) {
com.codename1.ui.Image i = (com.codename1.ui.Image) originalFlashingPropertyValue;
return i.modifyAlpha((byte) 128);
}
if (flashingProperty.indexOf("transparency") > -1) {
int v = Integer.parseInt((String) originalFlashingPropertyValue);
if (v < 128) {
return "255";
} else {
return "100";
}
}
/*
* if(flashingProperty.indexOf("scale") > -1) { return "false"; }
*/
if (flashingProperty.indexOf("padding") > -1 || flashingProperty.indexOf("margin") > -1) {
return "10,10,10,10";
}
if (flashingProperty.indexOf("border") > -1) {
if (originalFlashingPropertyValue != null) {
Border pressed = ((Border) originalFlashingPropertyValue).createPressedVersion();
if (pressed != null) {
return pressed;
}
}
return Border.createBevelRaised();
}
if (flashingProperty.indexOf("bgType") > -1) {
return originalFlashingPropertyValue;
}
if (flashingProperty.indexOf("bgGradient") > -1) {
Object[] gradient = new Object[4];
System.arraycopy(originalFlashingPropertyValue, 0, gradient, 0, 4);
gradient[0] = ((Object[]) originalFlashingPropertyValue)[1];
gradient[1] = ((Object[]) originalFlashingPropertyValue)[0];
return gradient;
}
if (flashingProperty.indexOf("align") > -1 || flashingProperty.indexOf("textDecoration") > -1) {
return originalFlashingPropertyValue;
}
throw new IllegalArgumentException("Unsupported property type: " + flashingProperty);
}
use of com.codename1.rad.models.Property in project CodenameOne by codenameone.
the class CSSTheme method updateResources.
public void updateResources() {
for (String id : elements.keySet()) {
if (!isModified(id)) {
continue;
}
String currToken = "";
try {
Element el = elements.get(id);
Map<String, LexicalUnit> unselectedStyles = el.getUnselected().getFlattenedStyle();
Map<String, LexicalUnit> selectedStyles = el.getSelected().getFlattenedStyle();
Map<String, LexicalUnit> pressedStyles = el.getPressed().getFlattenedStyle();
Map<String, LexicalUnit> disabledStyles = el.getDisabled().getFlattenedStyle();
Element selected = el.getSelected();
String selId = id + ".sel";
String unselId = id;
String pressedId = id + ".press";
String disabledId = id + ".dis";
currToken = "padding";
res.setThemeProperty(themeName, unselId + ".padding", el.getThemePadding(unselectedStyles));
currToken = "padUnit";
res.setThemeProperty(themeName, unselId + ".padUnit", el.getThemePaddingUnit(unselectedStyles));
currToken = "selected padding";
res.setThemeProperty(themeName, selId + "#padding", el.getThemePadding(selectedStyles));
currToken = "selected padUnit";
res.setThemeProperty(themeName, selId + "#padUnit", el.getThemePaddingUnit(selectedStyles));
currToken = "pressed padding";
res.setThemeProperty(themeName, pressedId + "#padding", el.getThemePadding(pressedStyles));
currToken = "pressed padUnit";
res.setThemeProperty(themeName, pressedId + "#padUnit", el.getThemePaddingUnit(pressedStyles));
currToken = "disabled padding";
res.setThemeProperty(themeName, disabledId + "#padding", el.getThemePadding(disabledStyles));
currToken = "disabled padUnit";
res.setThemeProperty(themeName, disabledId + "#padUnit", el.getThemePaddingUnit(disabledStyles));
currToken = "margin";
res.setThemeProperty(themeName, unselId + ".margin", el.getThemeMargin(unselectedStyles));
currToken = "marUnit";
res.setThemeProperty(themeName, unselId + ".marUnit", el.getThemeMarginUnit(unselectedStyles));
currToken = "selected margin";
res.setThemeProperty(themeName, selId + "#margin", el.getThemeMargin(selectedStyles));
currToken = "selected marUnit";
res.setThemeProperty(themeName, selId + "#marUnit", el.getThemeMarginUnit(selectedStyles));
currToken = "pressed margin";
res.setThemeProperty(themeName, pressedId + "#margin", el.getThemeMargin(pressedStyles));
currToken = "pressed marUnit";
res.setThemeProperty(themeName, pressedId + "#marUnit", el.getThemeMarginUnit(pressedStyles));
currToken = "disabled margin";
res.setThemeProperty(themeName, disabledId + "#margin", el.getThemeMargin(disabledStyles));
currToken = "disabled marUnit";
res.setThemeProperty(themeName, disabledId + "#marUnit", el.getThemeMarginUnit(disabledStyles));
currToken = "elevation";
if (unselectedStyles.containsKey("elevation")) {
res.setThemeProperty(themeName, unselId + ".elevation", el.getThemeElevation(unselectedStyles));
}
currToken = "selected elevation";
if (selectedStyles.containsKey("elevation")) {
res.setThemeProperty(themeName, selId + "#elevation", el.getThemeElevation(selectedStyles));
}
currToken = "pressed elevation";
if (pressedStyles.containsKey("elevation")) {
res.setThemeProperty(themeName, pressedId + "#elevation", el.getThemeElevation(pressedStyles));
}
currToken = "disabled elevation";
if (disabledStyles.containsKey("elevation")) {
res.setThemeProperty(themeName, disabledId + "#elevation", el.getThemeElevation(disabledStyles));
}
currToken = "iconGap";
float gap = el.getThemeIconGap(unselectedStyles);
if (gap < 0) {
res.setThemeProperty(themeName, unselId + ".iconGap", null);
currToken = "selected iconGap";
res.setThemeProperty(themeName, selId + "#iconGap", null);
currToken = "pressed iconGap";
res.setThemeProperty(themeName, pressedId + "#iconGap", null);
currToken = "disabled iconGap";
res.setThemeProperty(themeName, disabledId + "#iconGap", null);
currToken = "iconGapUnit";
res.setThemeProperty(themeName, unselId + ".iconGapUnit", null);
currToken = "selected iconGapUnit";
res.setThemeProperty(themeName, selId + "#iconGapUnit", null);
currToken = "pressed iconGapUnit";
res.setThemeProperty(themeName, pressedId + "#iconGapUnit", null);
currToken = "disabled iconGapUnit";
res.setThemeProperty(themeName, disabledId + "#iconGapUnit", null);
} else {
res.setThemeProperty(themeName, unselId + ".iconGap", gap);
currToken = "selected iconGap";
res.setThemeProperty(themeName, selId + "#iconGap", gap);
currToken = "pressed iconGap";
res.setThemeProperty(themeName, pressedId + "#iconGap", gap);
currToken = "disabled iconGap";
res.setThemeProperty(themeName, disabledId + "#iconGap", gap);
currToken = "iconGapUnit";
byte gapUnit = el.getThemeIconGapUnit(unselectedStyles);
res.setThemeProperty(themeName, unselId + ".iconGapUnit", gapUnit);
currToken = "selected iconGapUnit";
res.setThemeProperty(themeName, selId + "#iconGapUnit", gapUnit);
currToken = "pressed iconGapUnit";
res.setThemeProperty(themeName, pressedId + "#iconGapUnit", gapUnit);
currToken = "disabled iconGapUnit";
res.setThemeProperty(themeName, disabledId + "#iconGapUnit", gapUnit);
}
currToken = "surface";
if (unselectedStyles.containsKey("surface")) {
res.setThemeProperty(themeName, unselId + ".surface", el.getThemeSurface(unselectedStyles));
}
currToken = "selected surface";
if (selectedStyles.containsKey("surface")) {
res.setThemeProperty(themeName, selId + "#surface", el.getThemeSurface(selectedStyles));
}
currToken = "pressed surface";
if (pressedStyles.containsKey("surface")) {
res.setThemeProperty(themeName, pressedId + "#surface", el.getThemeSurface(pressedStyles));
}
currToken = "disabled surface";
if (disabledStyles.containsKey("surface")) {
res.setThemeProperty(themeName, disabledId + "#surface", el.getThemeSurface(disabledStyles));
}
currToken = "fgColor";
res.setThemeProperty(themeName, unselId + ".fgColor", el.getThemeFgColor(unselectedStyles));
currToken = "selected fgColor";
res.setThemeProperty(themeName, selId + "#fgColor", el.getThemeFgColor(selectedStyles));
currToken = "pressed fgColor";
res.setThemeProperty(themeName, pressedId + "#fgColor", el.getThemeFgColor(pressedStyles));
currToken = "disabled fgColor";
res.setThemeProperty(themeName, disabledId + "#fgColor", el.getThemeFgColor(disabledStyles));
currToken = "fgAlpha";
res.setThemeProperty(themeName, unselId + ".fgAlpha", el.getThemeFgAlpha(unselectedStyles));
currToken = "selected fgAlpha";
res.setThemeProperty(themeName, selId + "#fgAlpha", el.getThemeFgAlpha(selectedStyles));
currToken = "pressed fgAlpha";
res.setThemeProperty(themeName, pressedId + "#fgAlpha", el.getThemeFgAlpha(pressedStyles));
currToken = "disabled fgAlpha";
res.setThemeProperty(themeName, disabledId + "#fgAlpha", el.getThemeFgAlpha(disabledStyles));
currToken = "bgColor";
res.setThemeProperty(themeName, unselId + ".bgColor", el.getThemeBgColor(unselectedStyles));
currToken = "selected bgColor";
res.setThemeProperty(themeName, selId + "#bgColor", el.getThemeBgColor(selectedStyles));
currToken = "pressed bgColor";
res.setThemeProperty(themeName, pressedId + "#bgColor", el.getThemeBgColor(pressedStyles));
currToken = "disabled bgColor";
res.setThemeProperty(themeName, disabledId + "#bgColor", el.getThemeBgColor(disabledStyles));
currToken = "transparency";
res.setThemeProperty(themeName, unselId + ".transparency", el.getThemeTransparency(unselectedStyles));
currToken = "selected transparency";
res.setThemeProperty(themeName, selId + "#transparency", el.getThemeTransparency(selectedStyles));
currToken = "pressed transparency";
res.setThemeProperty(themeName, pressedId + "#transparency", el.getThemeTransparency(pressedStyles));
currToken = "disabled transparency";
res.setThemeProperty(themeName, disabledId + "#transparency", el.getThemeTransparency(disabledStyles));
currToken = "align";
res.setThemeProperty(themeName, unselId + ".align", el.getThemeAlignment(unselectedStyles));
currToken = "selected align";
res.setThemeProperty(themeName, selId + "#align", el.getThemeAlignment(selectedStyles));
currToken = "pressed align";
res.setThemeProperty(themeName, pressedId + "#align", el.getThemeAlignment(pressedStyles));
currToken = "disabled align";
res.setThemeProperty(themeName, disabledId + "#align", el.getThemeAlignment(disabledStyles));
currToken = "font";
res.setThemeProperty(themeName, unselId + ".font", el.getThemeFont(unselectedStyles));
currToken = "selected font";
res.setThemeProperty(themeName, selId + "#font", el.getThemeFont(selectedStyles));
currToken = "pressed font";
res.setThemeProperty(themeName, pressedId + "#font", el.getThemeFont(pressedStyles));
currToken = "disabled font";
res.setThemeProperty(themeName, disabledId + "#font", el.getThemeFont(disabledStyles));
currToken = "textDecoration";
res.setThemeProperty(themeName, unselId + ".textDecoration", el.getThemeTextDecoration(unselectedStyles));
currToken = "selected textDecoration";
res.setThemeProperty(themeName, selId + "#textDecoration", el.getThemeTextDecoration(selectedStyles));
currToken = "pressed textDecoration";
res.setThemeProperty(themeName, pressedId + "#textDecoration", el.getThemeTextDecoration(pressedStyles));
currToken = "disabled textDecoration";
res.setThemeProperty(themeName, disabledId + "#textDecoration", el.getThemeTextDecoration(disabledStyles));
currToken = "bgGradient";
res.setThemeProperty(themeName, unselId + ".bgGradient", el.getThemeBgGradient(unselectedStyles));
currToken = "selected bgGradient";
res.setThemeProperty(themeName, selId + "#bgGradient", el.getThemeBgGradient(selectedStyles));
currToken = "pressed bgGradient";
res.setThemeProperty(themeName, pressedId + "#bgGradient", el.getThemeBgGradient(pressedStyles));
currToken = "disabled bgGradient";
res.setThemeProperty(themeName, disabledId + "#bgGradient", el.getThemeBgGradient(disabledStyles));
currToken = "bgType";
res.setThemeProperty(themeName, unselId + ".bgType", el.getThemeBgType(unselectedStyles));
currToken = "selected bgType";
res.setThemeProperty(themeName, selId + "#bgType", el.getThemeBgType(selectedStyles));
currToken = "pressed bgType";
res.setThemeProperty(themeName, pressedId + "#bgType", el.getThemeBgType(pressedStyles));
currToken = "disabled bgType";
res.setThemeProperty(themeName, disabledId + "#bgType", el.getThemeBgType(disabledStyles));
currToken = "derive";
res.setThemeProperty(themeName, unselId + ".derive", el.getThemeDerive(unselectedStyles, ""));
currToken = "selected derive";
res.setThemeProperty(themeName, selId + "#derive", el.getThemeDerive(selectedStyles, ".sel"));
currToken = "pressed derive";
res.setThemeProperty(themeName, pressedId + "#derive", el.getThemeDerive(pressedStyles, ".press"));
currToken = "disabled derive";
res.setThemeProperty(themeName, disabledId + "#derive", el.getThemeDerive(disabledStyles, ".dis"));
currToken = "opacity";
res.setThemeProperty(themeName, unselId + ".opacity", el.getThemeOpacity(unselectedStyles));
currToken = "selected opacity";
res.setThemeProperty(themeName, selId + "#opacity", el.getThemeOpacity(selectedStyles));
currToken = "pressed opacity";
res.setThemeProperty(themeName, pressedId + "#opacity", el.getThemeOpacity(pressedStyles));
currToken = "disabled opacity";
res.setThemeProperty(themeName, disabledId + "#opacity", el.getThemeOpacity(disabledStyles));
currToken = "bgImage";
if (el.hasBackgroundImage(unselectedStyles) && !el.requiresBackgroundImageGeneration(unselectedStyles) && !el.requiresImageBorder(unselectedStyles)) {
Image[] imageId = getBackgroundImages(unselectedStyles);
if (imageId != null && imageId.length > 0) {
res.setThemeProperty(themeName, unselId + ".bgImage", imageId[0]);
}
}
currToken = "selected bgImage";
if (el.hasBackgroundImage(selectedStyles) && !el.requiresBackgroundImageGeneration(selectedStyles) && !el.requiresImageBorder(selectedStyles)) {
Image[] imageId = getBackgroundImages(selectedStyles);
if (imageId != null && imageId.length > 0) {
res.setThemeProperty(themeName, selId + "#bgImage", imageId[0]);
}
}
currToken = "pressed bgImage";
if (el.hasBackgroundImage(pressedStyles) && !el.requiresBackgroundImageGeneration(pressedStyles) && !el.requiresImageBorder(pressedStyles)) {
Image[] imageId = getBackgroundImages(pressedStyles);
if (imageId != null && imageId.length > 0) {
res.setThemeProperty(themeName, pressedId + "#bgImage", imageId[0]);
}
}
currToken = "disabled bgImage";
if (el.hasBackgroundImage(disabledStyles) && !el.requiresBackgroundImageGeneration(disabledStyles) && !el.requiresImageBorder(disabledStyles)) {
Image[] imageId = getBackgroundImages(disabledStyles);
if (imageId != null && imageId.length > 0) {
res.setThemeProperty(themeName, disabledId + "#bgImage", imageId[0]);
}
}
currToken = "border";
if (!el.requiresImageBorder(unselectedStyles) && !el.requiresBackgroundImageGeneration(unselectedStyles)) {
res.setThemeProperty(themeName, unselId + ".border", el.getThemeBorder(unselectedStyles));
}
currToken = "selected border";
if (!el.requiresImageBorder(selectedStyles) && !el.requiresBackgroundImageGeneration(selectedStyles)) {
res.setThemeProperty(themeName, selId + "#border", el.getThemeBorder(selectedStyles));
}
currToken = "pressed border";
if (!el.requiresImageBorder(pressedStyles) && !el.requiresBackgroundImageGeneration(pressedStyles)) {
res.setThemeProperty(themeName, pressedId + "#border", el.getThemeBorder(pressedStyles));
}
currToken = "disabled border";
if (!el.requiresImageBorder(disabledStyles) && !el.requiresBackgroundImageGeneration(disabledStyles)) {
res.setThemeProperty(themeName, disabledId + "#border", el.getThemeBorder(disabledStyles));
}
} catch (RuntimeException t) {
System.err.println("An error occurred while updating resources for UIID " + id + ". Processing property " + currToken);
throw t;
}
}
for (String constantKey : constants.keySet()) {
try {
LexicalUnit lu = constants.get(constantKey);
if (lu.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE || lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
if (constantKey.endsWith("Image")) {
// We have an image
Image im = res.getImage(lu.getStringValue());
if (im == null) {
im = getResourceImage(lu.getStringValue());
}
if (im == null) {
System.err.println("Error processing file " + this.baseURL);
throw new RuntimeException("Failed to set constant value " + constantKey + " to value " + lu.getStringValue() + " because no such image was found in the resource file");
}
res.setThemeProperty(themeName, "@" + constantKey, im);
} else {
res.setThemeProperty(themeName, "@" + constantKey, lu.getStringValue());
}
} else if (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
res.setThemeProperty(themeName, "@" + constantKey, String.valueOf(((ScaledUnit) lu).getIntegerValue()));
}
} catch (RuntimeException t) {
System.err.println("\nAn error occurred processing constant key " + constantKey);
throw t;
}
}
imagesMetadata.store(res);
Map<String, Object> theme = res.getTheme(themeName);
HashSet<String> keys = new HashSet<String>();
keys.addAll(theme.keySet());
Set<String> deletedIds = getDeletedElements();
for (String key : keys) {
if (key.startsWith("Default.")) {
res.setThemeProperty(themeName, key.substring(key.indexOf(".") + 1), theme.get(key));
} else {
for (String delId : deletedIds) {
if (key.startsWith(delId + ".") || key.startsWith(delId + "#")) {
res.setThemeProperty(themeName, key, null);
}
}
}
}
// Get rid of unused images now
deleteUnusedImages();
}
use of com.codename1.rad.models.Property in project CodenameOne by codenameone.
the class EditableResources method saveTheme.
private void saveTheme(DataOutputStream output, Hashtable theme, boolean newVersion) throws IOException {
theme.remove("name");
output.writeShort(theme.size());
ArrayList<String> setOfKeys = new ArrayList<String>(theme.keySet());
Collections.sort(setOfKeys);
for (Object currentKey : setOfKeys) {
String key = (String) currentKey;
output.writeUTF(key);
if (key.startsWith("@")) {
if (key.endsWith("Image")) {
output.writeUTF(findId(theme.get(key), true));
} else {
output.writeUTF((String) theme.get(key));
}
continue;
}
// if this is a simple numeric value
if (key.endsWith("Color")) {
output.writeInt(Integer.decode("0x" + theme.get(key)));
continue;
}
if (key.endsWith("align") || key.endsWith("textDecoration")) {
output.writeShort(((Number) theme.get(key)).shortValue());
continue;
}
// if this is a short numeric value
if (key.endsWith("transparency")) {
output.writeByte(Integer.parseInt((String) theme.get(key)));
continue;
}
if (key.endsWith("opacity")) {
output.writeInt(Integer.parseInt((String) theme.get(key)));
continue;
}
if (key.endsWith(Style.ICON_GAP)) {
output.writeFloat(((Number) theme.get(key)).floatValue());
continue;
}
if (key.endsWith(Style.ICON_GAP_UNIT)) {
output.writeByte(((Number) theme.get(key)).byteValue());
continue;
}
// if this is a padding or margin then we will have the 4 values as bytes
if (key.endsWith("padding") || key.endsWith("margin")) {
String[] arr = ((String) theme.get(key)).split(",");
output.writeFloat(Float.parseFloat(arr[0]));
output.writeFloat(Float.parseFloat(arr[1]));
output.writeFloat(Float.parseFloat(arr[2]));
output.writeFloat(Float.parseFloat(arr[3]));
continue;
}
// padding and or margin type
if (key.endsWith("Unit")) {
for (byte b : (byte[]) theme.get(key)) {
output.writeByte(b);
}
continue;
}
if (key.endsWith("border")) {
Border border = (Border) theme.get(key);
writeBorder(output, border, newVersion);
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;
output.writeBoolean(newFont);
if (newFont) {
String fontId = findId(f);
output.writeUTF(fontId);
} else {
output.writeByte(f.getFace());
output.writeByte(f.getStyle());
output.writeByte(f.getSize());
if (f instanceof EditorTTFFont && (((EditorTTFFont) f).getFontFile() != null || ((EditorTTFFont) f).getNativeFontName() != null)) {
output.writeBoolean(true);
EditorTTFFont ed = (EditorTTFFont) f;
if (ed.getNativeFontName() != null) {
output.writeUTF(ed.getNativeFontName());
output.writeUTF(ed.getNativeFontName());
} else {
output.writeUTF(ed.getFontFile().getName());
output.writeUTF(((java.awt.Font) ed.getNativeFont()).getPSName());
}
output.writeInt(ed.getSizeSetting());
output.writeFloat(ed.getActualSize());
} else {
output.writeBoolean(false);
}
}
continue;
}
// if this is a background image
if (key.endsWith("bgImage")) {
String imageId = findId(theme.get(key), true);
if (imageId == null) {
imageId = "";
}
output.writeUTF(imageId);
continue;
}
if (key.endsWith("scaledImage")) {
output.writeBoolean(theme.get(key).equals("true"));
continue;
}
if (key.endsWith("derive")) {
output.writeUTF((String) theme.get(key));
continue;
}
// if this is a background gradient
if (key.endsWith("bgGradient")) {
Object[] gradient = (Object[]) theme.get(key);
output.writeInt(((Integer) gradient[0]).intValue());
output.writeInt(((Integer) gradient[1]).intValue());
output.writeFloat(((Float) gradient[2]).floatValue());
output.writeFloat(((Float) gradient[3]).floatValue());
output.writeFloat(((Float) gradient[4]).floatValue());
continue;
}
if (key.endsWith(Style.BACKGROUND_TYPE) || key.endsWith(Style.BACKGROUND_ALIGNMENT)) {
output.writeByte(((Number) theme.get(key)).intValue());
continue;
}
if (key.endsWith(Style.ELEVATION)) {
output.writeInt(((Number) theme.get(key)).intValue());
continue;
}
if (key.endsWith(Style.FG_ALPHA)) {
output.writeInt(((Number) theme.get(key)).intValue());
continue;
}
if (key.endsWith(Style.SURFACE)) {
output.writeBoolean((Boolean) theme.get(key));
continue;
}
// thow an exception no idea what this is
throw new IOException("Error while trying to read theme property: " + key);
}
}
Aggregations