use of javax.swing.tree.TreeNode in project n2a by frothga.
the class Move method apply.
public static void apply(List<String> path, int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
model.removeNodeFromParent(moveNode);
NodeBase metadataNode = parent.child("$metadata");
if (createOrder) {
if (metadataNode == null) {
metadataNode = new NodeAnnotations((MPart) parent.source.set("$metadata", ""));
model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
}
NodeBase orderNode = new NodeAnnotation((MPart) metadataNode.source.set("gui.order", ""));
model.insertNodeIntoUnfiltered(orderNode, metadataNode, metadataNode.getChildCount());
}
if (destroyOrder) {
NodeBase orderNode = metadataNode.child("gui.order");
FontMetrics fm = orderNode.getFontMetrics(tree);
metadataNode.source.clear("gui.order");
model.removeNodeFromParent(metadataNode.child("gui.order"));
if (metadataNode.getChildCount() == 0) {
parent.source.clear("$metadata");
model.removeNodeFromParent(metadataNode);
} else {
metadataNode.updateTabStops(fm);
metadataNode.allNodesChanged(model);
}
}
model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
TreeNode[] movePath = moveNode.getPath();
if (!destroyOrder)
mep.panelEquations.updateOrder(movePath);
mep.panelEquations.updateVisibility(movePath);
}
use of javax.swing.tree.TreeNode in project megameklab by MegaMek.
the class BayWeaponCriticalTree method addToBay.
/**
* Adds an equipment mount to a bay. Changes the equipment mount's location and updates the bay's
* weapon or ammo list if necessary.
*
* @param bay
* @param eq
*/
public void addToBay(@Nullable Mounted bay, Mounted eq) {
// Check that we have a bay
if ((null == bay) || !canTakeEquipment(bay, eq)) {
if (eq.getType() instanceof WeaponType) {
EquipmentType bayType = ((WeaponType) eq.getType()).getBayType();
addToNewBay(bayType, eq);
} else {
addToLocation(eq);
}
return;
} else if (eq.getType() instanceof MiscType) {
if (eq.getType().hasFlag(MiscType.F_ARTEMIS) || eq.getType().hasFlag(MiscType.F_ARTEMIS_PROTO) || eq.getType().hasFlag(MiscType.F_ARTEMIS_V)) {
for (Integer eqNum : bay.getBayWeapons()) {
final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
final WeaponType wtype = (WeaponType) weapon.getType();
if ((weapon.getLinkedBy() == null) && ((wtype.getAmmoType() == AmmoType.T_LRM) || (wtype.getAmmoType() == AmmoType.T_SRM) || (wtype.getAmmoType() == AmmoType.T_MML) || (wtype.getAmmoType() == AmmoType.T_NLRM))) {
moveToArc(eq);
eq.setLinked(weapon);
break;
}
}
} else if (eq.getType().hasFlag(MiscType.F_APOLLO) || eq.getType().hasFlag(MiscType.F_PPC_CAPACITOR)) {
for (Integer eqNum : bay.getBayWeapons()) {
final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
if (weapon.getLinkedBy() == null) {
moveToArc(eq);
eq.setLinked(weapon);
break;
}
}
}
} else {
// there.
if (eq.getType() instanceof AmmoType) {
Optional<Mounted> addMount = bay.getBayAmmo().stream().map(n -> eSource.getEntity().getEquipment(n)).filter(m -> m.getType() == eq.getType()).findFirst();
if (addMount.isPresent()) {
addMount.get().setShotsLeft(addMount.get().getBaseShotsLeft() + eq.getBaseShotsLeft());
UnitUtil.removeMounted(eSource.getEntity(), eq);
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
return;
}
}
EquipmentNode bayNode = null;
for (Enumeration<?> e = ((TreeNode) model.getRoot()).children(); e.hasMoreElements(); ) {
final EquipmentNode node = (EquipmentNode) e.nextElement();
if (node.getMounted() == bay) {
bayNode = node;
break;
}
}
if (null != bayNode) {
moveToArc(eq);
EquipmentNode eqNode = new EquipmentNode(eq);
model.insertNodeInto(eqNode, bayNode, bayNode.getChildCount());
eqNode.setParent(bayNode);
if (eq.getType() instanceof WeaponType) {
bay.addWeaponToBay(eSource.getEntity().getEquipmentNum(eq));
if (eq.getLinkedBy() != null) {
moveToArc(eq.getLinkedBy());
}
} else if (eq.getType() instanceof AmmoType) {
bay.addAmmoToBay(eSource.getEntity().getEquipmentNum(eq));
}
} else {
// $NON-NLS-1$
MegaMekLab.getLogger().log(// $NON-NLS-1$
BayWeaponCriticalTree.class, // $NON-NLS-1$
"addToBay(Mounted,Mounted)", LogLevel.DEBUG, // $NON-NLS-1$
bay.getName() + "[" + eSource.getEntity().getEquipmentNum(bay) + "] not found in " + // $NON-NLS-1$
getLocationName());
}
}
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
}
use of javax.swing.tree.TreeNode in project JWildfire by thargor6.
the class FlamePropertiesTreeService method selectPropertyPath.
public void selectPropertyPath(JTree pTree, FlamePropertyPath pPath) {
if (pPath != null) {
TreeNode selNode = null;
TreeNode root = (TreeNode) pTree.getModel().getRoot();
List<String> pathNodes = pPath.getPathComponents();
// skip root
if (pathNodes.size() > 0 && root != null && root.getChildCount() == 1) {
root = root.getChildAt(0);
int d = 0;
while (d < pathNodes.size()) {
boolean found = false;
for (int i = 0; i < root.getChildCount(); i++) {
TreeNode node = root.getChildAt(i);
if (node instanceof FlamePropertiesTreeNode) {
FlamePropertiesTreeNode<?> fNode = (FlamePropertiesTreeNode<?>) node;
if (pathNodes.get(d).equals(fNode.getUserObject())) {
root = node;
found = true;
break;
}
}
}
if (!found) {
break;
} else if (d == pathNodes.size() - 1) {
selNode = root;
}
d++;
}
if (selNode != null) {
TreeNode[] nodes = ((DefaultTreeModel) pTree.getModel()).getPathToRoot(selNode);
TreePath path = new TreePath(nodes);
pTree.expandPath(path);
pTree.setSelectionPath(path);
}
}
}
}
use of javax.swing.tree.TreeNode in project checkstyle-idea by jshiell.
the class CheckStyleToolWindowPanel method expandNode.
/**
* Expand the given tree to the given level, starting from the given node
* and path.
*
* @param tree The tree to be expanded
* @param node The node to start from
* @param path The path to start from
* @param level The number of levels to expand to
*/
private static void expandNode(final JTree tree, final TreeNode node, final TreePath path, final int level) {
if (level <= 0) {
return;
}
tree.expandPath(path);
for (int i = 0; i < node.getChildCount(); ++i) {
final TreeNode childNode = node.getChildAt(i);
expandNode(tree, childNode, path.pathByAddingChild(childNode), level - 1);
}
}
use of javax.swing.tree.TreeNode in project sldeditor by robward-scisys.
the class ExpressionPanelv2 method dataApplied.
/**
* Data applied.
*/
@Override
public void dataApplied() {
btnOk.setEnabled(true);
if (selectedNode != null) {
DefaultMutableTreeNode node = null;
if (selectedNode.isLeaf()) {
node = (DefaultMutableTreeNode) selectedNode.getParent();
if (node == null) {
node = selectedNode;
}
} else {
node = selectedNode;
}
TreeNode[] tmpNode = node.getPath();
// This notifies the listeners and changes the GUI
model.reload();
tree.expandPath(new TreePath(tmpNode));
displayResult();
}
}
Aggregations