use of javax.swing.event.TreeSelectionEvent in project JWildfire by thargor6.
the class FlameBrowserInternalFrame method getFlameBrowserTree.
JTree getFlameBrowserTree() {
if (flameBrowserTree == null) {
flameBrowserTree = new JTree();
flameBrowserTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
if (tinaController != null) {
tinaController.getFlameBrowserController().flamesTree_changed();
}
}
});
}
return flameBrowserTree;
}
use of javax.swing.event.TreeSelectionEvent in project freeplane by freeplane.
the class SelectMenuItemDialog method createTree.
private JTree createTree() {
final DefaultMutableTreeNode treeRoot = MenuUtils.createMenuEntryTree(SELECTION_ROOT_KEY);
if (treeRoot.getUserObject() == null)
treeRoot.setUserObject(new MenuEntry(null, TextUtils.getText("select_menu_item_root_node")));
JTree jTree = new JTree(treeRoot);
jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
// replace the standard icons
jTree.setCellRenderer(new MenuIconRenderer());
jTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(final TreeSelectionEvent e) {
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
btnOK.setEnabled(node != null && nodeIsSelectable(node));
}
});
jTree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() >= 2) {
if (btnOK.isEnabled())
btnOK.doClick();
}
}
});
return jTree;
}
use of javax.swing.event.TreeSelectionEvent in project Course_Generator by patrovite.
the class CheckBoxTree method main.
public static void main(final String[] args) {
final DefaultMutableTreeNode root = new DefaultMutableTreeNode(new CheckBoxNodeData("Root", true));
final DefaultMutableTreeNode accessibility = add(root, "Accessibility", true);
add(accessibility, "Move system caret with focus/selection changes", false);
add(accessibility, "Always expand alt text for images", true);
root.add(accessibility);
final DefaultMutableTreeNode browsing = new DefaultMutableTreeNode(new CheckBoxNodeData("Browsing", null));
add(browsing, "Notify when downloads complete", true);
add(browsing, "Disable script debugging", true);
add(browsing, "Use AutoComplete", true);
add(browsing, "Browse in a new process", false);
root.add(browsing);
final CheckBoxTree tree = new CheckBoxTree(root);
((DefaultMutableTreeNode) tree.getModel().getRoot()).add(new DefaultMutableTreeNode(new CheckBoxNodeData("gggg", null)));
((DefaultTreeModel) tree.getModel()).reload();
// listen for changes in the selection
tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent e) {
// System.out.println("selection changed");
}
});
// show the tree on screen
final JFrame frame = new JFrame("CheckBox Tree");
final JScrollPane scrollPane = new JScrollPane(tree);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 150);
frame.setVisible(true);
}
use of javax.swing.event.TreeSelectionEvent in project UniversalMediaServer by UniversalMediaServer.
the class TranscodingTab method buildLeft.
public JComponent buildLeft() {
String colSpec = FormLayoutUtil.getColSpec(LEFT_COL_SPEC, orientation);
FormLayout layout = new FormLayout(colSpec, LEFT_ROW_SPEC);
PanelBuilder builder = new PanelBuilder(layout);
builder.border(Borders.EMPTY);
builder.opaque(false);
CellConstraints cc = new CellConstraints();
CustomJButton but = new CustomJButton(LooksFrame.readImageIcon("button-arrow-down.png"));
but.setToolTipText(Messages.getString("TrTab2.6"));
but.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TreePath path = tree.getSelectionModel().getSelectionPath();
if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings) {
TreeNodeSettings node = ((TreeNodeSettings) path.getLastPathComponent());
if (node.getPlayer() != null) {
// get the tree model
DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel();
// now get the index of the selected node in the DefaultTreeModel
int index = dtm.getIndexOfChild(node.getParent(), node);
// if selected node is first, return (can't move it up)
if (index < node.getParent().getChildCount() - 1) {
// move the node
dtm.insertNodeInto(node, (DefaultMutableTreeNode) node.getParent(), index + 1);
dtm.reload();
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
tree.getSelectionModel().setSelectionPath(new TreePath(node.getPath()));
updateEngineModel();
}
}
}
}
});
builder.add(but, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));
CustomJButton but2 = new CustomJButton(LooksFrame.readImageIcon("button-arrow-up.png"));
but2.setToolTipText(Messages.getString("TrTab2.6"));
but2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TreePath path = tree.getSelectionModel().getSelectionPath();
if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings) {
TreeNodeSettings node = ((TreeNodeSettings) path.getLastPathComponent());
if (node.getPlayer() != null) {
// get the tree model
DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel();
// now get the index of the selected node in the DefaultTreeModel
int index = dtm.getIndexOfChild(node.getParent(), node);
// if selected node is first, return (can't move it up)
if (index != 0) {
// move the node
dtm.insertNodeInto(node, (DefaultMutableTreeNode) node.getParent(), index - 1);
dtm.reload();
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
tree.getSelectionModel().setSelectionPath(new TreePath(node.getPath()));
updateEngineModel();
}
}
}
}
});
builder.add(but2, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation));
CustomJButton but3 = new CustomJButton(LooksFrame.readImageIcon("button-toggleengine.png"));
but3.setToolTipText(Messages.getString("TrTab2.0"));
but3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TreePath path = tree.getSelectionModel().getSelectionPath();
if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings && ((TreeNodeSettings) path.getLastPathComponent()).getPlayer() != null) {
((TreeNodeSettings) path.getLastPathComponent()).setEnable(!((TreeNodeSettings) path.getLastPathComponent()).isEnable());
updateEngineModel();
tree.updateUI();
}
}
});
builder.add(but3, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation));
DefaultMutableTreeNode root = new DefaultMutableTreeNode(Messages.getString("TrTab2.11"));
TreeNodeSettings commonEnc = new TreeNodeSettings(Messages.getString("TrTab2.5"), null, buildCommon());
commonEnc.getConfigPanel().addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
handleCardComponentChange(e.getComponent());
}
});
tabbedPanel.add(commonEnc.id(), commonEnc.getConfigPanel());
root.add(commonEnc);
parent = new DefaultMutableTreeNode[5];
parent[0] = new DefaultMutableTreeNode(Messages.getString("TrTab2.14"));
parent[1] = new DefaultMutableTreeNode(Messages.getString("TrTab2.15"));
parent[2] = new DefaultMutableTreeNode(Messages.getString("TrTab2.16"));
parent[3] = new DefaultMutableTreeNode(Messages.getString("TrTab2.17"));
parent[4] = new DefaultMutableTreeNode(Messages.getString("TrTab2.18"));
root.add(parent[0]);
root.add(parent[1]);
root.add(parent[2]);
root.add(parent[3]);
root.add(parent[4]);
tree = new JTree(new DefaultTreeModel(root)) {
private static final long serialVersionUID = -6703434752606636290L;
};
tree.setRootVisible(false);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (e.getNewLeadSelectionPath() != null && e.getNewLeadSelectionPath().getLastPathComponent() instanceof TreeNodeSettings) {
TreeNodeSettings tns = (TreeNodeSettings) e.getNewLeadSelectionPath().getLastPathComponent();
cl.show(tabbedPanel, tns.id());
}
}
});
tree.setRequestFocusEnabled(false);
tree.setCellRenderer(new TreeRenderer());
JScrollPane pane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
builder.add(pane, FormLayoutUtil.flip(cc.xyw(2, 1, 4), colSpec, orientation));
builder.addLabel(Messages.getString("TrTab2.19"), FormLayoutUtil.flip(cc.xyw(2, 5, 4), colSpec, orientation));
builder.addLabel(Messages.getString("TrTab2.20"), FormLayoutUtil.flip(cc.xyw(2, 7, 4), colSpec, orientation));
JPanel panel = builder.getPanel();
// Apply the orientation to the panel and all components in it
panel.applyComponentOrientation(orientation);
return panel;
}
use of javax.swing.event.TreeSelectionEvent in project CCDD by nasa.
the class CcddTableTreeHandler method createTreePanel.
/**
********************************************************************************************
* Create a table tree panel. The table tree is placed in a scroll pane. A check box is added
* that allows tree expansion/collapse
*
* @param label
* table tree title
*
* @param selectionMode
* tree item selection mode (single versus multiple)
*
* @param parent
* GUI component calling this method
*
* @return JPanel containing the table tree components
********************************************************************************************
*/
protected JPanel createTreePanel(String label, int selectionMode, 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
JPanel treePnl = new JPanel(new GridBagLayout());
treePnl.setBorder(emptyBorder);
// Check if a label is provided
if (label != null && !label.isEmpty()) {
// 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);
gbc.gridy++;
}
// 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;
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 table tree
addTreeSelectionListener(new TreeSelectionListener() {
/**
************************************************************************************
* Handle a change to the table tree selection
************************************************************************************
*/
@Override
public void valueChanged(TreeSelectionEvent lse) {
// tree selection value changes that should not be processed
if (!isBuilding) {
// Update the groups based on the tables selected
updateTableSelection();
}
}
});
// Add a listener for table tree expand and collapse events
addTreeExpansionListener(new TreeExpansionListener() {
/**
************************************************************************************
* Handle an expansion of the table tree
************************************************************************************
*/
@Override
public void treeExpanded(TreeExpansionEvent tee) {
// Update the table selection based on the selected group
updateGroupSelection();
}
/**
************************************************************************************
* Handle a collapse of the table tree
************************************************************************************
*/
@Override
public void treeCollapsed(TreeExpansionEvent tee) {
// Update the table selection based on the selected group
updateGroupSelection();
}
});
// Create a tree expansion check box
expandChkBx = new JCheckBox("Expand all");
expandChkBx.setBorder(emptyBorder);
expandChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
expandChkBx.setSelected(false);
// Check if this is the last component to add
if (!showGroupFilter && !showTypeFilter && !addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
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) {
setTreeExpansion(expandChkBx.isSelected());
}
});
// Check if instance tables are displayed in the tree
if (treeType != TableTreeType.PROTOTYPE_TABLES) {
// 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);
// Check if this is the last component to add
if (!showGroupFilter && !showTypeFilter && !addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
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(root);
setExpansionState(expState);
}
});
}
// Create the filtering node prefix storage and check boxes
final List<String> prefixes = new ArrayList<String>();
final JCheckBox groupFilterChkBx = new JCheckBox("Filter by group");
final JCheckBox typeFilterChkBx = new JCheckBox("Filter by type");
// table/variable divisions (e.g., 'Prototype', 'Parents & Children')
for (int index = 0; index < root.getChildCount(); index++) {
// Add the child node name with its path to the prefix list
prefixes.add("[" + root.getUserObject() + ", " + ((ToolTipTreeNode) root.getChildAt(index)).getUserObject());
}
// Check if the group check box is valid for this tree type
if (showGroupFilter) {
// Create a group filter check box
groupFilterChkBx.setBorder(emptyBorder);
groupFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
groupFilterChkBx.setSelected(false);
groupFilterChkBx.setEnabled(!groupHandler.getGroupInformation().isEmpty());
// Check if this is the last component to add
if (!showTypeFilter && !addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.gridy++;
treePnl.add(groupFilterChkBx, gbc);
// Create a listener for changes in selection of the group filter check box
groupFilterChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the group filter check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Set the filter by group flag based on the check box status
isByGroup = groupFilterChkBx.isSelected();
// Store the tree's current expansion state
String expState = getExpansionState();
// Rebuild the tree based on the filter selection
buildTableTree(expandChkBx.isSelected(), rateName, rateFilter, parent);
// Adjust the expansion state to account for the change in filtering, then
// restore the expansion state
expState = adjustExpansionState(expState, groupFilterChkBx.isSelected(), true, typeFilterChkBx.isSelected(), false, false, prefixes, groupHandler, tableTypeHandler);
setExpansionState(expState);
}
});
}
// Check if the type check box is valid for this tree type
if (showTypeFilter) {
// Create a type filter check box
typeFilterChkBx.setBorder(emptyBorder);
typeFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
typeFilterChkBx.setSelected(false);
// Check if this is the last component to add
if (!addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.gridy++;
treePnl.add(typeFilterChkBx, 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) {
// Set the filter by type flag based on the check box status
isByType = typeFilterChkBx.isSelected();
// Store the tree's current expansion state
String expState = getExpansionState();
// Rebuild the tree based on the filter selection
buildTableTree(expandChkBx.isSelected(), rateName, rateFilter, parent);
// Adjust the expansion state to account for the change in filtering, then
// restore the expansion state
expState = adjustExpansionState(expState, groupFilterChkBx.isSelected(), false, typeFilterChkBx.isSelected(), true, false, prefixes, groupHandler, tableTypeHandler);
setExpansionState(expState);
}
});
}
// tree panel. Check if the flag is set to add this check box
if (addHiddenCheckBox) {
// Create the hidden check box. 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.insets.bottom = 0;
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;
}
Aggregations