use of com.codename1.rad.attributes.UIID 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.attributes.UIID in project CodenameOne by codenameone.
the class ResourceEditorApp method _main.
/**
* Main method launching the application.
*/
public static void _main(String[] args) throws Exception {
JavaSEPortWithSVGSupport.blockMonitors();
JavaSEPortWithSVGSupport.setDesignMode(true);
JavaSEPortWithSVGSupport.setShowEDTWarnings(false);
JavaSEPortWithSVGSupport.setShowEDTViolationStacks(false);
// creates a deadlock between FX, Swing and CN1. Horrible horrible deadlock...
JavaSEPortWithSVGSupport.blockNativeBrowser = true;
if (args.length > 0) {
if (args[0].equalsIgnoreCase("-buildVersion")) {
Properties p = new Properties();
try {
p.load(ResourceEditorApp.class.getResourceAsStream("/version.properties"));
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println(p.getProperty("build", "1"));
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("-style")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
final String uiid = args[2];
String themeName = args[3];
boolean isXMLEnabled = Preferences.userNodeForPackage(ResourceEditorView.class).getBoolean("XMLFileMode", true);
EditableResources.setXMLEnabled(isXMLEnabled);
EditableResources res = new EditableResources();
File resourceFile = new File(args[1]);
res.openFileWithXMLSupport(resourceFile);
Hashtable themeHash = res.getTheme(themeName);
final AddThemeEntry entry = new AddThemeEntry(false, res, null, new Hashtable(themeHash), "", themeName);
entry.setKeyValues(uiid, "");
entry.setPreferredSize(new Dimension(1000, 600));
JPanel wrapper = new JPanel(new BorderLayout());
wrapper.add(entry, BorderLayout.CENTER);
JPanel bottom = new JPanel();
ButtonGroup gr = new ButtonGroup();
JRadioButton unsel = new JRadioButton("Unselected", true);
gr.add(unsel);
unsel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
entry.setPrefix("");
entry.setKeyValues(uiid, "");
entry.revalidate();
}
});
bottom.add(unsel);
JRadioButton sel = new JRadioButton("Selected");
gr.add(sel);
sel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
entry.setPrefix("sel#");
entry.setKeyValues(uiid, "sel#");
entry.revalidate();
}
});
bottom.add(sel);
JRadioButton press = new JRadioButton("Pressed");
gr.add(press);
press.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
entry.setPrefix("press#");
entry.setKeyValues(uiid, "press#");
entry.revalidate();
}
});
bottom.add(press);
JRadioButton dis = new JRadioButton("Disabled");
gr.add(dis);
dis.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
entry.setPrefix("dis#");
entry.setKeyValues(uiid, "dis#");
entry.revalidate();
}
});
bottom.add(dis);
wrapper.add(bottom, BorderLayout.SOUTH);
if (ModifiableJOptionPane.showConfirmDialog(null, wrapper, "Edit") == JOptionPane.OK_OPTION) {
Hashtable tmp = new Hashtable(themeHash);
entry.updateThemeHashtable(tmp);
res.setTheme(themeName, tmp);
}
try (FileOutputStream fos = new FileOutputStream(resourceFile)) {
res.save(fos);
}
res.saveXML(resourceFile);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("-img")) {
String imageName;
String fileName;
if (args.length == 3) {
imageName = args[2];
fileName = args[2];
} else {
if (args.length == 4) {
imageName = args[3];
fileName = args[2];
} else {
System.out.println("The img command works as: -img path_to_resourceFile.res pathToImageFile [image name]");
System.exit(1);
return;
}
}
File resourceFile = new File(args[1]);
File imageFile = new File(fileName);
if (!imageFile.exists()) {
System.out.println("File not found: " + imageFile.getAbsolutePath());
System.exit(1);
return;
}
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
CSSImageImporter cssImporter = new CSSImageImporter(resourceFile, imageFile, 0);
if (cssImporter.checkIfCSSProject()) {
// CSS projects can't just import images into the res file. They need to
// be added to the CSS file, and then have the resource file regenerated.
cssImporter.doImportAndExit();
System.exit(0);
return;
}
com.codename1.ui.Image img = ImageRGBEditor.createImageStatic(imageFile);
boolean isXMLEnabled = Preferences.userNodeForPackage(ResourceEditorView.class).getBoolean("XMLFileMode", true);
EditableResources.setXMLEnabled(isXMLEnabled);
EditableResources res = new EditableResources();
res.openFileWithXMLSupport(resourceFile);
res.setImage(imageName, img);
try (FileOutputStream fos = new FileOutputStream(resourceFile)) {
res.save(fos);
}
res.saveXML(resourceFile);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("-mimg")) {
String fileName;
if (args.length == 4) {
fileName = args[3];
} else {
System.out.println("The mimg command works as: -img path_to_resourceFile.res dpi pathToImageFile");
System.out.println("dpi can be one of: high, veryhigh, hd, 560, 2hd, 4k");
System.exit(1);
return;
}
String dpi = args[2];
int dpiInt = -1;
int sourceDpi = 0;
switch(dpi.toLowerCase()) {
case "high":
dpiInt = 3;
sourceDpi = 240;
break;
case "veryhigh":
dpiInt = 4;
sourceDpi = 320;
break;
case "hd":
dpiInt = 5;
sourceDpi = 480;
break;
case "560":
dpiInt = 6;
sourceDpi = 480;
break;
case "2hd":
dpiInt = 7;
sourceDpi = 640;
break;
case "4k":
dpiInt = 8;
sourceDpi = 720;
break;
default:
System.out.println("dpi can be one of: high, veryhigh, hd, 560, 2hd, 4k");
System.exit(1);
return;
}
File imageFile = new File(fileName);
if (!imageFile.exists()) {
System.out.println("File not found: " + imageFile.getAbsolutePath());
System.exit(1);
return;
}
File resourceFile = new File(args[1]);
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
CSSImageImporter cssImporter = new CSSImageImporter(resourceFile, imageFile, sourceDpi);
if (cssImporter.checkIfCSSProject()) {
cssImporter.doImportAndExit();
System.exit(0);
return;
}
boolean isXMLEnabled = Preferences.userNodeForPackage(ResourceEditorView.class).getBoolean("XMLFileMode", true);
EditableResources.setXMLEnabled(isXMLEnabled);
EditableResources res = new EditableResources();
res.openFileWithXMLSupport(resourceFile);
AddAndScaleMultiImage.generateImpl(new File[] { imageFile }, res, dpiInt);
try (FileOutputStream fos = new FileOutputStream(resourceFile)) {
res.save(fos);
}
res.saveXML(resourceFile);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("gen")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
File output = new File(args[1]);
generateResourceFile(output, args[2], args[3]);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("mig")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
File projectDir = new File(args[1]);
EditableResources.setXMLEnabled(true);
EditableResources res = new EditableResources();
res.openFileWithXMLSupport(new File(args[2]));
migrateGuiBuilder(projectDir, res, args[3]);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("-regen")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
File output = new File(args[1]);
EditableResources.setXMLEnabled(true);
EditableResources res = new EditableResources();
res.openFileWithXMLSupport(output);
FileOutputStream fos = new FileOutputStream(output);
res.save(fos);
fos.close();
generate(res, output);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("-sync-xml")) {
try {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
File output = new File(args[1]);
EditableResources.setXMLEnabled(true);
EditableResources res = new EditableResources();
res.openFileWithXMLSupport(output);
FileOutputStream fos = new FileOutputStream(output);
res.save(fos);
fos.close();
} finally {
System.exit(0);
}
return;
}
if (args.length >= 2 && args[0].equalsIgnoreCase("-css")) {
List<String> cssArgs = new ArrayList<String>(Arrays.asList(args));
cssArgs.remove(0);
CN1CSSCLI.main(cssArgs.toArray(new String[cssArgs.size()]));
return;
}
}
JavaSEPortWithSVGSupport.setDefaultInitTarget(new JPanel());
Display.init(null);
launch(ResourceEditorApp.class, args);
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class RoundBorder method createTargetImage.
private Image createTargetImage(Component c, int w, int h, boolean fast) {
Image target = ImageFactory.createImage(c, w, h, 0);
int shapeX = 0;
int shapeY = 0;
int shapeW = w;
int shapeH = h;
Graphics tg = target.getGraphics();
tg.setAntiAliased(true);
int shadowSpreadL = shadowSpread;
if (shadowMM) {
shadowSpreadL = Display.getInstance().convertToPixels(shadowSpreadL);
}
if (shadowOpacity > 0) {
shapeW -= shadowSpreadL;
shapeW -= (shadowBlur / 2);
shapeH -= shadowSpreadL;
shapeH -= (shadowBlur / 2);
shapeX += Math.round((shadowSpreadL + (shadowBlur / 2)) * shadowX);
shapeY += Math.round((shadowSpreadL + (shadowBlur / 2)) * shadowY);
// draw a gradient of sort for the shadow
for (int iter = shadowSpreadL - 1; iter >= 0; iter--) {
tg.translate(iter, iter);
fillShape(tg, 0, shadowOpacity / shadowSpreadL, w - (iter * 2), h - (iter * 2), false);
tg.translate(-iter, -iter);
}
if (Display.getInstance().isGaussianBlurSupported() && !fast) {
Image blured = Display.getInstance().gaussianBlurImage(target, shadowBlur / 2);
target = ImageFactory.createImage(c, w, h, 0);
tg = target.getGraphics();
tg.drawImage(blured, 0, 0);
tg.setAntiAliased(true);
}
}
tg.translate(shapeX, shapeY);
if (uiid && tg.isShapeClipSupported()) {
c.getStyle().setBorder(Border.createEmpty());
GeneralPath gp = new GeneralPath();
if (rectangle) {
float sw = this.stroke != null ? this.stroke.getLineWidth() : 0;
gp.moveTo(shapeH / 2.0, sw);
if (onlyLeftRounded) {
gp.lineTo(shapeW, sw);
gp.lineTo(shapeW, shapeH - sw);
} else {
gp.lineTo(shapeW - (shapeH / 2.0), sw);
gp.arcTo(shapeW - (shapeH / 2.0), shapeH / 2.0, shapeW - (shapeH / 2.0), shapeH - sw, true);
}
if (onlyRightRounded) {
gp.lineTo(sw, shapeH - sw);
gp.lineTo(sw, sw);
} else {
gp.lineTo(shapeH / 2.0, shapeH - sw);
gp.arcTo(shapeH / 2.0, shapeH / 2.0, shapeH / 2.0, sw, true);
}
gp.closePath();
} else {
int size = shapeW;
int xPos = 0;
int yPos = 0;
if (shapeW != shapeH) {
if (shapeW > shapeH) {
size = shapeH;
xPos = (shapeW - shapeH) / 2;
} else {
size = shapeW;
yPos = (shapeH - shapeW) / 2;
}
}
gp.arc(xPos, yPos, size, size, 0, 2 * Math.PI);
}
tg.setClip(gp);
c.getStyle().getBgPainter().paint(tg, new Rectangle(0, 0, w, h));
c.getStyle().setBorder(this);
if (strokeOpacity > 0 && this.stroke != null) {
tg.setColor(strokeColor);
tg.setAlpha(strokeOpacity);
tg.setAntiAliased(true);
tg.drawShape(gp, stroke);
}
} else {
fillShape(tg, color, opacity, shapeW, shapeH, true);
}
return target;
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class UIManager method parseStyle.
/**
* Creates a style by providing style strings in a specific format. This method allows for the use of inline styles
* to override the styles in {@link com.codename1.ui.Component}
* @param theme Theme used to retrieve images referenced in the style strings.
* @param id The style ID (UIID) to use to cache the style inside the theme.
* @param prefix Prefix to use for styles. Corresponds to the {@literal prefix} argument in {@link #getComponentStyleImpl(java.lang.String, boolean, java.lang.String)
* @param baseStyle The style class from which this new style should derive.
* @param selected True if this is for a selected style.
* @param styleString Array of style strings to be parsed. The format is {@literal key1:value1; key2:value2; etc...}. While this looks similar to CSS, it is important to note that it is NOT
* CSS. The keys and values correspond to the properties of {@link com.codename1.ui.plaf.Style} and their associated values.
* @return A style object representing the styles that were provided in the styleString.
*
* <h3>Example Usage</h3>
*
* {@code
* Style s = parseStyle(theme, "Button[MyCustomButton]", "", "Button", false,
* "fgColor:ff0000; font:18mm; border: 1px solid ff0000; bgType:none; padding: 3mm; margin: 1mm");
*
* // Create a 9-piece image border on the fly:
* Style s = parseStyle(theme, "Button[MyCustomButton]", "", "Button", false,
* "border:splicedImage /notes.png 0.3 0.4 0.3 0.4");
* // This splices the image found at /notes.png into 9 pieces. Splice insets are specified by the 4 floating point values
* // at the end of the border directive: [top] [right] [bottom] [left].
* }
*/
Style parseStyle(Resources theme, String id, String prefix, String baseStyle, boolean selected, String... styleString) {
String cacheKey = selected ? id + ".sel" : id + "." + prefix;
String originalId = id;
if (id == null || id.length() == 0) {
// if no id return the default style
id = "";
} else {
id = id + ".";
}
if (Arrays.toString(styleString).equals(parseCache().get(cacheKey)) && ((selected && selectedStyles.containsKey(id)) || (!selected && this.styles.containsKey(id)))) {
return getComponentStyleImpl(originalId, selected, prefix);
}
parseCache().put(cacheKey, Arrays.toString(styleString));
Style base = baseStyle != null ? getComponentStyleImpl(baseStyle, selected, prefix) : null;
Map<String, String> styles = new HashMap<String, String>();
for (String str : styleString) {
StyleParser.parseString(styles, str);
}
StyleInfo styleInfo = new StyleInfo(styles);
if (prefix != null && prefix.length() > 0) {
id += prefix;
}
if (themeProps == null) {
resetThemeProps(null);
}
if (baseStyle != null) {
themeProps.put(id + "derive", baseStyle);
} else {
themeProps.remove(id + "derive");
}
String val = null;
Integer bgColor = styleInfo.getBgColor();
if (bgColor != null) {
themeProps.put(id + Style.BG_COLOR, Integer.toHexString(bgColor));
} else {
themeProps.remove(id + Style.BG_COLOR);
}
Integer fgColor = styleInfo.getFgColor();
if (fgColor != null) {
themeProps.put(id + Style.FG_COLOR, Integer.toHexString(fgColor));
} else {
themeProps.remove(id + Style.FG_COLOR);
}
BorderInfo border = styleInfo.getBorder();
if (border != null) {
themeProps.put(id + Style.BORDER, border.createBorder(theme));
} else {
themeProps.remove(id + Style.BORDER);
}
Integer bgType = styleInfo.getBgType();
if (bgType != null) {
themeProps.put(id + Style.BACKGROUND_TYPE, bgType.byteValue());
} else {
themeProps.remove(id + Style.BACKGROUND_TYPE);
}
ImageInfo bgImage = styleInfo.getBgImage();
if (bgImage != null) {
themeProps.put(id + Style.BG_IMAGE, bgImage.getImage(theme));
} else {
themeProps.remove(id + Style.BG_IMAGE);
}
MarginInfo margin = styleInfo.getMargin();
if (margin != null) {
float[] marginArr = margin.createMargin(base);
themeProps.put(id + Style.MARGIN, marginArr[Component.TOP] + "," + marginArr[Component.BOTTOM] + "," + marginArr[Component.LEFT] + "," + marginArr[Component.RIGHT]);
byte[] unitArr = margin.createMarginUnit(base);
themeProps.put(id + Style.MARGIN_UNIT, new byte[] { unitArr[Component.TOP], unitArr[Component.BOTTOM], unitArr[Component.LEFT], unitArr[Component.RIGHT] });
} else {
themeProps.remove(id + Style.MARGIN);
themeProps.remove(id + Style.MARGIN_UNIT);
}
PaddingInfo padding = styleInfo.getPadding();
if (padding != null) {
float[] paddingArr = padding.createPadding(base);
themeProps.put(id + Style.PADDING, paddingArr[Component.TOP] + "," + paddingArr[Component.BOTTOM] + "," + paddingArr[Component.LEFT] + "," + paddingArr[Component.RIGHT]);
byte[] unitArr = padding.createPaddingUnit(base);
themeProps.put(id + Style.PADDING_UNIT, new byte[] { unitArr[Component.TOP], unitArr[Component.BOTTOM], unitArr[Component.LEFT], unitArr[Component.RIGHT] });
} else {
themeProps.remove(id + Style.PADDING);
themeProps.remove(id + Style.PADDING_UNIT);
}
Integer transparency = styleInfo.getTransparency();
if (transparency != null) {
themeProps.put(id + Style.TRANSPARENCY, String.valueOf(transparency.intValue()));
} else {
themeProps.remove(id + Style.TRANSPARENCY);
}
Integer opacity = styleInfo.getOpacity();
if (opacity != null) {
themeProps.put(id + Style.OPACITY, String.valueOf(opacity.intValue()));
} else {
themeProps.remove(id + Style.OPACITY);
}
Integer alignment = styleInfo.getAlignment();
if (alignment != null) {
themeProps.put(id + Style.ALIGNMENT, alignment);
} else {
themeProps.remove(id + Style.ALIGNMENT);
}
Integer textDecoration = styleInfo.getTextDecoration();
if (textDecoration != null) {
themeProps.put(id + Style.TEXT_DECORATION, textDecoration);
} else {
themeProps.remove(id + Style.TEXT_DECORATION);
}
FontInfo font = styleInfo.getFont();
if (font != null) {
themeProps.put(id + Style.FONT, font.createFont(base));
} else {
themeProps.remove(id + Style.FONT);
}
if (selected)
selectedStyles.remove(id);
else
this.styles.remove(id);
return getComponentStyleImpl(originalId, selected, prefix);
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class Validator method addConstraint.
/**
* Places a constraint on the validator, returns this object so constraint
* additions can be chained. Shows validation errors messages even when the
* TextModeLayout is not {@code onTopMode} (it's possible to disable this
* functionality setting to false the theme constant
* {@code showValidationErrorsIfNotOnTopMode}: basically, the error
* message is shown for two second in place of the label on the left of the
* InputComponent (or on right of the InputComponent for RTL languages);
* this solution never breaks the layout, because the error message is
* trimmed to fit the available space. The error message UIID is
* "ErrorLabel" when it's not onTopMode.
*
* @param cmp the component to validate
* @param c the constraint or constraints
* @return this object so we can write code like v.addConstraint(cmp1,
* cons).addConstraint(cmp2, otherConstraint);
*/
public Validator addConstraint(Component cmp, Constraint... c) {
Constraint constraint = null;
if (c.length == 1) {
constraint = c[0];
constraintList.put(cmp, constraint);
} else if (c.length > 1) {
constraint = new GroupConstraint(c);
constraintList.put(cmp, constraint);
}
if (constraint == null) {
throw new IllegalArgumentException("addConstraint needs at least a Constraint, but the Constraint array in empty");
}
bindDataListener(cmp);
boolean isV = isValid();
for (Component btn : submitButtons) {
btn.setEnabled(isV);
}
// Show validation error on iPhone
if (UIManager.getInstance().isThemeConstant("showValidationErrorsIfNotOnTopMode", true) && cmp instanceof InputComponent) {
final InputComponent inputComponent = (InputComponent) cmp;
if (!inputComponent.isOnTopMode()) {
Label labelForComponent = null;
if (inputComponent instanceof TextComponent) {
labelForComponent = ((TextComponent) inputComponent).getField().getLabelForComponent();
} else if (inputComponent instanceof PickerComponent) {
labelForComponent = ((PickerComponent) inputComponent).getPicker().getLabelForComponent();
}
if (labelForComponent != null) {
final Label myLabel = labelForComponent;
final String originalText = myLabel.getText();
final String originalUIID = myLabel.getUIID();
final Constraint myConstraint = constraint;
final Runnable showError = new Runnable() {
@Override
public void run() {
boolean isValid = false;
if (inputComponent instanceof TextComponent) {
isValid = myConstraint.isValid(((TextComponent) inputComponent).getField().getText());
} else if (inputComponent instanceof PickerComponent) {
isValid = myConstraint.isValid(((PickerComponent) inputComponent).getPicker().getValue());
}
String errorMessage = trimLongString(UIManager.getInstance().localize(myConstraint.getDefaultFailMessage(), myConstraint.getDefaultFailMessage()), "ErrorLabel", myLabel.getWidth());
if (errorMessage != null && errorMessage.length() > 0 && !isValid) {
// show the error in place of the label for component
myLabel.setUIID("ErrorLabel");
myLabel.setText(errorMessage);
UITimer.timer(2000, false, Display.getInstance().getCurrent(), new Runnable() {
@Override
public void run() {
myLabel.setUIID(originalUIID);
myLabel.setText(originalText);
}
});
} else {
// show the label for component without the error
myLabel.setUIID(originalUIID);
myLabel.setText(originalText);
}
}
};
FocusListener myFocusListener = new FocusListener() {
@Override
public void focusLost(Component cmp) {
showError.run();
}
@Override
public void focusGained(Component cmp) {
// no code here
}
};
if (inputComponent instanceof TextComponent) {
((TextComponent) inputComponent).getField().addFocusListener(myFocusListener);
} else if (inputComponent instanceof PickerComponent) {
((PickerComponent) inputComponent).getPicker().addFocusListener(myFocusListener);
}
}
}
}
return this;
}
Aggregations