Skip to content

Commit

Permalink
Merge pull request #616 from neph1/Issue#606-duplicate-materials
Browse files Browse the repository at this point in the history
Issue-606. replace String list with TreeSet
  • Loading branch information
tonihele authored Sep 28, 2024
2 parents e5b33e8 + fe12153 commit d02c3ca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
88 changes: 44 additions & 44 deletions jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -215,9 +216,7 @@ private void loadGradleClassLoader(List<URL> urls) {
runtimeFiles = sourceSet.getRuntimeClassPath();
}
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
} catch (IllegalArgumentException ex) {
} catch (IOException | IllegalArgumentException ex) {
Exceptions.printStackTrace(ex);
}

Expand All @@ -243,25 +242,31 @@ private void loadGradleClassLoader(List<URL> 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) {
}

Expand All @@ -271,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();
Expand All @@ -303,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) {
Expand All @@ -311,6 +313,7 @@ public void assetLoaded(AssetKey ak) {
}
}

@Override
public void assetRequested(AssetKey ak) {
synchronized (assetEventListeners) {
for (AssetEventListener assetEventListener : assetEventListeners) {
Expand All @@ -319,6 +322,7 @@ public void assetRequested(AssetKey ak) {
}
}

@Override
public void assetDependencyNotFound(AssetKey ak, AssetKey ak1) {
synchronized (assetEventListeners) {
for (AssetEventListener assetEventListener : assetEventListeners) {
Expand Down Expand Up @@ -425,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 + "/";
Expand Down Expand Up @@ -506,12 +511,12 @@ public String[] getMatDefs(boolean includeDependencies) {
return filesWithSuffix("j3md", includeDependencies);
}

public List<String> getProjectShaderNodeDefs() {
return collectProjectFilesWithSuffix("j3sn", new LinkedList<>());
public Set<String> getProjectShaderNodeDefs() {
return collectProjectFilesWithSuffix("j3sn", new TreeSet<>());
}

public List<String> getDependenciesShaderNodeDefs() {
return collectDependenciesFilesWithSuffix("j3sn", new LinkedList<>());
public Set<String> getDependenciesShaderNodeDefs() {
return collectDependenciesFilesWithSuffix("j3sn", new TreeSet<>());
}

public String[] getAssetsWithSuffix(String string) {
Expand All @@ -523,20 +528,20 @@ public String[] getAssetsWithSuffix(String string, boolean includeDependencies)
}

private String[] filesWithSuffix(String string, boolean includeDependencies) {
List<String> list = collectFilesWithSuffix(string, includeDependencies);
Set<String> list = collectFilesWithSuffix(string, includeDependencies);
return list.toArray(String[]::new);
}

private List<String> collectFilesWithSuffix(String suffix, boolean includeDependencies) {
List<String> list = new LinkedList<>();
private Set<String> collectFilesWithSuffix(String suffix, boolean includeDependencies) {
Set<String> list = new TreeSet<>();
collectProjectFilesWithSuffix(suffix, list);
if(includeDependencies) {
collectDependenciesFilesWithSuffix(suffix, list);
}
return list;
}

private List<String> collectProjectFilesWithSuffix(String suffix, List<String> list) {
private Set<String> collectProjectFilesWithSuffix(String suffix, Set<String> list) {
FileObject assetsFolder = getAssetFolder();
if (assetsFolder != null) {
Enumeration<FileObject> assets = (Enumeration<FileObject>) assetsFolder.getChildren(true);
Expand All @@ -550,12 +555,9 @@ private List<String> collectProjectFilesWithSuffix(String suffix, List<String> l
return list;
}

private List<String> collectDependenciesFilesWithSuffix(String suffix, List<String> list) {
private Set<String> collectDependenciesFilesWithSuffix(String suffix, Set<String> list) {
synchronized (classPathItems) {
// TODO I need to find out if classPathItems contains all jars added to a project
Iterator<ClassPathItem> 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
Expand All @@ -572,19 +574,18 @@ private List<String> collectDependenciesFilesWithSuffix(String suffix, List<Stri
}
}
}

}
return list;
// TODO I need to find out if classPathItems contains all jars added to a project
return list;
}
}

public InputStream getResourceAsStream(String name) {
InputStream in = null;//JmeSystem.getResourceAsStream(name);
synchronized (classPathItems) {
// TODO I need to find out if classPathItems contains all jars added to a project
Iterator<ClassPathItem> classPathItemsIter = classPathItems.iterator();
while (classPathItemsIter.hasNext()) {
ClassPathItem classPathItem = classPathItemsIter.next();

for (ClassPathItem classPathItem : classPathItems) {
FileObject jarFile = classPathItem.object;

Enumeration<FileObject> jarEntry;
Expand Down Expand Up @@ -692,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);
}
}
});
Expand Down Expand Up @@ -729,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;
Expand All @@ -743,7 +744,6 @@ public FileObject getProjectDirectory() {

private static class ClassPathItem {

ClassPath path;
FileObject object;
FileChangeListener listener;

Expand Down

0 comments on commit d02c3ca

Please sign in to comment.