use of com.codename1.rad.models.Property.Name 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);
}
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class EditableResources method writeTimeline.
private void writeTimeline(DataOutputStream output, Timeline t) throws IOException {
output.writeInt(t.getDuration());
output.writeInt(t.getSize().getWidth());
output.writeInt(t.getSize().getHeight());
AnimationObject[] animations = new AnimationObject[t.getAnimationCount()];
output.writeShort(animations.length);
for (int iter = 0; iter < animations.length; iter++) {
animations[iter] = t.getAnimation(iter);
String name = AnimationAccessor.getImageName(animations[iter]);
if (name == null) {
name = findId(AnimationAccessor.getImage(animations[iter]));
}
output.writeUTF(name);
int startTime = animations[iter].getStartTime();
int animDuration = animations[iter].getEndTime() - startTime;
output.writeInt(startTime);
output.writeInt(animDuration);
Motion motionX = AnimationAccessor.getMotionX(animations[iter]);
Motion motionY = AnimationAccessor.getMotionY(animations[iter]);
output.writeInt(motionX.getSourceValue());
output.writeInt(motionY.getSourceValue());
int frameDelay = AnimationAccessor.getFrameDelay(animations[iter]);
output.writeInt(frameDelay);
if (frameDelay > -1) {
output.writeInt(AnimationAccessor.getFrameWidth(animations[iter]));
output.writeInt(AnimationAccessor.getFrameHeight(animations[iter]));
}
if (motionX.getSourceValue() != motionX.getDestinationValue()) {
output.writeBoolean(true);
output.writeInt(AnimationAccessor.getMotionType(motionX));
output.writeInt(motionX.getDestinationValue());
} else {
output.writeBoolean(false);
}
if (motionY.getSourceValue() != motionY.getDestinationValue()) {
output.writeBoolean(true);
output.writeInt(AnimationAccessor.getMotionType(motionY));
output.writeInt(motionY.getDestinationValue());
} else {
output.writeBoolean(false);
}
writeMotion(AnimationAccessor.getWidth(animations[iter]), output);
writeMotion(AnimationAccessor.getHeight(animations[iter]), output);
writeMotion(AnimationAccessor.getOpacity(animations[iter]), output);
writeMotion(AnimationAccessor.getOrientation(animations[iter]), output);
}
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class EditableResources method openFileWithXMLSupport.
public void openFileWithXMLSupport(File f) throws IOException {
if (xmlEnabled && f.getParentFile().getName().equals("src")) {
File res = new File(f.getParentFile().getParentFile(), "res");
if (res.exists()) {
File xml = new File(res, f.getName().substring(0, f.getName().length() - 3) + "xml");
if (xml.exists()) {
loadingMode = true;
com.codename1.ui.Font.clearBitmapCache();
clear();
try {
File resDir = new File(res, f.getName().substring(0, f.getName().length() - 4));
// open the XML file...
JAXBContext ctx = JAXBContext.newInstance(ResourceFileXML.class);
ResourceFileXML xmlData = (ResourceFileXML) ctx.createUnmarshaller().unmarshal(xml);
boolean normalize = xmlData.getMajorVersion() > 1 || xmlData.getMinorVersion() > 5;
majorVersion = (short) xmlData.getMajorVersion();
minorVersion = (short) xmlData.getMinorVersion();
xmlUI = xmlData.isUseXmlUI();
if (xmlData.getData() != null) {
for (Data d : xmlData.getData()) {
setResource(d.getName(), MAGIC_DATA, readFile(resDir, d.getName(), normalize));
}
}
if (xmlData.getLegacyFont() != null) {
for (LegacyFont d : xmlData.getLegacyFont()) {
String name = d.getName();
if (normalize) {
name = normalizeFileName(name);
}
DataInputStream fi = new DataInputStream(new FileInputStream(new File(resDir, name)));
setResource(d.getName(), MAGIC_FONT, loadFont(fi, d.getName(), false));
fi.close();
}
}
if (xmlData.getImage() != null) {
for (com.codename1.ui.util.xml.Image d : xmlData.getImage()) {
if (d.getType() == null) {
// standara JPG or PNG
String name = d.getName();
if (normalize) {
name = normalizeFileName(name);
}
FileInputStream fi = new FileInputStream(new File(resDir, name));
EncodedImage e = EncodedImage.create(fi);
fi.close();
setResource(d.getName(), MAGIC_IMAGE, e);
continue;
}
if ("svg".equals(d.getType())) {
setResource(d.getName(), MAGIC_IMAGE, Image.createSVG(d.getType(), false, readFile(resDir, d.getName(), normalize)));
continue;
}
if ("timeline".equals(d.getType())) {
String name = d.getName();
if (normalize) {
name = normalizeFileName(name);
}
DataInputStream fi = new DataInputStream(new FileInputStream(new File(resDir, name)));
setResource(d.getName(), MAGIC_IMAGE, readTimeline(fi));
fi.close();
continue;
}
if ("multi".equals(d.getType())) {
String name = d.getName();
if (normalize) {
name = normalizeFileName(name);
}
File multiImageDir = new File(resDir, name);
File hd4k = new File(multiImageDir, "4k.png");
File hd2 = new File(multiImageDir, "2hd.png");
File hd560 = new File(multiImageDir, "560.png");
File hd = new File(multiImageDir, "hd.png");
File veryhigh = new File(multiImageDir, "veryhigh.png");
File high = new File(multiImageDir, "high.png");
File medium = new File(multiImageDir, "medium.png");
File low = new File(multiImageDir, "low.png");
File veryLow = new File(multiImageDir, "verylow.png");
Map<Integer, EncodedImage> images = new HashMap<Integer, EncodedImage>();
if (hd4k.exists()) {
images.put(new Integer(Display.DENSITY_4K), EncodedImage.create(readFileNoNormal(hd4k)));
}
if (hd2.exists()) {
images.put(new Integer(Display.DENSITY_2HD), EncodedImage.create(readFileNoNormal(hd2)));
}
if (hd560.exists()) {
images.put(new Integer(Display.DENSITY_560), EncodedImage.create(readFileNoNormal(hd560)));
}
if (hd.exists()) {
images.put(new Integer(Display.DENSITY_HD), EncodedImage.create(readFileNoNormal(hd)));
}
if (veryhigh.exists()) {
images.put(new Integer(Display.DENSITY_VERY_HIGH), EncodedImage.create(readFileNoNormal(veryhigh)));
}
if (high.exists()) {
images.put(new Integer(Display.DENSITY_HIGH), EncodedImage.create(readFileNoNormal(high)));
}
if (medium.exists()) {
images.put(new Integer(Display.DENSITY_MEDIUM), EncodedImage.create(readFileNoNormal(medium)));
}
if (low.exists()) {
images.put(new Integer(Display.DENSITY_LOW), EncodedImage.create(readFileNoNormal(low)));
}
if (veryLow.exists()) {
images.put(new Integer(Display.DENSITY_VERY_LOW), EncodedImage.create(readFileNoNormal(veryLow)));
}
int[] dpis = new int[images.size()];
EncodedImage[] imageArray = new EncodedImage[images.size()];
int count = 0;
for (Map.Entry<Integer, EncodedImage> m : images.entrySet()) {
dpis[count] = m.getKey().intValue();
imageArray[count] = m.getValue();
count++;
}
MultiImage result = new MultiImage();
result.setDpi(dpis);
result.setInternalImages(imageArray);
setResource(d.getName(), MAGIC_IMAGE, result);
continue;
}
}
}
if (xmlData.getL10n() != null) {
for (L10n d : xmlData.getL10n()) {
Hashtable<String, Hashtable<String, String>> l10n = new Hashtable<String, Hashtable<String, String>>();
for (Lang l : d.getLang()) {
Hashtable<String, String> language = new Hashtable<String, String>();
if (l != null && l.getEntry() != null) {
for (Entry e : l.getEntry()) {
language.put(e.getKey(), e.getValue());
}
}
l10n.put(l.getName(), language);
}
setResource(d.getName(), MAGIC_L10N, l10n);
}
}
if (xmlData.getTheme() != null) {
for (Theme d : xmlData.getTheme()) {
Hashtable<String, Object> theme = new Hashtable<String, Object>();
theme.put("uninitialized", Boolean.TRUE);
if (d.getVal() != null) {
for (Val v : d.getVal()) {
String key = v.getKey();
if (key.endsWith("align") || key.endsWith("textDecoration") || key.endsWith(Style.ELEVATION)) {
theme.put(key, Integer.valueOf(v.getValue()));
continue;
}
if (key.endsWith(Style.BACKGROUND_TYPE) || key.endsWith(Style.BACKGROUND_ALIGNMENT) || key.endsWith(Style.ICON_GAP_UNIT)) {
theme.put(key, Byte.valueOf(v.getValue()));
continue;
}
if (key.endsWith(Style.SURFACE)) {
theme.put(key, Boolean.valueOf(v.getValue()));
continue;
}
if (key.endsWith(Style.ICON_GAP)) {
theme.put(key, Float.valueOf(v.getValue()));
continue;
}
// padding and or margin type
if (key.endsWith("Unit")) {
String[] s = v.getValue().split(",");
theme.put(key, new byte[] { Byte.parseByte(s[0]), Byte.parseByte(s[1]), Byte.parseByte(s[2]), Byte.parseByte(s[3]) });
continue;
}
theme.put(key, v.getValue());
}
}
if (d.getBorder() != null) {
for (com.codename1.ui.util.xml.Border b : d.getBorder()) {
if ("empty".equals(b.getType())) {
theme.put(b.getKey(), Border.createEmpty());
continue;
}
if ("round".equals(b.getType())) {
RoundBorder rb = RoundBorder.create();
rb = rb.opacity(b.getOpacity());
rb = rb.color(b.getRoundBorderColor());
rb = rb.rectangle(b.isRectangle());
rb = rb.shadowBlur(b.getShadowBlur());
rb = rb.shadowOpacity(b.getShadowOpacity());
rb = rb.shadowSpread((int) b.getShadowSpread(), b.isShadowMM());
rb = rb.shadowX(b.getShadowX());
rb = rb.shadowY(b.getShadowY());
rb = rb.stroke(b.getStrokeThickness(), b.isStrokeMM());
rb = rb.strokeColor(b.getStrokeColor());
rb = rb.strokeOpacity(b.getStrokeOpacity());
theme.put(b.getKey(), rb);
continue;
}
if ("css".equals(b.getType())) {
CSSBorder cb = new CSSBorder(this, b.getCSS());
theme.put(b.getKey(), cb);
continue;
}
if ("roundRect".equals(b.getType())) {
RoundRectBorder rb = RoundRectBorder.create();
rb = rb.shadowBlur(b.getShadowBlur());
rb = rb.shadowOpacity(b.getShadowOpacity());
rb = rb.shadowSpread(b.getShadowSpread());
rb = rb.shadowX(b.getShadowX());
rb = rb.shadowY(b.getShadowY());
rb = rb.stroke(b.getStrokeThickness(), b.isStrokeMM());
rb = rb.strokeColor(b.getStrokeColor());
rb = rb.strokeOpacity(b.getStrokeOpacity());
rb = rb.bezierCorners(b.isBezierCorners());
if (b.isTopOnlyMode()) {
rb.topOnlyMode(true);
} else if (b.isBottomOnlyMode()) {
rb.bottomOnlyMode(true);
}
rb = rb.cornerRadius(b.getCornerRadius());
theme.put(b.getKey(), rb);
continue;
}
if ("line".equals(b.getType())) {
if (b.getColor() == null) {
if (b.isMillimeters()) {
theme.put(b.getKey(), Border.createLineBorder(b.getThickness().floatValue()));
} else {
theme.put(b.getKey(), Border.createLineBorder(b.getThickness().intValue()));
}
} else {
if (b.isMillimeters()) {
theme.put(b.getKey(), Border.createLineBorder(b.getThickness().floatValue(), b.getColor().intValue()));
} else {
theme.put(b.getKey(), Border.createLineBorder(b.getThickness().intValue(), b.getColor().intValue()));
}
}
continue;
}
if ("underline".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createUndelineBorder(b.getThickness().intValue()));
} else {
theme.put(b.getKey(), Border.createUnderlineBorder(b.getThickness().intValue(), b.getColor().intValue()));
}
continue;
}
if ("rounded".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createRoundBorder(b.getArcW().intValue(), b.getArcH().intValue()));
} else {
theme.put(b.getKey(), Border.createRoundBorder(b.getArcW().intValue(), b.getArcH().intValue(), b.getColor().intValue()));
}
continue;
}
if ("etchedRaised".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createEtchedRaised());
} else {
theme.put(b.getKey(), Border.createEtchedRaised(b.getColor().intValue(), b.getColorB().intValue()));
}
continue;
}
if ("etchedLowered".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createEtchedLowered());
} else {
theme.put(b.getKey(), Border.createEtchedLowered(b.getColor().intValue(), b.getColorB().intValue()));
}
continue;
}
if ("bevelLowered".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createBevelLowered());
} else {
theme.put(b.getKey(), Border.createBevelLowered(b.getColor().intValue(), b.getColorB().intValue(), b.getColorC().intValue(), b.getColorD().intValue()));
}
continue;
}
if ("bevelRaised".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createBevelRaised());
} else {
theme.put(b.getKey(), Border.createBevelRaised(b.getColor().intValue(), b.getColorB().intValue(), b.getColorC().intValue(), b.getColorD().intValue()));
}
continue;
}
if ("image".equals(b.getType())) {
int imageCount = 2;
if (b.getI9() != null) {
imageCount = 9;
} else {
if (b.getI8() != null) {
imageCount = 8;
} else {
if (b.getI3() != null) {
imageCount = 3;
}
}
}
String[] borderInstance;
switch(imageCount) {
case 2:
borderInstance = new String[] { b.getI1(), b.getI2() };
break;
case 3:
borderInstance = new String[] { b.getI1(), b.getI2(), b.getI3() };
break;
case 8:
borderInstance = new String[] { b.getI1(), b.getI2(), b.getI3(), b.getI4(), b.getI5(), b.getI6(), b.getI7(), b.getI8() };
break;
default:
borderInstance = new String[] { b.getI1(), b.getI2(), b.getI3(), b.getI4(), b.getI5(), b.getI6(), b.getI7(), b.getI8(), b.getI9() };
break;
}
theme.put(b.getKey(), borderInstance);
continue;
}
if ("imageH".equals(b.getType())) {
theme.put(b.getKey(), new String[] { "h", b.getI1(), b.getI2(), b.getI3() });
continue;
}
if ("imageV".equals(b.getType())) {
theme.put(b.getKey(), new String[] { "v", b.getI1(), b.getI2(), b.getI3() });
continue;
}
}
}
if (d.getFont() != null) {
for (com.codename1.ui.util.xml.Font b : d.getFont()) {
if ("ttf".equals(b.getType())) {
com.codename1.ui.Font system = com.codename1.ui.Font.createSystemFont(b.getFace().intValue(), b.getStyle().intValue(), b.getSize().intValue());
EditorTTFFont t;
if (b.getName().startsWith("native:")) {
t = new EditorTTFFont(b.getName(), b.getSizeSettings().intValue(), b.getActualSize().floatValue(), system);
} else {
t = new EditorTTFFont(new File(f.getParentFile(), b.getName()), b.getSizeSettings().intValue(), b.getActualSize().floatValue(), system);
}
theme.put(b.getKey(), t);
continue;
}
if ("system".equals(b.getType())) {
com.codename1.ui.Font system = com.codename1.ui.Font.createSystemFont(b.getFace().intValue(), b.getStyle().intValue(), b.getSize().intValue());
theme.put(b.getKey(), system);
continue;
}
// bitmap fonts aren't supported right now
}
}
if (d.getGradient() != null) {
for (com.codename1.ui.util.xml.Gradient b : d.getGradient()) {
theme.put(b.getKey(), new Object[] { b.getColor1(), b.getColor2(), b.getPosX(), b.getPosY(), b.getRadius() });
}
}
setResource(d.getName(), MAGIC_THEME, theme);
}
}
// we load the UI last since it might depend on images or other elements in the future
if (xmlData.getUi() != null) {
if (xmlData.isUseXmlUI()) {
ArrayList<ComponentEntry> guiElements = new ArrayList<ComponentEntry>();
// place renderers first
final ArrayList<String> renderers = new ArrayList<String>();
for (Ui d : xmlData.getUi()) {
JAXBContext componentContext = JAXBContext.newInstance(ComponentEntry.class);
File uiFile = new File(resDir, normalizeFileName(d.getName()) + ".ui");
ComponentEntry uiXMLData = (ComponentEntry) componentContext.createUnmarshaller().unmarshal(uiFile);
guiElements.add(uiXMLData);
uiXMLData.findRendererers(renderers);
}
Collections.sort(guiElements, new Comparator<ComponentEntry>() {
private final ArrayList<String> entries1 = new ArrayList<String>();
private final ArrayList<String> entries2 = new ArrayList<String>();
@Override
public int compare(ComponentEntry o1, ComponentEntry o2) {
if (renderers.contains(o1.getName())) {
return -1;
}
if (renderers.contains(o2.getName())) {
return 1;
}
entries1.clear();
entries2.clear();
o1.findEmbeddedDependencies(entries1);
o2.findEmbeddedDependencies(entries2);
if (entries1.size() == 0) {
if (entries2.size() == 0) {
return 0;
}
return -1;
} else {
if (entries2.size() == 0) {
return 1;
}
}
for (String e : entries1) {
if (e.equals(o2.getName())) {
return 1;
}
}
for (String e : entries2) {
if (e.equals(o1.getName())) {
return -1;
}
}
return 0;
}
});
for (ComponentEntry uiXMLData : guiElements) {
UIBuilderOverride uib = new UIBuilderOverride();
com.codename1.ui.Container cnt = uib.createInstance(uiXMLData, this);
// encountered an error loading the component fallback to loading with the binary types
if (cnt == null) {
for (Ui ui : xmlData.getUi()) {
setResource(uiXMLData.getName(), MAGIC_UI, readFile(resDir, ui.getName(), normalize));
}
break;
} else {
byte[] data = UserInterfaceEditor.persistContainer(cnt, this);
setResource(uiXMLData.getName(), MAGIC_UI, data);
}
}
} else {
for (Ui d : xmlData.getUi()) {
setResource(d.getName(), MAGIC_UI, readFile(resDir, d.getName(), normalize));
}
}
}
loadingMode = false;
modified = false;
updateModified();
// can occure when a resource file is opened via the constructor
if (undoQueue != null) {
undoQueue.clear();
redoQueue.clear();
}
return;
} catch (JAXBException err) {
err.printStackTrace();
}
}
}
}
openFile(new FileInputStream(f));
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class ResourceEditorView method addNewFontWizard.
/**
* Invoked by the "..." button in the add theme entry dialog, allows us to add
* a font on the fly while working on a theme
*/
public void addNewFontWizard() {
AddResourceDialog addResource = new AddResourceDialog(loadedResources, AddResourceDialog.FONT);
if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainPanel, addResource, "Add Font", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) {
if (addResource.checkName(loadedResources)) {
JOptionPane.showMessageDialog(mainPanel, "A resource with that name already exists", "Add Font", JOptionPane.ERROR_MESSAGE);
addNewFontWizard();
return;
}
// show the image editing dialog...
FontEditor font = new FontEditor(loadedResources, new EditorFont(com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_MEDIUM), null, "Arial-plain-12", true, RenderingHints.VALUE_TEXT_ANTIALIAS_ON, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,;:!/\\*()[]{}|#$%^&<>?'\"+- "), addResource.getResourceName());
font.setFactoryCreation(true);
if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainPanel, font, "Add Font", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) {
loadedResources.setFont(addResource.getResourceName(), font.createFont());
}
}
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class GenerateAppProjectMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
Properties props;
try {
props = generateAppProjectProperties();
} catch (Exception ex) {
throw new MojoExecutionException("Failed to load " + generateAppProjectConfigFile(), ex);
}
String templateType = props.getProperty("template.type");
if (templateType == null) {
// templateType == null is a proxy to test whether this is just a request to migrate
// an existing ANT project. If it is, then we will want to retain the main name and
// package name of the original project.
// We set the system properties here so that the call to generateProject() after this
// will use the correct coordinates.
Properties sourceAntProjectCn1Properties = loadSourceProjectProperties();
if (sourceAntProjectCn1Properties.getProperty("codename1.mainName") != null) {
System.setProperty("mainName", sourceAntProjectCn1Properties.getProperty("codename1.mainName"));
}
if (sourceAntProjectCn1Properties.getProperty("codename1.packageName") != null) {
System.setProperty("packageName", sourceAntProjectCn1Properties.getProperty("codename1.packageName"));
}
}
generateProject();
if (templateType != null) {
// This is a project template
// Make a copy of it so that we can turn it into a concrete proejct
File dest = new File(targetProjectDir(), path("target", "codenameone", "tmpProject"));
dest.getParentFile().mkdirs();
FileUtils.copyDirectory(sourceProject, dest);
File origSource = sourceProject;
sourceProject = dest;
Properties renderProperties = new Properties();
renderProperties.put("packageName", packageName());
renderProperties.put("mainName", mainName());
renderProperties.putAll(System.getProperties());
ProjectTemplate tpl = new ProjectTemplate(sourceProject, renderProperties);
if (props.getProperty("template.mainName") != null && props.getProperty("template.packageName") != null) {
tpl.convertToTemplate(props.getProperty("template.packageName"), props.getProperty("template.mainName"));
}
tpl.processFiles();
// The project should now be a concrete project
//
}
if (templateType == null || "ant".equalsIgnoreCase(templateType)) {
// The source project was an ANT project
copyPropertiesFiles();
copyIcon();
copySourceFiles();
copyTestSourceFiles();
copyAndroidFiles();
copyIosFiles();
copyJavascriptFiles();
copyWinFiles();
copyJavaseFiles();
copyCSSFiles();
copyCn1libs();
injectDependencies();
} else if ("maven".equalsIgnoreCase(templateType)) {
// The source project was a Maven project
{
File src = new File(sourceProject, path("common", "src"));
File destSrc = new File(targetProjectDir(), path("common", "src"));
if (src.exists()) {
FileUtils.deleteDirectory(destSrc);
FileUtils.copyDirectory(src, destSrc);
}
}
File cn1Settings = new File(sourceProject, path("common", "codenameone_settings.properties"));
File destCn1Settings = new File(targetProjectDir(), path("common", "codenameone_settings.properties"));
if (cn1Settings.exists()) {
FileUtils.copyFile(cn1Settings, destCn1Settings);
}
for (File child : new File(sourceProject, "common").listFiles()) {
if (child.getName().endsWith(".png")) {
FileUtils.copyFile(child, new File(targetProjectDir(), path("common", child.getName())));
}
}
injectDependencies();
}
} catch (IOException ex) {
throw new MojoExecutionException("Failed to copy files", ex);
}
}
Aggregations