How to create shapetext using Java - anylogic

I am trying to create shape texts directly using codes as the number of shapetext i need may vary.
I tried using the code below, and I created the shapes in a collection (with type shapetext). When I use "traceln(text.getX());" it prints 2500 but I do not see the text anywhere on the screen. May I understand what I have done wrongly and how can I make the shapetext be shown? Do I have to add shapetexts into my network/level and initialize it?
Thank you for your help!
ShapeText text = new ShapeText(SHAPE_DRAW_2D3D, true, (double) 2500, (double) 3000, (double) 0, 0, black, "testing", new Font("SansSerif", Font.BOLD, 100), ALIGNMENT_CENTER );

You have successfully created the text, but you need to add it to the presentation to be shown
Simply add
presentation.add(text);
An alternative option if you have an undetermined amount of texts is to rather create a single text object and then replicate it as many times as you want to show it. Once you add a replication to a presentation object a local variable called index is now available for you to use in many of the fields.
Use this in the dynamic text field to get the values you want to display (like in the example below I stored the texts in a collection)
And you also use this index to change the position of the text (See what I have done in the Y coordinates)

Related

Anylogic: Create text by Java with dynamic text content

I want to create text using Java so that I can use codes to control how many shapetext to create and auto position them, but I want to link the text content to a dynamic value that is changing (e.g. a variable storing a parameter that varies during runtime). I am using the code below to create the text, however, when I replace "Test" with a variable, the text captures the value at the initial instance and remains a static value.
Is there any way to make the content dynamic or I can only write a function to actively refresh the text content?
Also, using a function to actively update the value makes the model run slower right? I compared the runs and observe that the model runtime is significantly slower.
col_Label_EQ.add(new ShapeText(SHAPE_DRAW_2D,
true,
0,
0,
0,
0,
white,
"Test",
new Font("SansSerif",
Font.BOLD,
10),
ALIGNMENT_CENTER));
presentation.add(col_Label_EQ.get(0));

Do I have to create a reference for each text I have in a panel, if I want to access them to modify?

I have a panel with 8 text field, 4 are used as descriptive field (what a label would do, basically), while the other 4 are modified with values.
I am creating a GameObject variable for every element that I have in the panel, using find to find the specific text element. I can leverage on the fact that each text object has only one text object attached to it, so I can address to it directly with GetComponent
panel_info = GameObject.Find("infopanel");
textfield1 = GameObject.Find("text_name");
textfield2 = GameObject.Find("text_age");
textfield3 = GameObject.Find("text_role");
textfield4 = GameObject.Find("text_field");
textfield1.GetComponent<Text>().text = "joe";
textfield2.GetComponent<Text>().text = "22";
textfield3.GetComponent<Text>().text = "striker";
textfield4.GetComponent<Text>().text = "attack";
While this works, I can't foresee myself creating 20-30 objects if a panel has more info to display.
Since I have the reference to the object Panel, is there a way to address directly the text field which is a child of the panel, using the text field name for example?
So if a panel has 4 text field, I can modify each of it addressing directly by name, and then using GetComponent<Text>().textto change the value.
You MUST NOT call GetComponent<Text>() each time you want to access/modify text.
This is an extremely basic fact about Unity.
It is immediately mentioned in the relevant manual entries.
Since you have 8 textbox and I don't know how long you update each one. It would be good if you cache all of them in the beginning of the game then use them later on without GetComponent<Text>(). This will improve performance a lot and make your frame-rate happy.
Array looks good for something like this. And you need to comment each one too.
public Text[] textBoxArray;
On the editor, Expand the "Text Box Array" and change the array Size to 8.
Now drag each GameObject with the text to the arrays in order. If you do it in order, you can easily remember their names and be able to access them in order.
For example, if the first text gameobecjt you dragged to the array is called text_name, the access it, you use textBoxArray[0]. The second text which is text_age can be accessed with textBoxArray[1]. .....
To make it easier for you later on, you should have multiple line comment that describes which array points to what.You do this so that when you return to modify your code months after, you won't have to look around in the Editor to find what points to what. For example:
/*
textBoxArray[0] = text_name
textBoxArray[1] = text_age
textBoxArray[2] = text_role
textBoxArray[3] = text_field
*/
No performance lost and that decreases the amount of code in your game.
Initializing the arrays by code instead of the Editor
Assuming you want to initialize the arrays by code instead of the Editor. You can do it in the start function like below.
public Text[] textBoxArray;
void Start()
{
//Create arrays of 8
textBoxArray = new Text[8]; //8 texts
//Cache all the Text GameObjects
textBoxArray[0] = GameObject.Find("/infopanel/text_name").GetComponent<Text>();
textBoxArray[1] = GameObject.Find("/infopanel/text_age").GetComponent<Text>();
textBoxArray[2] = GameObject.Find("/infopanel/text_role").GetComponent<Text>();
textBoxArray[3] = GameObject.Find("/infopanel/text_field").GetComponent<Text>();
}
You should notice that GameObject.Find() starts with "/" and that increases performance too as it will only search for Texts under "infopanel" instead of searching in the whole scene.
Assuming that your hierarchy is setup that all your TextMeshes are children of the panel, you could use the Transform.Find method to get each child, then it's TextMesh, and assign a value.
So, for example, if you wanted to assign the value "Joe" to the TextMesh attached to "text_name", which in turn is a child of "infopanel", you could do the following
panel_info = GameObject.Find("infopanel");
panel_info.transform.Find("text_name").GetComponent<TextMesh>().text = "Joe";

Bokeh - How to use box tool without default selections?

I have built a bokeh app that allows users to select windows in data and run python code to find and label (with markers) extreme values within these limits. For ease of interaction, I use the box select tool for the range selection. My problem arises when repeating this process for subsequent cases. After markers are placed for the results, they are rendered invisible by setting alpha to zero and another case needs to be chosen. When the new select box includes previous markers, they become visible based on the selection. How do I override this default behavior? Can markers be made unselectable? or can I add code to the customJS to hide them after they are selected?
Thanks in advance for any help!
There are a few possible approaches. If you just want non-selected glyphs to "disappear" visually, you can set a policy to do that as described here:
http://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs
Basically, for bokeh.plotting, pass
nonselection_fill_alpha=0.0,
nonselection_line_alpha=0.0,
as arguments to your plot.circle call or whatever. Or if you are using the low level bokeh.models interface, something like:
renderer.nonselection_glyph = Circle(fill_alpha=0.0, line_alpha=0.0)
But be aware (I think you already are) that the invisible markers are still there, and still selectable if the user happens to draw a box over them with the selection tool.
If you truly want only a subset of the data to be visible and selectable after a selection, I'd say you want to replace the data in the column data source wholesale with the subset in your selection callback.

How to highlight first node of GtkTreeView

I would like to highlight the first node of a GtkTreeView and give that node the focus. gtk_tree_view_row_activated () seems appropriate for what I am trying to do, but I couldn't figure out the arguments it takes.
Thanks in advance.
gtk_tree_view_row_activated() actually acts on just one cell. I wonder if you really want to Highlight the row or just select it. I.e. if you want to leave the highlight even if the cursor is on another line.
If that's the case, note that you can define extra fields in the underlying model, for example, if you have 3 fields for your data, you can add field 4 with a color. Then you can tell the renderer to use the color in field 4 (instead of giving the renderer the color immediately).
This example not only changes the background, but also the text color:
http://faq.pygtk.org/index.py?req=show&file=faq13.031.htp
For more sophisticated work, you can even modify the atributes on a cell-per-cell basis:
http://www.pygtk.org/docs/pygtk/class-gtktreeviewcolumn.html#method-gtktreeviewcolumn--set-cell-data-func
Use set_cursor method:
TextView.set_cursor(0,None,False)
0 = Index of the first row

Text not fitting into form fields (iTextSharp)

I created a .PDF file using Adobe Acrobat Pro. The file has several text fields. Using iTextSharp, I'm able to populate all the fields and mail out the .PDF.
One thing is bugging me - some of the next will not "fit" in the textbox. In Adobe, if I type more that the allocated height, the scroll bar kicks in - this happens when font size is NOT set to auto and multi-line is allowed.
However, when I attempt to set the following properties:
//qSize is float and set to 15;
//auto size of font is not being set here.
pdfFormFields.SetFieldProperty("notification_desc", "textsize", qSize, null);
// set multiline
pdfFormFields.SetFieldProperty("notification_desc", "setfflags", PdfFormField.FF_MULTILINE, null);
//fill the field
pdfFormFields.SetField("notification_desc", complaintinfo.OWNER_DESC);
However upon compilation and after stamping, the scroll bar does not appear in the final .PDF.
I'm not sure if this is the right thing to do. I'm thinking that perhaps I should create a table and flood it with the the text but the documentation makes little or no reference to scroll bars....
When you flatten a document, you remove all interactivity. Expecting working scroll bars on a flattened form, is similar to expecting working scroll bars on printed paper. That's why you don't get a lot of response to your question: it's kind of absurd.
When you fill out a rectangle with text, all text that doesn't fit will be omitted. That's why some people set the font size to 0. In this case, the font size will be adapted to make the text fit. I don't know if that's an option for you as you clearly state that the font size must be 15 pt.
If you can't change the font size, you shouldn't expect the AcroForm form field to adapt itself to the content. ISO-32000-1 is clear about that: the coordinates of a text field are fixed.
Your only alternative is to take control over how iText should fill the field. I made an example showing how to do this in the context of my book: MovieAds.java/MovieAds.cs. In this example, I ask the field for its coordinates:
AcroFields.FieldPosition f = form.GetFieldPositions(TEXT)[0];
This object gives you the page number f.page and a Rectangle f.position. You can use these variables in combination with ColumnText to add the content exactly the way you want to (and to check if all content has been added).
I hope you understand that:
it's only normal that there are no scroll bars on a flattened form,
the standard way of filling out fields clips content that doesn't fit,
you need to do more programming if you want a custom result.
For more info: please consult "iText in Action - Second Edition".