use of javax.swing.event.TreeSelectionEvent in project Eidolons by IDemiurge.
the class TreeViewBuilder method remove.
public void remove() {
if (ArcaneVault.getMainBuilder().getSelectedNode() == null) {
return;
}
ArcaneVault.getMainBuilder().getSelectedNode().removeFromParent();
String selected = ArcaneVault.getMainBuilder().getSelectedTabName();
DataManager.removeType((String) ArcaneVault.getMainBuilder().getSelectedNode().getUserObject(), selected);
refresh();
int n = ArcaneVault.getMainBuilder().getTree().getRowCount();
ArcaneVault.getMainBuilder().getTree().setSelectionRow(Math.min(1, n));
ArcaneVault.getMainBuilder().getTree().getListeners(TreeSelectionListener.class)[0].valueChanged(new TreeSelectionEvent(tree.getTree(), null, null, null, null));
ArcaneVault.getMainBuilder().getEditViewPanel().refresh();
// getTree().updateUI();
}
use of javax.swing.event.TreeSelectionEvent in project Eidolons by IDemiurge.
the class AV_ButtonPanel method cleanUp.
private void cleanUp() {
String string = "What do I clean up now?..";
String TRUE = "Group";
String FALSE = "Subgroup";
String NULL = "XML";
Boolean result = DialogMaster.askAndWait(string, TRUE, FALSE, NULL);
if (result == null) {
XML_Transformer.cleanUp();
return;
}
OBJ_TYPE TYPE = ArcaneVault.getSelectedOBJ_TYPE();
String subgroup = (result) ? ArcaneVault.getSelectedType().getGroupingKey() : ArcaneVault.getSelectedType().getSubGroupingKey();
List<String> types = (result) ? DataManager.getTypesGroupNames(TYPE, subgroup) : DataManager.getTypesSubGroupNames(TYPE, subgroup);
List<String> retained = StringMaster.openContainer(new ListChooser(SELECTION_MODE.MULTIPLE, types, TYPE).choose());
for (String t : types) {
if (retained.contains(t)) {
continue;
}
DataManager.removeType(t, TYPE.getName());
}
ArcaneVault.getMainBuilder().getTreeBuilder().reload();
int n = ArcaneVault.getMainBuilder().getTree().getRowCount();
ArcaneVault.getMainBuilder().getTree().setSelectionRow(Math.min(1, n));
ArcaneVault.getMainBuilder().getTree().getListeners(TreeSelectionListener.class)[0].valueChanged(new TreeSelectionEvent(ArcaneVault.getMainBuilder().getTree(), null, null, null, null));
ArcaneVault.getMainBuilder().getEditViewPanel().refresh();
// reset tree
}
use of javax.swing.event.TreeSelectionEvent in project opennars by opennars.
the class NarseseTemplatePanel method newPanel.
private static JPanel newPanel(List<NarseseTemplate> templates) {
JPanel p = new JPanel(new BorderLayout());
JPanel menu = new JPanel(new BorderLayout());
DefaultMutableTreeNode tree = new DefaultMutableTreeNode();
for (NarseseTemplate n : templates) {
DefaultMutableTreeNode nt = new DefaultMutableTreeNode(n);
tree.add(nt);
}
JTree t = new JTree(tree);
menu.add(t, BorderLayout.CENTER);
final JComboBox formSelect = new JComboBox();
formSelect.addItem("en");
formSelect.addItem("narsese");
menu.add(formSelect, BorderLayout.NORTH);
p.add(menu, BorderLayout.WEST);
ActionListener change = new ActionListener() {
JPanel r = null;
@Override
public void actionPerformed(ActionEvent e) {
if (t.getSelectionModel().isSelectionEmpty())
return;
Object o = ((DefaultMutableTreeNode) t.getSelectionModel().getSelectionPath().getLastPathComponent()).getUserObject();
if (!(o instanceof NarseseTemplate))
return;
if (r != null) {
p.remove(r);
}
r = newPanel((NarseseTemplate) o, formSelect.getSelectedItem().toString());
p.add(r, BorderLayout.CENTER);
p.validate();
}
};
formSelect.addActionListener(change);
t.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
change.actionPerformed(null);
}
});
change.actionPerformed(null);
return p;
}
use of javax.swing.event.TreeSelectionEvent in project CCDD by nasa.
the class CcddLinkTreeHandler method createTreePanel.
/**
********************************************************************************************
* Create a link tree panel. The table tree is placed in a scroll pane. A check box is added
* that allows tree expansion/collapse
*
* @param label
* link tree title
*
* @param selectionMode
* tree item selection mode (single versus multiple)
*
* @return JPanel containing the link tree components
********************************************************************************************
*/
protected JPanel createTreePanel(String label, int selectionMode) {
// Create an empty border
Border emptyBorder = BorderFactory.createEmptyBorder();
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0);
// Set the table tree selection mode
getSelectionModel().setSelectionMode(selectionMode);
// Create a panel to contain the table tree
JPanel treePnl = new JPanel(new GridBagLayout());
treePnl.setBorder(emptyBorder);
// Create the tree labels
JLabel treeLbl = new JLabel(label);
treeLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
treeLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
treePnl.add(treeLbl, gbc);
// Create the tree scroll pane
JScrollPane treeScroll = new JScrollPane(this);
treeScroll.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing())));
// Add the tree to the panel
gbc.weighty = 1.0;
gbc.gridy++;
treePnl.add(treeScroll, gbc);
// Set the table tree font and number of rows to display
setFont(ModifiableFontInfo.TREE_NODE.getFont());
setVisibleRowCount(10);
// Add a listener for changes to the link tree
addTreeSelectionListener(new TreeSelectionListener() {
/**
************************************************************************************
* Handle a change to the link tree selection
************************************************************************************
*/
@Override
public void valueChanged(TreeSelectionEvent lse) {
// tree selection value changes that should not be processed
if (!isBuilding) {
// Update the link dialog based on the link(s) selected
updateTableSelection();
}
}
});
// Create a tree expansion check box
final JCheckBox expandChkBx = new JCheckBox("Expand all");
expandChkBx.setBorder(emptyBorder);
expandChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
expandChkBx.setSelected(false);
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(expandChkBx, gbc);
// Create a listener for changes in selection of the tree expansion check box
expandChkBx.addActionListener(new ActionListener() {
/**
************************************************************************************
* Handle a change to the tree expansion check box selection
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Set the flag indicating if the tree is fully expanded
isExpanded = expandChkBx.isSelected();
// Set the tree expansion based on the check box status
setTreeExpansion(isExpanded);
}
});
// Create a hide data type check box
final JCheckBox hideTypeChkBx = new JCheckBox("Hide data type");
hideTypeChkBx.setBorder(emptyBorder);
hideTypeChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
hideTypeChkBx.setSelected(false);
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(hideTypeChkBx, gbc);
// Create a listener for changes in selection of the hide data type check box
hideTypeChkBx.addActionListener(new ActionListener() {
/**
************************************************************************************
* Handle a change to the hide data type check box selection
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
setEnableDataType(!hideTypeChkBx.isSelected());
// Store the tree's current expansion state
String expState = getExpansionState();
// Force the root node to draw with the node additions
((DefaultTreeModel) treeModel).nodeStructureChanged(getRootNode());
setExpansionState(expState);
}
});
// In order to align the link and variable trees a phantom check box must be added to the
// link tree panel. To prevent display of the check box components an empty panel is placed
// over it
JPanel hiddenPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
hiddenPnl.setBorder(emptyBorder);
JCheckBox hiddenChkBx = new JCheckBox(" ");
hiddenChkBx.setBorder(emptyBorder);
gbc.gridy++;
treePnl.add(hiddenPnl, gbc);
hiddenChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
hiddenChkBx.setFocusable(false);
hiddenChkBx.setDisabledIcon(null);
hiddenChkBx.setEnabled(false);
treePnl.add(hiddenChkBx, gbc);
return treePnl;
}
use of javax.swing.event.TreeSelectionEvent in project CCDD by nasa.
the class CcddGroupTreeHandler method createTreePanel.
/**
********************************************************************************************
* Create a group tree panel. The table tree is placed in a scroll pane. A check box is added
* that allows tree expansion/collapse
*
* @param label
* group tree title
*
* @param selectionMode
* tree item selection mode (single versus multiple)
*
* @param noFilters
* true to not display the filter check boxes
*
* @param parent
* GUI component calling this method
*
* @return JPanel containing the group tree components
********************************************************************************************
*/
protected JPanel createTreePanel(String label, int selectionMode, boolean noFilters, final Component parent) {
// Create an empty border
Border emptyBorder = BorderFactory.createEmptyBorder();
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0);
// Set the table tree selection mode
getSelectionModel().setSelectionMode(selectionMode);
// Create a panel to contain the table tree
final JPanel treePnl = new JPanel(new GridBagLayout());
treePnl.setBorder(emptyBorder);
// Create the tree labels
JLabel treeLbl = new JLabel(label);
treeLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
treeLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
treePnl.add(treeLbl, gbc);
// Create the tree scroll pane
JScrollPane treeScroll = new JScrollPane(this);
treeScroll.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing())));
// Check if this is the last component to add
if (noFilters) {
gbc.insets.bottom = 0;
}
// Add the tree to the panel
gbc.weighty = 1.0;
gbc.gridy++;
treePnl.add(treeScroll, gbc);
// Set the table tree font and number of rows to display
setFont(ModifiableFontInfo.TREE_NODE.getFont());
setVisibleRowCount(10);
// Add a listener for changes to the group tree
addTreeSelectionListener(new TreeSelectionListener() {
/**
************************************************************************************
* Handle a change to the group tree selection
************************************************************************************
*/
@Override
public void valueChanged(TreeSelectionEvent lse) {
// tree selection value changes that should not be processed
if (!isBuilding) {
// Update the group dialog based on the group(s) selected
updateTableSelection();
}
}
});
// Check if the filter check boxes should be displayed
if (!noFilters) {
// Create a tree expansion check box
final JCheckBox expandChkBx = new JCheckBox("Expand all");
expandChkBx.setBorder(emptyBorder);
expandChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
expandChkBx.setSelected(false);
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(expandChkBx, gbc);
// Create a listener for changes in selection of the tree expansion check box
expandChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the tree expansion check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Set the flag indicating if the tree is fully expanded
isExpanded = expandChkBx.isSelected();
// Set the tree expansion based on the check box status
setTreeExpansion(isExpanded);
}
});
// Create a hide data type check box
final JCheckBox hideTypeChkBx = new JCheckBox("Hide data type");
hideTypeChkBx.setBorder(emptyBorder);
hideTypeChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
hideTypeChkBx.setSelected(false);
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(hideTypeChkBx, gbc);
// Create a listener for changes in selection of the hide data type check box
hideTypeChkBx.addActionListener(new ActionListener() {
/**
************************************************************************************
* Handle a change to the hide data type check box selection
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
setEnableDataType(!hideTypeChkBx.isSelected());
// Store the tree's current expansion state
String expState = getExpansionState();
// Force the root node to draw with the node additions
((DefaultTreeModel) treeModel).nodeStructureChanged(getRootNode());
setExpansionState(expState);
}
});
// Create a type filter check box
final JCheckBox typeFilterChkBx = new JCheckBox("Filter by type");
typeFilterChkBx.setBorder(emptyBorder);
typeFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
typeFilterChkBx.setSelected(false);
gbc.gridy++;
treePnl.add(typeFilterChkBx, gbc);
// Create an application filter check box
final JCheckBox appFilterChkBx = new JCheckBox("Filter by application");
appFilterChkBx.setBorder(emptyBorder);
appFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
appFilterChkBx.setSelected(false);
gbc.gridy++;
treePnl.add(appFilterChkBx, gbc);
// Create a listener for changes in selection of the type filter check box
typeFilterChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the type filter check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Recreate the group definitions based on the current tree members
groupDefinitions = createDefinitionsFromTree();
// Store the tree's current expansion state
String expState = getExpansionState();
// Rebuild the tree based on the filter selection
buildTree(typeFilterChkBx.isSelected(), appFilterChkBx.isSelected(), scheduleRate, isApplicationOnly, parent);
final List<String> topNodePrefixes = new ArrayList<String>();
// Step through each node immediately below the root node
for (int index = 0; index < root.getChildCount(); index++) {
// Add the node name to the list of prefixes
topNodePrefixes.add("[" + root.getUserObject() + ", " + ((ToolTipTreeNode) root.getChildAt(index)).getUserObject());
}
// Adjust the expansion state to account for the change in filtering, then
// restore the expansion state
expState = adjustExpansionState(expState, appFilterChkBx.isSelected(), false, typeFilterChkBx.isSelected(), true, true, topNodePrefixes, groupHandler, tableTypeHandler);
setExpansionState(expState);
}
});
// Create a listener for changes in selection of the application filter check box
appFilterChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the type filter check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Recreate the group definitions based on the current tree members
groupDefinitions = createDefinitionsFromTree();
// Store the tree's current expansion state
String expState = getExpansionState();
// Rebuild the tree based on the filter selection
buildTree(typeFilterChkBx.isSelected(), appFilterChkBx.isSelected(), scheduleRate, isApplicationOnly, parent);
final List<String> topNodePrefixes = new ArrayList<String>();
// Check if filtering by application is in effect
if (appFilterChkBx.isSelected()) {
// Application and Other nodes
for (int index = 0; index < root.getChildCount(); index++) {
// nodes
for (int subIndex = 0; subIndex < root.getChildAt(index).getChildCount(); subIndex++) {
// Add the node name to the list of prefixes
topNodePrefixes.add("[" + root.getUserObject() + ", " + ((ToolTipTreeNode) root.getChildAt(index)).getUserObject() + ", " + ((ToolTipTreeNode) root.getChildAt(index).getChildAt(subIndex)).getUserObject());
}
}
// Check if the tree is completely collapsed
if (expState.isEmpty()) {
// Set the expansion state to show the Application and Other nodes
expState = "[, " + APP_NODE + "], [, " + OTHER_NODE + "], ";
} else // The tree is expanded to some degree
{
// Insert Application and Other nodes names into the expansion paths
expState = expState.replaceAll("\\[, ", "[, " + APP_NODE + ", ") + " " + expState.replaceAll("\\[, ", "[, " + OTHER_NODE + ", ");
}
} else // Filtering by application is not in effect
{
// Remove Application and Other nodes names from the expansion paths
expState = expState.replaceAll("\\[, " + APP_NODE + ", ", "[, ").replaceAll("\\[, " + OTHER_NODE + ", ", "[, ");
}
// Adjust the expansion state to account for the change in filtering
expState = adjustExpansionState(expState, appFilterChkBx.isSelected(), true, typeFilterChkBx.isSelected(), false, true, topNodePrefixes, groupHandler, tableTypeHandler);
// Check if filtering by application is in effect
if (appFilterChkBx.isSelected()) {
// Add the Application and Other nodes to the expansion path
expState = "[, " + APP_NODE + "], [, " + OTHER_NODE + "], " + expState;
}
// Restore the expansion state
setExpansionState(expState);
}
});
}
return treePnl;
}
Aggregations