longPointerPress() not called for (most?) components - codenameone

I noticed that longPointerPress is not called for Label derivates.
Therefore I created some code to investigate further when longPointerPress() is called and was surprised that:
Label derivates do receive pointer events - however no longPointerPress
Button derivates do receive pointer events and longPointerPress just works
TextField derivates do receive pointer events unless editing, then they eat all the pointer events.
What I'd like to achieve is to be able to have various components in a Container and still be able to get notified for longPointerPress events under all circumstances.
How can I achieve this?
Here is the code - do a long tap on all the components and watch the console:
public class FormLongPointerPress extends Form {
#SuppressWarnings("unchecked")
private interface With<T> {
void act(T ... aTs);
}
public FormLongPointerPress() {
super("FormLongPointerPress");
setScrollableY(true);
setLayout(BoxLayout.y());
With<Component> with = (aComponents) -> {
Container container = FlowLayout.encloseCenter(aComponents);
container.addPointerPressedListener((aActionEvent) -> Log.p("container.pointerPressed(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
container.addPointerReleasedListener((aActionEvent) -> Log.p("container.pointerReleased(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
container.addLongPressListener((aActionEvent) -> Log.p("container.longPress(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
for (Component component: aComponents) {
component.addPointerPressedListener((aActionEvent) -> Log.p("component.pointerPressed(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
component.addPointerReleasedListener((aActionEvent) -> Log.p("component.pointerReleased(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
component.addLongPressListener((aActionEvent) -> Log.p("component.longPress(" + aActionEvent.getX() + ", " + aActionEvent.getY() + ")"));
}
getContentPane().add(container);
};
with.act();
with.act(new Label("A Label"));
with.act(new Button("A Button"));
with.act(new TextField("A TextField"));
}
}

Related

fnDrawCallback how to loop through each row

How do i loop through the enitre datset within the in datatables method?
"fnFooterCallback": function (nFoot, aData, iStart, iEnd, aiDisplay) {
$(aData).each(function (index) {
$(".it").append("<div class='mapdata' id='" + nFoot + "B' title='" + aData[index][14] + "|" + aData[index][15] + "' >");
});
},
The above works if the pagination is removed. But if iDisplayLength is set to 25 for example then it only goes through 25 records, not all 100 etc.
"fnFooterCallback": function (nFoot, aData, iStart, iEnd, aiDisplay) {
$(aData).each(function (index) {
$(".it").append("<div class='mapdata' id='" + nFoot + "B' title='" + aData[index][14] + "|" + aData[index][15] + "' data-id='true' data-id2='" + aData[index][1] + "' data-isapprove='" + aData[index][12] + "' ><div class='gTab1'><div class='info'><div class='maptitle'>" + aData[index][1] + "</div><div class='location'></div></div></div ></div >");
});
},
The above did it

Iterating through nested arrays with hyphen in object name

First of all, I know naming array objects with hyphens is completely incorrect, and I'm not the creator of this. I need to call an API within a service, and many objects are named improperly, like {"children-education": [ and { "Kid Stories": [.
I have tried assigning the name to a variable like let edChild = "child-education"and then parsing it to an object, like edChild = JSON.parse(edChild)to no avail. I really have no idea of what I'm doing, nor even if it's possible to do so.
I kinda have the option to call my customer and kindly ask his team to rename the objects to something less... stupid than special characters than I can't possible call in Typescript, but I'd like to learn if there's a way to surpass this in future occasions or if they can't rename it.
Here's an example of the JSON I'm trying to iterate through:
{
"business":
[
{
"anim":
[
{
"child-education": [
{
"Kid Stories": [
{
"id": 1,
"name": "Three Little Pinkies",
"url": "#",
"description": "shows how the world is beautiful"
},
(... and so on)
Thanks in advance.
You can parse that JSON string like any JSON string, using JSON.parse()
let str = "{\n" +
" \"business\":\n" +
" [\n" +
" {\n" +
" \"anim\":\n" +
" [\n" +
" {\n" +
" \"child-education\": [\n" +
" {\n" +
" \"Kid Stories\": [\n" +
"\n" +
" {\n" +
" \"id\": 1,\n" +
" \"name\": \"Three Little Pinkies\",\n" +
" \"url\": \"#\",\n" +
" \"description\": \"shows how the world is beautiful\"\n" +
" }]}]}]}]}" +
""
console.log(JSON.parse(str));
After that, you can use bracket notation to access any property names
let str = "{\n" +
" \"business\":\n" +
" [\n" +
" {\n" +
" \"anim\":\n" +
" [\n" +
" {\n" +
" \"child-education\": [\n" +
" {\n" +
" \"Kid Stories\": [\n" +
"\n" +
" {\n" +
" \"id\": 1,\n" +
" \"name\": \"Three Little Pinkies\",\n" +
" \"url\": \"#\",\n" +
" \"description\": \"shows how the world is beautiful\"\n" +
" }]}]}]}]}" +
""
const obj = JSON.parse(str);
console.log(obj.business[0].anim[0]['child-education'][0]['Kid Stories'][0]);

undefined JSON object / Array Javascript

JSON Data
myData = {"data":[{"pre":1,"post":2}]}
JSON.stringify(myData) shows that data is an array with one element, an object.
console.log("type of data: " + typeof(myData));
console.log("data: " + JSON.stringify(myData));
console.log("data.pre: " + data.pre);
Log result
type of data: object
data: {"data":[{"pre":1,"post":2}]}
data.pre: undefined
I manually adjusted and added a JSON.
It works with this JSON (without the object)
myData = {"pre":1,"post":2}
and
console.log("data.pre: " + data.pre);
Log result
data.pre: 1
How can i achieve this? I want to use it later as a variable.
pre = data.pre;
post = data.post;
If your data inside an array you need to specify the index of the object you want to access ex: data[0].pre
myData = {"data":[{"pre":1,"post":2}]}
console.log("type of data: " + typeof(myData));
console.log("type of data: " + typeof(myData.data));
console.log("data: " + JSON.stringify(myData.data));
console.log("data.pre: " + myData.data[0].pre);
console.log("data.post: " + myData.data[0].post);

How can I get the initial value of a comboBox?

I need get the initial value of a comboBox to charge a tooltip on my application, i got this method but this not charge nothing
var raw = ComboRegisted.combo.getRawValue();
Ext.QuickTips.register({ target: ComboRegisted.combo.getEl(), text: COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaFechaAprobacion") + raw.fechaAprobacion +
"<br/>" + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaCO") + raw.normaCO + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaUnidad1") +
"<br/>" + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaHC") + raw.normaHC + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaUnidad1") +
"<br/>" + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaNox") + raw.normaNox + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaUnidad1") +
"<br/>" + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaPM") + raw.normaPM + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaUnidad1") +
"<br/>" + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaHumo") + raw.normaHumo + COREProxy.languageMng.getText(oThis.CLASS_NAME, "tooltipNormativaUnidad2" )});
this.comboMap.register(ComboRegisted.ID, ComboRegisted.meta, ComboRegisted.combo);
No problem i get the answer now.
I do this:
var recordSelected = ComboRegisted.combo.store.getAt(ComboRegisted.combo.getValue());
var raw = recordSelected.raw;
and this go good.

Script to export layer coordinates to excel

I have found a script that export my layers coordinates form photoshop CS5 to XML
I hope somebody here can help me to edit that script to record coordinates to xls file?
Also if is possible to have each coordinates on separate row will be great.
Below is script I want to modify to do what I need.
//
// This script exports extended layer.bounds information to [psd_file_name].xml
// by pattesdours
//
function docCheck() {
// ensure that there is at least one document open
if (!documents.length) {
alert('There are no documents open.');
return; // quit
}
}
docCheck();
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var docRef = activeDocument;
var docWidth = docRef.width.value;
var docHeight = docRef.height.value;
var mySourceFilePath = activeDocument.fullName.path + "/";
// Code to get layer index / descriptor
//
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
function getLayerDescriptor (doc, layer) {
var ref = new ActionReference();
ref.putEnumerated(cTID("Lyr "), cTID("Ordn"), cTID("Trgt"));
return executeActionGet(ref)
};
function getLayerID(doc, layer) {
var d = getLayerDescriptor(doc, layer);
return d.getInteger(cTID('LyrI'));
};
var stackorder = 0;
// function from Xbytor to traverse all layers
traverseLayers = function(doc, ftn, reverse) {
function _traverse(doc, layers, ftn, reverse) {
var ok = true;
for (var i = 1; i <= layers.length && ok != false; i++) {
var index = (reverse == true) ? layers.length-i : i - 1;
var layer = layers[index];
if (layer.typename == "LayerSet") {
ok = _traverse(doc, layer.layers, ftn, reverse);
} else {
stackorder = stackorder + 1;
ok = ftn(doc, layer, stackorder);
}
}
return ok;
};
return _traverse(doc, doc.layers, ftn, reverse);
};
// create a string to hold the data
var str ="";
// class using a contructor
function cLayer(doc, layer) {
//this.layerID = Stdlib.getLayerID(doc, layer);
this.layerID = getLayerID(doc, layer);
//alert("layer ID: " + this.layerID);
this.layerWidth = layer.bounds[2].value - layer.bounds[0].value;
this.layerHeight = layer.bounds[3].value - layer.bounds[1].value;
// these return object coordinates relative to canvas
this.upperLeftX = layer.bounds[0].value;
this.upperLeftY = layer.bounds[1].value;
this.upperCenterX = this.layerWidth / 2 + layer.bounds[0].value;
this.upperCenterY = layer.bounds[1].value;
this.upperRightX = layer.bounds[2].value;
this.upperRightY = layer.bounds[1].value;
this.middleLeftX = layer.bounds[0].value;
this.middleLeftY = this.layerHeight / 2 + layer.bounds[1].value;
this.middleCenterX = this.layerWidth / 2 + layer.bounds[0].value;
this.middleCenterY = this.layerHeight / 2 + layer.bounds[1].value;
this.middleRightX = layer.bounds[2].value;
this.middleRightY = this.layerHeight / 2 + layer.bounds[1].value;
this.lowerLeftX = layer.bounds[0].value;
this.lowerLeftY = layer.bounds[3].value;
this.lowerCenterX = this.layerWidth / 2 + layer.bounds[0].value;
this.lowerCenterY = layer.bounds[3].value;
this.lowerRightX = layer.bounds[2].value;
this.lowerRightY = layer.bounds[3].value;
// I'm adding these for easier editing of flash symbol transformation point (outputs a 'x, y' format)
// because I like to assign shortcut keys that use the numeric pad keyboard, like such:
// 7 8 9
// 4 5 6
// 1 2 3
//
this.leftBottom = this.lowerLeftX + ", " + this.lowerLeftY;
this.bottomCenter = this.lowerCenterX + ", " + this.lowerCenterY;
this.rightBottom = this.lowerRightX + ", " + this.lowerRightY;
this.leftCenter = this.middleLeftX + ", " + this.middleLeftY;
this.center = this.middleCenterX + ", " + this.middleCenterY;
this.rightCenter = this.middleRightX + ", " + this.middleRightY;
this.leftTop = this.upperLeftX + ", " + this.upperLeftY;
this.topCenter = this.upperCenterX + ", " + this.upperCenterY;
this.rightTop = this.upperRightX + ", " + this.upperRightY;
// these return object coordinates relative to layer bounds
this.relUpperLeftX = layer.bounds[1].value - layer.bounds[1].value;
this.relUpperLeftY = layer.bounds[0].value - layer.bounds[0].value;
this.relUpperCenterX = this.layerWidth / 2;
this.relUpperCenterY = layer.bounds[0].value - layer.bounds[0].value;
this.relUpperRightX = this.layerWidth;
this.relUpperRightY = layer.bounds[0].value - layer.bounds[0].value;
this.relMiddleLeftX = layer.bounds[1].value - layer.bounds[1].value;
this.relMiddleLeftY = this.layerHeight / 2;
this.relMiddleCenterX = this.layerWidth / 2;
this.relMiddleCenterY = this.layerHeight / 2;
this.relMiddleRightX = this.layerWidth;
this.relMiddleRightY = this.layerHeight / 2;
this.relLowerLeftX = layer.bounds[1].value - layer.bounds[1].value;
this.relLowerLeftY = this.layerHeight;
this.relLowerCenterX = this.layerWidth / 2;
this.relLowerCenterY = this.layerHeight / 2;
this.relLowerRightY = this.layerHeight;
this.relLowerRightX = this.layerWidth;
this.relLowerRightY = this.layerHeight;
return this;
}
// add header line
//str = "<psd filename=\"" + docRef.name + "\" path=\"" + mySourceFilePath + "\" width=\"" + docWidth + "\" height=\"" + docHeight + "\">\n";
// now a function to collect the data
function exportBounds(doc, layer, i) {
var isVisible = layer.visible;
var layerData = cLayer(doc, layer);
// if(isVisible){
// Layer object main coordinates relative to its active pixels
var str2 = leftTop // this is the
// + "\" layerwidth=\"" + layerData.layerWidth
// + "\" layerheight=\"" + layerData.layerHeight
// + "\" transformpoint=\"" + "center" + "\">" // hard-coding 'center' as the default transformation point
+"\" \"" + layer.name + ".png" + "</layer>\n" // I have to put some content here otherwise sometimes tags are ignored
str += str2.toString();
};
//};
// call X's function using the one above
traverseLayers(app.activeDocument, exportBounds, true);
// Use this to export XML file to same directory where PSD file is located
var mySourceFilePath = activeDocument.fullName.path + "/";
// create a reference to a file for output
var csvFile = new File(mySourceFilePath.toString().match(/([^\.]+)/)[1] + app.activeDocument.name.match(/([^\.]+)/)[1] + ".xls");
// open the file, write the data, then close the file
csvFile.open('w');
csvFile.writeln(str + "</psd>");
csvFile.close();
preferences.rulerUnits = originalRulerUnits;
// Confirm that operation has completed
alert("Operation Complete!" + "\n" + "Layer coordinates were successfully exported to:" + "\n" + "\n" + mySourceFilePath.toString().match(/([^\.]+)/)[1] + app.activeDocument.name.match(/([^\.]+)/)[1] + ".xml");
Change
var str2 = leftTop // this is the
// + "\" layerwidth=\"" + layerData.layerWidth
// + "\" layerheight=\"" + layerData.layerHeight
// + "\" transformpoint=\"" + "center" + "\">" // hard-coding 'center' as the default transformation point
+"\" \"" + layer.name + ".png" + "</layer>\n" // I have to put some content here otherwise sometimes tags are ignored
str += str2.toString();
to
var str2 = leftTop + ","+ layer.name + "\n"
str += str2.toString();
and
var csvFile = new File(mySourceFilePath.toString().match(/([^\.]+)/)[1] + app.activeDocument.name.match(/([^\.]+)/)[1] + ".xls");
to
var csvFile = new File(mySourceFilePath.toString().match(/([^\.]+)/)[1] + app.activeDocument.name.match(/([^\.]+)/)[1] + ".csv");
This works great for me!

Resources