use of javax.swing.event.TreeSelectionListener in project JMRI by JMRI.
the class CombinedLocoSelTreePane method layoutDecoderSelection.
/**
* Create the panel used to select the decoder
*/
@Override
protected JPanel layoutDecoderSelection() {
JPanel pane1a = new JPanel(new BorderLayout());
pane1a.add(new JLabel(Bundle.getMessage("LabelDecoderInstalled")), BorderLayout.NORTH);
// create the list of manufacturers; get the list of decoders, and add elements
dRoot = new DecoderTreeNode("Root");
dModel = new InvisibleTreeModel(dRoot);
dTree = new JTree(dModel) {
@Override
public String getToolTipText(MouseEvent evt) {
if (getRowForLocation(evt.getX(), evt.getY()) == -1) {
return null;
}
TreePath curPath = getPathForLocation(evt.getX(), evt.getY());
return ((DecoderTreeNode) curPath.getLastPathComponent()).getToolTipText();
}
};
dTree.setToolTipText("");
createDecoderTypeContents();
// build the tree GUI
pane1a.add(new JScrollPane(dTree), BorderLayout.CENTER);
dTree.expandPath(new TreePath(dRoot));
dTree.setRootVisible(false);
dTree.setShowsRootHandles(true);
dTree.setScrollsOnExpand(true);
dTree.setExpandsSelectedPaths(true);
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
// tree listener
dTree.addTreeSelectionListener(dListener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
log.debug("selection changed " + dTree.isSelectionEmpty() + " " + dTree.getSelectionPath());
if (!dTree.isSelectionEmpty() && dTree.getSelectionPath() != null && // can't be just a mfg, has to be at least a family
dTree.getSelectionPath().getPathCount() > 2 && // can't be a multiple decoder selection
dTree.getSelectionCount() < 2) {
// decoder selected - reset and disable loco selection
log.debug("Selection event with " + dTree.getSelectionPath().toString());
if (locoBox != null) {
locoBox.setSelectedIndex(0);
}
go2.setEnabled(true);
go2.setRequestFocusEnabled(true);
go2.requestFocus();
go2.setToolTipText(Bundle.getMessage("TipClickToOpen"));
} else {
// decoder not selected - require one
go2.setEnabled(false);
go2.setToolTipText(Bundle.getMessage("TipSelectLoco"));
}
}
});
// Mouselistener for doubleclick activation of programmer
dTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
// Clear any status messages and ensure the tree is in single path select mode
if (_statusLabel != null) {
_statusLabel.setText(Bundle.getMessage("StateIdle"));
}
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
if (me.getClickCount() == 2) {
if (go2.isEnabled() && ((TreeNode) dTree.getSelectionPath().getLastPathComponent()).isLeaf()) {
go2.doClick();
}
}
}
});
viewButtons = new JPanel();
iddecoder = addDecoderIdentButton();
if (iddecoder != null) {
viewButtons.add(iddecoder);
}
showAll = new JRadioButton(Bundle.getMessage("LabelAll"));
showAll.setSelected(true);
showMatched = new JRadioButton(Bundle.getMessage("LabelMatched"));
if (jmri.InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) != null && jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).isGlobalProgrammerAvailable()) {
ButtonGroup group = new ButtonGroup();
group.add(showAll);
group.add(showMatched);
viewButtons.add(showAll);
viewButtons.add(showMatched);
pane1a.add(viewButtons, BorderLayout.SOUTH);
showAll.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (dModel.isActivatedFilter()) {
dModel.activateFilter(false);
dModel.reload();
for (TreePath path : selectedPath) {
dTree.expandPath(path);
dTree.addSelectionPath(path);
dTree.scrollPathToVisible(path);
}
}
}
});
showMatched.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!dModel.isActivatedFilter()) {
dModel.activateFilter(true);
dModel.reload();
for (TreePath path : selectedPath) {
log.debug("action selects path: " + path);
dTree.expandPath(path);
dTree.addSelectionPath(path);
dTree.scrollPathToVisible(path);
}
}
}
});
}
return pane1a;
}
use of javax.swing.event.TreeSelectionListener in project n2a by frothga.
the class FixedParameterSpacePanel method buildDomainTab.
private void buildDomainTab(ParameterDomain domain) {
TNode nRoot = new TNode(new NodeSimpleLabel(domain.getName()));
populate(nRoot, domain);
FilterableParameterTreePanel pnlFilterableTree = new FilterableParameterTreePanel(nRoot);
final ParameterTree treParams = pnlFilterableTree.getTree();
treParams.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
TreePath path = treParams.getPathForLocation(e.getX(), e.getY());
if (path == null || ((TNode) path.getLastPathComponent()).getUserObject() instanceof NodeSubdomain) {
treParams.setCursor(Cursor.getDefaultCursor());
} else {
treParams.setCursor(DragCursors.getOpenhandcursor());
}
}
});
treParams.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
updateDetailsPanelFromTree(treParams);
}
});
treParams.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1 && treParams.getSelectionCount() != 0) {
List<ParameterBundle> bundles = getSelectedParamsAsBundles(treParams.getSelectionPaths());
if (bundles != null) {
dropIntoGroups(bundles, dropEmphasis);
}
}
}
});
DragSource ds = new DragSource();
ds.createDefaultDragGestureRecognizer(treParams, DnDConstants.ACTION_LINK, this);
int existingIndex = tabParamDomains.indexOfTabByKey(domain.getName());
if (existingIndex != -1) {
tabParamDomains.remove(existingIndex);
}
tabParamDomains.add(domain.getName(), pnlFilterableTree);
int index = tabParamDomains.getTabCount();
tabParamDomains.setIconAt(index - 1, domain.getIcon());
tabParamDomains.setUseBorderAt(index - 1, true);
}
use of javax.swing.event.TreeSelectionListener 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.TreeSelectionListener 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.TreeSelectionListener in project sirix by sirixdb.
the class TreeView method dispose.
@Override
public void dispose() {
mTree.clearSelection();
mTree.setModel(null);
mTree.setCellRenderer(null);
for (final FocusListener listener : mTree.getFocusListeners()) {
mTree.removeFocusListener(listener);
}
for (final ComponentListener listener : mTree.getComponentListeners()) {
mTree.removeComponentListener(listener);
}
for (final TreeSelectionListener listener : mTree.getTreeSelectionListeners()) {
mTree.removeTreeSelectionListener(listener);
}
for (final ContainerListener listener : mTree.getContainerListeners()) {
mTree.removeContainerListener(listener);
}
}
Aggregations