Scala - Updating JFreeChart with Swing - swing

Is there a way to update a chart based on the user input on text field? I'm not familiar with both Swing and JFreeChart but I need to virtualize some data. So far I'm able to display simple graph but only with hardcoded data.
Thank you

Yes, of course that is possible. First of all, I recommend looking at Scala-Chart which is a nice wrapper around JFreeChart.
JFreeChart lets you alter and update any parameter. For example if you have a data-set, you can clear it and add new data, you can readjust the axes, etc. Here is an example from a project I'm working on, where a "series" (JFreeChart speak) is removed from a "dataset", then a new series is calculated and added again:
https://github.com/iem-projects/sysson/blob/70829bf80ad22dfc0b6020e00dd07397b100e401/src/main/scala/at/iem/sysson/gui/impl/PlotChartImpl.scala#L222

Related

Anylogic CompareRuns does not execute Main Agent

I am working on an agent-based model and now I'm trying to experiment with CompareRuns.
when I execute the experiment, it should simulate the model several times and after each simulation, a dataset of sample data should be filled.
there is also a state chart in Main agent and each state has a traceln("..."). so after passing through each state, something must be printed.
the problem is that neither the print commands return anything, nor the dataset in which I store my data returns anything but zeros.
P.S.: I also have a GIS map in my model. could that be the reason for misbehaving of Anylogic?
I found the problem and fixed it.
check and double check all the "Parameter"s in the Main agent and make sure they all have different names and labels. the problem was that two parameters had same labels and it messed up the whole experiment.
I fixed the labels and the default value of all parameters, deleted the CompareRun experiment, made a new one and it worked.

Dynamically generating FormFlow from JSON file

I am try to utilize JSON data to dynamically generate a form flow. In the Improved Sandwich Bot, each field in the form flow is independent to each other. For example, no matter I choose what kind of sandwich, I can continue to choose any type of bread. The only way to add some customization is using the following code:
.Field(new FieldJson(schema, "Specials")
.SetType(null)
.SetActive((state) => (string)state["Length"] == "FootLong")
.SetDefine(async (state, field) =>
{
field
.AddDescription("cookie", "FreeCookie")
.AddTerms("cookie", "cookie", "FreeCookie")
.AddDescription("drink", "FreeDrink")
.AddTerms("drink", "drink", "FreeDrink");
return true;
}))
However, since different sandwich stores have different menus, the dependency between different fields varies a lot. For example,
Store A may say only Sandwich1 can have toppings1, 2, 3. And store B
may say only Bread1 can have cheese1, 2, 3.
So I don't want to use the code above to implement the logic. It is not scalable.
So is it possible to include those dependency relations in the JSON file? In that way, the form builder can directly build the form flow with certain dependency relation.
No, it's not possible at this point but it seems like a very good suggestion. You can give the feedback at https://feedback.botframework.com/.

Formating Output in Information Design Tool

When working with IDT 4.1 and when making a query in business layer, is it possible to format the yielded numbers? What I mean is - the output looks something like "1.9982121921**E7**" (please noctice E7 part). I would like BO to display the whole number without any suffixes.
Additionally, it would be even better to add a delimiter after thousands, millions,...
Is 1.9982121921**E7** the value that is returned from the database? Thus not a number but a string (alphanumeric)? In that case, you'll have to change the select statement and use a database function to trim the non-numeric characters off (e.g. SUBSTR, MID, LEFT, …).
Once you have numeric data, you can use the Display Format function to change the layout of your object.
If you're not happy with the predefined formats to choose from, you can always define a custom format. The formatting options are described in the Information Design Tool User Guide (links to the documentation for IDT in BI 4.1 SP3), section 12.10.23 Creating and editing display formats for business layer objects.
Right-click and object and select Create Display Format… from the context menu.
Or click the Create Display Format… button in the object's properties (located in the Advanced tab).
Set the type to numeric and enable the high precision check mark.

how to implement a read-only table in Swing GUI?

I want to display my data in a table using scala GUI. But I need the contents of the table are read only. I know there is class Table(mutable) and ListView (read-only) in scala GUI.
My problem is I do not know how to combine them.
Thanks
See http://www.coderanch.com/t/334323/GUI/java/create-read-JTable which says
a JTable has a model behind, a TableModel. You can either implement this or you extend from the DefaultTableModel. Anyway, there is a function isCellEditable(int row, int col). This function should return false in every case, then your table is not editable, but selectable.
Ta have a good starting point, you should read the Table section of the Java Tutorial of SUN.
The Java tutorial being referred to here is this.

Validate DataGridColumn cells individually

How can I validate the cells in a DataGridColumn individually? (ActionScript 3.5) The validation is configured per-cell, based on fields in the given row. For example
FIELD VALUE TYPE
age 13 Integer
height 13x3 Integer
registered true Boolean
temperature 98.G6 Float
In this case, of course 13x3 and 98.G6 would be invalid.
It's easy to write a Validator ; and to access the data provider objects.
But how do I get individual access to the GUI cell objects so I can set the errorString on an individual cell, either directly or through a Validator?
The itemRenderer/ TextInput control is re-used across the cells for performance reasons, so accessing the GUI-level objects is tricky.
Edit
Answers:
One way to validate and display the invalidation markings, but not per-cell, is to validate all data-provider objects and then set the errorString on the entire grid.
One way to validate per-cell is on the itemEditEnd event handler. (See these pages A B C D). One disadvantage is that it only allows access to the cells from the "inside", not in an action that validates the grid on command.
A custom itemRenderer is another possibility, as in the answer below, but like 3 above, it only allows access to the cells from the "inside", not in an action that validates the grid on command.
See Richard Haven's answer below.
And here's how to access the GUI objects: The list of relevant GUI objects is a protected field; so you can access it by subclassing, then iterate over the GUI-components which represent the cells and set the errorString on each one.
This website at BigResource asks how to access an individual cell. The third post answers there question and provides a link to a better resource than this. Figured you would want both. Hopefully this helps.
If you are looking for arbitrary validation (e.g. on a button or page navigation) rather than immediate navigation (e.g. on cell exit or end-of-edit), then the data is in the underlying dataProvider. I would do validations there rather than dig around inside the grid.
You can add a flag to the data item so the item renderer displays it as an error (or use an external list to flag it).
Cheers
Are you sure you actually want to access the individual cells' DisplayObjects? The component manages instances so that it only creates as many as it needs to display (so that huge datasets don't require a huge number of DisplayObjects on screen).
I think a better alternative would be to provide your DataGridColumn with a custom itemRenderer. You can write this class to accept a validator and update its appearance, and there are a bunch of great tutorials around about that.