in code/debugger/src/main/kotlin/org/fbme/debugger/common/ui/DebuggerPanel.kt [256:323]
override fun getTreeCellRendererComponent(
tree: JTree?,
value: Any?,
selected: Boolean,
expanded: Boolean,
leaf: Boolean,
row: Int,
hasFocus: Boolean,
): Component {
val line = JPanel()
line.layout = BoxLayout(line, BoxLayout.X_AXIS)
val node = value as DefaultMutableTreeNode
if (node.parent != null) {
var path = node.userObject as String
var par = node.parent as DefaultMutableTreeNode
while (par.parent != null) {
val name = par.userObject as String
path = "$name.$path"
par = par.parent as DefaultMutableTreeNode
}
val selectedState = statesList.selectedValue?.state ?: error("no selected state")
val previousState =
statesListModel.items.getOrNull(statesList.selectedIndex - 1)?.state ?: selectedState
val pathAsList = path.split(".")
val watchDeclaration = when (declaration) {
is ResourceDeclaration -> declaration.resolvePath(pathAsList)
is FBTypeDeclaration -> declaration.resolvePath(pathAsList)
else -> error("Unsupported type")
}
line.add(JLabel(if (node.parent.parent == null) Icons.Watch else if (watchDeclaration is FBTypeDeclaration) AllIcons.Debugger.WatchLastReturnValue else AllIcons.Debugger.Value).apply {
verticalAlignment = CENTER
})
line.add(Box.createRigidArea(Dimension(5, 0)))
line.add(JLabel(node.userObject.toString()).apply {
initForeground(selected, hasFocus)
verticalAlignment = CENTER
})
when (watchDeclaration) {
is CompositeFBTypeDeclaration -> {}
is BasicFBTypeDeclaration -> {}
is StateDeclaration,
is ParameterDeclaration,
is EventDeclaration,
-> {
val curValue = selectedState.resolveValue(pathAsList)
val prevValue = previousState.resolveValue(pathAsList)
val isValueChanged = curValue != prevValue
line.add(JLabel(": ").apply {
initForeground(selected, hasFocus)
verticalAlignment = CENTER
})
line.add(JLabel("$curValue").apply {
initForeground(selected, hasFocus, isValueChanged)
verticalAlignment = CENTER
})
}
}
}
return line
}