use of com.codename1.ui 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 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")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
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 imageFile = new File(fileName);
if (!imageFile.exists()) {
System.out.println("File not found: " + imageFile.getAbsolutePath());
System.exit(1);
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();
File resourceFile = new File(args[1]);
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")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
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;
switch(dpi.toLowerCase()) {
case "high":
dpiInt = 3;
break;
case "veryhigh":
dpiInt = 4;
break;
case "hd":
dpiInt = 5;
break;
case "560":
dpiInt = 6;
break;
case "2hd":
dpiInt = 7;
break;
case "4k":
dpiInt = 8;
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;
}
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);
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;
}
}
JavaSEPortWithSVGSupport.setDefaultInitTarget(new JPanel());
Display.init(null);
launch(ResourceEditorApp.class, args);
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class AddAndScaleMultiImage method generate.
public void generate(File[] files, EditableResources res) {
for (File f : files) {
try {
BufferedImage bi = ImageIO.read(f);
EditableResources.MultiImage newImage = new EditableResources.MultiImage();
int[] DPIS = new int[] { com.codename1.ui.Display.DENSITY_VERY_LOW, com.codename1.ui.Display.DENSITY_LOW, com.codename1.ui.Display.DENSITY_MEDIUM, com.codename1.ui.Display.DENSITY_HIGH, com.codename1.ui.Display.DENSITY_VERY_HIGH, com.codename1.ui.Display.DENSITY_HD, com.codename1.ui.Display.DENSITY_560, com.codename1.ui.Display.DENSITY_2HD, com.codename1.ui.Display.DENSITY_4K };
EncodedImage[] images = new EncodedImage[DPIS.length];
int imageCount = 0;
JSpinner[] ws = { veryLowWidth, lowWidth, mediumWidth, highWidth, veryHighWidth, hdWidth, hd560Width, hd2Width, hd4kWidth };
JSpinner[] hs = { veryLowHeight, lowHeight, mediumHeight, highHeight, veryHighHeight, hdHeight, hd560Height, hd2Height, hd4kHeight };
if (squareImages.isSelected()) {
hs = ws;
}
for (int iter = 0; iter < ws.length; iter++) {
images[iter] = createScale(bi, ws[iter], hs[iter]);
if (images[iter] != null) {
imageCount++;
}
}
if (imageCount > 0) {
int offset = 0;
EncodedImage[] result = new EncodedImage[imageCount];
int[] resultDPI = new int[imageCount];
for (int iter = 0; iter < images.length; iter++) {
if (images[iter] != null) {
result[offset] = images[iter];
resultDPI[offset] = DPIS[iter];
offset++;
}
}
newImage.setDpi(resultDPI);
newImage.setInternalImages(result);
String destName = f.getName();
int count = 1;
while (res.containsResource(destName)) {
destName = f.getName() + " " + count;
}
res.setMultiImage(destName, newImage);
}
} catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Error reading file: " + f, "IO Error", JOptionPane.ERROR_MESSAGE);
}
}
}
use of com.codename1.ui 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 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