Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show hex identity hashcode in node tree #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/org/fxconnector/ConnectorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public static String formatSize(final double size) {
return DFMT.format(size);
}

public static String nodeIdentityCode(final Object node) {
return Integer.toHexString(System.identityHashCode(node));
}

public static String nodeClass(final Object node) {
final String value = classNames.get(node.getClass());
if (value == null) {
Expand Down
121 changes: 67 additions & 54 deletions src/main/java/org/fxconnector/helper/WorkerThread.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,67 @@
/*
* Scenic View,
* Copyright (C) 2012 Jonathan Giles, Ander Ruiz, Amy Fowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.fxconnector.helper;

import org.scenicview.utils.ExceptionLogger;

public abstract class WorkerThread extends Thread {

protected boolean running = true;
protected final int sleepTime;

public WorkerThread(final String name, final int sleepTime) {
super(name);
setDaemon(true);
this.sleepTime = sleepTime;
}

public void finish() {
this.running = false;
interrupt();
}

@Override public void run() {
long sleepTime = 0;
while (running) {
try {
Thread.sleep(sleepTime);
work();
} catch (final Exception e) {
if (running) {
ExceptionLogger.submitException(e);
}
}
sleepTime = this.sleepTime;
}
}

protected abstract void work();
}
/*
* Scenic View,
* Copyright (C) 2012 Jonathan Giles, Ander Ruiz, Amy Fowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.fxconnector.helper;

import org.scenicview.utils.ExceptionLogger;

import java.util.concurrent.atomic.AtomicBoolean;

public abstract class WorkerThread extends Thread {

protected boolean running = true;
protected final int sleepTime;
protected AtomicBoolean workEnabled = new AtomicBoolean(true);

public WorkerThread(final String name, final int sleepTime) {
super(name);
setDaemon(true);
this.sleepTime = sleepTime;
}

public void finish() {
this.running = false;
interrupt();
}

@Override public void run() {
long sleepTime = 0;
while (running) {
try {
Thread.sleep(sleepTime);
if (isEnabled()) {
work();
}
} catch (final Exception e) {
if (running) {
ExceptionLogger.submitException(e);
}
}
sleepTime = this.sleepTime;
}
}

public void setEnabled(Boolean enabled) {
workEnabled.set(enabled);
}

public boolean isEnabled() {
return workEnabled.get();
}

protected abstract void work();
}
2 changes: 1 addition & 1 deletion src/main/java/org/fxconnector/node/SVDummyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SVDummyNode() {
}

public SVDummyNode(final String name, final String nodeClass, final int nodeID, final NodeType nodeType) {
super(nodeClass, null);
super(nodeClass, null, null);
this.name = name;
this.nodeID = nodeID;
this.nodeType = nodeType;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/fxconnector/node/SVNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface SVNode {

String getNodeClass();

String getNodeIdentityCode();

String getExtendedId();

SVNode getParent();
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/fxconnector/node/SVNodeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ abstract class SVNodeImpl implements SVNode, Serializable {
boolean expanded;
protected String nodeClass;
protected String nodeClassName;
protected String nodeIdentityCode;

protected SVNodeImpl() {

}

protected SVNodeImpl(final String nodeClass, final String nodeClassName) {
protected SVNodeImpl(final String nodeClass, final String nodeClassName, final String nodeIdentityCode) {
this.nodeClass = nodeClass;
this.nodeClassName = nodeClassName;
this.nodeIdentityCode = nodeIdentityCode;
}

@Override public final void setInvalidForFilter(final boolean invalid) {
Expand Down Expand Up @@ -74,4 +76,7 @@ protected SVNodeImpl(final String nodeClass, final String nodeClassName) {
return nodeClassName;
}

public String getNodeIdentityCode() {
return nodeIdentityCode;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/fxconnector/node/SVRealNodeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public SVRealNodeAdapter(final Node node) {
}

public SVRealNodeAdapter(final Node node, final boolean collapseControls, final boolean collapseContentControls) {
super(ConnectorUtils.nodeClass(node), node.getClass().getName());
super(ConnectorUtils.nodeClass(node), node.getClass().getName(), ConnectorUtils.nodeIdentityCode(node));
this.node = node;
this.collapseControls = collapseControls;
this.collapseContentControls = collapseContentControls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public SVRemoteNodeAdapter(final Node node, final boolean collapseControls, fina
}

public SVRemoteNodeAdapter(final Node node, final boolean collapseControls, final boolean collapseContentControls, final boolean fillChildren, final SVRemoteNodeAdapter parent) {
super(ConnectorUtils.nodeClass(node), node.getClass().getName());
super(ConnectorUtils.nodeClass(node), node.getClass().getName(), ConnectorUtils.nodeIdentityCode(node));
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;
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/org/scenicview/view/ScenegraphTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import javafx.scene.control.TreeView;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.WindowEvent;

import org.fxconnector.AppController;
Expand Down Expand Up @@ -86,11 +88,24 @@ public ScenegraphTreeView(final List<NodeFilter> activeNodeFilters, final Scenic
setCellFactory(node -> new TreeCell<SVNode>() {
@Override public void updateItem(final SVNode item, final boolean empty) {
super.updateItem(item, empty);

TreeItem<SVNode> treeItem = getTreeItem();
setGraphic(treeItem == null ? null : treeItem.getGraphic());

setText(item == null ? null : item.toString());
if (item != null) {
Text txtName = new Text(item.toString());
txtName.getStyleClass().add("text");
Text txtCode = new Text(item.getNodeIdentityCode());
txtCode.getStyleClass().add("text");
txtCode.getStyleClass().add("textIdentityCode");
HBox hbox = new HBox(5.0);
if (getTreeItem() != null) {
hbox.getChildren().add(getTreeItem().getGraphic());
}
hbox.getChildren().add(txtName);
hbox.getChildren().add(txtCode);
setGraphic(hbox);
} else {
setGraphic(null);
}
//setText(item == null ? null : item.toString());
setText(null);
setOpacity(1);

if (item == null) return;
Expand Down
Loading