use of javax.swing.event.TreeSelectionListener in project artisynth_core by artisynth.
the class NavigationPanel method createTree.
private void createTree(RootModel rootModel) {
TreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
myTreeModel = new NavPanelTreeModel(rootModel, selectionModel);
tree = new JTree(myTreeModel);
// add a mouse listener to the tree
tree.addMouseListener(new TreeMouseListener());
tree.setSelectionModel(selectionModel);
for (TreeSelectionListener l : mySelectionListeners) {
tree.addTreeSelectionListener(l);
}
treeListener = new NavPanelSelectionListener(myTreeModel);
myTreeSelectionModel = tree.getSelectionModel();
myTreeSelectionModel.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
// adding listeners
tree.addTreeSelectionListener(treeListener);
tree.addTreeExpansionListener(new NavPanelExpansionListener());
tree.addTreeWillExpandListener(new NavPanelWillExpandListener());
final JPopupMenu menu = new JPopupMenu();
// Create and add a menu item
JMenuItem item = new JMenuItem("Item Label");
// item.addActionListener(actionListener);
menu.add(item);
tree.setLargeModel(true);
tree.setExpandsSelectedPaths(false);
tree.setEditable(true);
tree.setCellRenderer(new NavPanelRenderer());
tree.setRootVisible(true);
if (treeView != null) {
remove(treeView);
}
treeView = new JScrollPane(tree);
treeView.setPreferredSize(this.getSize());
treeView.setMinimumSize(new Dimension(100, 250));
add(treeView);
expandAll(tree);
}
use of javax.swing.event.TreeSelectionListener 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.TreeSelectionListener 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;
}
use of javax.swing.event.TreeSelectionListener in project CCDD by nasa.
the class CcddAssignmentTreeHandler method createTreePanel.
/**
********************************************************************************************
* Create an assignment tree panel. The table tree is placed in a scroll pane. A check box is
* added that allows tree expansion/collapse
*
* @param label
* assignment tree title
*
* @param selectionMode
* tree item selection mode (single versus multiple)
*
* @return JPanel containing the assignment tree components
********************************************************************************************
*/
protected JPanel createTreePanel(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, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2), 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 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
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 assignment tree
addTreeSelectionListener(new TreeSelectionListener() {
/**
************************************************************************************
* Handle a change to the assignment tree selection
************************************************************************************
*/
@Override
public void valueChanged(TreeSelectionEvent lse) {
// triggers tree selection value changes that should not be processed
if (!isBuilding) {
// Update the assignment dialog based on the assignment(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.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);
}
});
return treePnl;
}
use of javax.swing.event.TreeSelectionListener in project mafscaling by vimsh.
the class VVTCalc method createTreePanel.
protected void createTreePanel() {
DefaultMutableTreeNode wotTreeRoot = new DefaultMutableTreeNode("Root");
DefaultTreeModel treeModel = new DefaultTreeModel(wotTreeRoot);
pullTree = new JTree(treeModel);
pullTree.setCellRenderer(new PullNodeRenderer());
pullTree.setCellEditor(new CheckBoxNodeEditor(pullTree));
pullTree.setEditable(true);
pullTree.setRootVisible(false);
pullTree.setOpaque(false);
pullTree.setBackground(null);
pullTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
pullTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
Object obj = ((DefaultMutableTreeNode) e.getPath().getLastPathComponent()).getUserObject();
if (obj instanceof CheckBoxNodeData) {
CheckBoxNodeData checkBoxNode = (CheckBoxNodeData) obj;
XYSeriesCollection dataset;
XYSeries series;
for (int i = 0; i < hiddenSeries.size(); ++i) {
dataset = (XYSeriesCollection) chartPanels[i].getChart().getXYPlot().getDataset(0);
if (checkBoxNode.isChecked()) {
series = hiddenSeries.get(i).get(checkBoxNode.getText());
if (series != null) {
dataset.addSeries(series);
hiddenSeries.get(i).remove(checkBoxNode.getText());
}
} else {
for (int j = 0; j < dataset.getSeriesCount(); ++j) {
series = dataset.getSeries(j);
if (series.getDescription().equals(checkBoxNode.getText())) {
hiddenSeries.get(i).put(checkBoxNode.getText(), series);
dataset.removeSeries(j);
}
}
}
}
}
}
});
}
Aggregations