use of javax.swing.event.TreeExpansionEvent in project intellij-plugins by JetBrains.
the class DartConfigurable method createUIComponents.
private void createUIComponents() {
mySdkPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
myDartiumPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
final CheckboxTree.CheckboxTreeCellRenderer checkboxTreeCellRenderer = new CheckboxTree.CheckboxTreeCellRenderer() {
@Override
public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (!(value instanceof CheckedTreeNode))
return;
final boolean dartSupportEnabled = myEnableDartSupportCheckBox.isSelected();
final CheckedTreeNode node = (CheckedTreeNode) value;
final Object userObject = node.getUserObject();
if (userObject instanceof Project) {
if (!dartSupportEnabled) {
//disabled state is also used as partially selected, that's why we do not change 'enabled' state if dartSupportEnabled
getCheckbox().setEnabled(false);
}
getTextRenderer().setEnabled(dartSupportEnabled);
getTextRenderer().append(DartBundle.message("project.0", ((Project) userObject).getName()));
} else if (userObject instanceof Module) {
getCheckbox().setEnabled(dartSupportEnabled);
getTextRenderer().setEnabled(dartSupportEnabled);
final Icon moduleIcon = ModuleType.get((Module) userObject).getIcon();
getTextRenderer().setIcon(dartSupportEnabled ? moduleIcon : IconLoader.getDisabledIcon(moduleIcon));
getTextRenderer().append(((Module) userObject).getName());
}
}
};
myModulesCheckboxTreeTable = new CheckboxTreeTable(null, checkboxTreeCellRenderer, new ColumnInfo[] { new TreeColumnInfo("") });
myModulesCheckboxTreeTable.addCheckboxTreeListener(new CheckboxTreeAdapter() {
@Override
public void nodeStateChanged(@NotNull CheckedTreeNode node) {
updateErrorLabel();
}
});
//myModulesCheckboxTreeTable.setRowHeight(myModulesCheckboxTreeTable.getRowHeight() + 2);
myModulesCheckboxTreeTable.getTree().addTreeWillExpandListener(new TreeWillExpandListener() {
public void treeWillExpand(final TreeExpansionEvent event) throws ExpandVetoException {
}
public void treeWillCollapse(final TreeExpansionEvent event) throws ExpandVetoException {
throw new ExpandVetoException(event);
}
});
}
use of javax.swing.event.TreeExpansionEvent in project jdk8u_jdk by JetBrains.
the class bug6505523 method createAndShowGUI.
private static void createAndShowGUI() {
final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Problem with NPE under JDK 1.6");
final DefaultMutableTreeNode problematic = new DefaultMutableTreeNode("Expand me and behold a NPE in stderr");
problematic.add(new DefaultMutableTreeNode("some content"));
root.add(new DefaultMutableTreeNode("irrelevant..."));
root.add(problematic);
final DefaultTreeModel model = new DefaultTreeModel(root);
tree = new JTree(model);
tree.setRootVisible(true);
tree.setShowsRootHandles(true);
tree.expandRow(0);
tree.collapseRow(2);
// this is critical - without dragEnabled everything works
tree.setDragEnabled(true);
tree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
TreeNode parent = problematic.getParent();
if (parent instanceof DefaultMutableTreeNode) {
model.removeNodeFromParent(problematic);
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}
});
JFrame frame = new JFrame("JTree Problem");
frame.add(new JScrollPane(tree));
frame.setSize(500, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
use of javax.swing.event.TreeExpansionEvent in project sldeditor by robward-scisys.
the class FileSystemExtension method initialise.
/**
* Initialise.
*
* @param parent the parent
* @param toolMgr the tool manager
*/
@Override
public void initialise(LoadSLDInterface parent, ToolSelectionInterface toolMgr) {
this.toolMgr = toolMgr;
this.parentObj = parent;
if (toolMgr != null) {
toolMgr.addRecursiveListener(this);
}
// Add extensions
extensionList = FileSystemExtensionFactory.getFileExtensionList(toolMgr);
extensionPanel = new JPanel();
extensionPanel.setLayout(new BorderLayout());
extensionPanel.setPreferredSize(new Dimension(450, 400));
JPanel toolPanel = null;
if (toolMgr != null) {
toolPanel = toolMgr.getPanel();
}
if (toolPanel != null) {
extensionPanel.add(toolPanel, BorderLayout.NORTH);
}
tree = new FSTree();
tree.setRootVisible(true);
DefaultMutableTreeNode rootNode;
try {
rootNode = new DefaultMutableTreeNode(ROOT_NODE);
model = new DefaultTreeModel(rootNode);
FileSystemNodeManager.create(tree, model);
for (FileSystemInterface extension : extensionList) {
extension.populate(tree, model, rootNode);
}
} catch (SecurityException e1) {
ConsoleManager.getInstance().exception(this, e1);
}
tree.setModel(model);
tree.setDragEnabled(true);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
tree.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
int row = tree.getClosestRowForLocation(e.getX(), e.getY());
tree.setSelectionRow(row);
Object selectedItem = tree.getLastSelectedPathComponent();
Thread t1 = new Thread(new Runnable() {
public void run() {
JPopupMenu popupMenu = new JPopupMenu();
for (FileSystemInterface extension : extensionList) {
extension.rightMouseButton(popupMenu, selectedItem, e);
}
if ((popupMenu.getComponentCount() > 0) && (e != null)) {
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
});
t1.start();
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
// Listen for Tree Selection Events
tree.addTreeExpansionListener(new TreeExpansionListener() {
/*
* (non-Javadoc)
*
* @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.TreeExpansionEvent)
*/
public void treeExpanded(TreeExpansionEvent evt) {
TreePath path = evt.getPath();
Object selectedItem = path.getLastPathComponent();
for (FileSystemInterface extension : extensionList) {
if (extension.treeExpanded(selectedItem)) {
((DefaultTreeModel) tree.getModel()).nodeStructureChanged((TreeNode) selectedItem);
}
}
}
/*
* (non-Javadoc)
*
* @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.TreeExpansionEvent)
*/
public void treeCollapsed(TreeExpansionEvent evt) {
// Nothing to do
}
});
// Tree selection listener
tree.setTreeSelection(this);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
panel.add(new JScrollPane(tree));
extensionPanel.add(panel, BorderLayout.CENTER);
logger.debug("FileSystem initialise finished");
}
use of javax.swing.event.TreeExpansionEvent in project gate-core by GateNLP.
the class SerialDatastoreViewer method initGuiComponents.
protected void initGuiComponents() {
treeRoot = new DefaultMutableTreeNode(datastore.getName(), true);
treeModel = new DefaultTreeModel(treeRoot, true);
mainTree = new JTree();
mainTree.setModel(treeModel);
mainTree.setExpandsSelectedPaths(true);
mainTree.expandPath(new TreePath(treeRoot));
mainTree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillCollapse(TreeExpansionEvent e) {
// ignore these events as we don't care about collapsing trees, timmmmmmmmmber!
}
@Override
public void treeWillExpand(TreeExpansionEvent e) {
TreePath path = e.getPath();
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
if (node.getChildCount() == 0 && node.getUserObject() instanceof DSType) {
DSType dsType = (DSType) node.getUserObject();
if (dsType.expanded)
return;
node.removeAllChildren();
try {
Iterator<String> lrIDsIter = datastore.getLrIds(dsType.type).iterator();
while (lrIDsIter.hasNext()) {
String id = lrIDsIter.next();
DSEntry entry = new DSEntry(datastore.getLrName(id), id, dsType.type);
DefaultMutableTreeNode lrNode = new DefaultMutableTreeNode(entry, false);
treeModel.insertNodeInto(lrNode, node, node.getChildCount());
node.add(lrNode);
}
dsType.expanded = true;
} catch (PersistenceException pe) {
throw new GateRuntimeException(pe.toString());
}
}
}
});
try {
Iterator<String> lrTypesIter = datastore.getLrTypes().iterator();
CreoleRegister cReg = Gate.getCreoleRegister();
while (lrTypesIter.hasNext()) {
String type = lrTypesIter.next();
ResourceData rData = cReg.get(type);
DSType dsType = new DSType(rData.getName(), type);
DefaultMutableTreeNode node = new DefaultMutableTreeNode(dsType);
treeModel.insertNodeInto(node, treeRoot, treeRoot.getChildCount());
}
} catch (PersistenceException pe) {
throw new GateRuntimeException(pe.toString());
}
DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
selectionModel.setSelectionMode(DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
mainTree.setSelectionModel(selectionModel);
getViewport().setView(mainTree);
popup = new JPopupMenu();
deleteAction = new DeleteAction();
loadAction = new LoadAction();
popup.add(deleteAction);
popup.add(loadAction);
}
use of javax.swing.event.TreeExpansionEvent in project chatty by chatty.
the class Tree method createTree.
public static JTree createTree(Map<Page, List<Page>> nodes) {
// Create nodes structure based on Map
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
for (Page parent : nodes.keySet()) {
DefaultMutableTreeNode category = new DefaultMutableTreeNode(parent);
root.add(category);
List<Page> subNodes = nodes.get(parent);
for (Page child : subNodes) {
category.add(new DefaultMutableTreeNode(child));
}
}
// Create and configure tree
JTree tree = new JTree(root);
tree.setRootVisible(false);
tree.setShowsRootHandles(false);
// Disable icons and use default renderer
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
// Border to give text some more space
private final Border BORDER = BorderFactory.createEmptyBorder(0, 3, 0, 1);
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
label.setBorder(BORDER);
}
return c;
}
};
renderer.setLeafIcon(null);
renderer.setOpenIcon(null);
tree.setCellRenderer(renderer);
// Expand all branches
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
// Select closest node on click, to allow more leniency with selecting
tree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int row = tree.getClosestRowForLocation(e.getX(), e.getY());
if (row != -1) {
tree.setSelectionRow(row);
}
}
});
// Prevent collapsing of nodes completely
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
throw new ExpandVetoException(event);
}
});
return tree;
}
Aggregations