What is a style protochain? - actionscript-3

I keep encountering many references to style protochain in the documentation about css in flex. I tried to look it up but I couldn't find any relevant information. Can anyone tell me what does the class StyleProtochain do?
In its source code, there is the following comment.
/**
* #private
* This is an all-static class with methods for building the protochains
* that Flex uses to look up CSS style properties.
*/
Cool, it tells me that there are a couple of methods for building the protochains, now I am supposed to know what it does, but I have no idea what a protochain is.

CSS styles are inherited. This means that when you create a new object and place it as a child of another in the DOM, this new object will have to inherit all the "inheritable" styles from the parent. Then it will override these styles through its stylename or inline styles.
The StyleProtoChain class is responsible for building this style list of any object ( which can have a style ) that is created. It is named thus because this class has to go up the DOMtree ( like going up the prototype chain ... perhaps a misnomer!) and construct the list of styles for this object. The order in which this goes up is specified by this comment.
/**
* #private
* If the styleName property points to a UIComponent, then we search
* for stylable properties in the following order:
*
* 1) Look for inline styles on this object
* 2) Look for inline styles on the styleName object
* 3) Look for class selectors on the styleName object
* 4) Look for type selectors on the styleName object
* 5) Look for type selectors on this object
* 6) Follow the usual search path for the styleName object
*
* If this object doesn't have any type selectors, then the
* search path can be simplified to two steps:
*
* 1) Look for inline styles on this object
* 2) Follow the usual search path for the styleName object
*/
Hope this helps. If anyone wants further reference, you can find a link to the source here

Related

Yii2 override core class - class not found

I try to extend BaseHtml class by follow this tutorial
But is not find the BaseHtml extended class
namespace common\components;
class Html extends \yii\helpers\BaseHtml {
}
this is the error:
Class 'yii\helpers\BaseHtml' not found
Where I am wrong?
Update
I try to copied the Html.php file locate in Helpers and is still the same
<?php
/**
* #link http://www.yiiframework.com/
* #copyright Copyright (c) 2008 Yii Software LLC
* #license http://www.yiiframework.com/license/
*/
namespace yii\helpers;
/**
* Html provides a set of static methods for generating commonly used HTML tags.
*
* Nearly all of the methods in this class allow setting additional html attributes for the html
* tags they generate. You can specify, for example, `class`, `style` or `id` for an html element
* using the `$options` parameter. See the documentation of the [[tag()]] method for more details.
*
* For more details and usage information on Html, see the [guide article on html helpers](guide:helper-html).
*
* #author Qiang Xue <qiang.xue#gmail.com>
* #since 2.0
*/
class Html extends BaseHtml
{
}
And now I have another problem. It not find BaseHtml fro the original class
vendor/yiisoft/yii2/helpers/Html.php
Solution found
I refactored the override file and phpStorm change me the path to BaseHtml in vendor/yiisoft/yii2/classe.php
BaseHtml.php should be under /vendor/yiisoft/yii2/helpers/ folder.
If it's not there, you will need to update your vendors or try to copy file BaseHtml.php to your yii2/helpers at yii2 repo: https://github.com/yiisoft/yii2/blob/b7b9c8ba40d65ec7c745ee639a8a6eb96e7aea75/framework/helpers/BaseHtml.php
Hope it helps.

DOM Selector to get text of element ignoring children?

I'm using the Tab Modifier plugin for Chrome to dynamically rename some tabs that I use daily. In the tab Title definition, it says the following:
You can inject any DOM content with {selector}. Examples: {title} for website title, {h1}, {#id}, {.class}, etc.
Here is an example of the element I want to use to name the tab:
<td class="portalTitleInfoVal">
PORTALNAME
<a class="portalLink">Change Portal</a>
</td>
This is what I'm currently using for the title:
{.portalTitleInfoVal:nth-of-type(4)}
But, of course, the tab is named PORTALNAMEChange Portal.
How can I modify the DOM selector so that the tab is just named "PORTALNAME"?
I know I'm really late to the party, but I found this post while searching for an answer.
I'm working with a lot of old systems and all the tabs just says {title}, which is.. not useful when having 15-20 tabs open at once, and it's tedious to hard code every tab.
So.. I brute forced tested until I found a solution:
Every page has a breadcrumb:
<div class="breadcrumb noPrint">
Home "ยป"
Materials
123123
</div>
So they might have updated the extension since, but your guess was very close. I don't know why you were putting in 4, but I assume you had more elements than posted.
Anyhow, the way I got it to work were by:
{.breadcrumb :nth-last-child(2)} : {.breadcrumb :last-child}
So, there has to be a space between the .class and the child element, which in my case returns Materials : 12312
I haven't tried nearly half, but DoFactorys list of CSS selectors were a big help for me.
The element's first child node is the plain text, before the HTML element (<a>).
$('. portalTitleInfoVal')[0].childNodes[0].nodeValue
It looks like this plugin will only allow for CSS style element selectors compatible with querySelector. It then grabs the text from that element. From their github repo:
/**
* Returns the text related to the given CSS selector
* #param selector
* #returns {string}
*/
getTextBySelector = function (selector) {
var el = document.querySelector(selector), value = '';
if (el !== null) {
value = el.innerText || el.textContent;
}
return value.trim();
};

Weird NumberFormatter behavior in Flex, AS3

I came across this weird behavior while using NumberFormatter in AS3.
It's important to understand that I need to use NumberBaseRoundType.UP because I need to use NumberBaseRoundType.DOWN when applying a credit.
Considering the rounding precision that has a value of 2, I guess the NumberFormatter shouldn't change my number. In the example below, 2.43 once formatted become 2.44..!
So the Math.pow(...) is not the solution I'm looking for PLUS, I am very interested to understand what and why this is happening. THANKS!
var roundUp:NumberFormatter = new NumberFormatter();
roundUp.rounding = NumberBaseRoundType.UP;
roundUp.precision = 2;
trace(roundUp.format(2.41)); // Output : 2.41
trace(roundUp.format(2.42)); // Output : 2.42
trace(roundUp.format(2.43)); // Output : 2.44 <-- ???
trace(roundUp.format(2.44)); // Output : 2.44
trace(roundUp.format(2.45)); // Output : 2.46 <-- ???
trace(roundUp.format(2.46)); // Output : 2.46
This is not a complete answer. But to start off with which NumberFormatter class are you using (what's the package it comes from). Some of the source is available, some of it is contained in the player itself and isn't accessible, but in looking at the on included in Spark from the 4.6 framework it includes this class level comment that gives some insight:
/**
* The NumberFormatter class provides locale-sensitive formatting
* and parsing of numeric values. It can format <code>int</code>,
* <code>uint</code>, and <code>Number</code> objects.
*
* <p>This class is a wrapper class around the
* flash.globalization.NumberFormatter class.
* Therefore, the locale-specific formatting
* is provided by the flash.globalization.NumberFormatter.
* However, this NumberFormatter class can be used in MXML declarations,
* uses the locale style for the requested Locale ID name, and has
* methods and properties that are bindable.
* </p>
*
* <p>The flash.globalization.NumberFormatter class use the
* underlying operating system for the formatting functionality and
* to supply the locale-specific data. On some operating systems, the
* flash.globalization classes are unsupported, on these systems this wrapper
* class provides fallback functionality.</p>
*
* #mxml <p>The <code><s:NumberFormatter></code> tag inherits all of the tag
* attributes of its superclass and adds the following tag attributes:</p>
*
* <pre>
* <s:NumberFormatter
* <strong>Properties</strong>
* negativeNumberFormat="<i>locale and OS dependent</i>"
* />
* </pre>
*
* #includeExample examples/NumberFormatterExample1.mxml
* #includeExample examples/NumberFormatterExample2.mxml
*
* #see flash.globalization.NumberFormatter
*
* #langversion 3.0
* #playerversion Flash 10.1
* #playerversion AIR 2.5
* #productversion Flex 4.5
*/
Ultimately though it states that the player uses the underlying OS in some way to achieve the formatting. It is certainly a strange problem but I'd be surprised if this wasn't ever caught before and an explanation hasn't been posted or at least a bug report if it is in fact an issue in flash player. Some more details on your SDK version and player version may help, also have you tried fiddling with either of these is there any change in results?
Also depending on what you're attempting to achieve you may be able to just get around the issue by writing your own class to deal with doing the formatting for this case if it's just a one off scenario that you need to deal with this, if it's more of a system wide used thing that needs more of the functionality of the NumberFormatter class I could understand wanting to resolve the underlying issue.

Defining a "pass-through" style in Actionscript

I have a custom component called ButtonPanel written in Actionscript. Basically it's just a panel that displays a mx:ButtonBar in the upper right of the mx:Panel title bar and responds to the clicks of the buttons in the bar.
A ButtonBar has three styles available for the buttons: buttonStyleName, firstButtonStyleName, and lastButtonStyleName. I want to write these styles for the ButtonPanel so that if it is declared as such:
<comp:ButtonPanel buttonStyleName="myButtonStyle" ... />
then the ButtonPanel will pass the style through and set the corresponding style of the ButtonBar.
I really have no clue where to start on this because I've never messed with defining styles. Can someone help?
What you refer to as "pass-through" styles are actually called inheriting styles. The solution to your question is in fact quite simple.
You use the style metadata on your custom component to declare that ButtonPanel has a stylename called 'buttonStyleName':
[Style(name="buttonStyleName", inherit="yes")]
public class ButtonPanel extends Panel {
....
}
Note the 'inherit' flag which is set to true: this will make sure that any component inside your custom Panel that has the same style will inherit the value that you've given to that style at the Panel level.
Setting this metadata will make sure that FlashBuilder will suggest buttonStyleName as a style and not as a property (as would happen with Sam's solution).
Edit: already defined styles
I didn't realize at first that you were referring to the mx ButtonBar (as it's not explicitly mentioned). The reason this is not working for you is that mx:ButtonBar already has these styles defined as not inheriting. Look at the source code:
[Style(name="firstButtonStyleName", type="String", inherit="no")]
[Style(name="buttonStyleName", type="String", inherit="no")]
[Style(name="lastButtonStyleName", type="String", inherit="no")]
Because of this the compiler will complain when you try to override that definition in your custom Panel, because it simply wouldn't know which of the contradictory instructions to pick. So we'll have to do a little more work if you want to stick with mx:ButtonBar.
First define the styles on ButtonPanel exactly as they are defined in mx:ButtonBar so they have the same signature (you can just copy/paste the three lines above). This will shut up the compiler but the styles won't be inherited anymore, right?
So we'll have to pass them on manually: in your custom Panel skin, override the updateDisplayList() method and - assuming that the ButtonBar's id is 'buttonBar' - add the following:
private const buttonStyles:Array = [
"firstButtonStyleName",
"buttonStyleName",
"lastButtonStyleName"
];
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
if (buttonBar)
for each (var buttonStyle:String in buttonStyles)
buttonBar.setStyle(buttonStyle, getStyle(buttonStyle));
//some other code
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
This will take the styles from the host Panel and pass them on to the ButtonBar.
In order to pass these styles through, you only have to store them as string variables, and then pass them to the internal ButtonBar.
<mx:ButtonBar ... buttonStyleName="{buttonStyleName}" ... />
[Bindable]public var buttonStyleName:String;
If these two lines of code don't explain it fully to you, let me know and I can flesh out my example.

How to modify map element key

I have a container that holds map of elements.
class MyContainer{
.....
Map<String,MyElement> elements = new ...
...
}
Each element has name property. The key in the map is the element's name. i.e. the method insert is as follows:
void addElement(MyElement elem){
elements.put(elem.getName,elem);
}
I need to use the map data structure, because I have many read operations based on the element name.
The problem is that I need to support modification of the element's name. Changing element name must derive changes in the map. (insert the element with a new key otherwise I won't be able to find that element)
I have thought about two options:
add setName method to MyElement class that will update the container that its name was changed.
don't add setName method to MyElement class, add rename element method to the container, the container will be in charge of updating both the element name and the key in the map.
Option 1 means I have to maintain reference from each element to the container. (this part of the program should maintain low memory footprint).
What do you say? do you see a better option?
I would fire a property change notification on the setName method of the element and handle it in the container object which is listening that notification.
First of all, note that if MyElement can conceivably be used in a context without MyContainer, then option 1 is out.
MyContainer has an obvious relation with MyElement, since its code references MyElement instances through its map. The reverse is not true: the code in MyElement does not need to reference MyContainer. So option 2 is better.
Perhaps, though, you could go for a third hybrid option:
MyElement has a rename method that only changes its own name, and MyContainer has a rename method which calls MyElement.rename and moves the object in the map to the new key.
If the element is only used in this container.
Put the rename operation on the container.
Make the rename method on the element private so another programmer can't accidentally change just the element and forget to update the container.
Option 2 is the simplest and most efficient, thus my choice.
Clearly you know that, so what's the dillema?
Another option is to make a MyString class, that will serve as both a std::string AND a reference to MyContainer. MyString's modifying methods would be in charge of re-maping, and you'd still have a low footprint. E.g.:
class MyString;
class MyElement {
...
MyString name;
...
};
MyContainer * aContainer = new MyContainer;
new MyElement(MyString("Yaron Cohen",aContainer), ...); /* MyString need to be explicit only upon MyElement construction. takes care of inserting into container. */
...
MyElement * someElement = aContainer["Yaron Cohen"]; /* just std::string for lookup */
someElement->name = "Dana International": /* MyString takes care of remapping */
Note that this option supprts multiple keys and containers as well, e.g. FirstName, LastName (if only these were unique...)
Another option is if MyContainer is a singleton.
One more thing to consider is, how often does name change?