use of javax.swing.event.TreeExpansionListener 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.TreeExpansionListener 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.TreeExpansionListener in project IBMiProgTool by vzupka.
the class MainWindow method createNewLeftSide.
/**
* Create split panes containing the PC file tree and table on the left side
* of the window.
*
* @param leftRoot
*/
protected void createNewLeftSide(String leftRoot) {
// Create new left hand tree
leftPathString = leftRoot;
leftTopNode = new DefaultMutableTreeNode(leftPathString);
leftTreeMap.put(leftRoot, 0);
// Create left hand tree
leftTree = new JTree(leftTopNode);
// Create tree model
leftTreeModel = (DefaultTreeModel) leftTree.getModel();
// Mouse listener for left tree
leftTreeMouseListener = new LeftTreeMouseAdapter();
leftTree.addMouseListener(leftTreeMouseListener);
// Tree expansion listener for left tree
TreeExpansionListener leftTreeExpansionListener = new LeftTreeExpansionListener();
leftTree.addTreeExpansionListener(leftTreeExpansionListener);
leftTree.setDragEnabled(true);
leftTree.setDropMode(DropMode.USE_SELECTION);
leftTree.setTransferHandler(new LeftTreeTransferHandler(this));
leftTreeSelModel = leftTree.getSelectionModel();
leftTreeSelModel.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
leftRowMapper = leftTreeSelModel.getRowMapper();
leftTree.setRootVisible(true);
leftTree.setShowsRootHandles(true);
leftTree.setSelectionRow(0);
// Add PC nodes to the left tree
leftTreeMap.put(leftPathString, 0);
addPCNodes(Paths.get(leftPathString), leftTopNode);
leftTree.expandRow(0);
// Place the left tree in scroll pane
scrollPaneLeft.setViewportView(leftTree);
// Change cursor to default
// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
// Remove setting last element of messages
scrollMessagePane.getVerticalScrollBar().removeAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
}
use of javax.swing.event.TreeExpansionListener in project WorldPainter by Captain-Chaos.
the class MapExplorer method main.
public static void main(String[] args) throws IOException, ClassNotFoundException {
// Load or initialise configuration
File configDir = Configuration.getConfigDir();
if (!configDir.isDirectory()) {
configDir.mkdirs();
}
// This will migrate the configuration directory if necessary
Configuration config = Configuration.load();
if (config == null) {
if (!logger.isDebugEnabled()) {
// If debug logging is on, the Configuration constructor will
// already log this
logger.info("Creating new configuration");
}
config = new Configuration();
}
Configuration.setInstance(config);
logger.info("Installation ID: " + config.getUuid());
// Load and install trusted WorldPainter root certificate
X509Certificate trustedCert = null;
try {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
trustedCert = (X509Certificate) certificateFactory.generateCertificate(Main.class.getResourceAsStream("/wproot.pem"));
WPTrustManager trustManager = new WPTrustManager(trustedCert);
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new TrustManager[] { trustManager }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
} catch (CertificateException e) {
logger.error("Certificate exception while loading trusted root certificate", e);
} catch (NoSuchAlgorithmException e) {
logger.error("No such algorithm exception while loading trusted root certificate", e);
} catch (KeyManagementException e) {
logger.error("Key management exception while loading trusted root certificate", e);
}
// Load the plugins
if (trustedCert != null) {
PluginManager.loadPlugins(new File(configDir, "plugins"), trustedCert.getPublicKey());
} else {
logger.error("Trusted root certificate not available; not loading plugins");
}
WPPluginManager.initialise(config.getUuid());
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("Minecraft Map Explorer");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
MapTreeModel treeModel = new MapTreeModel();
// File minecraftDir = MinecraftUtil.findMinecraftDir();
// File defaultDir;
// if (minecraftDir != null) {
// defaultDir = new File(minecraftDir, "saves");
// } else {
// defaultDir = new File(System.getProperty("user.home"));
// }
JTree tree = new JTree(treeModel);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.setCellRenderer(new MapTreeCellRenderer());
JScrollPane scrollPane = new JScrollPane(tree);
// tree.expandPath(treeModel.getPath(defaultDir));
// tree.scrollPathToVisible(treeModel.getPath(defaultDir));
// Automatically expand any nodes if they only have one child
tree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
Object node = event.getPath().getLastPathComponent();
if ((!treeModel.isLeaf(node)) && (treeModel.getChildCount(node) == 1)) {
tree.expandPath(event.getPath().pathByAddingChild(treeModel.getChild(node, 0)));
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}
});
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
if (path != null) {
((Node) path.getLastPathComponent()).doubleClicked();
}
}
}
});
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setSize(1024, 768);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
}
use of javax.swing.event.TreeExpansionListener in project cayenne by apache.
the class DbImportTree method createTreeExpandListener.
private void createTreeExpandListener() {
TreeExpansionListener treeExpansionListener = new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
TreePath path = event.getPath();
Object lastPathComponent = path.getLastPathComponent();
if (!(lastPathComponent instanceof TransferableNode)) {
return;
}
DbImportTreeNode node = (DbImportTreeNode) lastPathComponent;
if ((node.isIncludeTable() || node.isSchema() || node.isCatalog()) && !node.isLoaded()) {
// reload tables and columns action.
LoadDbSchemaAction action = Application.getInstance().getActionManager().getAction(LoadDbSchemaAction.class);
action.performAction(null, path);
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}
};
this.addTreeExpansionListener(treeExpansionListener);
}
Aggregations