Implement Path Navigation bar (Breadcrumb bar) control [closed] - javafx

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to generate an UI where someone can navigate through the path of a tree structure. Here is an example of what I want, taken from JavaFX Scene Builder.
Depending on the actual position in an TreeView, this UI is updated. By clicking on individual items the tree is updated.
My question:
What Nodes/Controls are best used for this approach? (no full code required. Just mention the name of the controls).
My first idea is to generate a row of buttons closely to each other, but maybe there are better ideas.
Thanks.

You can use ControlsFx's BreadCrumbBar
Pane root = ...
Label selectedCrumbLbl = new Label();
BreadCrumbBar<String> sampleBreadCrumbBar = new BreadCrumbBar<>();
root.getChildren().addAll(sampleBreadCrumbBar, selectedCrumbLbl);
TreeItem<String> model = BreadCrumbBar.buildTreeModel("Hello", "World", "This", "is", "cool");
sampleBreadCrumbBar.setSelectedCrumb(model);
sampleBreadCrumbBar.setOnCrumbAction(new EventHandler<BreadCrumbBar.BreadCrumbActionEvent<String>>() {
#Override public void handle(BreadCrumbActionEvent<String> bae) {
selectedCrumbLbl.setText("You just clicked on '" + bae.getSelectedCrumb() + "'!");
}
});
https://github.com/controlsfx/controlsfx/blob/master/controlsfx-samples/src/main/java/org/controlsfx/samples/button/HelloBreadCrumbBar.java

The chosen solution did not work for me. I had to listen to the selectedCrumbProperty.
TreeItem<String> helloView = new TreeItem("Hello");
TreeItem<String> worldView = new TreeItem("World");
hellowView.getChildren().add(worldView);
TreeItem<String> thisView = new TreeItem("This");
worldView.getChildren().add(thisView);
TreeItem<String> isView = new TreeItem("is");
thisView.getChildren().add(isView);
BreadCrumbBar<String> sampleBreadCrumbBar = new BreadCrumbBar<>(helloView);
sampleBreadCrumbBar.setSelectedCrumb(helloView);
sampleBreadCrumbBar.selectedCrumbProperty().addListener((observable, oldValue, newValue) -> {
System.out.println(newValue);
if (newValue == worldView) {
//load this view
}
});
I typed this directly into the answer. There may be errors. Leave a note.

Related

JavaFx cursor measurement [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I'm designing a small system that should be able to locate itself in the real world, it's basically an electric RC car with a PC mounted on it. This car should be able to navigate in the real world and know where it is on a map. Since it needs a good precision, GPS isn't an option (the best I can get is 4 meters, way over what I can accept) and encoding the wheels in any way is too expensive for my budget, so the workaround is to place a mouse under this car and use its feedback as the relative positioning system.
My first idea was to calculate the difference in the pixel distance between two instants (using a timer), I even tried to apply the same principle using the mouseMoved event, but the problem is still there: if I vary the speed of the mouse, the calculated distance varies too.
At this point I have no other ideas, what do you think is wrong with my approach?
public class Main extends Application {
public static void main(String args[]) {
launch(args);
}
private double cmToPixel = 1;
private int totalX;
private int totalY;
private Robot robot;
private int counter;
#Override
public void start(Stage primaryStage) throws Exception {
VBox pane = new VBox();
pane.setFillWidth(false);
pane.setMinWidth(200);
javafx.scene.control.TextArea textArea = new TextArea();
javafx.scene.control.TextArea logArea = new TextArea();
javafx.scene.control.TextArea debugArea = new TextArea();
pane.getChildren().addAll(textArea, logArea, debugArea);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.centerOnScreen();
robot = new Robot();
robot.mouseMove((int) (Screen.getPrimary().getBounds().getWidth() / 2), (int) (Screen.getPrimary().getBounds().getHeight() / 2));
scene.setOnMouseMoved(e -> {
double deltaX = e.getX() - Screen.getPrimary().getBounds().getWidth() / 2;
double deltaY = Screen.getPrimary().getBounds().getHeight() / 2 - e.getY() ;
totalX += deltaX;
totalY += deltaY;
textArea.appendText((totalX / cmToPixel) + " - " + (totalY / cmToPixel) + "\n");
debugArea.appendText(deltaX+" - "+deltaY+"\n");
logArea.appendText("Center: ["+(int) (Screen.getPrimary().getBounds().getWidth() / 2)+";"+(int) (Screen.getPrimary().getBounds().getHeight() / 2)+"] cursorPosition: "+e.getX()+" - "+e.getY()+"\n");
robot.mouseMove((int) (Screen.getPrimary().getBounds().getWidth() / 2), (int) (Screen.getPrimary().getBounds().getHeight() / 2));
});
primaryStage.show();
primaryStage.setFullScreen(true);
}}
if you want to reproduce my results, just mark two lines on a piece of paper and try to run the mouse between those lines at different speeds while keeping an eye on the program
The reported distances of a mouse device depend on the speed at which you move the mouse. This is normally desired if a mouse is used for what it is made for but in your case this is a problem. I'd try to switch this feature of in your mouse settings. Maybe this link can help you.
https://askubuntu.com/questions/698961/disable-mouse-acceleration-in-ubuntu-15-10
If you're reading this post you may want to know that yes, the problem was with acceleration, and even when "disabled" something still doesn't work out, I solved this problem by connecting a PS2 mouse to an Arduino, and with JSSC I ask it the delta X and Y since last check (take a look here http://www.instructables.com/id/Optical-Mouse-Odometer-for-Arduino-Robot/)

How to migrate content from one alfresco repository to other using Open CMIS [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I want to migrate all alfresco repository contents from one repository to other. but i don't want the existing folder structure.
while migrating i have to validate the content according to some business requirement, and based on content type i have to create different folder structure in new repository.
Does any one did this previously.
Please help.
Thanks in Advance...
Ok, the solution that i give is not the best one, but i think it will work, we will start with a simple document and see if it's working (we will modifie the answer)
Getting the inputStram of a document
I think it's the most important part
public InputStream getTheInputStream () {
Document newDocument = (Document) getSession(serverURL, userName, password).getObject(path);
ContentStream cs = newDocument.getContentStream(null);
return cs.getStream();
}
Moving the inputStram from Server A to Server B
public void transfert() throws FileNotFoundException, IOException {
Session sessionB = getSession(serverUrlB, usernameB, passwordB);
//////////////////////////// GET THE FOLDER THAT YOU WILL WORK WITH
Folder root = sessionB.getRootFolder();
//////////////////////////// GET THE FOLDER THAT YOU WILL WORK WITH
File newfile = new File(fileName);
String nom = fileName;
Map<String, Object> properties = new HashMap<>();
properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
properties.put(PropertyIds.NAME, nom);
List<Ace> addAces = new LinkedList<>();
List<Ace> removeAces = new LinkedList<>();
List<Policy> policies = new LinkedList<>();
String extension = FilenameUtils.getExtension(nom);
ContentStream contentStream = new ContentStreamImpl("content." + extension, BigInteger.valueOf(nom).length()),
new MimetypesFileTypeMap().getContentType(newfile), (theInputStream);
Document dc = root.createDocument(properties, contentStream, VersioningState.MAJOR, policies, addAces, removeAces, sessionB.getDefaultContext());
}
Try this method and tell me if it's working, if you don't have the getSession method just look to this post get session method.

Javafx ComboBox list contents in sorted order

I'm trying to have a ComboBox list the contents in sorted order. I've come up with one solution, but it still has some issues.
final ObservableList<String> oal = FXCollections.observableArrayList();
final SimpleListProperty<String> slp = new SimpleListProperty<String>(oal);
final SortedList<String> sl = new SortedList<String>(slp, (string1, string2) -> {
return string1.compareTo(string2);
});
final ComboBox<String> comboBox = new ComboBox<String>();
comboBox.setItems(sl);
I can add values to OAL or SLP.
oal.addAll("cccc", "aaaa", "bbbb");
slp.addAll("ffff", "dddd", "eeee");
But if I try to add values to SL, it fails.
sl.addAll("iiii", "hhhh", "gggg");
Exception in thread "main" java.lang.UnsupportedOperationException
So of course any attempts to add values to comboBox also fail. Does anybody know a way to fix this, or is there a totally different approach to sorting the contents of the ComboBox?
I appreciate any help here.
I'm using Java 8u5.
Can't you just add items to the underlying list instead of the sorted list?
final ObservableList<String> comboBoxItems = FXCollections.observableArrayList();
final ComboBox<String> comboBox = new ComboBox<String>();
comboBox.setItems(new SortedList<String>(comboBoxItems, Collator.getInstance()));
And then just always add items to comboBoxItems.
I'm adding this as an answer as I don't have enough stackoverflow reputation to comment.
Be aware that there is currently (Java 8u92 and probably before) a bug JDK-8087838 that causes extra unwanted Combobox OnAction events to fire when adding items to an editable combobox when a SortedList is used instead of an ObservableList. This bug makes it difficult to properly code for the combobox events, so I suggest not using a SortedList until the bug is fixed. See also this stackoverflow question.

JavaFX architecture in building dynamic "rows"

I have an application that I am building that has a table in it, I'm not using a tableview to build this table because I need each row to be able to expand similar to an accordion. I was able to achieve what I need by using a timeline and looping through the data and building each row (its kind of crude right now since I'm still working with dummy data eventually it will be a list iterator and not just a for loop) but I'm not happy with how its done. There are a lot of default values that will never change so I don't really need to set them in my worker class every time, I decided to just add them to the object class that I put together. So basically, at a high level it looks something like this:
for (int i = 0; i < 30; i++) {
RowBuilder builder = new RowBuilder(tableBox, i);
try {
builder.run();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I'm passing it the parent which is a VBox - tableBox, then I'm passing the count for later use.
Inside the RowBuilder I'm getting a new instance of the object DashboardRow which has all the defaults set in it, then I'm setting the data for each row and returning the DashboardRow.
Here is an example of a getter setting values in the DashboardRow
public HBox getMainRow() {
mainRow.setAlignment(Pos.CENTER_LEFT);
mainRow.setPrefHeight(60);
mainRow.setMinHeight(60);
mainRow.setMaxHeight(60);
mainRow.setPrefWidth(-1);
mainRow.setStyle("-fx-background-color:#FFFFFF;");
return mainRow;
}
Inside the DashboardRow class I have a ton of new objects being created for every element I need in the row. There are 21 for each row, mostly VBox, HBox and StackPane to build the actual row, the rest are just labels and buttons.
This is what is looks like so far. Opened and closed states.
Is there a better way to dynamically build things like this in javafx? I'm basically pulling data from a database and looping through that data to populate a row.
I can't comment but it may be an answer anyway. Why can't you use the setGraphic method of a custom table cell and put the accordion node in a table. setGraphic takes any kind of node.
It sounds simpler than what you're doing.
I just tried it out with the Oracle sample and it works great.
I added
Callback<TableColumn<Person, String>, TableCell<Person, String>> accCellFactory
= new Callback<TableColumn<Person, String>, TableCell<Person, String>>() {
#Override
public TableCell call(TableColumn p) {
TitledPane t1 = new TitledPane("T1", new Button("B1"));
TitledPane t2 = new TitledPane("T2", new Button("B2"));
TitledPane t3 = new TitledPane("T3", new Button("B3"));
Accordion accordion = new Accordion();
accordion.getPanes().addAll(t1, t2, t3);
TableCell tc = new TableCell();
tc.setGraphic(accordion);
return tc;
}
};
and changed this line firstNameCol.setCellFactory(accCellFactory);
and I get
Of course you might want something other than buttons but I just copied the Accordion sample from the javadoc.

ASP.net - Dynamically displaying controls

I am developing Quiz project. In DetailsView I want to display the Question and answers.
The number of answers vary for question to question.Say example
1 ) C# Support
(i) Generics
(ii) LINQ
(iii)EntLib
2 ) Find the odd one
(i) DB2
(ii) Oracle
(iii)MS-Access
(iv) Sql Server
(v) Javascript
so i can not fix the number of radio buttons.Some questions may have multiple answers.so i need to display checkboxes instead of radio buttons.
My Question is how to generate Radio Buttons or Checkboxed Dynamically ?
Create a RadioButtonList or CheckBoxList for each question and use its Items collection to add the answers.
Very simple example in C#:
class Question
{
public string QuestionText;
public List<string> Answers;
}
protected void AddQuestionsToContainer(Control container, List<Question> questions)
{
foreach (Question q in questions)
{
var qt = new Label();
qt.Text = q.QuestionText;
container.Controls.Add(qt);
var rbl = new RadioButtonList();
foreach (string answer in q.Answers)
{
rbl.Items.Add(new ListItem(answer));
}
container.Controls.Add(rbl);
}
}
I think your question more specifically is how to decide which quiz question has multiple answers.
If I'm correct than you need to have an extra column like isMultipleAnswers BIT in the table in DB (or whatever the source is you need to have a flag for each question), and handle a event for the DetailView like DataBinding, check the value for this field, based on that either add RadioButtonList or CheckBoxList.
Hope this helps!
BTW, why aren't you using Repeater??

Resources