Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DarkLaf equivalent of "File breadcrumbs" #237

Open
GraxCode opened this issue Jun 13, 2021 · 19 comments
Open

DarkLaf equivalent of "File breadcrumbs" #237

GraxCode opened this issue Jun 13, 2021 · 19 comments
Labels
enhancement New feature or request

Comments

@GraxCode
Copy link

General description
image
This component was included in WebLaF under the name "File breadcrumbs". I am looking for a darklaf implementation. Is there one?

Additional context
Intellij also has such a bar. Examples here:
image
image

@GraxCode GraxCode added the enhancement New feature or request label Jun 13, 2021
@weisJ
Copy link
Owner

weisJ commented Jun 13, 2021

I'm currently writing a library swingdsl containing several quality of life enhancements for developing swing applications. It also contains a BreadcrumbBar implementation. Though it currently doesn't provide the popup mechanism from WebLaf or IntelliJ, this is something I can add (including some specialized version for Files).

@weisJ
Copy link
Owner

weisJ commented Jun 15, 2021

I think the most convenient way to do this would be to connect the breadcrumb bar with a TreeModel, where clicking an element opens a popup with all children. Do you already have a tree model of the folder structure at hand?

@GraxCode
Copy link
Author

I don't. I intend to use it as a simple file browsing tool (as in intellij).

@weisJ
Copy link
Owner

weisJ commented Jun 15, 2021

I see. Luckily I already have a TreeModel for file structures at hand 😄

@weisJ
Copy link
Owner

weisJ commented Jun 20, 2021

With the latest snapshot version of swing.dsl there is now a BreadcrumbBar for files available.

Here is a short working example of how to use it:

fun main() = onSwingThread {
    LafManager.install()
    frame {
        content {
            borderPanel {
                val fsv = FileSystemView.getFileSystemView()
                val rootFiles = fsv.getFiles(fsv.roots[0], true)
                val fileTree = FileTree(showHiddenFiles = false, *rootFiles)
                fileTree.setSelectionRow(0)
                north {
                    +createFileBreadcrumbBar(fileTree)
                }
                center {
                    scrollPane { +fileTree }
                }
            }
        }
        centerOnScreen()
        visible = true
    }
}

Note that the FileTree implementation populates it's content lazily, which may result in a tiny amount of wait before child nodes are visible, even for small directories. I'll probably add support for pre-fetching directories up to a certain depth further down the road.
Also the popup, which is displayed, when clicking a folder in the breadcrumbs currently isn't limited in it's size. Eventually this will make use of the scrollable popups available in darklaf.

@GraxCode
Copy link
Author

Is this also usable using a down-to-earth java swing application? I really appreciate your work. Thank you very much.

@weisJ
Copy link
Owner

weisJ commented Jun 20, 2021

Yes :). Here is the equivalent Java code:

SwingUtilities.invokeLater(() -> {
    LafManager.install();

    JFrame frame = new JFrame();
    JPanel content = new JPanel(new BorderLayout());

    FileSystemView fsv = FileSystemView.getFileSystemView();
    File[] rootFiles = fsv.getFiles(fsv.getRoots()[0], true);
    FileTree fileTree = new FileTree(false, rootFiles);

    content.add(FileBreadcrumbBar.create(fileTree), BorderLayout.NORTH);
    content.add(new JScrollPane(fileTree), BorderLayout.CENTER);
    frame.setContentPane(content);
    frame.pack();

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
});

@GraxCode
Copy link
Author

Do I have to add swing-dsl as a library? Is it on maven / jitpack?

@weisJ
Copy link
Owner

weisJ commented Jun 22, 2021

The library is available on maven: https://search.maven.org/artifact/com.github.weisj/swing-dsl
Though the file breadcrumbs aren’t yet available in a released version, so you‘ll need to use a snapshot version.

@GraxCode
Copy link
Author

GraxCode commented Jul 4, 2021

I don't really want to add an unnecessary library to my project for a look and feel class. It would be nicer to have it as a darklaf implementation, but that's probably going to eat some time as it is written in kotlin i assume.

@weisJ
Copy link
Owner

weisJ commented Jul 4, 2021

I'll try to see whether it's feasible to port it to a standalone Java library.

@weisJ
Copy link
Owner

weisJ commented Jul 8, 2021

What I’ll do for now is to extract the components into a separate library. Of course this will still pull in the kotlin stdlib (which isn’t too big), but will allow me to rewrite the components in java once I find time for it.

@weisJ
Copy link
Owner

weisJ commented Jul 9, 2021

I have now done that. The coordinates are:

implementation("com.github.weisj:swing-extensions-components:latest.integration")

@GraxCode
Copy link
Author

Wow, that's pretty amazing! Will try it out when I have time.

@GraxCode
Copy link
Author

Getting a java.lang.ClassNotFoundException: com.github.weisj.darklaf.icons.IconLoader when trying to use with 3.0.0.

@weisJ
Copy link
Owner

weisJ commented Apr 19, 2022

Please try implementation("com.github.weisj:swing-extensions-components:0.2.0-SNAPSHOT"). If it works I'll release it as a stable version.

@GraxCode
Copy link
Author

Seems to work now. (I only tested the breadcrumb stuff.)

@GraxCode
Copy link
Author

I am still not sure how to implement a BreadcrumbBar correctly with my own tree structure.

@weisJ
Copy link
Owner

weisJ commented Apr 20, 2022

Here is an example

DefaultMutableTreeNode root = new DefaultMutableTreeNode();
root.add(new DefaultMutableTreeNode("Child 1"));
root.add(new DefaultMutableTreeNode("Child 2"));
TreeModel treeModel = new DefaultTreeModel(root);
JTree tree = new JTree(treeModel);
TreeBreadCrumbModel<DefaultMutableTreeNode, String> breadCrumbModel = new TreeBreadCrumbModel<>(
    tree, treeNode -> (String) treeNode.getUserObject());
BreadcrumbBar<DefaultMutableTreeNode, String> breadcrumbBar = new BreadcrumbBar<>(breadCrumbModel);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants