Make Label Displayed Inside a Vertex Box (jgraphx library) - java

I need my vertex label displayed entirely inside vertex bounds. I mean if my label is too long then part of it will be displayed outside the vertex box. Is there any way to automatically split label into multiple lines and make it fit the vertex bounds? This line breaks should be recalculated after vertex resize. Can i do it using styles? mxUtils.wordWrap() seems to be the way but i cannot figure out how to use it properly. Give me an example of using it please. Thanks for your answers

Another similar question: Calculate the display width of a string in Java
Abstract:
Graphics.getFontMetrics + FontMetrics.stringWidth
From this, I suppose you could create a List<String> and add the words of the text one at a time until you reach your max length, then add a new node to the list for the overflow. Finally, append each node in the List to each other with a line break in between.
On another note, from what research I did, it seems jGraphX runs on swing. Swing now supports HTML. Here's a link to further info: http://docs.oracle.com/javase/tutorial/uiswing/components/html.html.
I will see if I can get a quick test coded up, but that must wait until I get home.

Related

Letting users change array values by dragging a plot line in java

I have a bit of a tricky question. I have an ArrayList with double values in it. I would like the users to be able to change these values easily.
Ideally I want to display the array as a line plot and allow users to drag the line. When they click ok, the new line is accepted and saved as an arraylist again.
I have worked with java quite a bit, but I don't know how I can make a draggable line plot and use that as input. Any suggestions are highly valued!
It doesn't even necessarily need to be java. Could be something web based that I could call from java...

Using the Java StarTeam API, how can I find which revisions of a StarTeam Item have a certain label?

I'm using the StarTeam java API (v10.4).
I am having a heckuva time trying to find which specific revisions a Label is applied to. What makes this tricky is that there seems to be no method on the Label object which provides a list of what that label is applied to.
So you (seemingly) need to go backwards and find a list of items that you want to check for a particular Label, e.g.
int[] check_these_items = new int[]{ item_to_check.getID() };
int[] labelledItems = myLabel.getLabeledItemIDs(check_these_items)
First, that's kind of convoluted because you need to have a Label in the first place when really what I wanted was to get a list of labels attached to a single revision. But ok, let's go with that for now. So now I need to find a single revision from the history. Let's make this simple and say I want to get the third (or fourth) revision:
Item specific_child = item_to_check.getHistory()[3];
Now the problem is that this new child from history has the same ID (via getID()) as the parent so using getLabeledItemIds(check_these_items) will return the same labels and essentially, we haven't gotten anywhere.
I did find a question related to finding past revisions but it wasn't pertaining to finding labels on past revisions.
Of course, I checked Borland's API documentation but have not come up with the solution.
I know the UI can do it so certainly there is way, I'm just having a time finding it.
Any suggestions even at a high-level would be greatly appreciated!
Once you have the Item and the Label at hand, use getFromHistoryByLabelID(int)
to "Returns the specified version of this item based on the given label ID"
This still doesn't seem like the right answer, but eventually I had to move on and ended up using a workaround of finding the revision date/time of the label I wanted and then comparing the item revision to that. So by that type of reverse logic, I was able to check each label attached to the element and find which revisions had that label.

is that possible to built a simple text editor in java without using JTextArea?

I have questions according to my final project in my IT Faculty.. I have to make A simple text editor (like notepad) without using JTextArea (GUI Java), I have to make my own JTextArea..
Idea/Topic= Own Text Editor
Algorithms= doesnt have any idea yet
Data Structure= Rope(Member of Binary Trees)
Requirement= Typing without JTextArea...
Is that possible to make that? Can a panel (or something else like that) has a listener or make a listener to do that?
simply thinking, First step I just want to try for typing on a panel, absolutely algorithms needed but i dont get right algorithms so far.. Is that possible?
My thinking is, for text that im typing is stored to a tree.. Is that Rope(Member of Binary Trees) for my data Structure?
Thanks for helping...
It's possible.
Use as you mentioned JPanel attaching KeyListener and MouseListener.
You need a model (Document). For simplest case it could be e.g StringBuilder where you can add content and show the StringBuilder content.
You need caret position (int field) to indicate where the edit should happen.
You need Font field to keep all the font info to be used in the editor.
Override paintComponent() and use FontMetrics to measure the text and calculate necessary width/height. For the start I would create a text area without line wrap.
Implement viewToModel/modelToView methods. They should calculate position of caret for given x,y and x,y for given caret position.

JList: Horizontal_WRAP fitted?

Hey,.. i wanna show pictures with names onit in a jList, i know it get's also in a JPanel but i'm now using a jList, doesn't matter..
My question is why does the jlist don't fit the images only in 2 horizontal 'cells' and then go one row down?
sry my english is bad and i don't know how to describe it better, but look on the picture, why does the jlist dont set the e.g. 3rd picture right next to the 2nd?
JList.HORIZONTAL_WRAP works correctly in the ListDialog JWS demo, as described in Initializing a List. I suspect a layout problem, but you might compare your code to the examples found there.
If you use HORIZONTAL_WRAP you can adjust the number of columns with setVisibleRowCount. If you want them automatically fitted to the width of the list, use 0 or something negative.

JList strike through

I have a list of data in a JList component in my GUI.
I would like to know if there is a method that i can call on the list element(s) to strike through a particular element in the list. I would like to draw a line through the element to appear as if that element is canceled.
I want a similar thing like the strike through functionality in Microsoft Word document whereby a line i drawn through the text.
thanks for your help
You can apply html formating to each element of a list. Therefore if you know what element you want struck through you can modify the string held by that element as such:
<html><strike>this text will be struck through</strike></html>
Edit: I should note that I haven't tested this so if the strike tag isn't supported in Java try just s. One of those should work
JIDE Common Layer has a StyledListCellRenderer that can be used to provide this functionality.

Categories