Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
Protos
Nomad 3D
nomad-3d-editor
Commits
b5b71cb8
Commit
b5b71cb8
authored
Feb 08, 2019
by
legoc
Browse files
Manage the expanded state of the tree items
parent
5958a67e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/ill/ics/n3d/Nomad3DEditor.java
View file @
b5b71cb8
package
fr.ill.ics.n3d
;
import
java.io.File
;
import
java.util.HashMap
;
import
java.util.Optional
;
import
java.util.logging.FileHandler
;
import
java.util.logging.Level
;
...
...
@@ -36,10 +37,11 @@ import javafx.scene.Scene;
import
javafx.scene.SceneAntialiasing
;
import
javafx.scene.SubScene
;
import
javafx.scene.control.Alert
;
import
javafx.scene.control.Alert.AlertType
;
import
javafx.scene.control.ButtonType
;
import
javafx.scene.control.MenuBar
;
import
javafx.scene.control.TreeItem
;
import
javafx.scene.control.TreeView
;
import
javafx.scene.control.Alert.AlertType
;
import
javafx.scene.input.KeyCode
;
import
javafx.scene.layout.BorderPane
;
import
javafx.scene.layout.StackPane
;
...
...
@@ -379,6 +381,7 @@ public class Nomad3DEditor extends Application {
buildCamera
();
TreeView
<
Component
>
hierarchyView
=
buildHierarchyView
();
this
.
pane
=
new
BorderPane
();
pane
.
setTop
(
buildMenuBar
());
...
...
@@ -415,10 +418,20 @@ public class Nomad3DEditor extends Application {
/**
* Builds the hierarchy view.
* @return The tr
r
e view.
* @return The tr
e
e view.
*/
private
TreeView
<
Component
>
buildHierarchyView
()
{
TreeView
<
Component
>
hierarchyView
=
(
model
!=
null
&&
model
.
getRoot
()
!=
null
)
?
new
TreeView
<
Component
>(
model
.
getRoot
().
getTreeItem
())
:
new
TreeView
<
Component
>();
TreeView
<
Component
>
hierarchyView
=
null
;
if
((
model
!=
null
&&
model
.
getRoot
()
!=
null
))
{
hierarchyView
=
new
TreeView
<
Component
>(
model
.
getRoot
().
getTreeItem
());
expandTreeView
(
model
.
getRoot
().
getTreeItem
());
}
else
{
hierarchyView
=
new
TreeView
<
Component
>();
}
hierarchyView
.
setEditable
(
true
);
hierarchyView
.
setMinWidth
(
100
);
hierarchyView
.
setPrefWidth
(
300
);
...
...
@@ -584,4 +597,73 @@ public class Nomad3DEditor extends Application {
}
});
}
/**
* Expands all the tree item hierarchy.
* @param item The item to begin.
*/
public
void
expandTreeView
(
TreeItem
<
Component
>
item
)
{
if
(
item
!=
null
&&
!
item
.
isLeaf
())
{
item
.
setExpanded
(
true
);
for
(
TreeItem
<
Component
>
child
:
item
.
getChildren
())
{
expandTreeView
(
child
);
}
}
}
/**
* Gets the current expanded state of the tree item hierarchy.
* @param item The item to begin.
* @param states The map to save the states.
*/
private
void
getTreeViewExpandedStates
(
TreeItem
<
Component
>
item
,
HashMap
<
String
,
Boolean
>
states
)
{
if
(
item
!=
null
&&
!
item
.
isLeaf
())
{
states
.
put
(
item
.
getValue
().
getName
(),
item
.
expandedProperty
().
getValue
());
for
(
TreeItem
<
Component
>
child
:
item
.
getChildren
())
{
getTreeViewExpandedStates
(
child
,
states
);
}
}
}
/**
* Gets the current expanded state of the tree item hierarchy.
* @param item The item to begin.
* @return The map of the states.
*/
public
HashMap
<
String
,
Boolean
>
getTreeViewExpandedStates
(
TreeItem
<
Component
>
item
)
{
HashMap
<
String
,
Boolean
>
states
=
new
HashMap
<>();
getTreeViewExpandedStates
(
item
,
states
);
return
states
;
}
/**
* Expands all the tree item hierarchy following the initial states map.
* @param item The item to begin.
* @param states The map of the states.
*/
public
void
expandTreeView
(
TreeItem
<
Component
>
item
,
HashMap
<
String
,
Boolean
>
states
)
{
if
(
item
!=
null
&&
!
item
.
isLeaf
())
{
String
componentName
=
item
.
getValue
().
getName
();
if
(
states
.
containsKey
(
componentName
))
{
item
.
setExpanded
(
states
.
get
(
componentName
));
}
else
{
item
.
setExpanded
(
true
);
}
for
(
TreeItem
<
Component
>
child
:
item
.
getChildren
())
{
expandTreeView
(
child
,
states
);
}
}
}
}
src/main/java/fr/ill/ics/n3d/gui/EditorMenuBar.java
View file @
b5b71cb8
...
...
@@ -5,6 +5,7 @@ import java.nio.file.Files;
import
java.nio.file.Path
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.Optional
;
...
...
@@ -702,8 +703,6 @@ public class EditorMenuBar extends MenuBar {
// Do not save the operation if the axis is the same.
if
(!
selectedAxis
.
equals
(
initialAxis
))
{
System
.
out
.
println
(
"Axis modified"
);
// Stop the build.
Nomad3DEditor
.
getInstance
().
getAxisBuilder
().
stop
(
selectedComponent
);
...
...
@@ -745,9 +744,6 @@ public class EditorMenuBar extends MenuBar {
// Change the title.
updateModified
(
true
);
}
else
{
System
.
out
.
println
(
"Axis NOT modified"
);
}
Nomad3DEditor
.
getInstance
().
getModel
().
clearSelection
();
updateScene
();
...
...
@@ -2415,12 +2411,19 @@ public class EditorMenuBar extends MenuBar {
if
(!
modelLoaded
())
{
return
;
}
// Save the expanded state of the tree items.
HashMap
<
String
,
Boolean
>
itemStates
=
Nomad3DEditor
.
getInstance
().
getTreeViewExpandedStates
(
Nomad3DEditor
.
getInstance
().
getModel
().
getRoot
().
getTreeItem
());
Nomad3DEditor
.
getInstance
().
getModel
().
clearSelection
();
Nomad3DEditor
.
getInstance
().
getRoot
().
getChildren
().
remove
(
Nomad3DEditor
.
getInstance
().
getModel
().
getRoot
().
getSceneNode
());
Nomad3DEditor
.
getInstance
().
getModel
().
computeSceneHierarchies
(
activeLod
);
Nomad3DEditor
.
getInstance
().
getRoot
().
getChildren
().
add
(
Nomad3DEditor
.
getInstance
().
getModel
().
getRoot
().
getSceneNode
());
((
TreeView
<
Component
>)
Nomad3DEditor
.
getInstance
().
getPane
().
getLeft
()).
setRoot
(
Nomad3DEditor
.
getInstance
().
getModel
().
getRoot
().
getTreeItem
());
// Restore the expanded state of the tree items.
Nomad3DEditor
.
getInstance
().
expandTreeView
(
Nomad3DEditor
.
getInstance
().
getModel
().
getRoot
().
getTreeItem
(),
itemStates
);
updateAxes
();
updateWalls
();
updateSystem
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment