下面列出了javafx.scene.Node#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public EventHandler<Event> viewerHandler(final PainteraBaseView paintera, final KeyTracker keyTracker) {
return event -> {
final EventTarget target = event.getTarget();
if (!(target instanceof Node))
return;
Node node = (Node) target;
LOG.trace("Handling event {} in target {}", event, target);
// kind of hacky way to accomplish this:
while (node != null) {
if (node instanceof ViewerPanelFX) {
handlers.computeIfAbsent((ViewerPanelFX) node, k -> this.makeHandler(paintera, keyTracker, k)).handle(event);
return;
}
node = node.getParent();
}
};
}
private void updateDisclosureNode() {
Node disclosureNode = ((JFXTreeTableCell<S, T>) getSkinnable()).getDisclosureNode();
if (disclosureNode != null) {
TreeItem<S> item = getSkinnable().getTreeTableRow().getTreeItem();
final S value = item == null ? null : item.getValue();
boolean disclosureVisible = value != null
&& !item.isLeaf()
&& value instanceof RecursiveTreeObject
&& ((RecursiveTreeObject) value).getGroupedColumn() == getSkinnable().getTableColumn();
disclosureNode.setVisible(disclosureVisible);
if (!disclosureVisible) {
getChildren().remove(disclosureNode);
} else if (disclosureNode.getParent() == null) {
getChildren().add(disclosureNode);
disclosureNode.toFront();
} else {
disclosureNode.toBack();
}
if (disclosureNode.getScene() != null) {
disclosureNode.applyCss();
}
}
}
/**
* A tricky workaround to get the real plot view hidden behind its content views (Bezier curve, dots, etc.).
* If the view has a ViewPlot as its user data, this view plot is returned. The source view is returned otherwise.
* setMouseTransparency cannot be used since the mouse over would not work anymore.
* @param view The view to check. Cannot be null.
* @return The given view or the plot view.
*/
private static ViewShape<?> getRealViewShape(final ViewShape<?> view) {
if(view == null) {
return null;
}
// Checking whether the shape is not part of another shape
ViewShape<?> currView = view;
while(currView.getUserData() instanceof ViewShape) {
currView = (ViewShape<?>) currView.getUserData();
}
// Checking whether the shape is not part of a group
Node parent = currView;
while(parent.getParent() != null && !(parent.getParent() instanceof ViewGroup)) {
parent = parent.getParent();
}
if(parent.getParent() instanceof ViewGroup) {
return (ViewShape<?>) parent.getParent();
}
return currView;
}
public static boolean isParent(Parent parent, Node child) {
if (child == null) {
return false;
}
Parent curr = child.getParent();
while (curr != null) {
if (curr == parent) {
return true;
}
curr = curr.getParent();
}
return false;
}
@MustCallOnJavaFXThread
private Optional<LogViewWrapper> getFocusedView() {
Node node = pane.getScene().focusOwnerProperty().get();
// go up in the hierarchy until we find a wrapper, or just hit null
while ( node != null && !( node instanceof LogViewWrapper ) ) {
node = node.getParent();
}
if ( node != null ) {
return Optional.of( ( LogViewWrapper ) node );
} else {
return Optional.empty();
}
}
private Node getTargetNode( Object objectTarget ) {
if ( objectTarget instanceof Node ) {
Node target = ( Node ) objectTarget;
// try to go up in the hierarchy until we find a selectable node or the root node
while ( target != root && !( target instanceof SelectableNode ) ) {
target = target.getParent();
}
return target;
} else {
return root;
}
}
/** @param node Node from which to remove focus */
public static void removeFocus(Node node)
{
// Cannot un-focus, can only focus on _other_ node.
// --> Find the uppermost node and focus on that.
Node parent = node.getParent();
if (parent == null)
return;
while (parent.getParent() != null)
parent = parent.getParent();
parent.requestFocus();
}
protected void initRootView(Node node){
Node parent = node.getParent();
Node notNullParent = node;
while(parent != null){
notNullParent = parent;
parent = parent.getParent();
}
mRootView = notNullParent;
}
public SVRemoteNodeAdapter(final Node node, final boolean collapseControls, final boolean collapseContentControls, final boolean fillChildren, final SVRemoteNodeAdapter parent) {
super(ConnectorUtils.nodeClass(node), node.getClass().getName());
boolean mustBeExpanded = !(node instanceof Control) || !collapseControls;
if (!mustBeExpanded && !collapseContentControls) {
mustBeExpanded = node instanceof TabPane || node instanceof SplitPane || node instanceof ScrollPane || node instanceof Accordion || node instanceof TitledPane;
}
setExpanded(mustBeExpanded);
this.id = node.getId();
this.nodeId = ConnectorUtils.getNodeUniqueID(node);
this.focused = node.isFocused();
if (node.getParent() != null && parent == null) {
this.parent = new SVRemoteNodeAdapter(node.getParent(), collapseControls, collapseContentControls, false, null);
} else if (parent != null) {
this.parent = parent;
}
/**
* Check visibility and mouse transparency after calculating the parent
*/
this.mouseTransparent = node.isMouseTransparent() || (this.parent != null && this.parent.isMouseTransparent());
this.visible = node.isVisible() && (this.parent == null || this.parent.isVisible());
/**
* TODO This should be improved
*/
if (fillChildren) {
nodes = ChildrenGetter.getChildren(node)
.stream()
.map(childNode -> new SVRemoteNodeAdapter(childNode, collapseControls, collapseContentControls, true, this))
.collect(Collectors.toList());
}
}
/**
* Gets the closest ancestor (e.g. parent, grandparent) to a node that is a subclass of {@link Region}.
*
* @param node a JavaFX {@link Node}
* @return the node's closest ancestor that is a subclass of {@link Region}, or {@code null} if none exists
*/
private Region getContainer(final Node node) {
final Parent parent = node.getParent();
if (parent == null) {
return null;
} else if (parent instanceof Region) {
return (Region) parent;
} else {
return getContainer(parent);
}
}
private static void setConstraint(Node node, Object key, Object value) {
if (value == null) {
node.getProperties().remove(key);
} else {
node.getProperties().put(key, value);
}
if (node.getParent() != null) {
node.getParent().requestLayout();
}
}
public static <T> T findParentOfType( Node node, Class<T> type ){
if( node == null ) return null;
Parent parent = node.getParent();
if( parent == null ) return null;
if( type.isAssignableFrom(parent.getClass()) ) return (T)parent;
return findParentOfType( parent, type );
}
private boolean isChildOf(Node node) {
Node parent = getParent();
while (parent != null) {
parent = parent.getParent();
if (parent == node) {
return true;
}
}
return false;
}
/**
* Update error list, hiding it if no errors are found.
*/
protected void toggleErrorDisplay() {
Node content = errorList;
while (!(content instanceof SplitPane) && content != null)
content = content.getParent();
if (content == null)
return;
SplitPane parent = (SplitPane) content;
if(problems.isEmpty())
parent.setDividerPositions(1);
else if(parent.getDividerPositions()[0] > 0.98)
parent.setDividerPositions(DEFAULT_ERROR_DISPLAY_PERCENT);
}
/**
* Handle a click to a tab.
*/
private void processMouseClick(@NotNull final MouseEvent event) {
final EventTarget target = event.getTarget();
if (!(target instanceof Node)) return;
final Node node = (Node) target;
if (!(node instanceof Text) || node.getStyleClass().contains("tab-container")) {
return;
}
final Parent label = node.getParent();
if (!(label instanceof Label)) {
return;
}
final Parent tabContainer = label.getParent();
if (!tabContainer.getStyleClass().contains("tab-container")) {
return;
}
if (isChangingTab()) {
setChangingTab(false);
return;
}
processExpandOrCollapse();
}
private static boolean isContainedInHierarchy(Node container, Node node) {
Node candidate = node;
do {
if (candidate == container) {
return true;
}
candidate = candidate.getParent();
} while (candidate != null);
return false;
}
public static InternalWindow resolveInternalWindow(Node node) {
if (node == null) {
return null;
}
Node candidate = node;
while (candidate != null) {
if (candidate instanceof InternalWindow) {
return (InternalWindow) candidate;
}
candidate = candidate.getParent();
}
return null;
}
protected List<IJavaFXElement> found(List<IJavaFXElement> pElements, IJavaFXAgent driver) {
List<IJavaFXElement> r = new ArrayList<IJavaFXElement>();
for (IJavaFXElement je : pElements) {
Node component = je.getComponent();
if (!(component instanceof Parent)) {
continue;
}
int index = getIndexOfComponentInParent(component);
if (index < 0) {
continue;
}
Parent parent = component.getParent();
JFXWindow topContainer = driver.switchTo().getTopContainer();
index += 1;
if (index < parent.getChildrenUnmodifiable().size()) {
Node c = parent.getChildrenUnmodifiable().get(index);
IJavaFXElement je2 = JavaFXElementFactory.createElement(c, driver, driver.switchTo().getTopContainer());
List<IJavaFXElement> matched = sibling.matchesSelector(je2);
for (IJavaFXElement javaElement : matched) {
IJavaFXElement e = topContainer.addElement(javaElement);
if (!r.contains(e)) {
r.add(e);
}
}
}
}
return r;
}
/**
* Checks if the given connection is behind this one.
*
* @param other another {@link GConnection} instance
* @return {@code true} if the given connection is behind this one
*/
private boolean checkIfBehind(final GConnection other) {
final Node node = skinLookup.lookupConnection(connection).getRoot();
final Node otherNode = skinLookup.lookupConnection(other).getRoot();
if (node.getParent() == null) {
return false;
} else {
final int connectionIndex = node.getParent().getChildrenUnmodifiable().indexOf(node);
final int otherIndex = node.getParent().getChildrenUnmodifiable().indexOf(otherNode);
return otherIndex < connectionIndex;
}
}
protected void dump(Node n)
{
SB sb = new SB(4096);
sb.nl();
while(n != null)
{
sb.a(CKit.getSimpleName(n));
String id = n.getId();
if(CKit.isNotBlank(id))
{
sb.a(" #");
sb.a(id);
}
for(String s: n.getStyleClass())
{
sb.a(" .").a(s);
}
for(PseudoClass c: n.getPseudoClassStates())
{
sb.a(" :").a(c);
}
sb.nl();
if(n instanceof Text)
{
sb.sp(4);
sb.a("text: ");
sb.a(TextTools.escapeControlsForPrintout(((Text)n).getText()));
sb.nl();
}
CList<CssMetaData<? extends Styleable,?>> md = new CList<>(n.getCssMetaData());
sort(md);
for(CssMetaData d: md)
{
String k = d.getProperty();
Object v = d.getStyleableProperty(n).getValue();
if(shouldShow(v))
{
Object val = describe(v);
sb.sp(4).a(k);
sb.sp().a(val);
if(d.isInherits())
{
sb.a(" *");
}
sb.nl();
}
}
n = n.getParent();
}
D.print(sb);
}