how do one pass a non-string object as argment using #namedArg in javafx? I cannot find a single nutshell example regarding this question online!
I am currently trying to instantiate a InlineCssTextArea from RichTextFX wrapped in a VirtualizedScrollPane - please have a look at this source code:
public VirtualizedScrollPane(#NamedArg("content") V content) {
[...]
}
where the custom type V is extending Node. In my case, I want to pass InlineCssTextArea as V. Doing this programmatically is pretty easy:
InlineCssTextArea area = new InlineCssTextArea();
Scene scene = new Scene(new StackPane(new VirtualizedScrollPane<>(area)), 600, 400);
but translating that to FXML is quite challenging. I have already tried a few things, like fx:factory based on the official oracle fxml tutorial:
<VirtualizedScrollPane fx:factory="content">
<InlineCssTextArea />
</VirtualizedScrollPane>
or how #namedArg suggests, as argument:
<VirtualizedScrollPane content="InlineCssTextArea" />
-or-
<VirtualizedScrollPane content="<InlineCssTextArea />" />
Is there a fxml solution for this problem?
my question is based on the the following answer from James D: What is the purpose of #NamedArg annotation in javaFX 8?
You basically need to pass a value for an argument called content. The two ways to pass a value for an argument in FXML are as an attribute: content="..." or using a property element. Using an attribute only works if you can pass a string which the FXML loader knows how to convert to the appropriate value (i.e. if the value is a string or a primitive type), which isn't the case here. Using a property element you just nest an element whose name is the property name and nest the value inside it:
<VirtualizedScrollPane>
<content>
<InlineCssTextArea />
</content>
</VirtualizedScrollPane>
Related
Im pretty pretty new to Dynamic-Jasper, but due to work i had to add a new feature to our already implemented solution.
My Problem
The Goal is to add a Column to a report that consists only out of a background-color based on some Information. I managed to do that, but while testing I stumbled upon a Problem. While all my Columns in the html and pdf view had the right color, the Excel one only colored the fields in the last Color.
While debugging i noticed, that the same colored Fields had the same templateId, but while all Views run through mostly the same Code the Excel one showed different behavior and had the same ID in all fields.
My Code where I manipulate the template
for(JRPrintElement elemt : jasperPrint.getPages().get(0).getElements()) {
if(elemt instanceof JRTemplatePrintText) {
JRTemplatePrintText text = (JRTemplatePrintText) elemt;
(...)
if (text.getFullText().startsWith("COLOR_IDENTIFIER")) {
String marker = text.getFullText().substring(text.getFullText().indexOf('#') + 1);
text.setText("ID = " + ((JRTemplatePrintText) elemt).getTemplate().getId());
int rgb = TypeConverter.string2int(Integer.parseInt(marker, 16) + "", 0);
((JRTemplatePrintText) elemt).getTemplate().setBackcolor(new Color(rgb));
}
}
}
The html view
The Excel view
Temporary Conclusion
The same styles uses the same Objects in the background and the JR-Excel export messes something up by assigning the same Object to all the Fields that I manipulated there. If anyone knows of a misstake by me or potential Solutions to change something different to result the same thing please let me know.
Something different I tried earlier, was trying to set the field in an evaluate Method that was called by Jasper. In that method we assign the textvalue of each field. It contained a map with JRFillFields, but unfortunatelly the Map-Implementation denied access to them and just retuned the Value of those. The map was provided by dj and couldn't be switched with a different one.
Edit
We are using JasperReports 6.7.1
I found a Solution, where I replaced each template with a new one that was supposed to look exactly alike. That way every Field has its own ID guaranteed and its not up to chance, how JasperReports handles its Data internaly.
JRTemplateElement custom =
new JRTemplateText(((JRTemplatePrintText) elemt).getTemplate().getOrigin(),
((JRTemplatePrintText) elemt).getTemplate().getDefaultStyleProvider());
custom.setBackcolor(new Color(rgb));
custom.setStyle(((JRTemplatePrintText) elemt).getTemplate().getStyle());
((JRTemplatePrintText) elemt).setTemplate(custom);
I was wondering if by javafx-css it's possible to set label text.
On the official documentation i found a reference to
-fx-text: "whatever";
but isn't working, basically i'm searching for and equivalent of css3
content: "whatever";
specified here: W3School
This is not possible in JavaFX and you can easily verify this by getting all the styleable properties from a Label:
Label label = new Label();
label.getCssMetaData().stream().map(CssMetaData::getProperty).sorted().forEach(System.out::println);
Which yields the following list (not including -fx-text or anything that allows you to set the content according to the CSS Reference Guide):
-fx-alignment
-fx-blend-mode
-fx-content-display
-fx-cursor
-fx-effect
-fx-ellipsis-string
-fx-focus-traversable
-fx-font
-fx-graphic
-fx-graphic-text-gap
-fx-label-padding
-fx-line-spacing
-fx-max-height
-fx-max-width
-fx-min-height
-fx-min-width
-fx-opacity
-fx-opaque-insets
-fx-padding
-fx-position-shape
-fx-pref-height
-fx-pref-width
-fx-region-background
-fx-region-border
-fx-rotate
-fx-scale-shape
-fx-scale-x
-fx-scale-y
-fx-scale-z
-fx-shape
-fx-skin
-fx-snap-to-pixel
-fx-text-alignment
-fx-text-fill
-fx-text-overrun
-fx-translate-x
-fx-translate-y
-fx-translate-z
-fx-underline
-fx-wrap-text
visibility
I am currently in need of custom attributes which I can fetch anytime. Is there any way to create custom data attributes for nodes and then get those values in javafx?
Lets assume I have the the follwing Button.
<Button text="Im a button" fooBar="I hold some value" />
Similar to: https://developer.mozilla.org/de/docs/Web/Guide/HTML/Using_data_attributes
Now in HTML I could simply do the following:
<div id="example" data-foobar="I hold some value"></div>
Then I could easily get the data like this:
document.getElementById("example").dataset.foobar;
Edit: I need more than 1 data property for a node because a node can hold various information.
The data can be stored in the properties ObservableMap of a Node
Node node = ...
node.getProperties().put("foo", "bar");
...
Object foo = node.getProperties().get("foo");
Note however that some layout properties use this map too, so no property names similar to javafx properties / "static" properties should be used as key. To be sure you could create a custom key class that does not return true if an object of another type is passed as parameter to equals.
To solve your problem you should to use userData it can be any object that you need.
node.setUserData("Hello world");
node2.setUserData(123);
etc.
If you need to set multiple values you can save your values in an array, list, json etc.
ArrayList<String> vals = new ArrayList();
vals.add("Hello");
vals.add("World");
node3.setUserData(vals);
//some code
ArrayList<String> result = (ArrayList) node3.getUserData();
I'm working in a project for Android using libGDX framework in which I show some examples of the use of three graphic libraries. Once started, the app must show a menu with a link for each sample, its title and a little description. For the time being, I'm creating all manually, declaring a new link for each sample, but as I will have a lot of samples and I'll add new ones in each app version, I would like to identify them and generate a new entry automatically.
The samples part is composed of an abstract class called Sample and a class for each sample that extends from Sample. How could I accomplish this? The requisites will be to have the possibility to identify all samples at run-time and get information about them (name, description, etc.) without the need of create an instance previously.
My actual options are use Annotations (don't know if it is possible or if I need an external library to search for this annotations at run-time) or use something like a JSON file. What do you think is the best way (I'm open to other solutions of course) to solve this problem?
I would recomend using XML and take the class you want to create as Tag so something like this:
<root>
<sampleimplement1 name ="sampleimplement1" descript="sample1 description" ..... more attributes here... />
<sampleimplement2 name ="sampleimplement2" descript="sample2 description" ..... more attributes here... />
<sampleimplement3 name ="sampleimplement3" descript="sample3 description" ..... more attributes here... />
</root>
This can now be parsed with the XmlReader of libgdx to a Element. So the element is not the root.
Last but not least you can iterate over the childs of the root and check what the name of the Tag is. Depending on the name you create a different implementation of your Sample.
XmlReader r = new XmlReader();
Element e = r.parse(xml);//<--- the XML as string also possible as file
for (int i = 0; i < e.getChildCount(); i++)
{
Element child = e.getChild(i);
switch(child.getName()){
case "sampleimplement1":
//create sample1
break;
....
....
}
I've a Form where an property of source Item need to be formatter by an custom format.
Source property (of my own bean) is a Integer, but need to be formatted as a Currency-like format.
I tried to implement my own PropertyFormatter, and setup it inside my FieldFactory.createField for this form as
TextField tf = new TextField("Price");
tf.setPropertyDataSource(new MyPriceFormatter());
return tf;
But as I see from the logs, only format() method is called. But parse() method is never used, and setValue is never called
What's wrong with my code? How to use custom PropertyFomatter for forms? Or how to add custom format for form's field?
After some investigation i found that there is something just replaces my formatter, with an new MethodProperty data source. So i'd implemented my own PriceField, with overrided setPropertyDataSource, that fix this situation. btw, it seems to bee hacky, and i'm still looking for an other way
I have also experienced this problem and solved it another way. Actually I also had to make a textfield formated with a currency :-)
The problem is that the datasource in the PropertyFormatter is null at the time you are creating the fields in the FormFieldFactory. You can instead set the datasource on your field after the FormFieldFactory has been called:
addCountryRatesForm.setFormFieldFactory(new MyFormFieldFactory());
Field internationalRate = addCountryRatesForm.getField("internationalRate");
internationalRate.setPropertyDataSource(new CurrencyFormatter("#0.00 ", currency, internationalRate.getPropertyDataSource()));
So unfortunately with Vaadin you cannot create a TextField that sets its own formatter.