use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class AddResourceDialog method addResource.
public String addResource(EditableResources res, ResourceEditorView view) {
// "Image", "Animation", "Font", "Theme", "Data", "Localization (L10N)"
String newName = name.getText();
for (String r : res.getResourceNames()) {
if (r.equalsIgnoreCase(newName)) {
JOptionPane.showMessageDialog(this, "A resource called: " + newName + " already exists\nYou must delete the resource first.", "Add Resource", JOptionPane.ERROR_MESSAGE);
return null;
}
}
switch(type.getSelectedIndex()) {
case // image
IMAGE:
ImageRGBEditor imageEditor = new ImageRGBEditor(res, name.getText(), view);
imageEditor.selectFile();
view.setSelectedResource(name.getText());
break;
case MULTI_IMAGE:
ImageMultiEditor multiImageEditor = new ImageMultiEditor(res, name.getText(), view);
view.setSelectedResource(name.getText());
break;
case TIMELINE:
new TimelineEditor(res, name.getText(), view);
view.setSelectedResource(name.getText());
break;
case // animation
ANIMATION:
TimelineEditor.selectFile(view, res, name.getText());
/*ImageEditor animationEditor = new ImageEditor(res, name.getText());
animationEditor.setAnimation(true);
animationEditor.selectFile(view);*/
break;
case // font
FONT:
new FontEditor(res, 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.,;:!@/\\*()[]{}|#$%^&<>?'\"+- "), name.getText()).createFont();
view.setSelectedResource(name.getText());
break;
case // theme
THEME:
res.setTheme(name.getText(), new Hashtable());
view.setSelectedResource(name.getText());
// ResourceEditorView.expandAndSelect(tree, name.getText());
break;
case // data
DATA:
DataEditor dataEditor = new DataEditor(res, name.getText());
dataEditor.selectDataFile(view);
view.setSelectedResource(name.getText());
break;
case // localization
LOCALIZATION:
Hashtable h = new Hashtable();
Hashtable local = new Hashtable();
local.put("cancel", "Cancel");
local.put("ok", "OK");
local.put("menu", "Menu");
local.put("select", "Select");
local.put("edit", "Edit");
h.put("en", local);
res.setL10N(name.getText(), h);
view.setSelectedResource(name.getText());
// ResourceEditorView.expandAndSelect(tree, name.getText());
break;
case UI:
UserInterfaceEditor uiEditor = new UserInterfaceEditor(name.getText(), res, view.getProjectGeneratorSettings(), view);
view.setSelectedResource(name.getText());
break;
}
return name.getText();
}
use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class AddThemeResource method addResource.
// GEN-LAST:event_templateActionPerformed
public String addResource(EditableResources res, ResourceEditorView view) {
String newName = name.getText();
for (String r : res.getResourceNames()) {
if (r.equalsIgnoreCase(newName)) {
JOptionPane.showMessageDialog(this, "A resource called: " + newName + " already exists\nYou must delete the resource first.", "Add Resource", JOptionPane.ERROR_MESSAGE);
return null;
}
}
Hashtable theme = new Hashtable();
InputStream is = getClass().getResourceAsStream("/templates/" + template.getSelectedItem().toString() + ".res");
if (is != null) {
try {
EditableResources r = new EditableResources();
r.openFile(is);
is.close();
theme = r.getTheme(r.getThemeResourceNames()[0]);
view.checkDuplicateResourcesLoop(r, res.getImageResourceNames(), r.getImageResourceNames(), "Rename Image", "Image ", true);
view.checkDuplicateResourcesLoop(r, res.getL10NResourceNames(), r.getL10NResourceNames(), "Rename Localization", "Localization ", true);
view.checkDuplicateResourcesLoop(r, res.getDataResourceNames(), r.getDataResourceNames(), "Rename Data", "Data ", true);
view.checkDuplicateResourcesLoop(r, res.getUIResourceNames(), r.getUIResourceNames(), "Rename GUI", "GUI ", true);
view.checkDuplicateResourcesLoop(r, res.getFontResourceNames(), r.getFontResourceNames(), "Rename Font", "Font ", true);
for (String s : r.getImageResourceNames()) {
if (r.isMultiImage(s)) {
res.setMultiImage(s, (EditableResources.MultiImage) r.getResourceObject(s));
} else {
res.setImage(s, r.getImage(s));
}
}
for (String s : r.getL10NResourceNames()) {
res.setL10N(s, (Hashtable) r.getResourceObject(s));
}
for (String s : r.getDataResourceNames()) {
res.setData(s, (byte[]) r.getResourceObject(s));
}
for (String s : r.getUIResourceNames()) {
res.setUi(s, (byte[]) r.getResourceObject(s));
}
for (String s : r.getFontResourceNames()) {
res.setFont(s, r.getFont(s));
}
} catch (IOException err) {
err.printStackTrace();
}
}
res.setTheme(name.getText(), theme);
view.setSelectedResource(name.getText());
return name.getText();
}
use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class GameCanvasImplementation method playNativeBuiltinSound.
/**
* @inheritDoc
*/
protected void playNativeBuiltinSound(Object data) {
try {
try {
Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mpeg", null);
m.play();
} catch (Exception err) {
// some simulators take issue with the audio/mpeg string but the mp3 string
// works fine
Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mp3", null);
m.play();
}
} catch (IOException ex) {
// not likely since the stream is a byte array input stream
ex.printStackTrace();
}
}
use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class BlackBerryImplementation method playNativeBuiltinSound.
/**
* @inheritDoc
*/
protected void playNativeBuiltinSound(Object data) {
try {
try {
Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mpeg", null);
m.play();
} catch (Exception err) {
// some simulators take issue with the audio/mpeg string but the mp3 string
// works fine
Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mp3", null);
m.play();
}
} catch (IOException ex) {
// not likely since the stream is a byte array input stream
ex.printStackTrace();
}
}
use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class Security method verify.
/**
* Verifies that the signature from the server matches the computed
* signature on the data. Returns true if the data is correctly signed.
*
* @param publicKey public key associated with the developer account
* @param signedData signed data from server
* @param signature server signature
* @return true if the data and signature match
*/
public static boolean verify(PublicKey publicKey, String signedData, String signature) {
Signature sig;
try {
sig = Signature.getInstance(SIGNATURE_ALGORITHM);
sig.initVerify(publicKey);
sig.update(signedData.getBytes());
if (!sig.verify(Base64.decode(signature))) {
Log.e(TAG, "Signature verification failed.");
return false;
}
return true;
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "NoSuchAlgorithmException.");
} catch (InvalidKeyException e) {
Log.e(TAG, "Invalid key specification.");
} catch (SignatureException e) {
Log.e(TAG, "Signature exception.");
} catch (Base64DecoderException e) {
Log.e(TAG, "Base64 decoding failed.");
}
return false;
}
Aggregations