From fea615b85aed5d77c4d1552966a022e1be3b828e Mon Sep 17 00:00:00 2001 From: rickard Date: Tue, 24 Sep 2024 18:56:01 +0200 Subject: [PATCH 1/3] Issue-606. replace String list with TreeSet --- .../gde/core/assets/ProjectAssetManager.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java b/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java index 14798ec9..0a465a67 100644 --- a/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java +++ b/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java @@ -50,6 +50,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.api.java.classpath.ClassPath; @@ -506,12 +507,12 @@ public String[] getMatDefs(boolean includeDependencies) { return filesWithSuffix("j3md", includeDependencies); } - public List getProjectShaderNodeDefs() { - return collectProjectFilesWithSuffix("j3sn", new LinkedList<>()); + public Set getProjectShaderNodeDefs() { + return collectProjectFilesWithSuffix("j3sn", new TreeSet<>()); } - public List getDependenciesShaderNodeDefs() { - return collectDependenciesFilesWithSuffix("j3sn", new LinkedList<>()); + public Set getDependenciesShaderNodeDefs() { + return collectDependenciesFilesWithSuffix("j3sn", new TreeSet<>()); } public String[] getAssetsWithSuffix(String string) { @@ -523,12 +524,12 @@ public String[] getAssetsWithSuffix(String string, boolean includeDependencies) } private String[] filesWithSuffix(String string, boolean includeDependencies) { - List list = collectFilesWithSuffix(string, includeDependencies); + Set list = collectFilesWithSuffix(string, includeDependencies); return list.toArray(String[]::new); } - private List collectFilesWithSuffix(String suffix, boolean includeDependencies) { - List list = new LinkedList<>(); + private Set collectFilesWithSuffix(String suffix, boolean includeDependencies) { + Set list = new TreeSet<>(); collectProjectFilesWithSuffix(suffix, list); if(includeDependencies) { collectDependenciesFilesWithSuffix(suffix, list); @@ -536,7 +537,7 @@ private List collectFilesWithSuffix(String suffix, boolean includeDepend return list; } - private List collectProjectFilesWithSuffix(String suffix, List list) { + private Set collectProjectFilesWithSuffix(String suffix, Set list) { FileObject assetsFolder = getAssetFolder(); if (assetsFolder != null) { Enumeration assets = (Enumeration) assetsFolder.getChildren(true); @@ -550,7 +551,7 @@ private List collectProjectFilesWithSuffix(String suffix, List l return list; } - private List collectDependenciesFilesWithSuffix(String suffix, List list) { + private Set collectDependenciesFilesWithSuffix(String suffix, Set list) { synchronized (classPathItems) { // TODO I need to find out if classPathItems contains all jars added to a project Iterator classPathItemsIter = classPathItems.iterator(); From e9d85c9462ecfc545ce5bfb83ab2afee5c946039 Mon Sep 17 00:00:00 2001 From: rickard Date: Tue, 24 Sep 2024 19:03:31 +0200 Subject: [PATCH 2/3] Mandatory maintenance --- .../gde/core/assets/ProjectAssetManager.java | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java b/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java index 0a465a67..d19e45d9 100644 --- a/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java +++ b/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2010 jMonkeyEngine + * Copyright (c) 2009-2024 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -216,9 +216,7 @@ private void loadGradleClassLoader(List urls) { runtimeFiles = sourceSet.getRuntimeClassPath(); } } - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } catch (IllegalArgumentException ex) { + } catch (IOException | IllegalArgumentException ex) { Exceptions.printStackTrace(ex); } @@ -244,25 +242,31 @@ private void loadGradleClassLoader(List urls) { } FileChangeListener listener = new FileChangeListener() { + @Override public void fileFolderCreated(FileEvent fe) { fireChange(fe); } + @Override public void fileDataCreated(FileEvent fe) { fireChange(fe); } + @Override public void fileChanged(FileEvent fe) { fireChange(fe); } + @Override public void fileDeleted(FileEvent fe) { } + @Override public void fileRenamed(FileRenameEvent fe) { fireChange(fe); } + @Override public void fileAttributeChanged(FileAttributeEvent fae) { } @@ -272,26 +276,22 @@ private void fireChange(FileEvent fe) { } }; - private PropertyChangeListener classPathListener = new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - logger.log(Level.FINE, "Classpath event: {0}", evt); - if (null != evt.getPropertyName()) switch (evt.getPropertyName()) { - case ClassPath.PROP_ROOTS -> updateClassLoader(); - case ClassPath.PROP_ENTRIES -> updateClassLoader(); - case ClassPath.PROP_INCLUDES -> updateClassLoader(); - default -> { - } + private PropertyChangeListener classPathListener = (PropertyChangeEvent evt) -> { + logger.log(Level.FINE, "Classpath event: {0}", evt); + if (null != evt.getPropertyName()) switch (evt.getPropertyName()) { + case ClassPath.PROP_ROOTS -> updateClassLoader(); + case ClassPath.PROP_ENTRIES -> updateClassLoader(); + case ClassPath.PROP_INCLUDES -> updateClassLoader(); + default -> { } } }; public void updateClassLoader() { - ProjectManager.mutex().postWriteRequest(new Runnable() { - public void run() { - synchronized (classPathItems) { - clearClassLoader(); - loadClassLoader(); - } + ProjectManager.mutex().postWriteRequest(() -> { + synchronized (classPathItems) { + clearClassLoader(); + loadClassLoader(); } }); notifyClassPathListeners(); @@ -304,6 +304,7 @@ public void setAssetEventListener(AssetEventListener listener) { private void prepAssetEventListeners() { super.setAssetEventListener(new AssetEventListener() { + @Override public void assetLoaded(AssetKey ak) { synchronized (assetEventListeners) { for (AssetEventListener assetEventListener : assetEventListeners) { @@ -312,6 +313,7 @@ public void assetLoaded(AssetKey ak) { } } + @Override public void assetRequested(AssetKey ak) { synchronized (assetEventListeners) { for (AssetEventListener assetEventListener : assetEventListeners) { @@ -320,6 +322,7 @@ public void assetRequested(AssetKey ak) { } } + @Override public void assetDependencyNotFound(AssetKey ak, AssetKey ak1) { synchronized (assetEventListeners) { for (AssetEventListener assetEventListener : assetEventListeners) { @@ -426,6 +429,7 @@ public FileObject createAsset(String path, FileObject source) { /** * Adds a locator to a folder within the main project directory + * @param relativePath */ public void addFolderLocator(String relativePath) { String string = project.getProjectDirectory().getPath() + "/" + relativePath + "/"; @@ -553,10 +557,7 @@ private Set collectProjectFilesWithSuffix(String suffix, Set lis private Set collectDependenciesFilesWithSuffix(String suffix, Set list) { synchronized (classPathItems) { - // TODO I need to find out if classPathItems contains all jars added to a project - Iterator classPathItemsIter = classPathItems.iterator(); - while (classPathItemsIter.hasNext()) { - ClassPathItem classPathItem = classPathItemsIter.next(); + for (ClassPathItem classPathItem : classPathItems) { FileObject jarFile = classPathItem.object; // Gradle projects don't know that the dependency is a Jar file @@ -573,9 +574,9 @@ private Set collectDependenciesFilesWithSuffix(String suffix, Set classPathItemsIter = classPathItems.iterator(); - while (classPathItemsIter.hasNext()) { - ClassPathItem classPathItem = classPathItemsIter.next(); + + for (ClassPathItem classPathItem : classPathItems) { FileObject jarFile = classPathItem.object; Enumeration jarEntry; @@ -693,12 +693,10 @@ public void removeClassPathEventListener(ClassPathChangeListener listener) { private void notifyClassPathListeners() { final ProjectAssetManager pm = this; - java.awt.EventQueue.invokeLater(new Runnable() { - public void run() { - synchronized (classPathListeners) { - for (ClassPathChangeListener classPathChangeListener : classPathListeners) { - classPathChangeListener.classPathChanged(pm); - } + java.awt.EventQueue.invokeLater(() -> { + synchronized (classPathListeners) { + for (ClassPathChangeListener classPathChangeListener : classPathListeners) { + classPathChangeListener.classPathChanged(pm); } } }); @@ -730,10 +728,12 @@ public DummyProject(ProjectAssetManager pm) { this.pm = pm; } + @Override public Lookup getLookup() { return Lookups.fixed(this, pm); } + @Override public FileObject getProjectDirectory() { if (folder != null) { return folder; @@ -744,7 +744,6 @@ public FileObject getProjectDirectory() { private static class ClassPathItem { - ClassPath path; FileObject object; FileChangeListener listener; From fe12153fcd2128631a87f29bcc535939dc84b364 Mon Sep 17 00:00:00 2001 From: rickard Date: Wed, 25 Sep 2024 17:07:41 +0200 Subject: [PATCH 3/3] Fix AssetBrowser issue if filter is null --- .../src/com/jme3/gde/assetbrowser/AssetBrowser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jme3-assetbrowser/src/com/jme3/gde/assetbrowser/AssetBrowser.java b/jme3-assetbrowser/src/com/jme3/gde/assetbrowser/AssetBrowser.java index 14ab678e..8e58124c 100644 --- a/jme3-assetbrowser/src/com/jme3/gde/assetbrowser/AssetBrowser.java +++ b/jme3-assetbrowser/src/com/jme3/gde/assetbrowser/AssetBrowser.java @@ -90,7 +90,7 @@ public class AssetBrowser extends javax.swing.JPanel implements PreviewInteracti private int lastGridColumns = 0; private int lastGridRows = 0; - private String lastFilter; + private String lastFilter = ""; private int sizeX = Constants.sizeX; private int sizeY = Constants.sizeY; @@ -155,7 +155,7 @@ private void loadAssets(String filter) { Dimension size = previewsPanel.getSize(); int rows = Math.min(size.height, getHeight() - 30) / sizeY; - + final var textures = Arrays.stream(assetManager.getTextures()).filter(s -> filter.isEmpty() || s.toLowerCase().contains(filter)).collect(Collectors.toList()); final var materials = Arrays.stream(assetManager.getMaterials()).filter(s -> filter.isEmpty() || s.toLowerCase().contains(filter)).collect(Collectors.toList()); final var models = Arrays.stream(assetManager.getModels()).filter(s -> filter.isEmpty() || s.toLowerCase().contains(filter)).collect(Collectors.toList());