├── .prettierrc.js ├── readme_images ├── img_1.png ├── img_2.png ├── img_3.png ├── img_4.png ├── img_5.png ├── img_6.png ├── img_7.png ├── img_8.png ├── img_9.png ├── img_10.png └── img_11.png ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ ├── maven-wrapper.properties │ └── MavenWrapperDownloader.java ├── src └── main │ ├── resources │ ├── trayicon.png │ ├── META-INF │ │ └── resources │ │ │ └── icons │ │ │ ├── icon.ico │ │ │ └── icon.png │ ├── banner.txt │ └── application.properties │ └── java │ └── bt │ └── assetmanager │ ├── obj │ ├── HasFilePath.java │ └── FileBundler.java │ ├── workers │ ├── BackgroundWorker.java │ ├── AssetSearchWorker.java │ ├── ExportTagsToMetadataWorker.java │ ├── FileSearchWorker.java │ └── FileImportWorker.java │ ├── data │ ├── entity │ │ ├── Asset.java │ │ ├── ImageFileEnding.java │ │ ├── SoundFileEnding.java │ │ ├── TempImageAsset.java │ │ ├── TempSoundAsset.java │ │ ├── Tag.java │ │ ├── ImageAsset.java │ │ ├── SoundAsset.java │ │ └── UserOption.java │ ├── repository │ │ ├── UserOptionsRepository.java │ │ ├── ImageFileEndingRepository.java │ │ ├── SoundFileEndingRepository.java │ │ ├── TagRepository.java │ │ ├── TempImageAssetRepository.java │ │ ├── TempSoundAssetRepository.java │ │ ├── ImageAssetRepository.java │ │ └── SoundAssetRepository.java │ └── service │ │ ├── AssetService.java │ │ ├── BaseAssetService.java │ │ ├── TagService.java │ │ ├── ImageAssetService.java │ │ ├── SoundAssetService.java │ │ └── UserOptionService.java │ ├── constants │ └── AssetManagerConstants.java │ ├── util │ ├── UIUtils.java │ └── metadata │ │ ├── image │ │ └── ImageFileMetadataUtils.java │ │ └── FileMetadataUtils.java │ ├── components │ ├── options │ │ ├── UserOptionCheckbox.java │ │ ├── UserOptionNumberField.java │ │ └── DefaultUserOptionsSetter.java │ ├── assetview │ │ ├── AssetGridRow.java │ │ ├── AssetDisplay.java │ │ ├── AssetView.java │ │ ├── AssetListDisplay.java │ │ └── AssetGridDisplay.java │ ├── AudioPlayer.java │ ├── TagSearchTextField.java │ ├── ScrollTreeGrid.java │ └── AssetSearchPanel.java │ ├── views │ ├── sounds │ │ └── SoundsView.java │ ├── images │ │ └── ImagesView.java │ ├── import_ │ │ └── AssetImportRow.java │ ├── MainLayout.java │ └── options │ │ └── OptionsView.java │ ├── tray │ └── SystemTrayOptions.java │ └── Application.java ├── frontend └── themes │ └── btassetmanager │ ├── theme.json │ ├── views │ ├── options-view.css │ ├── import-view.css │ ├── sounds-view.css │ └── images-view.css │ ├── components │ └── vaadin-button.css │ ├── styles.css │ └── main-layout.css ├── packageAssets ├── linux │ └── BtAssetManager.png ├── mac │ └── BtAssetManager.icns └── windows │ └── BtAssetManager.ico ├── types.d.ts ├── .npmrc ├── .gitignore ├── tsconfig.json ├── webpack.config.js ├── README.md ├── mvnw.cmd ├── mvnw ├── LICENSE └── pom.xml /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | singleQuote: true, 3 | printWidth: 120, 4 | }; 5 | -------------------------------------------------------------------------------- /readme_images/img_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_1.png -------------------------------------------------------------------------------- /readme_images/img_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_2.png -------------------------------------------------------------------------------- /readme_images/img_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_3.png -------------------------------------------------------------------------------- /readme_images/img_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_4.png -------------------------------------------------------------------------------- /readme_images/img_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_5.png -------------------------------------------------------------------------------- /readme_images/img_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_6.png -------------------------------------------------------------------------------- /readme_images/img_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_7.png -------------------------------------------------------------------------------- /readme_images/img_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_8.png -------------------------------------------------------------------------------- /readme_images/img_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_9.png -------------------------------------------------------------------------------- /readme_images/img_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_10.png -------------------------------------------------------------------------------- /readme_images/img_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/readme_images/img_11.png -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/trayicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/src/main/resources/trayicon.png -------------------------------------------------------------------------------- /frontend/themes/btassetmanager/theme.json: -------------------------------------------------------------------------------- 1 | { 2 | "lumoImports" : [ "typography", "color", "spacing", "badge", "utility" ] 3 | } -------------------------------------------------------------------------------- /packageAssets/linux/BtAssetManager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/packageAssets/linux/BtAssetManager.png -------------------------------------------------------------------------------- /packageAssets/mac/BtAssetManager.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/packageAssets/mac/BtAssetManager.icns -------------------------------------------------------------------------------- /packageAssets/windows/BtAssetManager.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/packageAssets/windows/BtAssetManager.ico -------------------------------------------------------------------------------- /types.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.css' { 2 | import { CSSResultGroup } from 'lit'; 3 | const content: CSSResultGroup; 4 | export default content; 5 | } 6 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | # 2 | # NOTICE: this is an auto-generated file 3 | # 4 | # This file sets the default parameters for manual `pnpm install`. 5 | # 6 | shamefully-hoist=true 7 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/resources/icons/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/src/main/resources/META-INF/resources/icons/icon.ico -------------------------------------------------------------------------------- /src/main/resources/META-INF/resources/icons/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bowtie8904/BtAssetManager/HEAD/src/main/resources/META-INF/resources/icons/icon.png -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/obj/HasFilePath.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.obj; 2 | 3 | /** 4 | * @author Lukas Hartwig 5 | * @since 08.09.2022 6 | */ 7 | public interface HasFilePath 8 | { 9 | public String getPath(); 10 | } -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/workers/BackgroundWorker.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.workers; 2 | 3 | import com.vaadin.flow.component.UI; 4 | 5 | /** 6 | * @author Lukas Hartwig 7 | * @since 07.09.2022 8 | */ 9 | public interface BackgroundWorker 10 | { 11 | public void work(UI ui); 12 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/entity/Asset.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.entity; 2 | 3 | import bt.assetmanager.obj.HasFilePath; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Lukas Hartwig 9 | * @since 31.08.2022 10 | */ 11 | public interface Asset extends HasFilePath 12 | { 13 | public List getTags(); 14 | 15 | public void setTags(List tags); 16 | 17 | public String getFileName(); 18 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/repository/UserOptionsRepository.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.repository; 2 | 3 | import bt.assetmanager.data.entity.UserOption; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Lukas Hartwig 8 | * @since 08.09.2022 9 | */ 10 | public interface UserOptionsRepository extends JpaRepository 11 | { 12 | public UserOption findByName(String name); 13 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/repository/ImageFileEndingRepository.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.repository; 2 | 3 | import bt.assetmanager.data.entity.ImageFileEnding; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @author Lukas Hartwig 9 | * @since 29.08.2022 10 | */ 11 | @Repository 12 | public interface ImageFileEndingRepository extends JpaRepository 13 | { 14 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/repository/SoundFileEndingRepository.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.repository; 2 | 3 | import bt.assetmanager.data.entity.SoundFileEnding; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @author Lukas Hartwig 9 | * @since 29.08.2022 10 | */ 11 | @Repository 12 | public interface SoundFileEndingRepository extends JpaRepository 13 | { 14 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | .idea/ 3 | .vscode/ 4 | .settings 5 | .project 6 | .classpath 7 | 8 | *.iml 9 | .DS_Store 10 | 11 | # The following files are generated/updated by vaadin-maven-plugin 12 | node_modules/ 13 | frontend/generated/ 14 | pnpmfile.js 15 | vite.generated.ts 16 | 17 | # Browser drivers for local integration tests 18 | drivers/ 19 | # Error screenshots generated by TestBench for failed integration tests 20 | error-screenshots/ 21 | webpack.generated.js 22 | /jdk/ 23 | /jre/ 24 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/constants/AssetManagerConstants.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.constants; 2 | 3 | import java.nio.file.Path; 4 | 5 | /** 6 | * @author Lukas Hartwig 7 | * @since 05.09.2022 8 | */ 9 | public final class AssetManagerConstants 10 | { 11 | public static final Path TEMP_FILE_DIRECTORY = Path.of(".\\tempFiles\\"); 12 | public static final String UNTAGGED_TAG_NAME = "UNTAGGED"; 13 | 14 | static 15 | { 16 | TEMP_FILE_DIRECTORY.toFile().mkdirs(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ____ _ _ _ __ __ 2 | | __ ) | |_ / \ ___ ___ ___ | |_ | \/ | __ _ _ __ __ _ __ _ ___ _ __ 3 | | _ \ | __| / _ \ / __|/ __| / _ \| __|| |\/| | / _` || '_ \ / _` | / _` | / _ \| '__| 4 | | |_) || |_ / ___ \ \__ \\__ \| __/| |_ | | | || (_| || | | || (_| || (_| || __/| | 5 | |____/ \__|/_/ \_\|___/|___/ \___| \__||_| |_| \__,_||_| |_| \__,_| \__, | \___||_| 6 | |___/ 7 | -------------------------------------------------------------------------------- /frontend/themes/btassetmanager/views/options-view.css: -------------------------------------------------------------------------------- 1 | .options-view { 2 | display: flex; 3 | flex-direction: column; 4 | height: 100%; 5 | } 6 | 7 | .options-view vaadin-split-layout { 8 | width: 100%; 9 | height: 100%; 10 | } 11 | 12 | .options-view vaadin-checkbox { 13 | padding-top: 50px; 14 | } 15 | 16 | .options-view vaadin-horizontal-layout { 17 | padding-top: 50px; 18 | } 19 | 20 | .options-view vaadin-vertical-layout { 21 | padding-top: 50px; 22 | padding-left: 100px; 23 | } 24 | 25 | .options-view vaadin-horizontal-layout label { 26 | padding-bottom: 25px; 27 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/util/UIUtils.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.util; 2 | 3 | import com.vaadin.flow.component.html.Span; 4 | 5 | /** 6 | * @author Lukas Hartwig 7 | * @since 02.09.2022 8 | */ 9 | public final class UIUtils 10 | { 11 | private UIUtils() 12 | { 13 | 14 | } 15 | 16 | public static Span heightFiller(String height) 17 | { 18 | Span span = new Span(); 19 | span.setHeight(height); 20 | return span; 21 | } 22 | 23 | public static Span widthFiller(String width) 24 | { 25 | Span span = new Span(); 26 | span.setWidth(width); 27 | return span; 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/service/AssetService.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.service; 2 | 3 | import bt.assetmanager.data.entity.Asset; 4 | 5 | import java.io.Serializable; 6 | import java.util.List; 7 | 8 | /** 9 | * @author Lukas Hartwig 10 | * @since 31.08.2022 11 | */ 12 | public interface AssetService extends Serializable 13 | { 14 | public List findByTags(List tags); 15 | 16 | public List findByFileName(String fileName); 17 | 18 | public void save(T entity, boolean saveTagsInMetadataFile); 19 | 20 | public void delete(T entity); 21 | 22 | public List findAll(); 23 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/repository/TagRepository.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.repository; 2 | 3 | import bt.assetmanager.data.entity.Tag; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | /** 11 | * @author Lukas Hartwig 12 | * @since 29.08.2022 13 | */ 14 | @Repository 15 | public interface TagRepository extends JpaRepository, Serializable 16 | { 17 | public Tag findByNameIgnoreCase(String name); 18 | 19 | public boolean existsByNameIgnoreCase(String name); 20 | 21 | public List findFirst5ByNameContainingIgnoreCase(String name); 22 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/options/UserOptionCheckbox.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components.options; 2 | 3 | import bt.assetmanager.data.service.UserOptionService; 4 | import com.vaadin.flow.component.checkbox.Checkbox; 5 | 6 | /** 7 | * @author Lukas Hartwig 8 | * @since 08.09.2022 9 | */ 10 | public class UserOptionCheckbox extends Checkbox 11 | { 12 | 13 | public UserOptionCheckbox(UserOptionService optionsService, String optionName, String label, String tooltip) 14 | { 15 | setValue(optionsService.getBooleanValue(optionName)); 16 | setLabel(label); 17 | getElement().setProperty("title", tooltip); 18 | 19 | addValueChangeListener(e -> optionsService.setValue(optionName, e.getValue())); 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/entity/ImageFileEnding.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.entity; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | /** 8 | * @author Lukas Hartwig 9 | * @since 29.08.2022 10 | */ 11 | @Entity 12 | public class ImageFileEnding 13 | { 14 | @Id 15 | @GeneratedValue 16 | private Long id; 17 | 18 | private String ending; 19 | 20 | public Long getId() 21 | { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) 26 | { 27 | this.id = id; 28 | } 29 | 30 | public String getEnding() 31 | { 32 | return ending; 33 | } 34 | 35 | public void setEnding(String ending) 36 | { 37 | this.ending = ending; 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/entity/SoundFileEnding.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.entity; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | /** 8 | * @author Lukas Hartwig 9 | * @since 29.08.2022 10 | */ 11 | @Entity 12 | public class SoundFileEnding 13 | { 14 | @Id 15 | @GeneratedValue 16 | private Long id; 17 | 18 | private String ending; 19 | 20 | public Long getId() 21 | { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) 26 | { 27 | this.id = id; 28 | } 29 | 30 | public String getEnding() 31 | { 32 | return ending; 33 | } 34 | 35 | public void setEnding(String ending) 36 | { 37 | this.ending = ending; 38 | } 39 | } -------------------------------------------------------------------------------- /frontend/themes/btassetmanager/components/vaadin-button.css: -------------------------------------------------------------------------------- 1 | 2 | :host(:not([theme~="tertiary"])) { 3 | background-image: linear-gradient(var(--lumo-tint-5pct), var(--lumo-shade-5pct)); 4 | box-shadow: inset 0 0 0 1px var(--lumo-contrast-20pct); 5 | } 6 | :host(:not([theme~="tertiary"]):not([theme~="primary"]):not([theme~="error"]):not([theme~="success"])) { 7 | color: var(--lumo-body-text-color); 8 | } 9 | :host([focus-ring]:not([theme~="tertiary"])) { 10 | box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct), inset 0 0 0 1px var(--lumo-primary-color); 11 | } 12 | :host([focus-ring][theme~="primary"]) { 13 | box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct), inset 0 0 0 1px var(--lumo-primary-contrast-color); 14 | } 15 | :host([theme~="primary"]) { 16 | text-shadow: 0 -1px 0 var(--lumo-shade-20pct); 17 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/assetview/AssetGridRow.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components.assetview; 2 | 3 | import bt.assetmanager.data.entity.Asset; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * @author Lukas Hartwig 10 | * @since 08.09.2022 11 | */ 12 | public class AssetGridRow 13 | { 14 | private Map assets; 15 | private int currentIndex; 16 | 17 | public AssetGridRow() 18 | { 19 | this.assets = new HashMap<>(); 20 | this.currentIndex = 0; 21 | } 22 | 23 | public void add(Asset asset) 24 | { 25 | this.assets.put(this.currentIndex, asset); 26 | this.currentIndex++; 27 | } 28 | 29 | public Asset get(int index) 30 | { 31 | return this.assets.get(index); 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/entity/TempImageAsset.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.Id; 6 | 7 | /** 8 | * @author Lukas Hartwig 9 | * @since 28.08.2022 10 | */ 11 | @Entity 12 | public class TempImageAsset 13 | { 14 | @Id 15 | @Column(length = 9999) 16 | private String path; 17 | 18 | @Column(length = 9999) 19 | private String fileName; 20 | 21 | public String getPath() 22 | { 23 | return path; 24 | } 25 | 26 | public void setPath(String path) 27 | { 28 | this.path = path; 29 | } 30 | 31 | public String getFileName() 32 | { 33 | return fileName; 34 | } 35 | 36 | public void setFileName(String fileName) 37 | { 38 | this.fileName = fileName; 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/entity/TempSoundAsset.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.Id; 6 | 7 | /** 8 | * @author Lukas Hartwig 9 | * @since 28.08.2022 10 | */ 11 | @Entity 12 | public class TempSoundAsset 13 | { 14 | @Id 15 | @Column(length = 9999) 16 | private String path; 17 | 18 | @Column(length = 9999) 19 | private String fileName; 20 | 21 | public String getPath() 22 | { 23 | return path; 24 | } 25 | 26 | public void setPath(String path) 27 | { 28 | this.path = path; 29 | } 30 | 31 | public String getFileName() 32 | { 33 | return fileName; 34 | } 35 | 36 | public void setFileName(String fileName) 37 | { 38 | this.fileName = fileName; 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/repository/TempImageAssetRepository.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.repository; 2 | 3 | import bt.assetmanager.data.entity.TempImageAsset; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author Lukas Hartwig 12 | * @since 28.08.2022 13 | */ 14 | @Repository 15 | public interface TempImageAssetRepository extends JpaRepository 16 | { 17 | @Query("select tia " + 18 | "from TempImageAsset tia " + 19 | "where not exists " + 20 | "(" + 21 | "select ia " + 22 | "from ImageAsset ia " + 23 | "where ia.path = tia.path" + 24 | ")") 25 | public List getAllNonExisting(); 26 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/repository/TempSoundAssetRepository.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.repository; 2 | 3 | import bt.assetmanager.data.entity.TempSoundAsset; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author Lukas Hartwig 12 | * @since 28.08.2022 13 | */ 14 | @Repository 15 | public interface TempSoundAssetRepository extends JpaRepository 16 | { 17 | @Query("select tsa " + 18 | "from TempSoundAsset tsa " + 19 | "where not exists " + 20 | "(" + 21 | "select sa " + 22 | "from SoundAsset sa " + 23 | "where sa.path = tsa.path" + 24 | ")") 25 | public List getAllNonExisting(); 26 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/AudioPlayer.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components; 2 | 3 | import com.vaadin.flow.component.Component; 4 | import com.vaadin.flow.component.Tag; 5 | import com.vaadin.flow.server.AbstractStreamResource; 6 | 7 | /** 8 | * @author Lukas Hartwig 9 | * @since 30.08.2022 10 | */ 11 | @Tag("audio") 12 | public class AudioPlayer extends Component 13 | { 14 | public AudioPlayer() 15 | { 16 | getElement().setAttribute("controls", true); 17 | getElement().setAttribute("loop", ""); 18 | } 19 | 20 | public void setSource(String path) 21 | { 22 | getElement().setProperty("src", path); 23 | } 24 | 25 | public void setSource(AbstractStreamResource resource) 26 | { 27 | getElement().setAttribute("src", resource); 28 | } 29 | 30 | public void play() 31 | { 32 | getElement().callJsFunction("play"); 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/assetview/AssetDisplay.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components.assetview; 2 | 3 | import bt.assetmanager.data.entity.Asset; 4 | import com.vaadin.flow.component.html.Div; 5 | import com.vaadin.flow.function.SerializableConsumer; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author Lukas Hartwig 11 | * @since 02.09.2022 12 | */ 13 | public abstract class AssetDisplay extends Div 14 | { 15 | protected SerializableConsumer onElementSelection; 16 | protected Class clazz; 17 | 18 | protected AssetDisplay(Class clazz) 19 | { 20 | this.clazz = clazz; 21 | } 22 | 23 | protected void setup() 24 | { 25 | } 26 | 27 | public void onElementSelection(SerializableConsumer consumer) 28 | { 29 | this.onElementSelection = consumer; 30 | } 31 | 32 | public abstract void setItems(List items); 33 | 34 | public abstract void removeItem(T item); 35 | } 36 | -------------------------------------------------------------------------------- /frontend/themes/btassetmanager/views/import-view.css: -------------------------------------------------------------------------------- 1 | .import-view { 2 | display: flex; 3 | flex-direction: column; 4 | height: 100%; 5 | } 6 | 7 | .import-view vaadin-split-layout { 8 | width: 100%; 9 | height: 100%; 10 | } 11 | 12 | .import-view vaadin-grid { 13 | height: 100%; 14 | } 15 | 16 | .import-view .input-layout { 17 | display: flex; 18 | flex-direction: column; 19 | width: 400px; 20 | } 21 | 22 | .import-view .input { 23 | flex-grow: 1; 24 | padding: var(--lumo-space-l); 25 | } 26 | 27 | .import-view .input vaadin-checkbox { 28 | padding-top: var(--lumo-space-m); 29 | } 30 | 31 | .import-view .button-layout { 32 | width: 100%; 33 | flex-wrap: wrap; 34 | background-color: var(--lumo-contrast-5pct); 35 | padding-bottom: var(--lumo-space-s); 36 | padding-top: var(--lumo-space-s); 37 | padding-left: var(--lumo-space-l); 38 | padding-right: var(--lumo-space-l); 39 | gap: var(--lumo-space-m); 40 | } 41 | 42 | .import-view .grid-wrapper { 43 | width: 100%; 44 | } 45 | -------------------------------------------------------------------------------- /frontend/themes/btassetmanager/views/sounds-view.css: -------------------------------------------------------------------------------- 1 | .sounds-view { 2 | display: flex; 3 | flex-direction: column; 4 | height: 100%; 5 | } 6 | 7 | .sounds-view vaadin-split-layout { 8 | width: 100%; 9 | height: 100%; 10 | } 11 | 12 | .sounds-view vaadin-grid { 13 | height: 100%; 14 | } 15 | 16 | .sounds-view .input-layout { 17 | display: flex; 18 | flex-direction: column; 19 | width: 400px; 20 | } 21 | 22 | .sounds-view .input { 23 | flex-grow: 1; 24 | padding: var(--lumo-space-l); 25 | } 26 | 27 | .sounds-view .input vaadin-checkbox { 28 | padding-top: var(--lumo-space-m); 29 | } 30 | 31 | .sounds-view .button-layout { 32 | width: 100%; 33 | flex-wrap: wrap; 34 | background-color: var(--lumo-contrast-5pct); 35 | padding-bottom: var(--lumo-space-s); 36 | padding-top: var(--lumo-space-s); 37 | padding-left: var(--lumo-space-l); 38 | padding-right: var(--lumo-space-l); 39 | gap: var(--lumo-space-m); 40 | } 41 | 42 | .sounds-view .grid-wrapper { 43 | width: 100%; 44 | } 45 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | // This TypeScript configuration file is generated by vaadin-maven-plugin. 2 | // This is needed for TypeScript compiler to compile your TypeScript code in the project. 3 | // It is recommended to commit this file to the VCS. 4 | // You might want to change the configurations to fit your preferences 5 | // For more information about the configurations, please refer to http://www.typescriptlang.org/docs/handbook/tsconfig-json.html 6 | { 7 | "compilerOptions": { 8 | "sourceMap": true, 9 | "inlineSources": true, 10 | "module": "esNext", 11 | "target": "es2019", 12 | "moduleResolution": "node", 13 | "strict": true, 14 | "noFallthroughCasesInSwitch": true, 15 | "noImplicitReturns": true, 16 | "noImplicitAny": true, 17 | "noImplicitThis": true, 18 | "noUnusedLocals": false, 19 | "noUnusedParameters": false, 20 | "experimentalDecorators": true, 21 | "baseUrl": "frontend", 22 | "paths": { 23 | "Frontend/*": [ 24 | "*" 25 | ] 26 | } 27 | }, 28 | "include": [ 29 | "frontend/**/*.ts", 30 | "frontend/index.js", 31 | "types.d.ts" 32 | ], 33 | "exclude": [] 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/repository/ImageAssetRepository.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.repository; 2 | 3 | import bt.assetmanager.data.entity.ImageAsset; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.query.Param; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author Lukas Hartwig 13 | * @since 28.08.2022 14 | */ 15 | @Repository 16 | public interface ImageAssetRepository extends JpaRepository 17 | { 18 | @Query("select distinct ia " + 19 | "from ImageAsset ia " + 20 | "join ia.tags as t " + 21 | "where t.name in :tagNames " + 22 | "group by ia " + 23 | "having count(t.id) = :size " + 24 | "order by ia.path") 25 | public List getAllForTags(@Param("tagNames") List tagNames, @Param("size") Long size); 26 | 27 | public List findByFileNameContainingIgnoreCase(String fileName); 28 | 29 | public boolean existsByPathIgnoreCase(String path); 30 | 31 | public List findAllByOrderByPathAsc(); 32 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/repository/SoundAssetRepository.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.repository; 2 | 3 | import bt.assetmanager.data.entity.SoundAsset; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.query.Param; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author Lukas Hartwig 13 | * @since 28.08.2022 14 | */ 15 | @Repository 16 | public interface SoundAssetRepository extends JpaRepository 17 | { 18 | @Query("select distinct sa " + 19 | "from SoundAsset sa " + 20 | "join sa.tags as t " + 21 | "where t.name in :tagNames " + 22 | "group by sa " + 23 | "having count(t.id) = :size " + 24 | "order by sa.path") 25 | public List getAllForTags(@Param("tagNames") List tagNames, @Param("size") Long size); 26 | 27 | public List findByFileNameContainingIgnoreCase(String fileName); 28 | 29 | public boolean existsByPathIgnoreCase(String path); 30 | 31 | public List findAllByOrderByPathAsc(); 32 | } -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=${PORT:4567} 2 | logging.level.org.atmosphere=warn 3 | spring.mustache.check-template-location=false 4 | # Launch the default browser when starting the application in development mode 5 | vaadin.launch-browser=false 6 | # To improve the performance during development. 7 | # For more information https://vaadin.com/docs/flow/spring/tutorial-spring-configuration.html#special-configuration-parameters 8 | vaadin.whitelisted-packages=com.vaadin,org.vaadin,dev.hilla,bt.assetmanager 9 | # Enabling H2 Console 10 | #spring.datasource.url=jdbc:h2:mem:testdb 11 | spring.datasource.url=jdbc:h2:file:./database/btam 12 | spring.jpa.hibernate.ddl-auto=update 13 | spring.datasource.driverClassName=org.h2.Driver 14 | spring.datasource.username=btam 15 | spring.datasource.password=secret 16 | spring.jpa.database-platform=org.hibernate.dialect.H2Dialect 17 | spring.h2.console.enabled=true 18 | spring.h2.console.path=/h2-console 19 | spring.h2.console.settings.trace=false 20 | spring.h2.console.settings.web-allow-others=true 21 | spring.data.jpa.repositories.bootstrap-mode=default 22 | spring.jpa.defer-datasource-initialization=true 23 | spring.jpa.show-sql=false 24 | spring.jpa.properties.hibernate.format_sql=true 25 | -------------------------------------------------------------------------------- /frontend/themes/btassetmanager/styles.css: -------------------------------------------------------------------------------- 1 | @import url('./main-layout.css'); 2 | @import url('./views/images-view.css'); 3 | @import url('./views/sounds-view.css'); 4 | @import url('./views/import-view.css'); 5 | @import url('./views/options-view.css'); 6 | @import url('line-awesome/dist/line-awesome/css/line-awesome.min.css'); 7 | [theme~="dark"] { 8 | --lumo-primary-color: hsl(220, 43%, 44%); 9 | --lumo-primary-color-50pct: hsla(220, 43%, 44%, 0.5); 10 | --lumo-primary-color-10pct: hsla(220, 43%, 44%, 0.1); 11 | --lumo-primary-text-color: hsl(214, 77%, 72%); 12 | --lumo-base-color: hsl(214, 12%, 21%); 13 | --lumo-shade: hsl(214, 31%, 11%); 14 | --lumo-shade-5pct: hsla(214, 31%, 11%, 0.05); 15 | --lumo-shade-10pct: hsla(214, 31%, 11%, 0.1); 16 | --lumo-shade-20pct: hsla(214, 31%, 11%, 0.2); 17 | --lumo-shade-30pct: hsla(214, 31%, 11%, 0.3); 18 | --lumo-shade-40pct: hsla(214, 31%, 11%, 0.4); 19 | --lumo-shade-50pct: hsla(214, 31%, 11%, 0.5); 20 | --lumo-shade-60pct: hsla(214, 31%, 11%, 0.6); 21 | --lumo-shade-70pct: hsla(214, 31%, 11%, 0.7); 22 | --lumo-shade-80pct: hsla(214, 31%, 11%, 0.8); 23 | --lumo-shade-90pct: hsla(214, 31%, 11%, 0.9); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/service/BaseAssetService.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.service; 2 | 3 | import bt.assetmanager.data.entity.Asset; 4 | import bt.assetmanager.util.metadata.FileMetadataUtils; 5 | import bt.assetmanager.util.metadata.image.ImageFileMetadataUtils; 6 | 7 | import java.io.File; 8 | import java.io.Serializable; 9 | 10 | /** 11 | * @author Lukas Hartwig 12 | * @since 04.09.2022 13 | */ 14 | public abstract class BaseAssetService implements AssetService 15 | { 16 | @Override 17 | public void save(T entity, boolean saveTagsInMetadataFile) 18 | { 19 | saveMetadata(entity, saveTagsInMetadataFile); 20 | } 21 | 22 | public void saveMetadata(T entity, boolean saveTagsInMetadataFile) 23 | { 24 | saveTagsInOSFileMetadata(entity); 25 | 26 | if (saveTagsInMetadataFile) 27 | { 28 | FileMetadataUtils.addTagsToMetadataFile(entity); 29 | } 30 | } 31 | 32 | protected void saveTagsInOSFileMetadata(T entity) 33 | { 34 | File file = new File(entity.getPath()); 35 | 36 | if (ImageFileMetadataUtils.isValidImageFormat(file)) 37 | { 38 | ImageFileMetadataUtils.saveWindowsExifMetadataTags(file, entity.getTags()); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/views/sounds/SoundsView.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.views.sounds; 2 | 3 | import bt.assetmanager.components.assetview.AssetView; 4 | import bt.assetmanager.data.entity.SoundAsset; 5 | import bt.assetmanager.data.service.SoundAssetService; 6 | import bt.assetmanager.data.service.TagService; 7 | import bt.assetmanager.data.service.UserOptionService; 8 | import bt.assetmanager.views.MainLayout; 9 | import com.vaadin.flow.component.dependency.Uses; 10 | import com.vaadin.flow.component.html.Div; 11 | import com.vaadin.flow.component.icon.Icon; 12 | import com.vaadin.flow.component.splitlayout.SplitLayout; 13 | import com.vaadin.flow.router.PageTitle; 14 | import com.vaadin.flow.router.Route; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | 17 | @PageTitle("Sounds - Asset manager") 18 | @Route(value = "sounds", layout = MainLayout.class) 19 | @Uses(Icon.class) 20 | public class SoundsView extends Div 21 | { 22 | @Autowired 23 | public SoundsView(SoundAssetService assetService, TagService tagService, UserOptionService optionsService) 24 | { 25 | addClassNames("images-view"); 26 | SplitLayout splitLayout = new AssetView(SoundAsset.class, assetService, tagService, optionsService); 27 | add(splitLayout); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/tray/SystemTrayOptions.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.tray; 2 | 3 | import bt.gui.swing.tray.DefaultSwingSystemTrayFrame; 4 | import bt.log.Log; 5 | 6 | import javax.imageio.ImageIO; 7 | import java.awt.*; 8 | import java.io.IOException; 9 | import java.net.URI; 10 | 11 | /** 12 | * @author Lukas Hartwig 13 | * @since 02.09.2022 14 | */ 15 | public class SystemTrayOptions extends DefaultSwingSystemTrayFrame 16 | { 17 | private String url; 18 | 19 | public SystemTrayOptions(int port) throws IOException 20 | { 21 | super(ImageIO.read(SystemTrayOptions.class.getResourceAsStream("/trayicon.png"))); 22 | 23 | this.url = "http://localhost:" + port + "/images"; 24 | 25 | var settings = getSystemTraySettings(); 26 | 27 | settings.addLabel("Asset manager"); 28 | settings.addSeparator(); 29 | 30 | settings.addOption("Open in browser", e -> openBrowser()); 31 | settings.addOption("Shutdown", e -> System.exit(0)); 32 | sendToSystemTray(); 33 | } 34 | 35 | public void openBrowser() 36 | { 37 | try 38 | { 39 | Desktop.getDesktop().browse(new URI(this.url)); 40 | } 41 | catch (Exception ex) 42 | { 43 | Log.error("Could not open browser", ex); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/service/TagService.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.service; 2 | 3 | import bt.assetmanager.data.entity.Tag; 4 | import bt.assetmanager.data.repository.TagRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.io.Serializable; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Lukas Hartwig 13 | * @since 29.08.2022 14 | */ 15 | @Service 16 | public class TagService implements Serializable 17 | { 18 | @Autowired 19 | private TagRepository tagRepo; 20 | 21 | public Tag obtainTag(String name) 22 | { 23 | if (this.tagRepo.existsByNameIgnoreCase(name)) 24 | { 25 | return this.tagRepo.findByNameIgnoreCase(name); 26 | } 27 | 28 | Tag newTag = new Tag(); 29 | newTag.setName(name.toUpperCase()); 30 | 31 | newTag = this.tagRepo.save(newTag); 32 | 33 | return newTag; 34 | } 35 | 36 | public List getTagNamesForValue(String partialTagName) 37 | { 38 | return this.tagRepo.findFirst5ByNameContainingIgnoreCase(partialTagName) 39 | .stream() 40 | .map(Tag::getName) 41 | .sorted() 42 | .toList(); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/entity/Tag.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import java.util.Objects; 8 | 9 | /** 10 | * @author Lukas Hartwig 11 | * @since 28.08.2022 12 | */ 13 | @Entity 14 | public class Tag 15 | { 16 | @Id 17 | @GeneratedValue 18 | private Long id; 19 | 20 | @Column(unique = true) 21 | private String name; 22 | 23 | public Long getId() 24 | { 25 | return id; 26 | } 27 | 28 | public void setId(Long id) 29 | { 30 | this.id = id; 31 | } 32 | 33 | public String getName() 34 | { 35 | return name; 36 | } 37 | 38 | public void setName(String name) 39 | { 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public int hashCode() 45 | { 46 | return Objects.hash(name); 47 | } 48 | 49 | @Override 50 | public boolean equals(Object o) 51 | { 52 | if (o instanceof Tag) 53 | { 54 | return ((Tag)o).getName().equalsIgnoreCase(this.name); 55 | } 56 | else if (o instanceof String) 57 | { 58 | return ((String)o).equalsIgnoreCase(this.name); 59 | } 60 | 61 | return false; 62 | } 63 | } -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has been autogenerated as it didn't exist or was made for an older incompatible version. 3 | * This file can be used for manual configuration will not be modified if the flowDefaults constant exists. 4 | */ 5 | const merge = require('webpack-merge'); 6 | const flowDefaults = require('./webpack.generated.js'); 7 | 8 | module.exports = merge(flowDefaults, { 9 | 10 | }); 11 | 12 | /** 13 | * This file can be used to configure the flow plugin defaults. 14 | * 15 | * // Add a custom plugin 16 | * flowDefaults.plugins.push(new MyPlugin()); 17 | * 18 | * // Update the rules to also transpile `.mjs` files 19 | * if (!flowDefaults.module.rules[0].test) { 20 | * throw "Unexpected structure in generated webpack config"; 21 | * } 22 | * flowDefaults.module.rules[0].test = /\.m?js$/ 23 | * 24 | * // Include a custom JS in the entry point in addition to generated-flow-imports.js 25 | * if (typeof flowDefaults.entry.index != "string") { 26 | * throw "Unexpected structure in generated webpack config"; 27 | * } 28 | * flowDefaults.entry.index = [flowDefaults.entry.index, "myCustomFile.js"]; 29 | * 30 | * or add new configuration in the merge block. 31 | * 32 | * module.exports = merge(flowDefaults, { 33 | * mode: 'development', 34 | * devtool: 'inline-source-map' 35 | * }); 36 | * 37 | */ 38 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/views/images/ImagesView.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.views.images; 2 | 3 | import bt.assetmanager.components.assetview.AssetView; 4 | import bt.assetmanager.data.entity.ImageAsset; 5 | import bt.assetmanager.data.service.ImageAssetService; 6 | import bt.assetmanager.data.service.TagService; 7 | import bt.assetmanager.data.service.UserOptionService; 8 | import bt.assetmanager.views.MainLayout; 9 | import com.vaadin.flow.component.dependency.Uses; 10 | import com.vaadin.flow.component.html.Div; 11 | import com.vaadin.flow.component.icon.Icon; 12 | import com.vaadin.flow.component.splitlayout.SplitLayout; 13 | import com.vaadin.flow.router.PageTitle; 14 | import com.vaadin.flow.router.Route; 15 | import com.vaadin.flow.router.RouteAlias; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | 18 | @PageTitle("Images - Asset manager") 19 | @Route(value = "images", layout = MainLayout.class) 20 | @RouteAlias(value = "", layout = MainLayout.class) 21 | @Uses(Icon.class) 22 | public class ImagesView extends Div 23 | { 24 | @Autowired 25 | public ImagesView(ImageAssetService assetService, TagService tagService, UserOptionService optionsService) 26 | { 27 | addClassNames("images-view"); 28 | SplitLayout splitLayout = new AssetView(ImageAsset.class, assetService, tagService, optionsService); 29 | add(splitLayout); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /frontend/themes/btassetmanager/main-layout.css: -------------------------------------------------------------------------------- 1 | header vaadin-context-menu { 2 | align-items: center; 3 | display: flex; 4 | } 5 | 6 | header nav a:hover { 7 | text-decoration: none; 8 | } 9 | 10 | header nav a[highlight] { 11 | color: var(--lumo-primary-text-color); 12 | } 13 | 14 | header nav a::before, 15 | header nav a::after { 16 | background-color: var(--lumo-contrast-60pct); 17 | border-radius: var(--lumo-border-radius) var(--lumo-border-radius) 0 0; 18 | bottom: 0; 19 | content: ""; 20 | display: block; 21 | height: 2px; 22 | left: 50%; 23 | position: absolute; 24 | transform: translateX(-50%) scale(0); 25 | transform-origin: 50% 100%; 26 | width: var(--lumo-size-s); 27 | will-change: transform; 28 | } 29 | 30 | header nav a::before { 31 | transition: 0.14s transform cubic-bezier(.12, .32, .54, 1); 32 | } 33 | 34 | header nav a::after { 35 | box-shadow: 0 0 0 4px var(--lumo-primary-color); 36 | opacity: 0.15; 37 | transition: 0.15s 0.02s transform, 0.8s 0.17s opacity; 38 | } 39 | 40 | header nav a[highlight]::before, 41 | nav a[highlight]::after { 42 | background-color: var(--lumo-primary-color); 43 | } 44 | 45 | header nav a[highlight]::before, 46 | header nav a[highlight]::after { 47 | transform: translateX(-50%) scale(1); 48 | transition-timing-function: cubic-bezier(.12, .32, .54, 1.5); 49 | } 50 | 51 | header nav a[highlight]:not([active])::after { 52 | opacity: 0; 53 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/service/ImageAssetService.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.service; 2 | 3 | import bt.assetmanager.data.entity.ImageAsset; 4 | import bt.assetmanager.data.repository.ImageAssetRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author Lukas Hartwig 12 | * @since 31.08.2022 13 | */ 14 | @Service 15 | public class ImageAssetService extends BaseAssetService 16 | { 17 | @Autowired 18 | private ImageAssetRepository imageAssetRepo; 19 | 20 | @Override 21 | public List findByTags(List tags) 22 | { 23 | return this.imageAssetRepo.getAllForTags(tags, (long)tags.size()); 24 | } 25 | 26 | @Override 27 | public List findByFileName(String fileName) 28 | { 29 | return this.imageAssetRepo.findByFileNameContainingIgnoreCase(fileName); 30 | } 31 | 32 | @Override 33 | public void save(ImageAsset entity, boolean saveTagsInMetadataFile) 34 | { 35 | this.imageAssetRepo.save(entity); 36 | super.save(entity, saveTagsInMetadataFile); 37 | } 38 | 39 | @Override 40 | public void delete(ImageAsset entity) 41 | { 42 | this.imageAssetRepo.delete(entity); 43 | } 44 | 45 | @Override 46 | public List findAll() 47 | { 48 | return this.imageAssetRepo.findAllByOrderByPathAsc(); 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/service/SoundAssetService.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.service; 2 | 3 | import bt.assetmanager.data.entity.SoundAsset; 4 | import bt.assetmanager.data.repository.SoundAssetRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author Lukas Hartwig 12 | * @since 31.08.2022 13 | */ 14 | @Service 15 | public class SoundAssetService extends BaseAssetService 16 | { 17 | @Autowired 18 | private SoundAssetRepository soundAssetRepo; 19 | 20 | @Override 21 | public List findByTags(List tags) 22 | { 23 | return this.soundAssetRepo.getAllForTags(tags, (long)tags.size()); 24 | } 25 | 26 | @Override 27 | public List findByFileName(String fileName) 28 | { 29 | return this.soundAssetRepo.findByFileNameContainingIgnoreCase(fileName); 30 | } 31 | 32 | @Override 33 | public void save(SoundAsset entity, boolean saveTagsInMetadataFile) 34 | { 35 | this.soundAssetRepo.save(entity); 36 | super.save(entity, saveTagsInMetadataFile); 37 | } 38 | 39 | @Override 40 | public void delete(SoundAsset entity) 41 | { 42 | this.soundAssetRepo.delete(entity); 43 | } 44 | 45 | @Override 46 | public List findAll() 47 | { 48 | return this.soundAssetRepo.findAllByOrderByPathAsc(); 49 | } 50 | } -------------------------------------------------------------------------------- /frontend/themes/btassetmanager/views/images-view.css: -------------------------------------------------------------------------------- 1 | .images-view { 2 | display: flex; 3 | flex-direction: column; 4 | height: 100%; 5 | } 6 | 7 | .images-view vaadin-split-layout { 8 | width: 100%; 9 | height: 100%; 10 | } 11 | 12 | .images-view vaadin-grid { 13 | height: 100%; 14 | } 15 | 16 | .images-view .input-layout { 17 | display: flex; 18 | flex-direction: column; 19 | width: 400px; 20 | } 21 | 22 | .images-view .input { 23 | flex-grow: 1; 24 | padding: var(--lumo-space-l); 25 | } 26 | 27 | .images-view .input vaadin-checkbox { 28 | padding-top: var(--lumo-space-m); 29 | } 30 | 31 | .images-view .button-layout { 32 | width: 100%; 33 | flex-wrap: wrap; 34 | background-color: var(--lumo-contrast-5pct); 35 | padding-bottom: var(--lumo-space-s); 36 | padding-top: var(--lumo-space-s); 37 | padding-left: var(--lumo-space-l); 38 | padding-right: var(--lumo-space-l); 39 | gap: var(--lumo-space-m); 40 | } 41 | 42 | .images-view .grid-wrapper { 43 | width: 100%; 44 | } 45 | 46 | .images-view .image-container { 47 | position: relative; 48 | } 49 | 50 | .image-container:after { 51 | content: ""; 52 | display: block; 53 | padding-bottom: 100%; /* The padding depends on the width, not on the height, so with a padding-bottom of 100% you will get a square */ 54 | } 55 | 56 | .image-container .grid-image-ignore-ratio { 57 | position: absolute; /* Take your picture out of the flow */ 58 | top: 0; 59 | bottom: 0; 60 | left: 0; 61 | right: 0; 62 | width: 80%; 63 | height: 80%; 64 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/options/UserOptionNumberField.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components.options; 2 | 3 | import bt.assetmanager.data.service.UserOptionService; 4 | import com.vaadin.flow.component.html.Label; 5 | import com.vaadin.flow.component.orderedlayout.FlexComponent; 6 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 7 | import com.vaadin.flow.component.textfield.IntegerField; 8 | 9 | /** 10 | * @author Lukas Hartwig 11 | * @since 08.09.2022 12 | */ 13 | public class UserOptionNumberField extends HorizontalLayout 14 | { 15 | public UserOptionNumberField(UserOptionService optionsService, String optionName, String labelText, String tooltip, int min, int max) 16 | { 17 | IntegerField field = new IntegerField(); 18 | field.setValue(optionsService.getIntValue(optionName)); 19 | field.setMin(min); 20 | field.setMax(max); 21 | field.setHasControls(true); 22 | field.setHelperText("Between " + min + " and " + max); 23 | field.getElement().setProperty("title", tooltip); 24 | 25 | field.addValueChangeListener(e -> { 26 | if (e.getValue() >= min && e.getValue() <= max) 27 | { 28 | optionsService.setValue(optionName, e.getValue()); 29 | } 30 | }); 31 | 32 | Label label = new Label(labelText); 33 | label.getElement().setProperty("title", tooltip); 34 | 35 | setVerticalComponentAlignment(FlexComponent.Alignment.CENTER, field, label); 36 | add(field, label); 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/options/DefaultUserOptionsSetter.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components.options; 2 | 3 | import bt.assetmanager.data.entity.UserOption; 4 | import bt.assetmanager.data.service.UserOptionService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.context.event.ApplicationReadyEvent; 7 | import org.springframework.context.ApplicationListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * @author Lukas Hartwig 12 | * @since 08.09.2022 13 | */ 14 | @Component 15 | public class DefaultUserOptionsSetter implements ApplicationListener 16 | { 17 | @Autowired 18 | private UserOptionService optionsService; 19 | 20 | @Override 21 | public void onApplicationEvent(ApplicationReadyEvent event) 22 | { 23 | this.optionsService.setValueIfNotExist(UserOption.DISPLAY_ALL_ASSETS_ON_PAGE_OPEN, false); 24 | this.optionsService.setValueIfNotExist(UserOption.IMAGE_GRID_IMAGES_PER_ROW, 10); 25 | this.optionsService.setValueIfNotExist(UserOption.IMAGE_GRID_KEEP_ASPECT_RATIO, false); 26 | this.optionsService.setValueIfNotExist(UserOption.IMAGE_GRID_OR_LIST_VIEW, "grid"); 27 | this.optionsService.setValueIfNotExist(UserOption.LAST_SEARCHED_FOLDER, ""); 28 | this.optionsService.setValueIfNotExist(UserOption.READ_TAGS_FROM_METADATA_FILE, true); 29 | this.optionsService.setValueIfNotExist(UserOption.REMOVE_ASSETS_FROM_TOOL_IF_THEY_CANT_BE_FOUND, false); 30 | this.optionsService.setValueIfNotExist(UserOption.SAVE_TAGS_IN_FILE_FORMAT_METADATA, false); 31 | this.optionsService.setValueIfNotExist(UserOption.SAVE_TAGS_IN_METADATA_FILE, true); 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/entity/ImageAsset.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.entity; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | import java.util.List; 6 | import java.util.Objects; 7 | 8 | /** 9 | * @author Lukas Hartwig 10 | * @since 28.08.2022 11 | */ 12 | @Entity 13 | public class ImageAsset implements Asset, Serializable 14 | { 15 | @Id 16 | @GeneratedValue 17 | private Long id; 18 | 19 | @Column(length = 9999, unique = true) 20 | private String path; 21 | 22 | @Column(length = 9999) 23 | private String fileName; 24 | 25 | @ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.EAGER) 26 | @JoinColumn(name = "tagId", referencedColumnName = "id") 27 | private List tags; 28 | 29 | public Long getId() 30 | { 31 | return id; 32 | } 33 | 34 | public void setId(Long id) 35 | { 36 | this.id = id; 37 | } 38 | 39 | public String getPath() 40 | { 41 | return path; 42 | } 43 | 44 | public void setPath(String path) 45 | { 46 | this.path = path; 47 | } 48 | 49 | public String getFileName() 50 | { 51 | return fileName; 52 | } 53 | 54 | public void setFileName(String fileName) 55 | { 56 | this.fileName = fileName; 57 | } 58 | 59 | public List getTags() 60 | { 61 | return tags; 62 | } 63 | 64 | public void setTags(List tags) 65 | { 66 | this.tags = tags; 67 | } 68 | 69 | @Override 70 | public boolean equals(Object o) 71 | { 72 | if (this == o) 73 | return true; 74 | if (o == null || getClass() != o.getClass()) 75 | return false; 76 | ImageAsset that = (ImageAsset)o; 77 | return Objects.equals(id, that.id); 78 | } 79 | 80 | @Override 81 | public int hashCode() 82 | { 83 | return Objects.hash(id); 84 | } 85 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/entity/SoundAsset.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.entity; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | import java.util.List; 6 | import java.util.Objects; 7 | 8 | /** 9 | * @author Lukas Hartwig 10 | * @since 28.08.2022 11 | */ 12 | @Entity 13 | public class SoundAsset implements Asset, Serializable 14 | { 15 | @Id 16 | @GeneratedValue 17 | private Long id; 18 | 19 | @Column(length = 9999, unique = true) 20 | private String path; 21 | 22 | @Column(length = 9999) 23 | private String fileName; 24 | 25 | @ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.EAGER) 26 | @JoinColumn(name = "tagId", referencedColumnName = "id") 27 | private List tags; 28 | 29 | public Long getId() 30 | { 31 | return id; 32 | } 33 | 34 | public void setId(Long id) 35 | { 36 | this.id = id; 37 | } 38 | 39 | public String getPath() 40 | { 41 | return path; 42 | } 43 | 44 | public void setPath(String path) 45 | { 46 | this.path = path; 47 | } 48 | 49 | public String getFileName() 50 | { 51 | return fileName; 52 | } 53 | 54 | public void setFileName(String fileName) 55 | { 56 | this.fileName = fileName; 57 | } 58 | 59 | public List getTags() 60 | { 61 | return tags; 62 | } 63 | 64 | public void setTags(List tags) 65 | { 66 | this.tags = tags; 67 | } 68 | 69 | @Override 70 | public boolean equals(Object o) 71 | { 72 | if (this == o) 73 | return true; 74 | if (o == null || getClass() != o.getClass()) 75 | return false; 76 | SoundAsset that = (SoundAsset)o; 77 | return Objects.equals(id, that.id); 78 | } 79 | 80 | @Override 81 | public int hashCode() 82 | { 83 | return Objects.hash(id); 84 | } 85 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/entity/UserOption.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * @author Lukas Hartwig 10 | * @since 08.09.2022 11 | */ 12 | @Entity 13 | public class UserOption 14 | { 15 | public static final String SAVE_TAGS_IN_FILE_FORMAT_METADATA = "SAVE_TAGS_IN_FILE_FORMAT_METADATA"; 16 | public static final String SAVE_TAGS_IN_METADATA_FILE = "SAVE_TAGS_IN_METADATA_FILE"; 17 | public static final String READ_TAGS_FROM_METADATA_FILE = "READ_TAGS_FROM_METADATA_FILE"; 18 | public static final String DISPLAY_ALL_ASSETS_ON_PAGE_OPEN = "DISPLAY_ALL_ASSETS_ON_PAGE_OPEN"; 19 | public static final String REMOVE_ASSETS_FROM_TOOL_IF_THEY_CANT_BE_FOUND = "REMOVE_ASSETS_FROM_TOOL_IF_THEY_CANT_BE_FOUND"; 20 | public static final String IMAGE_GRID_IMAGES_PER_ROW = "IMAGE_GRID_IMAGES_PER_ROW"; 21 | public static final String IMAGE_GRID_KEEP_ASPECT_RATIO = "IMAGE_GRID_KEEP_ASPECT_RATIO"; 22 | public static final String LAST_SEARCHED_FOLDER = "LAST_SEARCHED_FOLDER"; 23 | public static final String IMAGE_GRID_OR_LIST_VIEW = "IMAGE_GRID_OR_LIST_VIEW"; 24 | 25 | @Id 26 | @GeneratedValue 27 | private Long id; 28 | 29 | @Column(length = 9999) 30 | private String name; 31 | 32 | @Column(length = 9999) 33 | private String optionnValue; 34 | 35 | public Long getId() 36 | { 37 | return id; 38 | } 39 | 40 | public void setId(Long id) 41 | { 42 | this.id = id; 43 | } 44 | 45 | public String getName() 46 | { 47 | return name; 48 | } 49 | 50 | public void setName(String name) 51 | { 52 | this.name = name; 53 | } 54 | 55 | public String getOptionValue() 56 | { 57 | return optionnValue; 58 | } 59 | 60 | public void setOptionValue(String optionnValue) 61 | { 62 | this.optionnValue = optionnValue; 63 | } 64 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/obj/FileBundler.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.obj; 2 | 3 | import java.io.File; 4 | import java.util.*; 5 | 6 | /** 7 | * @author Lukas Hartwig 8 | * @since 06.09.2022 9 | */ 10 | public class FileBundler 11 | { 12 | private Map> bundlesFiles; 13 | private int size; 14 | 15 | public FileBundler() 16 | { 17 | this.bundlesFiles = new HashMap<>(); 18 | this.size = 0; 19 | } 20 | 21 | private Bundle obtainBundle(T asset) 22 | { 23 | String folder = new File(asset.getPath()).getParent().toLowerCase(); 24 | return this.bundlesFiles.computeIfAbsent(folder, f -> new Bundle()); 25 | } 26 | 27 | public void addImage(T asset) 28 | { 29 | Bundle bundle = obtainBundle(asset); 30 | bundle.addImage(asset); 31 | this.size++; 32 | } 33 | 34 | public void addSound(T asset) 35 | { 36 | Bundle bundle = obtainBundle(asset); 37 | bundle.addSound(asset); 38 | this.size++; 39 | } 40 | 41 | public Set getFolderNames() 42 | { 43 | return this.bundlesFiles.keySet(); 44 | } 45 | 46 | public Bundle getBundle(String folder) 47 | { 48 | return this.bundlesFiles.get(folder); 49 | } 50 | 51 | public int getSize() 52 | { 53 | return size; 54 | } 55 | 56 | public class Bundle 57 | { 58 | private List imageAssets; 59 | private List soundAssets; 60 | 61 | public Bundle() 62 | { 63 | this.imageAssets = new LinkedList<>(); 64 | this.soundAssets = new LinkedList<>(); 65 | } 66 | 67 | public void addImage(K asset) 68 | { 69 | this.imageAssets.add(asset); 70 | } 71 | 72 | public void addSound(K asset) 73 | { 74 | this.soundAssets.add(asset); 75 | } 76 | 77 | public List getImageAssets() 78 | { 79 | return imageAssets; 80 | } 81 | 82 | public List getSoundAssets() 83 | { 84 | return soundAssets; 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/views/import_/AssetImportRow.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.views.import_; 2 | 3 | import bt.assetmanager.obj.HasFilePath; 4 | import com.vaadin.flow.component.checkbox.Checkbox; 5 | 6 | /** 7 | * @author Lukas Hartwig 8 | * @since 29.08.2022 9 | */ 10 | public class AssetImportRow implements HasFilePath 11 | { 12 | private boolean shouldImport; 13 | private String fileName; 14 | private String absolutePath; 15 | private String relativePath; 16 | private Checkbox importCheckbox; 17 | private int index; 18 | 19 | public boolean isShouldImport() 20 | { 21 | return shouldImport; 22 | } 23 | 24 | public void setShouldImport(boolean shouldImport) 25 | { 26 | this.shouldImport = shouldImport; 27 | } 28 | 29 | public void checkImportBox(boolean checked) 30 | { 31 | if (this.importCheckbox != null) 32 | { 33 | this.importCheckbox.setValue(checked); 34 | } 35 | } 36 | 37 | public String getFileName() 38 | { 39 | return fileName; 40 | } 41 | 42 | public void setFileName(String fileName) 43 | { 44 | this.fileName = fileName; 45 | } 46 | 47 | public String getPath() 48 | { 49 | return absolutePath; 50 | } 51 | 52 | public void setPath(String absolutePath) 53 | { 54 | this.absolutePath = absolutePath; 55 | } 56 | 57 | public String getRelativePath() 58 | { 59 | return relativePath; 60 | } 61 | 62 | public void setRelativePath(String relativePath) 63 | { 64 | this.relativePath = relativePath; 65 | } 66 | 67 | public Checkbox getImportCheckbox() 68 | { 69 | return importCheckbox; 70 | } 71 | 72 | public void setImportCheckbox(Checkbox importCheckbox) 73 | { 74 | this.importCheckbox = importCheckbox; 75 | } 76 | 77 | public int getIndex() 78 | { 79 | return index; 80 | } 81 | 82 | public void setIndex(int index) 83 | { 84 | this.index = index; 85 | } 86 | 87 | @Override 88 | public boolean equals(Object o) 89 | { 90 | if (o instanceof AssetImportRow row) 91 | { 92 | return row.getPath().equalsIgnoreCase(this.absolutePath); 93 | } 94 | 95 | return false; 96 | } 97 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/TagSearchTextField.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components; 2 | 3 | import bt.assetmanager.data.service.TagService; 4 | import bt.utils.Null; 5 | import com.vaadin.componentfactory.Autocomplete; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.concurrent.Executors; 10 | import java.util.concurrent.ScheduledExecutorService; 11 | import java.util.concurrent.TimeUnit; 12 | import java.util.stream.Collectors; 13 | 14 | /** 15 | * @author Lukas Hartwig 16 | * @since 31.08.2022 17 | */ 18 | public class TagSearchTextField extends Autocomplete 19 | { 20 | private static ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); 21 | private TagService tagService; 22 | private String currentTagTextFieldValue; 23 | private boolean processAutoCompleteApplyEvent = true; 24 | 25 | public TagSearchTextField(int limit, TagService tagService) 26 | { 27 | super(limit); 28 | 29 | this.tagService = tagService; 30 | 31 | addChangeListener(event -> { 32 | String text = event.getValue(); 33 | String[] singleTags = text.split(","); 34 | 35 | String currentTag = singleTags[singleTags.length - 1].trim(); 36 | 37 | if (!currentTag.isEmpty()) 38 | { 39 | setOptions(this.tagService.getTagNamesForValue(currentTag)); 40 | } 41 | else 42 | { 43 | setOptions(List.of()); 44 | } 45 | 46 | this.currentTagTextFieldValue = event.getValue(); 47 | }); 48 | 49 | addAutocompleteValueAppliedListener(e -> { 50 | if (this.processAutoCompleteApplyEvent) 51 | { 52 | this.processAutoCompleteApplyEvent = false; 53 | 54 | String[] singleTags = Null.nullValue(this.currentTagTextFieldValue, "").split(","); 55 | List newTagList = Arrays.asList(singleTags).stream().map(String::trim).collect(Collectors.toList()); 56 | newTagList.set(newTagList.size() - 1, e.getValue()); 57 | 58 | setValue(String.join(", ", newTagList)); 59 | 60 | focus(); 61 | 62 | executorService.schedule(() -> this.processAutoCompleteApplyEvent = true, 200, TimeUnit.MILLISECONDS); 63 | } 64 | }); 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/ScrollTreeGrid.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components; 2 | 3 | import bt.log.Log; 4 | import com.vaadin.flow.component.treegrid.TreeGrid; 5 | import com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicator; 6 | import com.vaadin.flow.data.provider.hierarchy.HierarchicalDataProvider; 7 | import com.vaadin.flow.data.provider.hierarchy.HierarchyMapper; 8 | 9 | import java.lang.reflect.Method; 10 | 11 | /** 12 | * @author Lukas Hartwig 13 | * @since 30.08.2022 14 | */ 15 | public class ScrollTreeGrid extends TreeGrid 16 | { 17 | public ScrollTreeGrid(Class beanType) 18 | { 19 | super(beanType); 20 | } 21 | 22 | public ScrollTreeGrid() 23 | { 24 | super(); 25 | } 26 | 27 | public ScrollTreeGrid(HierarchicalDataProvider dataProvider) 28 | { 29 | super(dataProvider); 30 | } 31 | 32 | /** 33 | * The method for scrolling to an item. Takes into account lazy loading nature 34 | * of grid and does the scroll operation only until the grid has finished 35 | * loading data 36 | * 37 | * @param item the item where to scroll to 38 | */ 39 | public void scrollToItem(T item) 40 | { 41 | int index = getIndexForItem(item); 42 | 43 | if (index >= 0) 44 | { 45 | scrollToIndex(index); 46 | } 47 | } 48 | 49 | /** 50 | * This is a method for getting the row index of an item in a treegrid. This 51 | * works but is prone to break in the future versions due to its usage of 52 | * reflection to access private methods to get access to the index. 53 | * 54 | * @param 55 | */ 56 | private int getIndexForItem(T item) 57 | { 58 | HierarchicalDataCommunicator dataCommunicator = super.getDataCommunicator(); 59 | Method getHierarchyMapper = null; 60 | 61 | try 62 | { 63 | getHierarchyMapper = HierarchicalDataCommunicator.class.getDeclaredMethod("getHierarchyMapper"); 64 | getHierarchyMapper.setAccessible(true); 65 | HierarchyMapper mapper = (HierarchyMapper)getHierarchyMapper.invoke(dataCommunicator); 66 | return mapper.getIndex(item); 67 | } 68 | catch (Exception e) 69 | { 70 | Log.error("Failed to find index for item", e); 71 | } 72 | 73 | return -1; 74 | } 75 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/data/service/UserOptionService.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.data.service; 2 | 3 | import bt.assetmanager.data.entity.UserOption; 4 | import bt.assetmanager.data.repository.UserOptionsRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * @author Lukas Hartwig 10 | * @since 08.09.2022 11 | */ 12 | @Service 13 | public class UserOptionService 14 | { 15 | @Autowired 16 | private UserOptionsRepository optionsRepo; 17 | 18 | public String getValue(String optionName) 19 | { 20 | UserOption option = this.optionsRepo.findByName(optionName); 21 | String value = null; 22 | 23 | if (option != null) 24 | { 25 | value = option.getOptionValue(); 26 | } 27 | 28 | return value; 29 | } 30 | 31 | public boolean getBooleanValue(String optionName) 32 | { 33 | UserOption option = this.optionsRepo.findByName(optionName); 34 | boolean value = false; 35 | 36 | if (option != null) 37 | { 38 | value = Boolean.parseBoolean(option.getOptionValue()); 39 | } 40 | 41 | return value; 42 | } 43 | 44 | public int getIntValue(String optionName) 45 | { 46 | UserOption option = this.optionsRepo.findByName(optionName); 47 | int value = 0; 48 | 49 | if (option != null) 50 | { 51 | value = Integer.parseInt(option.getOptionValue()); 52 | } 53 | 54 | return value; 55 | } 56 | 57 | public void setValue(String optionName, Object value) 58 | { 59 | UserOption option = this.optionsRepo.findByName(optionName); 60 | 61 | if (option == null) 62 | { 63 | option = new UserOption(); 64 | option.setName(optionName); 65 | } 66 | 67 | option.setOptionValue(value != null ? value.toString() : ""); 68 | 69 | this.optionsRepo.save(option); 70 | } 71 | 72 | public void setValueIfNotExist(String optionName, Object value) 73 | { 74 | UserOption option = this.optionsRepo.findByName(optionName); 75 | 76 | if (option == null) 77 | { 78 | option = new UserOption(); 79 | option.setName(optionName); 80 | option.setOptionValue(value != null ? value.toString() : ""); 81 | 82 | this.optionsRepo.save(option); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/workers/AssetSearchWorker.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.workers; 2 | 3 | import bt.assetmanager.components.AssetSearchPanel; 4 | import bt.assetmanager.data.entity.Asset; 5 | import com.vaadin.flow.component.UI; 6 | 7 | import java.io.Serializable; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Lukas Hartwig 13 | * @since 08.09.2022 14 | */ 15 | public class AssetSearchWorker implements BackgroundWorker 16 | { 17 | private AssetSearchPanel searchPanel; 18 | private Runnable onFinish; 19 | 20 | public AssetSearchWorker(AssetSearchPanel searchPanel) 21 | { 22 | this.searchPanel = searchPanel; 23 | } 24 | 25 | @Override 26 | public void work(UI ui) 27 | { 28 | ui.access(() -> { 29 | this.searchPanel.getProgressBar().setIndeterminate(true); 30 | this.searchPanel.getProgressBar().setVisible(true); 31 | this.searchPanel.getProgressLabel().setText("Searching..."); 32 | }); 33 | 34 | List resultSet = null; 35 | 36 | if (this.searchPanel.getSearchTextField().getValue().trim().isEmpty()) 37 | { 38 | resultSet = this.searchPanel.getAssetService().findAll(); 39 | } 40 | else 41 | { 42 | if (Boolean.TRUE.equals(this.searchPanel.getFileNameFilterCheckbox().getValue())) 43 | { 44 | resultSet = this.searchPanel.getAssetService().findByFileName(this.searchPanel.getSearchTextField().getValue().trim()); 45 | } 46 | else 47 | { 48 | String[] singleTags = this.searchPanel.getSearchTextField().getValue().split(","); 49 | List singleTagList = Arrays.asList(singleTags).stream().map(String::trim).map(String::toUpperCase).toList(); 50 | 51 | resultSet = this.searchPanel.getAssetService().findByTags(singleTagList); 52 | } 53 | } 54 | 55 | List finalResultSet = resultSet; 56 | 57 | ui.access(() -> this.searchPanel.getProgressLabel().setText("Filling view...")); 58 | 59 | ui.access(() -> { 60 | this.searchPanel.getFoundFilesLabel().setText(finalResultSet.size() + " files found"); 61 | 62 | if (this.searchPanel.getOnSearchConsumer() != null) 63 | { 64 | this.searchPanel.getOnSearchConsumer().accept(finalResultSet); 65 | } 66 | 67 | if (this.onFinish != null) 68 | { 69 | this.onFinish.run(); 70 | } 71 | }); 72 | 73 | ui.setPollInterval(-1); 74 | } 75 | 76 | public void onFinish(Runnable onFinish) 77 | { 78 | this.onFinish = onFinish; 79 | } 80 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/Application.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager; 2 | 3 | import bt.assetmanager.tray.SystemTrayOptions; 4 | import bt.log.ConsoleLoggerHandler; 5 | import bt.log.FileLoggerHandler; 6 | import bt.log.Log; 7 | import bt.log.LoggerConfiguration; 8 | import com.vaadin.flow.component.dependency.NpmPackage; 9 | import com.vaadin.flow.component.page.AppShellConfigurator; 10 | import com.vaadin.flow.server.PWA; 11 | import com.vaadin.flow.theme.Theme; 12 | import com.vaadin.flow.theme.lumo.Lumo; 13 | import org.springframework.beans.factory.annotation.Value; 14 | import org.springframework.boot.SpringApplication; 15 | import org.springframework.boot.autoconfigure.SpringBootApplication; 16 | import org.springframework.boot.context.event.ApplicationReadyEvent; 17 | import org.springframework.boot.logging.LoggingSystem; 18 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 19 | import org.springframework.context.event.EventListener; 20 | 21 | import java.io.IOException; 22 | import java.util.logging.Level; 23 | 24 | /** 25 | * The entry point of the Spring Boot application. 26 | *

27 | * Use the @PWA annotation make the application installable on phones, tablets 28 | * and some desktop browsers. 29 | */ 30 | @SpringBootApplication 31 | @Theme(value = "btassetmanager", variant = Lumo.DARK) 32 | @PWA(name = "BtAssetManager", shortName = "BtAssetManager", offlineResources = {}) 33 | @NpmPackage(value = "line-awesome", version = "1.3.0") 34 | public class Application extends SpringBootServletInitializer implements AppShellConfigurator 35 | { 36 | @Value("${server.port}") 37 | private int serverPort; 38 | 39 | public static void main(String[] args) throws IOException 40 | { 41 | // disable logging system to force spring into using SLF4J binding 42 | System.setProperty(LoggingSystem.SYSTEM_PROPERTY, "none"); 43 | 44 | // making Desktop class work to open file locations 45 | System.setProperty("java.awt.headless", "false"); 46 | 47 | LoggerConfiguration config = new LoggerConfiguration().level(Level.INFO) 48 | .invalidCallerPackages("org.apache.commons.logging", 49 | "org.springframework.boot.autoconfigure.logging", 50 | "org.springframework.core.log"); 51 | 52 | Log.createDefaultLogFolder(); 53 | Log.configureDefaultJDKLogger(new ConsoleLoggerHandler(config), new FileLoggerHandler(config, 54 | "./logs/assetmanager_%u.log", 55 | 10_000_000, 56 | 10, 57 | true)); 58 | 59 | SpringApplication.run(Application.class, args); 60 | } 61 | 62 | @EventListener(ApplicationReadyEvent.class) 63 | public void afterStartup() 64 | { 65 | try 66 | { 67 | var systemTray = new SystemTrayOptions(this.serverPort); 68 | systemTray.openBrowser(); 69 | } 70 | catch (IOException e) 71 | { 72 | Log.error("Failed to load system tray icon", e); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/views/MainLayout.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.views; 2 | 3 | import bt.assetmanager.views.images.ImagesView; 4 | import bt.assetmanager.views.import_.ImportView; 5 | import bt.assetmanager.views.options.OptionsView; 6 | import bt.assetmanager.views.sounds.SoundsView; 7 | import com.vaadin.flow.component.Component; 8 | import com.vaadin.flow.component.applayout.AppLayout; 9 | import com.vaadin.flow.component.dependency.NpmPackage; 10 | import com.vaadin.flow.component.html.*; 11 | import com.vaadin.flow.router.RouterLink; 12 | 13 | /** 14 | * The main view is a top-level placeholder for other views. 15 | */ 16 | public class MainLayout extends AppLayout 17 | { 18 | 19 | public MainLayout() 20 | { 21 | addToNavbar(createHeaderContent()); 22 | } 23 | 24 | private Component createHeaderContent() 25 | { 26 | Header header = new Header(); 27 | header.addClassNames("bg-base", "border-b", "border-contrast-10", "box-border", "flex", "flex-col", "w-full"); 28 | Nav nav = new Nav(); 29 | nav.addClassNames("flex", "gap-s", "overflow-auto", "px-m"); 30 | 31 | // Wrap the links in a list; improves accessibility 32 | UnorderedList list = new UnorderedList(); 33 | list.addClassNames("flex", "list-none", "m-0", "p-0"); 34 | nav.add(list); 35 | 36 | for (MenuItemInfo menuItem : createMenuItems()) 37 | { 38 | list.add(menuItem); 39 | } 40 | 41 | header.add(nav); 42 | return header; 43 | } 44 | 45 | private MenuItemInfo[] createMenuItems() 46 | { 47 | return new MenuItemInfo[] { 48 | new MenuItemInfo("Images", "la la-image", ImagesView.class), 49 | new MenuItemInfo("Sounds", "la la-music", SoundsView.class), 50 | new MenuItemInfo("Import", "la la-upload", ImportView.class), 51 | new MenuItemInfo("Options", "la la-cog", OptionsView.class) 52 | }; 53 | } 54 | 55 | /** 56 | * A simple navigation item component, based on ListItem element. 57 | */ 58 | public static class MenuItemInfo extends ListItem 59 | { 60 | 61 | private final Class view; 62 | 63 | public MenuItemInfo(String menuTitle, String iconClass, Class view) 64 | { 65 | this.view = view; 66 | RouterLink link = new RouterLink(); 67 | // Use Lumo classnames for various styling 68 | link.addClassNames("flex", "h-m", "items-center", "px-s", "relative", "text-secondary"); 69 | link.setRoute(view); 70 | 71 | Span text = new Span(menuTitle); 72 | // Use Lumo classnames for various styling 73 | text.addClassNames("font-medium", "text-s", "whitespace-nowrap"); 74 | 75 | link.add(new LineAwesomeIcon(iconClass), text); 76 | add(link); 77 | } 78 | 79 | public Class getView() 80 | { 81 | return view; 82 | } 83 | 84 | /** 85 | * Simple wrapper to create icons using LineAwesome iconset. See 86 | * https://icons8.com/line-awesome 87 | */ 88 | @NpmPackage(value = "line-awesome", version = "1.3.0") 89 | public static class LineAwesomeIcon extends Span 90 | { 91 | public LineAwesomeIcon(String lineawesomeClassnames) 92 | { 93 | // Use Lumo classnames for suitable font size and margin 94 | addClassNames("me-s", "text-l"); 95 | if (!lineawesomeClassnames.isEmpty()) 96 | { 97 | addClassNames(lineawesomeClassnames); 98 | } 99 | } 100 | } 101 | 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/assetview/AssetView.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components.assetview; 2 | 3 | import bt.assetmanager.components.AssetSearchPanel; 4 | import bt.assetmanager.data.entity.Asset; 5 | import bt.assetmanager.data.entity.ImageAsset; 6 | import bt.assetmanager.data.entity.UserOption; 7 | import bt.assetmanager.data.service.AssetService; 8 | import bt.assetmanager.data.service.TagService; 9 | import bt.assetmanager.data.service.UserOptionService; 10 | import bt.log.Log; 11 | import com.vaadin.flow.component.splitlayout.SplitLayout; 12 | 13 | import java.io.File; 14 | import java.io.Serializable; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | 19 | /** 20 | * @author Lukas Hartwig 21 | * @since 01.09.2022 22 | */ 23 | public class AssetView extends SplitLayout 24 | { 25 | private AssetDisplay grid; 26 | private AssetSearchPanel assetSearchPanel; 27 | private Class clazz; 28 | private transient List items = new ArrayList<>(); 29 | private UserOptionService optionsService; 30 | private AssetService assetService; 31 | 32 | public AssetView(Class clazz, AssetService assetService, TagService tagService, UserOptionService optionsService) 33 | { 34 | this.clazz = clazz; 35 | this.optionsService = optionsService; 36 | this.assetService = assetService; 37 | 38 | boolean showGridView = this.clazz.equals(ImageAsset.class) && this.optionsService.getValue(UserOption.IMAGE_GRID_OR_LIST_VIEW).equals("grid"); 39 | boolean saveTagsInMetadata = this.optionsService.getBooleanValue(UserOption.SAVE_TAGS_IN_FILE_FORMAT_METADATA); 40 | 41 | this.assetSearchPanel = new AssetSearchPanel<>(clazz, assetService, tagService, showGridView, saveTagsInMetadata); 42 | addToSecondary(this.assetSearchPanel); 43 | 44 | if (showGridView) 45 | { 46 | createGridView(); 47 | } 48 | else 49 | { 50 | createListView(); 51 | } 52 | 53 | this.assetSearchPanel.onViewChange(displayList -> { 54 | if (Boolean.TRUE.equals(displayList)) 55 | { 56 | createListView(); 57 | this.optionsService.setValue(UserOption.IMAGE_GRID_OR_LIST_VIEW, "list"); 58 | } 59 | else 60 | { 61 | createGridView(); 62 | this.optionsService.setValue(UserOption.IMAGE_GRID_OR_LIST_VIEW, "grid"); 63 | } 64 | 65 | this.grid.setItems(this.items); 66 | }); 67 | 68 | this.assetSearchPanel.onSearch(this::setItems); 69 | 70 | this.assetSearchPanel.onDelete(item -> { 71 | getItems().remove(item); 72 | this.grid.removeItem(item); 73 | }); 74 | 75 | if (this.optionsService.getBooleanValue(UserOption.DISPLAY_ALL_ASSETS_ON_PAGE_OPEN)) 76 | { 77 | this.assetSearchPanel.onSearchButton(); 78 | } 79 | } 80 | 81 | protected void createGridView() 82 | { 83 | this.grid = new AssetGridDisplay<>(this.clazz, 84 | this.optionsService.getIntValue(UserOption.IMAGE_GRID_IMAGES_PER_ROW), 85 | this.optionsService.getBooleanValue(UserOption.IMAGE_GRID_KEEP_ASPECT_RATIO)); 86 | this.grid.onElementSelection(element -> this.assetSearchPanel.setSelectedElement(element)); 87 | addToPrimary(this.grid); 88 | } 89 | 90 | protected void createListView() 91 | { 92 | this.grid = new AssetListDisplay<>(this.clazz); 93 | this.grid.onElementSelection(element -> this.assetSearchPanel.setSelectedElement(element)); 94 | 95 | ((AssetListDisplay)this.grid).onElementPlay(element -> { 96 | this.assetSearchPanel.setSelectedElement(element); 97 | this.assetSearchPanel.playSound(); 98 | }); 99 | addToPrimary(this.grid); 100 | } 101 | 102 | private List getItems() 103 | { 104 | return this.items; 105 | } 106 | 107 | private void setItems(List items) 108 | { 109 | if (this.optionsService.getBooleanValue(UserOption.REMOVE_ASSETS_FROM_TOOL_IF_THEY_CANT_BE_FOUND)) 110 | { 111 | items = items.stream() 112 | .filter(asset -> { 113 | File assetFile = new File(asset.getPath()); 114 | 115 | if (assetFile.exists()) 116 | { 117 | return true; 118 | } 119 | else 120 | { 121 | this.assetService.delete(asset); 122 | Log.info("Deleted asset " + asset.getPath() + " because the file no longer exists"); 123 | return false; 124 | } 125 | }).collect(Collectors.toList()); 126 | } 127 | 128 | this.items = items; 129 | this.grid.setItems(this.items); 130 | } 131 | } -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.io.*; 17 | import java.net.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.6"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is 26 | * provided. 27 | */ 28 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 29 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 30 | 31 | /** 32 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl 33 | * property to use instead of the default one. 34 | */ 35 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; 41 | 42 | /** 43 | * Name of the property which should be used to override the default download 44 | * url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a 54 | // custom 55 | // wrapperUrl parameter. 56 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 57 | String url = DEFAULT_DOWNLOAD_URL; 58 | if (mavenWrapperPropertyFile.exists()) { 59 | FileInputStream mavenWrapperPropertyFileInputStream = null; 60 | try { 61 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 62 | Properties mavenWrapperProperties = new Properties(); 63 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 64 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 65 | } catch (IOException e) { 66 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 67 | } finally { 68 | try { 69 | if (mavenWrapperPropertyFileInputStream != null) { 70 | mavenWrapperPropertyFileInputStream.close(); 71 | } 72 | } catch (IOException e) { 73 | // Ignore ... 74 | } 75 | } 76 | } 77 | System.out.println("- Downloading from: " + url); 78 | 79 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 80 | if (!outputFile.getParentFile().exists()) { 81 | if (!outputFile.getParentFile().mkdirs()) { 82 | System.out.println( 83 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 84 | } 85 | } 86 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 87 | try { 88 | downloadFileFromURL(url, outputFile); 89 | System.out.println("Done"); 90 | System.exit(0); 91 | } catch (Throwable e) { 92 | System.out.println("- Error downloading"); 93 | e.printStackTrace(); 94 | System.exit(1); 95 | } 96 | } 97 | 98 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 99 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 100 | String username = System.getenv("MVNW_USERNAME"); 101 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 102 | Authenticator.setDefault(new Authenticator() { 103 | @Override 104 | protected PasswordAuthentication getPasswordAuthentication() { 105 | return new PasswordAuthentication(username, password); 106 | } 107 | }); 108 | } 109 | URL website = new URL(urlString); 110 | ReadableByteChannel rbc; 111 | rbc = Channels.newChannel(website.openStream()); 112 | FileOutputStream fos = new FileOutputStream(destination); 113 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 114 | fos.close(); 115 | rbc.close(); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/assetview/AssetListDisplay.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components.assetview; 2 | 3 | import bt.assetmanager.data.entity.Asset; 4 | import bt.assetmanager.data.entity.ImageAsset; 5 | import bt.log.Log; 6 | import com.vaadin.flow.component.button.Button; 7 | import com.vaadin.flow.component.grid.Grid; 8 | import com.vaadin.flow.component.grid.GridVariant; 9 | import com.vaadin.flow.component.html.Image; 10 | import com.vaadin.flow.data.renderer.ComponentRenderer; 11 | import com.vaadin.flow.function.SerializableConsumer; 12 | import com.vaadin.flow.server.StreamResource; 13 | 14 | import java.awt.*; 15 | import java.io.File; 16 | import java.io.FileInputStream; 17 | import java.io.FileNotFoundException; 18 | import java.io.IOException; 19 | import java.util.List; 20 | 21 | /** 22 | * @author Lukas Hartwig 23 | * @since 01.09.2022 24 | */ 25 | public class AssetListDisplay extends AssetDisplay 26 | { 27 | private Grid grid; 28 | private List items; 29 | private SerializableConsumer onElementPlay; 30 | 31 | public AssetListDisplay(Class clazz) 32 | { 33 | super(clazz); 34 | setClassName("grid-wrapper"); 35 | setup(); 36 | } 37 | 38 | @Override 39 | protected void setup() 40 | { 41 | super.setup(); 42 | this.grid = createGrid(); 43 | add(this.grid); 44 | } 45 | 46 | public void onElementPlay(SerializableConsumer consumer) 47 | { 48 | this.onElementPlay = consumer; 49 | } 50 | 51 | @Override 52 | public void setItems(List items) 53 | { 54 | this.items = items; 55 | this.grid.setItems(this.items); 56 | this.grid.scrollToStart(); 57 | } 58 | 59 | @Override 60 | public void removeItem(T item) 61 | { 62 | this.items.remove(item); 63 | this.grid.setItems(this.items); 64 | } 65 | 66 | protected Grid createGrid() 67 | { 68 | Grid newGrid = new Grid<>(this.clazz, false); 69 | 70 | newGrid.addSelectionListener(e -> { 71 | if (e.getFirstSelectedItem().isPresent() && this.onElementSelection != null) 72 | { 73 | this.onElementSelection.accept(e.getFirstSelectedItem().get()); 74 | } 75 | }); 76 | 77 | newGrid.addColumn(new ComponentRenderer<>( 78 | element -> { 79 | Button button = new Button("Open folder"); 80 | button.addClickListener(e -> { 81 | try 82 | { 83 | Desktop.getDesktop().open(new File(element.getPath()).getParentFile()); 84 | } 85 | catch (IOException ex) 86 | { 87 | Log.error("Failed to open file location", ex); 88 | } 89 | }); 90 | 91 | return button; 92 | } 93 | ) 94 | ).setHeader("").setKey("openFolder").setAutoWidth(true); 95 | 96 | if (this.clazz.equals(ImageAsset.class)) 97 | { 98 | newGrid.addColumn(new ComponentRenderer<>( 99 | row -> { 100 | StreamResource imageResource = new StreamResource(row.getFileName() + "", () -> { 101 | try 102 | { 103 | return new FileInputStream(row.getPath()); 104 | } 105 | catch (final FileNotFoundException e) 106 | { 107 | Log.error("", e); 108 | return null; 109 | } 110 | }); 111 | 112 | Image image = new Image(imageResource, "Couldn't load image"); 113 | image.setHeight("50px"); 114 | 115 | return image; 116 | } 117 | ) 118 | ).setHeader("").setKey("image"); 119 | } 120 | else 121 | { 122 | newGrid.addColumn(new ComponentRenderer<>( 123 | element -> { 124 | Button button = new Button("Play"); 125 | button.addClickListener(e -> { 126 | if (this.onElementPlay != null) 127 | { 128 | this.onElementPlay.accept(element); 129 | } 130 | }); 131 | 132 | return button; 133 | } 134 | ) 135 | ).setHeader("").setKey("playSound").setAutoWidth(true); 136 | } 137 | 138 | newGrid.addColumn("fileName").setAutoWidth(true); 139 | newGrid.addColumn("path").setAutoWidth(true); 140 | newGrid.addThemeVariants(GridVariant.LUMO_NO_BORDER); 141 | 142 | newGrid.setSelectionMode(Grid.SelectionMode.SINGLE); 143 | 144 | return newGrid; 145 | } 146 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BtAssetManager 2 | 3 | This application allows you to easily categorize large amounts of image and sound files. 4 | 5 | You can apply tags to each individual file to search for them based on your own criteria. 6 | 7 | The tool has been tested with files of the following format: 8 | 9 | - jpg 10 | - png 11 | - gif 12 | - svg 13 | - wav 14 | - mp3 15 | 16 | It is intended for sound files and pixel art images. Using large scale textures might lead to poor performance. 17 | 18 | ## Getting started 19 | 20 | Go to the [release page](https://github.com/Bowtie8904/BtAssetManager/releases) and download the jar file from the latest release. 21 | 22 | After the download you can double click the application to start the asset manager. It will now create its database structure. Once its started up it will open your default browser and navigate to the 23 | managers website. You should now also see a small blue bowtie in your system tray. Right clicking that icon allows you to open the browser again or to shut down the application. 24 | 25 | ## Import files 26 | 27 | To search for files you first need to import them on the "Import" page. Use the navigation bar at the top to select the "Import" tab. 28 | 29 | ![img_1.png](readme_images/img_1.png) 30 | 31 | On the right side of the import page you see a bunch of text fields and buttons. 32 | 33 | - **Directory** 34 | - This is where you specifiy which folder the manager should search for files in. It can be any folder on your computer and you can still import files from other folders later on, so there is no 35 | need to put everything in one place 36 | - Either type in your folders name or use the browse button to select it from the list 37 | - **Image and sound file endings** 38 | - Here you specify which file endings you want to import for both images and sounds 39 | - You can use commas to separate multiple endings 40 | - The manager will only look for files that have file endings in one of your text boxes 41 | 42 | ![img_2.png](readme_images/img_2.png) 43 | - **Search** 44 | - Once you have put in a directory to search in and file endings to search for you can press the "Search" button 45 | - The manager will now go through the directory and all its sub-directories and add the found files to the two lists on the left 46 | - **Apply tags on import** 47 | - You can already tag files when you import them 48 | - Add all the tags that you want to apply to the selected files in this field 49 | - You can add multiple tags by separating them with a comma 50 | - The manager will suggest similar tags that you already used before 51 | 52 | ![img_3.png](readme_images/img_3.png) 53 | - **Import all and import none** 54 | - These buttons will either select all found files for import or deselect them all 55 | - **Import** 56 | - This is the button that this page is all about 57 | - Pressing this button will import all selected files from the two lists on the left 58 | - Imported files will disappear from the lists and wont return if you press search again 59 | - After importing you can find the files depending on their type either on the "Images" or the "Sounds" page 60 | - If you specified tags before the import then those will be applied to the files 61 | - If you did not specify any tags then these files will have the tag "UNTAGGED" so that you can find them easily 62 | 63 | After the import your files are NOT moved. The manager does only save the path to those files. This also means that if you move the files to a different location later on the manager wont be able to 64 | display them anymore. 65 | 66 | ![img_4.png](readme_images/img_4.png) 67 | 68 | ## Search for files 69 | 70 | Searching for images and sounds functions the same, so I will only show screenshots of the image search. 71 | 72 | Once you have imported your files you can go over to the "Images" or "Sounds" tabs to search for specific tags. 73 | 74 | If you just want to look at all your files then click the search button once. 75 | 76 | The first button at the top right lets you switch between a grid and a list view. The list view gives you a bit more information about the filename and path while the grid view allows to display more 77 | images at once. 78 | 79 | ![img_5.png](readme_images/img_5.png) 80 | 81 | ![img_6.png](readme_images/img_6.png) 82 | 83 | To search for files you can type tags into the search text field. You can specifiy multiple tags by separating them with a comma. For an image to be found it needs to have all tags in the search field 84 | applied to it. It can have additional ones though that are not in the search field. 85 | 86 | If I want to find all my images of head gear then I can search for the tag "head". 87 | 88 | ![img_7.png](readme_images/img_7.png) 89 | 90 | But if I would rather find headgear that is more of the armor kind then I can type in "head, armor". 91 | 92 | ![img_8.png](readme_images/img_8.png) 93 | 94 | If you want to search for filenames instead of tags then you can check the little box below the search field. The manager will now search for imported files with names that contain the text from the 95 | search field. You can NOT specifiy multiple values with commas. Searching for "helmet" will for example find files like armor_helmet_01.png. 96 | 97 | Clicking on an image will show a large version of it on the right side. You can now also click on the "Open folder" button to open the folder that the file in contained in. 98 | 99 | At the bottom you can apply single tags to the file or remove existing ones by pressing the "X" button. If you remove all tags from a file it will receive the "UNTAGGED" tag automatically. 100 | 101 | ![img_11.png](readme_images/img_11.png) 102 | 103 | If you scroll to the very bottom on the right side you find a delete button. This allows you to remove single files from the manager. You can reimport them on the "Import" page. 104 | 105 | ![img_10.png](readme_images/img_10.png) 106 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/workers/ExportTagsToMetadataWorker.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.workers; 2 | 3 | import bt.assetmanager.data.entity.Asset; 4 | import bt.assetmanager.data.entity.UserOption; 5 | import bt.assetmanager.data.service.ImageAssetService; 6 | import bt.assetmanager.data.service.SoundAssetService; 7 | import bt.assetmanager.data.service.UserOptionService; 8 | import bt.assetmanager.obj.FileBundler; 9 | import bt.assetmanager.util.metadata.FileMetadataUtils; 10 | import bt.assetmanager.util.metadata.image.ImageFileMetadataUtils; 11 | import bt.assetmanager.views.options.OptionsView; 12 | import bt.log.Log; 13 | import com.vaadin.flow.component.UI; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * @author Lukas Hartwig 20 | * @since 08.09.2022 21 | */ 22 | public class ExportTagsToMetadataWorker implements BackgroundWorker 23 | { 24 | private ImageAssetService imageService; 25 | private SoundAssetService soundService; 26 | private UserOptionService optionsService; 27 | private OptionsView optionsView; 28 | private Runnable onFinish; 29 | 30 | public ExportTagsToMetadataWorker(OptionsView optionsView, 31 | ImageAssetService imageService, 32 | SoundAssetService soundService, 33 | UserOptionService optionsService) 34 | { 35 | this.imageService = imageService; 36 | this.soundService = soundService; 37 | this.optionsService = optionsService; 38 | this.optionsView = optionsView; 39 | } 40 | 41 | public void onFinish(Runnable onFinish) 42 | { 43 | this.onFinish = onFinish; 44 | } 45 | 46 | @Override 47 | public void work(UI ui) 48 | { 49 | ui.access(() -> { 50 | this.optionsView.getProgressBar().setIndeterminate(true); 51 | this.optionsView.getProgressBar().setVisible(true); 52 | this.optionsView.getProgressLabel().setText("Bundling assets..."); 53 | }); 54 | 55 | boolean writeToFoleFormatMetadata = this.optionsService.getBooleanValue(UserOption.SAVE_TAGS_IN_FILE_FORMAT_METADATA); 56 | boolean writeToMetadataFile = this.optionsService.getBooleanValue(UserOption.SAVE_TAGS_IN_METADATA_FILE); 57 | 58 | FileBundler bundler = new FileBundler<>(); 59 | 60 | for (var asset : this.imageService.findAll()) 61 | { 62 | bundler.addImage(asset); 63 | } 64 | 65 | for (var asset : this.soundService.findAll()) 66 | { 67 | bundler.addSound(asset); 68 | } 69 | 70 | int totalAssets = bundler.getSize(); 71 | int processedAssets = 0; 72 | 73 | ui.access(() -> { 74 | this.optionsView.getProgressBar().setIndeterminate(false); 75 | this.optionsView.getProgressBar().setValue(0); 76 | this.optionsView.getProgressLabel().setText("Writing tags to metadata... 0 / " + totalAssets + " (0%)"); 77 | }); 78 | 79 | for (String folder : bundler.getFolderNames()) 80 | { 81 | var bundle = bundler.getBundle(folder); 82 | List fileContent = new ArrayList<>(bundle.getImageAssets().size() + bundle.getSoundAssets().size()); 83 | 84 | for (var asset : bundle.getImageAssets()) 85 | { 86 | if (writeToMetadataFile) 87 | { 88 | String tagString = FileMetadataUtils.tagsToString(asset.getTags()); 89 | fileContent.add(asset.getFileName() + ": " + tagString); 90 | } 91 | 92 | if (writeToFoleFormatMetadata) 93 | { 94 | ImageFileMetadataUtils.saveWindowsExifMetadataTags(asset); 95 | } 96 | 97 | processedAssets++; 98 | 99 | if (processedAssets % 100 == 0) 100 | { 101 | updateProgress(totalAssets, processedAssets, ui); 102 | } 103 | } 104 | 105 | for (var asset : bundle.getSoundAssets()) 106 | { 107 | if (writeToMetadataFile) 108 | { 109 | String tagString = FileMetadataUtils.tagsToString(asset.getTags()); 110 | fileContent.add(asset.getFileName() + ": " + tagString); 111 | } 112 | 113 | if (writeToFoleFormatMetadata) 114 | { 115 | ImageFileMetadataUtils.saveWindowsExifMetadataTags(asset); 116 | } 117 | 118 | processedAssets++; 119 | 120 | if (processedAssets % 100 == 0) 121 | { 122 | updateProgress(totalAssets, processedAssets, ui); 123 | } 124 | } 125 | 126 | if (writeToMetadataFile) 127 | { 128 | Log.info("Saving metadata to file in " + folder); 129 | FileMetadataUtils.overwriteMetadataFile(folder, fileContent); 130 | Log.info("Done saving metadata to file in " + folder); 131 | } 132 | 133 | updateProgress(totalAssets, processedAssets, ui); 134 | } 135 | 136 | ui.access(() -> { 137 | if (this.onFinish != null) 138 | { 139 | this.onFinish.run(); 140 | } 141 | }); 142 | 143 | ui.setPollInterval(-1); 144 | } 145 | 146 | private void updateProgress(int totalNumFiles, int processedFiles, UI ui) 147 | { 148 | double completion = processedFiles / (double)totalNumFiles; 149 | ui.access(() -> { 150 | this.optionsView.getProgressBar().setValue(completion); 151 | this.optionsView.getProgressLabel().setText("Writing tags to metadata... " + processedFiles + " / " + totalNumFiles + " (" + (int)(completion * 100) + "%)"); 152 | }); 153 | } 154 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/util/metadata/image/ImageFileMetadataUtils.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.util.metadata.image; 2 | 3 | import bt.assetmanager.constants.AssetManagerConstants; 4 | import bt.assetmanager.data.entity.Asset; 5 | import bt.assetmanager.data.entity.Tag; 6 | import bt.log.Log; 7 | import org.apache.commons.imaging.ImageReadException; 8 | import org.apache.commons.imaging.ImageWriteException; 9 | import org.apache.commons.imaging.Imaging; 10 | import org.apache.commons.imaging.common.ImageMetadata; 11 | import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; 12 | import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; 13 | import org.apache.commons.imaging.formats.tiff.TiffField; 14 | import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; 15 | import org.apache.commons.imaging.formats.tiff.constants.MicrosoftTagConstants; 16 | import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; 17 | import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; 18 | import org.apache.commons.lang3.SystemUtils; 19 | 20 | import java.io.*; 21 | import java.nio.file.Files; 22 | import java.nio.file.Path; 23 | import java.nio.file.StandardCopyOption; 24 | import java.util.HashSet; 25 | import java.util.List; 26 | import java.util.Set; 27 | import java.util.stream.Collectors; 28 | 29 | /** 30 | * @author Lukas Hartwig 31 | * @since 05.09.2022 32 | */ 33 | public final class ImageFileMetadataUtils 34 | { 35 | private static Set supportedFileFormats; 36 | 37 | static 38 | { 39 | supportedFileFormats = new HashSet<>(); 40 | supportedFileFormats.add("jpeg"); 41 | } 42 | 43 | private ImageFileMetadataUtils() 44 | { 45 | } 46 | 47 | public static boolean isValidImageFormat(File imageFile) 48 | { 49 | String fileFormat = "invalid"; 50 | 51 | try 52 | { 53 | fileFormat = Imaging.guessFormat(imageFile).getName(); 54 | } 55 | catch (IOException e) 56 | { 57 | Log.error("Failed to guess file format", e); 58 | } 59 | 60 | return supportedFileFormats.contains(fileFormat.toLowerCase()); 61 | } 62 | 63 | public static Set getTagsFromWindowsFileMetadata(File imageFile) 64 | { 65 | Set tagSet = new HashSet<>(); 66 | 67 | if (SystemUtils.IS_OS_WINDOWS && ImageFileMetadataUtils.isValidImageFormat(imageFile)) 68 | { 69 | try 70 | { 71 | ImageMetadata metadata = Imaging.getMetadata(imageFile); 72 | 73 | if (metadata instanceof JpegImageMetadata jpegMetadata) 74 | { 75 | TiffField field = jpegMetadata.findEXIFValueWithExactMatch(MicrosoftTagConstants.EXIF_TAG_XPKEYWORDS); 76 | 77 | for (String tag : field.getValue().toString().split(";")) 78 | { 79 | tagSet.add(tag.trim().toUpperCase()); 80 | } 81 | } 82 | } 83 | catch (IOException | ImageReadException e) 84 | { 85 | Log.error("Failed to read tags from Windows file metadata", e); 86 | } 87 | } 88 | 89 | return tagSet; 90 | } 91 | 92 | public static void saveWindowsExifMetadataTags(Asset entity) 93 | { 94 | File file = new File(entity.getPath()); 95 | 96 | if (ImageFileMetadataUtils.isValidImageFormat(file)) 97 | { 98 | ImageFileMetadataUtils.saveWindowsExifMetadataTags(file, entity.getTags()); 99 | } 100 | } 101 | 102 | public static void saveWindowsExifMetadataTags(File imageFile, List tags) 103 | { 104 | if (SystemUtils.IS_OS_WINDOWS) 105 | { 106 | // create semicolon separated list of the tags 107 | String tagString = tags.stream() 108 | .map(Tag::getName) 109 | .collect(Collectors.joining(";")); 110 | 111 | try 112 | { 113 | TiffOutputSet outputSet = null; 114 | 115 | ImageMetadata metadata = Imaging.getMetadata(imageFile); 116 | JpegImageMetadata jpegMetadata = (JpegImageMetadata)metadata; 117 | 118 | if (jpegMetadata != null) 119 | { 120 | TiffImageMetadata exif = jpegMetadata.getExif(); 121 | 122 | if (null != exif) 123 | { 124 | outputSet = exif.getOutputSet(); 125 | } 126 | } 127 | 128 | if (outputSet == null) 129 | { 130 | outputSet = new TiffOutputSet(); 131 | } 132 | 133 | // overwrite tags in file metadata 134 | TiffOutputDirectory exifDirectory = outputSet.getOrCreateRootDirectory(); 135 | exifDirectory.removeField(MicrosoftTagConstants.EXIF_TAG_XPKEYWORDS); 136 | exifDirectory.add(MicrosoftTagConstants.EXIF_TAG_XPKEYWORDS, tagString); 137 | 138 | Path tempDestFile = Path.of(AssetManagerConstants.TEMP_FILE_DIRECTORY.toString(), imageFile.getName()); 139 | 140 | try (FileOutputStream fos = new FileOutputStream(tempDestFile.toFile()); 141 | OutputStream os = new BufferedOutputStream(fos)) 142 | { 143 | // write new data to a new temp file 144 | new ExifRewriter().updateExifMetadataLossy(imageFile, os, outputSet); 145 | 146 | // replace the original file with the just created temp file 147 | Files.move(tempDestFile, imageFile.toPath(), StandardCopyOption.REPLACE_EXISTING); 148 | } 149 | } 150 | catch (IOException | ImageReadException | ImageWriteException e) 151 | { 152 | Log.error("Failed to save tags to Windows file metadata " + imageFile.getAbsolutePath()); 153 | Log.error(e.getMessage()); 154 | } 155 | } 156 | } 157 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/util/metadata/FileMetadataUtils.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.util.metadata; 2 | 3 | import bt.assetmanager.constants.AssetManagerConstants; 4 | import bt.assetmanager.data.entity.Asset; 5 | import bt.assetmanager.data.entity.Tag; 6 | import bt.log.Log; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | import java.nio.charset.StandardCharsets; 11 | import java.nio.file.Files; 12 | import java.nio.file.Path; 13 | import java.nio.file.StandardOpenOption; 14 | import java.util.ArrayList; 15 | import java.util.LinkedList; 16 | import java.util.List; 17 | import java.util.Set; 18 | import java.util.stream.Collectors; 19 | import java.util.stream.Stream; 20 | 21 | /** 22 | * @author Lukas Hartwig 23 | * @since 06.09.2022 24 | */ 25 | public final class FileMetadataUtils 26 | { 27 | private static final String METADATA_FILE_NAME = ".asset_tags.meta"; 28 | 29 | private FileMetadataUtils() 30 | { 31 | } 32 | 33 | public static String tagsToString(List tags) 34 | { 35 | return tags.stream() 36 | .map(Tag::getName) 37 | .collect(Collectors.joining(",")); 38 | } 39 | 40 | public static void addTagsToMetadataFile(Asset asset) 41 | { 42 | try 43 | { 44 | File assetFile = new File(asset.getPath()); 45 | File metadataFile = Path.of(assetFile.getParent(), METADATA_FILE_NAME).toFile(); 46 | 47 | List fileContent = null; 48 | 49 | if (!metadataFile.exists()) 50 | { 51 | fileContent = new LinkedList<>(); 52 | metadataFile.createNewFile(); 53 | } 54 | else 55 | { 56 | fileContent = new ArrayList<>(Files.readAllLines(metadataFile.toPath(), StandardCharsets.UTF_8)); 57 | } 58 | 59 | String tagString = tagsToString(asset.getTags()); 60 | 61 | String lineContent = asset.getFileName() + ": " + tagString; 62 | 63 | boolean found = false; 64 | 65 | for (int i = 0; i < fileContent.size(); i++) 66 | { 67 | if (fileContent.get(i).toLowerCase().startsWith(asset.getFileName().toLowerCase())) 68 | { 69 | fileContent.set(i, lineContent); 70 | found = true; 71 | break; 72 | } 73 | } 74 | 75 | if (!found) 76 | { 77 | fileContent.add(lineContent); 78 | } 79 | 80 | Files.write(metadataFile.toPath(), fileContent, StandardCharsets.UTF_8); 81 | } 82 | catch (IOException e) 83 | { 84 | Log.error("Failed to write tags to external metadata file", e); 85 | } 86 | } 87 | 88 | public static void overwriteMetadataFile(String folder, List lines) 89 | { 90 | try 91 | { 92 | Files.write(Path.of(folder, METADATA_FILE_NAME), 93 | lines, 94 | StandardCharsets.UTF_8, 95 | StandardOpenOption.CREATE, 96 | StandardOpenOption.TRUNCATE_EXISTING); 97 | } 98 | catch (IOException e) 99 | { 100 | Log.error("Failed to write tags to external metadata file", e); 101 | } 102 | } 103 | 104 | public static List getMetadataFileContent(String folder) 105 | { 106 | File metadataFile = Path.of(folder, METADATA_FILE_NAME).toFile(); 107 | List fileContent = new ArrayList<>(); 108 | 109 | if (metadataFile.exists()) 110 | { 111 | try 112 | { 113 | fileContent = new ArrayList<>(Files.readAllLines(metadataFile.toPath(), StandardCharsets.UTF_8)); 114 | } 115 | catch (IOException e) 116 | { 117 | Log.error("Failed to read lines from external metadata file", e); 118 | } 119 | } 120 | 121 | return fileContent; 122 | } 123 | 124 | public static Set getTagsFromLine(String line) 125 | { 126 | return Stream.of(line.substring(line.lastIndexOf(":") + 1).split(",")) 127 | .map(String::trim) 128 | .map(String::toUpperCase) 129 | .filter(tag -> !tag.equals(AssetManagerConstants.UNTAGGED_TAG_NAME)) 130 | .distinct() 131 | .collect(Collectors.toSet()); 132 | } 133 | 134 | public static boolean lineMatch(String fileName, String line) 135 | { 136 | return line.toLowerCase().startsWith(fileName.toLowerCase() + ":"); 137 | } 138 | 139 | public static Set getTagsFromLines(Asset asset, List lines) 140 | { 141 | Set tagSet = null; 142 | 143 | for (int i = 0; i < lines.size(); i++) 144 | { 145 | String line = lines.get(i); 146 | 147 | if (lineMatch(asset.getFileName(), line)) 148 | { 149 | tagSet = getTagsFromLine(line); 150 | break; 151 | } 152 | } 153 | 154 | if (tagSet == null) 155 | { 156 | tagSet = Set.of(); 157 | } 158 | 159 | return tagSet; 160 | } 161 | 162 | public static Set getTagsFromMetadataFile(Asset asset) 163 | { 164 | Set tagSet = null; 165 | 166 | try 167 | { 168 | File assetFile = new File(asset.getPath()); 169 | File metadataFile = Path.of(assetFile.getParent(), METADATA_FILE_NAME).toFile(); 170 | 171 | if (metadataFile.exists()) 172 | { 173 | List fileContent = new ArrayList<>(Files.readAllLines(metadataFile.toPath(), StandardCharsets.UTF_8)); 174 | tagSet = getTagsFromLines(asset, fileContent); 175 | } 176 | 177 | if (tagSet == null) 178 | { 179 | tagSet = Set.of(); 180 | } 181 | } 182 | catch (IOException e) 183 | { 184 | Log.error("Failed to read tags from external metadata file", e); 185 | } 186 | 187 | return tagSet; 188 | } 189 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/assetview/AssetGridDisplay.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components.assetview; 2 | 3 | import bt.assetmanager.data.entity.Asset; 4 | import bt.assetmanager.util.UIUtils; 5 | import bt.log.Log; 6 | import com.vaadin.flow.component.grid.Grid; 7 | import com.vaadin.flow.component.grid.GridVariant; 8 | import com.vaadin.flow.component.html.Div; 9 | import com.vaadin.flow.component.html.Image; 10 | import com.vaadin.flow.data.renderer.ComponentRenderer; 11 | import com.vaadin.flow.server.StreamResource; 12 | 13 | import java.io.FileInputStream; 14 | import java.io.FileNotFoundException; 15 | import java.util.LinkedList; 16 | import java.util.List; 17 | 18 | /** 19 | * @author Lukas Hartwig 20 | * @since 02.09.2022 21 | */ 22 | public class AssetGridDisplay extends AssetDisplay 23 | { 24 | private Grid grid; 25 | private List items; 26 | private int elementsPerRow; 27 | private Image selectedImage; 28 | private boolean keepImageAspectRatio; 29 | 30 | public AssetGridDisplay(Class clazz, int elementsPerRow, boolean keepImageAspectRatio) 31 | { 32 | super(clazz); 33 | setClassName("grid-wrapper"); 34 | this.elementsPerRow = elementsPerRow; 35 | this.keepImageAspectRatio = keepImageAspectRatio; 36 | setup(); 37 | } 38 | 39 | @Override 40 | protected void setup() 41 | { 42 | super.setup(); 43 | this.grid = createGrid(); 44 | add(this.grid); 45 | } 46 | 47 | private void buildRows(List items) 48 | { 49 | List rows = new LinkedList<>(); 50 | int currentIndex = 0; 51 | AssetGridRow currentRow = new AssetGridRow(); 52 | 53 | if (!items.isEmpty()) 54 | { 55 | rows.add(currentRow); 56 | } 57 | 58 | for (T item : items) 59 | { 60 | if (currentIndex >= this.elementsPerRow) 61 | { 62 | currentRow = new AssetGridRow(); 63 | rows.add(currentRow); 64 | currentIndex = 0; 65 | } 66 | 67 | currentRow.add(item); 68 | currentIndex++; 69 | } 70 | 71 | this.grid.setItems(rows); 72 | } 73 | 74 | @Override 75 | public void setItems(List items) 76 | { 77 | this.items = items; 78 | buildRows(items); 79 | this.grid.scrollToStart(); 80 | } 81 | 82 | @Override 83 | public void removeItem(T item) 84 | { 85 | this.items.remove(items); 86 | buildRows(this.items); 87 | } 88 | 89 | public void selectImage(Image image) 90 | { 91 | if (this.selectedImage != null) 92 | { 93 | setImageBorder(this.selectedImage, "6px solid transparent"); 94 | } 95 | 96 | this.selectedImage = image; 97 | setImageBorder(this.selectedImage, "6px solid DarkOrange"); 98 | this.selectedImage.getStyle().set("border-radius", "15px"); 99 | } 100 | 101 | protected Grid createGrid() 102 | { 103 | Grid newGrid = new Grid<>(AssetGridRow.class, false); 104 | 105 | String imageSize = (100.0 / this.elementsPerRow) + "%"; 106 | 107 | for (int i = 0; i < this.elementsPerRow; i++) 108 | { 109 | final int finalCounter = i; 110 | newGrid.addColumn(new ComponentRenderer<>( 111 | row -> { 112 | T asset = (T)row.get(finalCounter); 113 | 114 | if (asset != null) 115 | { 116 | StreamResource imageResource = new StreamResource(asset.getFileName() + "", () -> { 117 | try 118 | { 119 | return new FileInputStream(asset.getPath()); 120 | } 121 | catch (final FileNotFoundException e) 122 | { 123 | Log.error("", e); 124 | return null; 125 | } 126 | }); 127 | 128 | Image image = new Image(imageResource, "Couldn't load image"); 129 | 130 | setImageBorder(image, "6px solid transparent"); 131 | image.getStyle().set("border-radius", "15px"); 132 | 133 | image.addClickListener(e -> { 134 | if (this.onElementSelection != null) 135 | { 136 | this.onElementSelection.accept(asset); 137 | } 138 | 139 | selectImage(image); 140 | }); 141 | 142 | if (this.keepImageAspectRatio) 143 | { 144 | image.setWidth("100%"); 145 | image.setHeight("100%"); 146 | 147 | return image; 148 | } 149 | else 150 | { 151 | Div wrapper = new Div(); 152 | wrapper.setWidth("100%"); 153 | 154 | wrapper.addClassName("image-container"); 155 | image.addClassName("grid-image-ignore-ratio"); 156 | wrapper.add(image); 157 | 158 | return wrapper; 159 | } 160 | } 161 | else 162 | { 163 | return UIUtils.heightFiller("80px"); 164 | } 165 | } 166 | ) 167 | ).setHeader("").setKey("image" + i).setWidth(imageSize); 168 | } 169 | 170 | newGrid.setSelectionMode(Grid.SelectionMode.NONE); 171 | newGrid.addThemeVariants(GridVariant.LUMO_NO_ROW_BORDERS); 172 | 173 | return newGrid; 174 | } 175 | 176 | private void setImageBorder(Image image, String borderValue) 177 | { 178 | image.getStyle().set("border", borderValue); 179 | } 180 | } -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/views/options/OptionsView.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.views.options; 2 | 3 | import bt.assetmanager.components.options.UserOptionCheckbox; 4 | import bt.assetmanager.components.options.UserOptionNumberField; 5 | import bt.assetmanager.data.entity.UserOption; 6 | import bt.assetmanager.data.service.ImageAssetService; 7 | import bt.assetmanager.data.service.SoundAssetService; 8 | import bt.assetmanager.data.service.UserOptionService; 9 | import bt.assetmanager.util.UIUtils; 10 | import bt.assetmanager.views.MainLayout; 11 | import bt.assetmanager.workers.ExportTagsToMetadataWorker; 12 | import com.vaadin.flow.component.UI; 13 | import com.vaadin.flow.component.button.Button; 14 | import com.vaadin.flow.component.dependency.Uses; 15 | import com.vaadin.flow.component.html.Div; 16 | import com.vaadin.flow.component.html.Label; 17 | import com.vaadin.flow.component.icon.Icon; 18 | import com.vaadin.flow.component.notification.Notification; 19 | import com.vaadin.flow.component.orderedlayout.VerticalLayout; 20 | import com.vaadin.flow.component.progressbar.ProgressBar; 21 | import com.vaadin.flow.component.splitlayout.SplitLayout; 22 | import com.vaadin.flow.router.PageTitle; 23 | import com.vaadin.flow.router.Route; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | 26 | import java.util.concurrent.ExecutorService; 27 | import java.util.concurrent.Executors; 28 | 29 | /** 30 | * @author Lukas Hartwig 31 | * @since 08.09.2022 32 | */ 33 | @PageTitle("Options - Asset manager") 34 | @Route(value = "options", layout = MainLayout.class) 35 | @Uses(Icon.class) 36 | public class OptionsView extends Div 37 | { 38 | private static ExecutorService executorService = Executors.newCachedThreadPool(); 39 | private UserOptionService optionsService; 40 | private ImageAssetService imageService; 41 | private SoundAssetService soundService; 42 | private ProgressBar progressBar; 43 | private Label progressLabel; 44 | private Button exportTagsButton; 45 | 46 | @Autowired 47 | public OptionsView(UserOptionService optionsService, ImageAssetService imageService, SoundAssetService soundService) 48 | { 49 | this.optionsService = optionsService; 50 | this.imageService = imageService; 51 | this.soundService = soundService; 52 | addClassNames("options-view"); 53 | 54 | SplitLayout layout = new SplitLayout(); 55 | 56 | createLeftSide(layout); 57 | createRightSide(layout); 58 | 59 | add(layout); 60 | } 61 | 62 | private void createLeftSide(SplitLayout layout) 63 | { 64 | VerticalLayout wrapper = new VerticalLayout(); 65 | layout.addToPrimary(wrapper); 66 | 67 | wrapper.add(new UserOptionCheckbox(optionsService, 68 | UserOption.DISPLAY_ALL_ASSETS_ON_PAGE_OPEN, 69 | "Show all assets when opening an asset page", 70 | "If enabled all assets will be loaded and shown when entering an asset page. If disabled you need to click the search button once.")); 71 | 72 | wrapper.add(new UserOptionNumberField(optionsService, 73 | UserOption.IMAGE_GRID_IMAGES_PER_ROW, 74 | "Number of images per row in image grid view", 75 | "Defines the number of images per row when using the grid view on the Images page", 76 | 1, 77 | 20)); 78 | 79 | wrapper.add(new UserOptionCheckbox(optionsService, 80 | UserOption.IMAGE_GRID_KEEP_ASPECT_RATIO, 81 | "Keep aspect ratio of images in grid view", 82 | "If enabled images in grid view will be displayed with their correct aspect ratio. If disabled images will be stretched/squished into a square.")); 83 | } 84 | 85 | private void createRightSide(SplitLayout layout) 86 | { 87 | VerticalLayout wrapper = new VerticalLayout(); 88 | layout.addToSecondary(wrapper); 89 | 90 | wrapper.add(new UserOptionCheckbox(optionsService, 91 | UserOption.SAVE_TAGS_IN_FILE_FORMAT_METADATA, 92 | "Save tags in the file formats metadata (currently only JPEG on Windows supported)", 93 | "If enabled tags will be saved in the metadata of the file itself utilizing the \"Tags\" property.")); 94 | 95 | wrapper.add(new UserOptionCheckbox(optionsService, 96 | UserOption.SAVE_TAGS_IN_METADATA_FILE, 97 | "Save tags in a separate metadata file in the same folder as the assets", 98 | "If enabled tags are also saved in a separate metadata file in the same folder as the asset.")); 99 | 100 | wrapper.add(new UserOptionCheckbox(optionsService, 101 | UserOption.READ_TAGS_FROM_METADATA_FILE, 102 | "Read tags from separate metadata file on import", 103 | "If enabled tags will be read from the separate metadata file when an asset is imported. This allows you to safely move file structures without losing your tags.")); 104 | 105 | wrapper.add(new UserOptionCheckbox(optionsService, 106 | UserOption.REMOVE_ASSETS_FROM_TOOL_IF_THEY_CANT_BE_FOUND, 107 | "Remove assets from this tool if their files can't be found anymore", 108 | "If enabled this will remove assets from the tool if their files don't exist anymore, for example if you moved them.")); 109 | 110 | this.exportTagsButton = new Button("Export tags to metadata"); 111 | this.exportTagsButton.getElement().setProperty("title", "Exports all existing tags to the metadata. Make sure to enable the appropriate metadata options above."); 112 | this.exportTagsButton.addClickListener(e -> writeTagsToMetadata()); 113 | 114 | wrapper.add(UIUtils.heightFiller("150px"), this.exportTagsButton); 115 | 116 | this.progressBar = new ProgressBar(); 117 | this.progressBar.setVisible(false); 118 | this.progressBar.setWidth("300px"); 119 | 120 | this.progressLabel = new Label(""); 121 | 122 | wrapper.add(this.progressLabel, this.progressBar); 123 | } 124 | 125 | private void writeTagsToMetadata() 126 | { 127 | this.exportTagsButton.setEnabled(false); 128 | UI.getCurrent().setPollInterval(500); 129 | UI ui = UI.getCurrent(); 130 | 131 | executorService.submit(() -> { 132 | var worker = new ExportTagsToMetadataWorker(this, this.imageService, this.soundService, this.optionsService); 133 | 134 | worker.onFinish(() -> { 135 | this.exportTagsButton.setEnabled(true); 136 | this.progressBar.setVisible(false); 137 | this.progressLabel.setText(""); 138 | Notification.show("Finished exporting tags"); 139 | }); 140 | 141 | worker.work(ui); 142 | }); 143 | } 144 | 145 | public ProgressBar getProgressBar() 146 | { 147 | return progressBar; 148 | } 149 | 150 | public Label getProgressLabel() 151 | { 152 | return progressLabel; 153 | } 154 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/workers/FileSearchWorker.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.workers; 2 | 3 | import bt.assetmanager.data.entity.ImageFileEnding; 4 | import bt.assetmanager.data.entity.SoundFileEnding; 5 | import bt.assetmanager.data.entity.TempImageAsset; 6 | import bt.assetmanager.data.entity.TempSoundAsset; 7 | import bt.assetmanager.views.import_.AssetImportRow; 8 | import bt.assetmanager.views.import_.ImportView; 9 | import com.vaadin.flow.component.UI; 10 | import com.vaadin.flow.component.checkbox.Checkbox; 11 | import com.vaadin.flow.component.notification.Notification; 12 | 13 | import java.io.File; 14 | import java.util.ArrayList; 15 | import java.util.LinkedList; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | 19 | /** 20 | * @author Lukas Hartwig 21 | * @since 07.09.2022 22 | */ 23 | public class FileSearchWorker implements BackgroundWorker 24 | { 25 | private ImportView importView; 26 | private Runnable onFinish; 27 | private UI ui; 28 | 29 | public FileSearchWorker(ImportView importView) 30 | { 31 | this.importView = importView; 32 | } 33 | 34 | public void onFinish(Runnable onFinish) 35 | { 36 | this.onFinish = onFinish; 37 | } 38 | 39 | @Override 40 | public void work(UI ui) 41 | { 42 | this.ui = ui; 43 | 44 | ui.access(() -> { 45 | this.importView.getProgressBar().setIndeterminate(true); 46 | this.importView.getProgressBar().setVisible(true); 47 | this.importView.getProgressLabel().setText("Searching files..."); 48 | }); 49 | 50 | this.importView.setLastCheckedImageRow(null); 51 | this.importView.setLastCheckedSoundRow(null); 52 | 53 | replaceImageEndings(); 54 | replaceSoundEndings(); 55 | 56 | ui.access(() -> { 57 | this.importView.setImageFiles(new ArrayList<>()); 58 | this.importView.setSoundFiles(new ArrayList<>()); 59 | }); 60 | ui.access(() -> this.importView.getImageGrid().setItems(this.importView.getImageFiles())); 61 | ui.access(() -> this.importView.getSoundGrid().setItems(this.importView.getSoundFiles())); 62 | 63 | List tempImageFiles = new LinkedList<>(); 64 | List tempSoundFiles = new LinkedList<>(); 65 | 66 | this.importView.setSelectedOriginDirectory(new File(this.importView.getDirectoryTextField().getValue())); 67 | 68 | if (this.importView.getSelectedOriginDirectory().exists() && !this.importView.getSelectedOriginDirectory().isDirectory()) 69 | { 70 | this.importView.setSelectedOriginDirectory(this.importView.getSelectedOriginDirectory().getParentFile()); 71 | } 72 | 73 | if (!this.importView.getSelectedOriginDirectory().exists()) 74 | { 75 | Notification.show("Folder " + this.importView.getSelectedOriginDirectory().getAbsolutePath() + " does not exist"); 76 | return; 77 | } 78 | 79 | fillFileGrids(this.importView.getSelectedOriginDirectory(), tempImageFiles, tempSoundFiles); 80 | 81 | this.ui.access(() -> this.importView.getProgressFolderLabel().setText("")); 82 | this.ui.access(() -> this.importView.getProgressLabel().setText("Filtering out already imported files...")); 83 | 84 | this.importView.getTempImageRepo().saveAll(tempImageFiles); 85 | this.importView.getTempSoundRepo().saveAll(tempSoundFiles); 86 | 87 | tempImageFiles = this.importView.getTempImageRepo().getAllNonExisting(); 88 | tempSoundFiles = this.importView.getTempSoundRepo().getAllNonExisting(); 89 | 90 | this.importView.setImageFiles(tempImageFiles.parallelStream().map(temp -> { 91 | var row = new AssetImportRow(); 92 | row.setFileName(temp.getFileName()); 93 | row.setPath(temp.getPath()); 94 | row.setRelativePath(temp.getPath().substring(this.importView.getSelectedOriginDirectory().getAbsolutePath().length())); 95 | return row; 96 | }).collect(Collectors.toList())); 97 | 98 | this.importView.setSoundFiles(tempSoundFiles.parallelStream().map(temp -> { 99 | var row = new AssetImportRow(); 100 | row.setFileName(temp.getFileName()); 101 | row.setPath(temp.getPath()); 102 | row.setRelativePath(temp.getPath().substring(this.importView.getSelectedOriginDirectory().getAbsolutePath().length())); 103 | return row; 104 | }).collect(Collectors.toList())); 105 | 106 | this.importView.getTempImageRepo().deleteAll(); 107 | this.importView.getTempSoundRepo().deleteAll(); 108 | 109 | this.ui.access(() -> this.importView.getProgressLabel().setText("Creating rows...")); 110 | 111 | for (int i = 0; i < this.importView.getImageFiles().size(); i++) 112 | { 113 | var row = this.importView.getImageFiles().get(i); 114 | row.setIndex(i); 115 | createCheckBoxForRow(row); 116 | 117 | row.getImportCheckbox().addClickListener(event -> { 118 | if (event.isShiftKey() && this.importView.getLastCheckedImageRow() != null) 119 | { 120 | selectAllInRange(this.importView.getImageFiles(), row.getIndex(), this.importView.getLastCheckedImageRow().getIndex()); 121 | } 122 | 123 | this.importView.setLastCheckedImageRow(row); 124 | }); 125 | } 126 | 127 | for (int i = 0; i < this.importView.getSoundFiles().size(); i++) 128 | { 129 | var row = this.importView.getSoundFiles().get(i); 130 | row.setIndex(i); 131 | createCheckBoxForRow(row); 132 | 133 | row.getImportCheckbox().addClickListener(event -> { 134 | if (event.isShiftKey() && this.importView.getLastCheckedSoundRow() != null) 135 | { 136 | selectAllInRange(this.importView.getSoundFiles(), row.getIndex(), this.importView.getLastCheckedSoundRow().getIndex()); 137 | } 138 | 139 | this.importView.setLastCheckedSoundRow(row); 140 | }); 141 | } 142 | 143 | ui.access(() -> { 144 | if (this.onFinish != null) 145 | { 146 | this.onFinish.run(); 147 | } 148 | }); 149 | 150 | ui.setPollInterval(-1); 151 | } 152 | 153 | public void selectAllInRange(List rows, int index1, int index2) 154 | { 155 | int min = Math.min(index1, index2); 156 | int max = Math.max(index1, index2); 157 | 158 | for (int i = min; i <= max; i++) 159 | { 160 | rows.get(i).checkImportBox(true); 161 | } 162 | } 163 | 164 | private void createCheckBoxForRow(AssetImportRow row) 165 | { 166 | Checkbox checkbox = new Checkbox(); 167 | checkbox.setValue(row.isShouldImport()); 168 | 169 | checkbox.addValueChangeListener(event -> row.setShouldImport(event.getValue())); 170 | 171 | row.setImportCheckbox(checkbox); 172 | } 173 | 174 | private void fillFileGrids(File root, List tempImageFiles, List tempSoundFiles) 175 | { 176 | this.ui.access(() -> this.importView.getProgressFolderLabel().setText(root.getAbsolutePath())); 177 | 178 | for (File file : root.listFiles()) 179 | { 180 | if (file.isDirectory()) 181 | { 182 | fillFileGrids(file, tempImageFiles, tempSoundFiles); 183 | } 184 | else 185 | { 186 | if (file.getName().lastIndexOf(".") > -1) 187 | { 188 | String fileEnding = file.getName().substring(file.getName().lastIndexOf(".") + 1); 189 | 190 | if (this.importView.getImageFileEndings().contains(fileEnding.toLowerCase().trim())) 191 | { 192 | var asset = new TempImageAsset(); 193 | asset.setPath(file.getAbsolutePath()); 194 | asset.setFileName(file.getName()); 195 | tempImageFiles.add(asset); 196 | } 197 | else if (this.importView.getSoundFileEndings().contains(fileEnding.toLowerCase().trim())) 198 | { 199 | var asset = new TempSoundAsset(); 200 | asset.setPath(file.getAbsolutePath()); 201 | asset.setFileName(file.getName()); 202 | tempSoundFiles.add(asset); 203 | 204 | } 205 | } 206 | } 207 | } 208 | } 209 | 210 | private void replaceImageEndings() 211 | { 212 | this.importView.getImageFileEndingRepo().deleteAll(); 213 | String[] endings = this.importView.getImageFileEndingsTextField().getValue().split(","); 214 | 215 | for (String ending : endings) 216 | { 217 | var imageEnding = new ImageFileEnding(); 218 | imageEnding.setEnding(ending.trim().toLowerCase()); 219 | this.importView.getImageFileEndingRepo().save(imageEnding); 220 | } 221 | 222 | this.importView.setImageFileEndings(this.importView.getImageFileEndingRepo().findAll().stream().map(ImageFileEnding::getEnding).toList()); 223 | } 224 | 225 | private void replaceSoundEndings() 226 | { 227 | this.importView.getSoundFileEndingRepo().deleteAll(); 228 | String[] endings = this.importView.getSoundFileEndingsTextField().getValue().split(","); 229 | 230 | for (String ending : endings) 231 | { 232 | var soundEnding = new SoundFileEnding(); 233 | soundEnding.setEnding(ending.trim().toLowerCase()); 234 | this.importView.getSoundFileEndingRepo().save(soundEnding); 235 | } 236 | 237 | this.importView.setSoundFileEndings(this.importView.getSoundFileEndingRepo().findAll().stream().map(SoundFileEnding::getEnding).toList()); 238 | } 239 | } -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/workers/FileImportWorker.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.workers; 2 | 3 | import bt.assetmanager.constants.AssetManagerConstants; 4 | import bt.assetmanager.data.entity.ImageAsset; 5 | import bt.assetmanager.data.entity.SoundAsset; 6 | import bt.assetmanager.data.entity.Tag; 7 | import bt.assetmanager.data.entity.UserOption; 8 | import bt.assetmanager.data.service.UserOptionService; 9 | import bt.assetmanager.obj.FileBundler; 10 | import bt.assetmanager.util.metadata.FileMetadataUtils; 11 | import bt.assetmanager.views.import_.AssetImportRow; 12 | import bt.assetmanager.views.import_.ImportView; 13 | import bt.log.Log; 14 | import com.vaadin.flow.component.UI; 15 | import com.vaadin.flow.component.notification.Notification; 16 | 17 | import java.util.ArrayList; 18 | import java.util.HashSet; 19 | import java.util.List; 20 | import java.util.Set; 21 | import java.util.stream.Collectors; 22 | 23 | /** 24 | * @author Lukas Hartwig 25 | * @since 07.09.2022 26 | */ 27 | public class FileImportWorker implements BackgroundWorker 28 | { 29 | private ImportView importView; 30 | private Runnable onFinish; 31 | private UserOptionService optionsService; 32 | 33 | public FileImportWorker(ImportView importView, UserOptionService optionsService) 34 | { 35 | this.importView = importView; 36 | this.optionsService = optionsService; 37 | } 38 | 39 | public void onFinish(Runnable onFinish) 40 | { 41 | this.onFinish = onFinish; 42 | } 43 | 44 | @Override 45 | public void work(UI ui) 46 | { 47 | List tags = new ArrayList<>(); 48 | 49 | // get tags from tag field in case there are any 50 | for (String tag : this.importView.getApplyTagsTextField().getValue().trim().split(",")) 51 | { 52 | tag = tag.trim(); 53 | 54 | if (!tag.isEmpty()) 55 | { 56 | tags.add(this.importView.getTagService().obtainTag(tag)); 57 | } 58 | } 59 | 60 | // get selected rows for images and sounds 61 | List selectedImages = this.importView.getImageFiles().stream() 62 | .filter(AssetImportRow::isShouldImport) 63 | .toList(); 64 | 65 | List selectedSounds = this.importView.getSoundFiles().stream() 66 | .filter(AssetImportRow::isShouldImport) 67 | .toList(); 68 | 69 | int totalNumFiles = selectedImages.size() + selectedSounds.size(); 70 | int processedFiles = 0; 71 | 72 | ui.access(() -> { 73 | this.importView.getProgressBar().setIndeterminate(true); 74 | this.importView.getProgressBar().setVisible(true); 75 | this.importView.getProgressLabel().setText("Bundling files..."); 76 | }); 77 | 78 | ui.access(() -> Notification.show("Importing " + selectedImages.size() + " images and " + selectedSounds.size() + " sounds")); 79 | 80 | Tag untaggedTag = this.importView.getTagService().obtainTag(AssetManagerConstants.UNTAGGED_TAG_NAME); 81 | 82 | FileBundler bundler = new FileBundler<>(); 83 | 84 | Log.info("Starting to bundle " + totalNumFiles + " files"); 85 | 86 | for (AssetImportRow row : selectedImages) 87 | { 88 | bundler.addImage(row); 89 | } 90 | 91 | for (AssetImportRow row : selectedSounds) 92 | { 93 | bundler.addSound(row); 94 | } 95 | 96 | Log.info("Done bundling " + totalNumFiles + " files into " + bundler.getFolderNames().size() + " folders"); 97 | 98 | ui.access(() -> { 99 | this.importView.getProgressBar().setIndeterminate(false); 100 | this.importView.getProgressBar().setValue(0); 101 | this.importView.getProgressLabel().setText("Importing... 0 / " + totalNumFiles + " (0%)"); 102 | }); 103 | 104 | Log.info("Starting to import " + totalNumFiles + " files"); 105 | 106 | boolean readFromMetadataFile = this.optionsService.getBooleanValue(UserOption.READ_TAGS_FROM_METADATA_FILE); 107 | boolean writeToMetadataFile = this.optionsService.getBooleanValue(UserOption.SAVE_TAGS_IN_METADATA_FILE); 108 | 109 | for (String folder : bundler.getFolderNames()) 110 | { 111 | ui.access(() -> this.importView.getProgressFolderLabel().setText(folder)); 112 | 113 | var bundle = bundler.getBundle(folder); 114 | List fileContent = null; 115 | 116 | if (readFromMetadataFile) 117 | { 118 | fileContent = FileMetadataUtils.getMetadataFileContent(folder); 119 | } 120 | 121 | for (AssetImportRow row : bundle.getImageAssets()) 122 | { 123 | ImageAsset asset = new ImageAsset(); 124 | asset.setPath(row.getPath()); 125 | asset.setFileName(row.getFileName()); 126 | 127 | if (readFromMetadataFile) 128 | { 129 | asset.setTags(new ArrayList<>(getTagsForImportFile(tags, row, fileContent, untaggedTag))); 130 | } 131 | else 132 | { 133 | asset.setTags(tags); 134 | } 135 | 136 | this.importView.getImageService().save(asset, false); 137 | Log.debug("Saved image asset " + asset.getPath()); 138 | 139 | processedFiles++; 140 | 141 | if (processedFiles % 100 == 0) 142 | { 143 | updateProgress(totalNumFiles, processedFiles, ui); 144 | } 145 | } 146 | 147 | ui.access(() -> this.importView.getImageFiles().removeAll(bundle.getImageAssets())); 148 | 149 | for (AssetImportRow row : bundle.getSoundAssets()) 150 | { 151 | SoundAsset asset = new SoundAsset(); 152 | asset.setPath(row.getPath()); 153 | asset.setFileName(row.getFileName()); 154 | 155 | if (readFromMetadataFile) 156 | { 157 | asset.setTags(new ArrayList<>(getTagsForImportFile(tags, row, fileContent, untaggedTag))); 158 | } 159 | else 160 | { 161 | asset.setTags(tags); 162 | } 163 | 164 | this.importView.getSoundService().save(asset, false); 165 | Log.debug("Saved sound asset " + asset.getPath()); 166 | 167 | processedFiles++; 168 | 169 | if (processedFiles % 100 == 0) 170 | { 171 | updateProgress(totalNumFiles, processedFiles, ui); 172 | } 173 | } 174 | 175 | ui.access(() -> this.importView.getSoundFiles().removeAll(bundle.getSoundAssets())); 176 | 177 | if (writeToMetadataFile) 178 | { 179 | Log.info("Saving metadata to file in " + folder); 180 | FileMetadataUtils.overwriteMetadataFile(folder, fileContent); 181 | Log.info("Done saving metadata to file in " + folder); 182 | } 183 | 184 | updateProgress(totalNumFiles, processedFiles, ui); 185 | } 186 | 187 | Log.info("Done importing " + totalNumFiles + " files"); 188 | 189 | for (int i = 0; i < this.importView.getImageFiles().size(); i++) 190 | { 191 | var row = this.importView.getImageFiles().get(i); 192 | row.setIndex(i); 193 | } 194 | 195 | for (int i = 0; i < this.importView.getSoundFiles().size(); i++) 196 | { 197 | var row = this.importView.getSoundFiles().get(i); 198 | row.setIndex(i); 199 | } 200 | 201 | ui.access(() -> { 202 | if (this.onFinish != null) 203 | { 204 | this.onFinish.run(); 205 | } 206 | }); 207 | 208 | ui.setPollInterval(-1); 209 | } 210 | 211 | private void updateProgress(int totalNumFiles, int processedFiles, UI ui) 212 | { 213 | double completion = processedFiles / (double)totalNumFiles; 214 | ui.access(() -> { 215 | this.importView.getProgressBar().setValue(completion); 216 | this.importView.getProgressLabel().setText("Importing... " + processedFiles + " / " + totalNumFiles + " (" + (int)(completion * 100) + "%)"); 217 | }); 218 | } 219 | 220 | private Set getTagsForImportFile(List startTags, AssetImportRow row, List fileContent, Tag untaggedTag) 221 | { 222 | Set tagSet = new HashSet<>(startTags); 223 | 224 | boolean found = false; 225 | int index = -1; 226 | 227 | for (int i = 0; i < fileContent.size(); i++) 228 | { 229 | String line = fileContent.get(i); 230 | 231 | if (FileMetadataUtils.lineMatch(row.getFileName(), line)) 232 | { 233 | for (String tag : FileMetadataUtils.getTagsFromLine(line)) 234 | { 235 | tagSet.add(this.importView.getTagService().obtainTag(tag.trim())); 236 | } 237 | 238 | index = i; 239 | found = true; 240 | break; 241 | } 242 | } 243 | 244 | if (tagSet.isEmpty()) 245 | { 246 | tagSet.add(untaggedTag); 247 | } 248 | 249 | String tagString = tagSet.stream() 250 | .map(Tag::getName) 251 | .collect(Collectors.joining(",")); 252 | 253 | String lineContent = row.getFileName() + ": " + tagString; 254 | 255 | if (found) 256 | { 257 | fileContent.set(index, lineContent); 258 | } 259 | else 260 | { 261 | fileContent.add(lineContent); 262 | } 263 | 264 | return tagSet; 265 | } 266 | } -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/main/java/bt/assetmanager/components/AssetSearchPanel.java: -------------------------------------------------------------------------------- 1 | package bt.assetmanager.components; 2 | 3 | import bt.assetmanager.data.entity.Asset; 4 | import bt.assetmanager.data.entity.ImageAsset; 5 | import bt.assetmanager.data.entity.Tag; 6 | import bt.assetmanager.data.service.AssetService; 7 | import bt.assetmanager.data.service.TagService; 8 | import bt.assetmanager.util.UIUtils; 9 | import bt.assetmanager.workers.AssetSearchWorker; 10 | import bt.log.Log; 11 | import com.vaadin.flow.component.Component; 12 | import com.vaadin.flow.component.UI; 13 | import com.vaadin.flow.component.button.Button; 14 | import com.vaadin.flow.component.button.ButtonVariant; 15 | import com.vaadin.flow.component.checkbox.Checkbox; 16 | import com.vaadin.flow.component.formlayout.FormLayout; 17 | import com.vaadin.flow.component.html.Div; 18 | import com.vaadin.flow.component.html.Hr; 19 | import com.vaadin.flow.component.html.Image; 20 | import com.vaadin.flow.component.html.Label; 21 | import com.vaadin.flow.component.icon.Icon; 22 | import com.vaadin.flow.component.icon.VaadinIcon; 23 | import com.vaadin.flow.component.notification.Notification; 24 | import com.vaadin.flow.component.orderedlayout.FlexComponent; 25 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 26 | import com.vaadin.flow.component.progressbar.ProgressBar; 27 | import com.vaadin.flow.component.virtuallist.VirtualList; 28 | import com.vaadin.flow.data.renderer.ComponentRenderer; 29 | import com.vaadin.flow.function.SerializableConsumer; 30 | import com.vaadin.flow.server.StreamResource; 31 | 32 | import java.awt.*; 33 | import java.io.*; 34 | import java.util.List; 35 | import java.util.concurrent.ExecutorService; 36 | import java.util.concurrent.Executors; 37 | import java.util.function.Consumer; 38 | 39 | /** 40 | * @author Lukas Hartwig 41 | * @since 31.08.2022 42 | */ 43 | public class AssetSearchPanel extends Div 44 | { 45 | private static ExecutorService executorService = Executors.newCachedThreadPool(); 46 | private AssetService assetService; 47 | private TagService tagService; 48 | private T currentlySelectedElement; 49 | private Class clazz; 50 | private AudioPlayer audioPlayer; 51 | private Image image; 52 | private TagSearchTextField searchTextField; 53 | private TagSearchTextField addTagTextField; 54 | private Checkbox fileNameFilterCheckbox; 55 | private Button searchButton; 56 | private Button addTagButton; 57 | private Label foundFilesLabel; 58 | private VirtualList tagList; 59 | private SerializableConsumer> onSearchConsumer; 60 | private SerializableConsumer onViewChange; 61 | private SerializableConsumer onDelete; 62 | private Button switchLayoutButton; 63 | private boolean displayLines; 64 | private Button openFolderButton; 65 | private Button deleteButton; 66 | private ProgressBar progressBar; 67 | private Label progressLabel; 68 | private boolean saveTagsInMetadata; 69 | 70 | public AssetSearchPanel(Class clazz, AssetService assetService, TagService tagService, boolean gridView, boolean saveTagsInMetadata) 71 | { 72 | this.assetService = assetService; 73 | this.tagService = tagService; 74 | this.clazz = clazz; 75 | this.displayLines = !gridView; 76 | this.saveTagsInMetadata = saveTagsInMetadata; 77 | createUI(); 78 | } 79 | 80 | public void setSelectedElement(T element) 81 | { 82 | this.currentlySelectedElement = element; 83 | 84 | StreamResource resource = new StreamResource(this.currentlySelectedElement.getFileName() + "", () -> { 85 | try 86 | { 87 | return new FileInputStream(this.currentlySelectedElement.getPath()); 88 | } 89 | catch (final FileNotFoundException e) 90 | { 91 | return null; 92 | } 93 | }); 94 | 95 | if (this.clazz.equals(ImageAsset.class)) 96 | { 97 | this.image.setSrc(resource); 98 | } 99 | else 100 | { 101 | this.audioPlayer.setSource(resource); 102 | } 103 | 104 | this.tagList.setItems(this.currentlySelectedElement.getTags().stream().map(Tag::getName)); 105 | } 106 | 107 | public void playSound() 108 | { 109 | if (this.audioPlayer != null) 110 | { 111 | this.audioPlayer.play(); 112 | } 113 | } 114 | 115 | public void onSearch(SerializableConsumer> consumer) 116 | { 117 | this.onSearchConsumer = consumer; 118 | } 119 | 120 | public void onViewChange(SerializableConsumer consumer) 121 | { 122 | this.onViewChange = consumer; 123 | } 124 | 125 | public void onDelete(SerializableConsumer consumer) 126 | { 127 | this.onDelete = consumer; 128 | } 129 | 130 | private void createUI() 131 | { 132 | setClassName("input-layout"); 133 | 134 | Div innerDiv = new Div(); 135 | innerDiv.setClassName("input"); 136 | add(innerDiv); 137 | 138 | FormLayout formLayout = new FormLayout(); 139 | 140 | this.image = new Image(); 141 | this.image.setWidth("300px"); 142 | this.audioPlayer = new AudioPlayer(); 143 | 144 | this.searchTextField = new TagSearchTextField(4, this.tagService); 145 | this.searchTextField.setLabel("Search (comma separated tags)"); 146 | this.addTagTextField = new TagSearchTextField(4, this.tagService); 147 | this.addTagTextField.setLabel("Tag to apply"); 148 | 149 | this.foundFilesLabel = new Label("0 files found"); 150 | 151 | this.fileNameFilterCheckbox = new Checkbox("Search for file name instead of tags"); 152 | 153 | this.searchButton = new Button("Search"); 154 | this.searchButton.addClickListener(e -> onSearchButton()); 155 | this.searchButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY); 156 | 157 | this.addTagButton = new Button("Add tag"); 158 | this.addTagButton.addClickListener(e -> onAddTagButton()); 159 | 160 | this.tagList = new VirtualList<>(); 161 | this.tagList.setRenderer(new ComponentRenderer<>(tagName -> { 162 | Button removeButton = new Button("x"); 163 | removeButton.addClickListener(e -> onRemoveTagButton(tagName)); 164 | 165 | Label label = new Label(tagName); 166 | 167 | HorizontalLayout tagLayout = new HorizontalLayout(); 168 | tagLayout.setVerticalComponentAlignment(FlexComponent.Alignment.CENTER, removeButton, label); 169 | tagLayout.add(removeButton, label); 170 | 171 | return tagLayout; 172 | })); 173 | 174 | this.switchLayoutButton = new Button(); 175 | 176 | if (this.displayLines) 177 | { 178 | this.switchLayoutButton.setIcon(new Icon(VaadinIcon.GRID_SMALL)); 179 | } 180 | else 181 | { 182 | this.switchLayoutButton.setIcon(new Icon(VaadinIcon.LINES_LIST)); 183 | } 184 | 185 | this.switchLayoutButton.addClickListener(e -> { 186 | this.displayLines = !this.displayLines; 187 | 188 | if (this.displayLines) 189 | { 190 | this.switchLayoutButton.setIcon(new Icon(VaadinIcon.GRID_SMALL)); 191 | } 192 | else 193 | { 194 | this.switchLayoutButton.setIcon(new Icon(VaadinIcon.LINES_LIST)); 195 | } 196 | 197 | if (this.onViewChange != null) 198 | { 199 | this.onViewChange.accept(this.displayLines); 200 | } 201 | }); 202 | 203 | this.openFolderButton = new Button("Open folder"); 204 | 205 | this.openFolderButton.addClickListener(e -> { 206 | if (this.currentlySelectedElement != null) 207 | { 208 | try 209 | { 210 | Desktop.getDesktop().open(new File(this.currentlySelectedElement.getPath()).getParentFile()); 211 | } 212 | catch (IOException ex) 213 | { 214 | Log.error("Failed to open file location", ex); 215 | } 216 | } 217 | }); 218 | 219 | this.deleteButton = new Button("Delete"); 220 | 221 | this.deleteButton.addClickListener(e -> { 222 | if (this.currentlySelectedElement != null) 223 | { 224 | this.assetService.delete(this.currentlySelectedElement); 225 | 226 | if (this.onDelete != null) 227 | { 228 | this.onDelete.accept(this.currentlySelectedElement); 229 | } 230 | 231 | Notification.show("Removed file " + this.currentlySelectedElement.getFileName()); 232 | 233 | this.currentlySelectedElement = null; 234 | } 235 | }); 236 | 237 | this.deleteButton.addThemeVariants(ButtonVariant.LUMO_ERROR); 238 | 239 | this.progressBar = new ProgressBar(); 240 | this.progressBar.setVisible(false); 241 | 242 | this.progressLabel = new Label(""); 243 | 244 | Component[] fields = new Component[] { this.clazz.equals(ImageAsset.class) ? this.switchLayoutButton : UIUtils.heightFiller("40px"), 245 | UIUtils.heightFiller("10px"), 246 | this.clazz.equals(ImageAsset.class) ? this.openFolderButton : UIUtils.heightFiller("40px"), 247 | this.foundFilesLabel, 248 | UIUtils.heightFiller("30px"), 249 | this.searchTextField, 250 | this.fileNameFilterCheckbox, 251 | this.searchButton, 252 | UIUtils.heightFiller("10px"), 253 | this.progressLabel, 254 | this.progressBar, 255 | new Hr(), 256 | this.clazz.equals(ImageAsset.class) ? this.image : this.audioPlayer, 257 | new Hr(), 258 | this.addTagTextField, 259 | this.addTagButton, 260 | this.tagList, 261 | UIUtils.heightFiller("40px"), 262 | this.deleteButton 263 | }; 264 | 265 | formLayout.add(fields); 266 | innerDiv.add(formLayout); 267 | } 268 | 269 | private void onAddTagButton() 270 | { 271 | List tags = this.currentlySelectedElement.getTags(); 272 | String newTagName = this.addTagTextField.getValue().trim(); 273 | 274 | if (!tags.contains(newTagName) && !newTagName.isEmpty()) 275 | { 276 | tags.add(this.tagService.obtainTag(newTagName)); 277 | 278 | if (tags.size() > 1) 279 | { 280 | // if we have more than one tag we can remove the UNTAGGED tag if it exists 281 | Tag removeTag = new Tag(); 282 | removeTag.setName("UNTAGGED"); 283 | 284 | tags.remove(removeTag); 285 | } 286 | 287 | this.currentlySelectedElement.setTags(tags); 288 | this.assetService.save(this.currentlySelectedElement, this.saveTagsInMetadata); 289 | this.tagList.setItems(this.currentlySelectedElement.getTags().stream().map(Tag::getName)); 290 | } 291 | 292 | this.addTagTextField.focus(); 293 | } 294 | 295 | private void onRemoveTagButton(String tagName) 296 | { 297 | List tags = this.currentlySelectedElement.getTags(); 298 | 299 | Tag removeTag = new Tag(); 300 | removeTag.setName(tagName); 301 | 302 | tags.remove(removeTag); 303 | 304 | if (tags.isEmpty()) 305 | { 306 | tags.add(this.tagService.obtainTag("UNTAGGED")); 307 | } 308 | 309 | this.currentlySelectedElement.setTags(tags); 310 | this.assetService.save(this.currentlySelectedElement, this.saveTagsInMetadata); 311 | this.tagList.setItems(this.currentlySelectedElement.getTags().stream().map(Tag::getName)); 312 | } 313 | 314 | public void onSearchButton() 315 | { 316 | this.switchLayoutButton.setEnabled(false); 317 | this.openFolderButton.setEnabled(false); 318 | this.searchButton.setEnabled(false); 319 | this.addTagButton.setEnabled(false); 320 | this.deleteButton.setEnabled(false); 321 | 322 | UI.getCurrent().setPollInterval(500); 323 | UI ui = UI.getCurrent(); 324 | 325 | executorService.submit(() -> { 326 | var worker = new AssetSearchWorker(this); 327 | 328 | worker.onFinish(() -> { 329 | this.progressBar.setVisible(false); 330 | this.progressLabel.setText(""); 331 | 332 | this.switchLayoutButton.setEnabled(true); 333 | this.openFolderButton.setEnabled(true); 334 | this.searchButton.setEnabled(true); 335 | this.addTagButton.setEnabled(true); 336 | this.deleteButton.setEnabled(true); 337 | }); 338 | 339 | worker.work(ui); 340 | }); 341 | } 342 | 343 | public AssetService getAssetService() 344 | { 345 | return assetService; 346 | } 347 | 348 | public TagSearchTextField getSearchTextField() 349 | { 350 | return searchTextField; 351 | } 352 | 353 | public Checkbox getFileNameFilterCheckbox() 354 | { 355 | return fileNameFilterCheckbox; 356 | } 357 | 358 | public Label getFoundFilesLabel() 359 | { 360 | return foundFilesLabel; 361 | } 362 | 363 | public Consumer> getOnSearchConsumer() 364 | { 365 | return onSearchConsumer; 366 | } 367 | 368 | public ProgressBar getProgressBar() 369 | { 370 | return progressBar; 371 | } 372 | 373 | public Label getProgressLabel() 374 | { 375 | return progressLabel; 376 | } 377 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | bt.assetmanager 7 | btassetmanager 8 | BtAssetManager 9 | 1.1 10 | jar 11 | 12 | 13 | 17 14 | 23.1.7 15 | 4.2.1 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.7.3 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | central 30 | https://repo.maven.apache.org/maven2 31 | 32 | false 33 | 34 | 35 | 36 | vaadin-prereleases 37 | 38 | https://maven.vaadin.com/vaadin-prereleases/ 39 | 40 | 41 | 42 | 43 | Vaadin Directory 44 | https://maven.vaadin.com/vaadin-addons 45 | 46 | false 47 | 48 | 49 | 50 | 51 | jitpack.io 52 | https://jitpack.io 53 | 54 | 55 | 56 | vaadin-addons 57 | https://maven.vaadin.com/vaadin-addons 58 | 59 | 60 | 61 | 62 | 63 | 64 | central 65 | https://repo.maven.apache.org/maven2 66 | 67 | false 68 | 69 | 70 | 71 | vaadin-prereleases 72 | 73 | https://maven.vaadin.com/vaadin-prereleases/ 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | com.vaadin 82 | vaadin-bom 83 | ${vaadin.version} 84 | pom 85 | import 86 | 87 | 88 | 89 | 90 | 91 | 92 | com.vaadin 93 | 94 | vaadin 95 | 96 | 97 | com.vaadin 98 | vaadin-spring-boot-starter 99 | 100 | 101 | org.springframework.boot 102 | spring-boot-starter-logging 103 | 104 | 105 | 106 | 107 | com.h2database 108 | h2 109 | runtime 110 | 111 | 112 | 113 | com.vaadin 114 | exampledata 115 | 6.0.0 116 | 117 | 118 | 119 | org.springframework.boot 120 | spring-boot-starter-data-jpa 121 | 122 | 123 | org.springframework.boot 124 | spring-boot-starter-logging 125 | 126 | 127 | 128 | 129 | 130 | org.springframework.boot 131 | spring-boot-starter-validation 132 | 133 | 134 | org.springframework.boot 135 | spring-boot-starter-logging 136 | 137 | 138 | 139 | 140 | org.springframework.boot 141 | spring-boot-devtools 142 | true 143 | 144 | 145 | org.springframework.boot 146 | spring-boot-starter-logging 147 | 148 | 149 | 150 | 151 | org.springframework.boot 152 | spring-boot-starter-test 153 | test 154 | 155 | 156 | org.springframework.boot 157 | spring-boot-starter-logging 158 | 159 | 160 | 161 | 162 | com.vaadin 163 | vaadin-testbench 164 | test 165 | 166 | 167 | 168 | org.junit.vintage 169 | junit-vintage-engine 170 | test 171 | 172 | 173 | org.hamcrest 174 | hamcrest-core 175 | 176 | 177 | 178 | 179 | io.github.bonigarcia 180 | webdrivermanager 181 | 5.1.1 182 | test 183 | 184 | 185 | 186 | com.github.Bowtie8904 187 | BtCommons 188 | ba8fe2d70f 189 | 190 | 191 | 192 | org.vaadin.filesystemdataprovider 193 | filesystemdataprovider 194 | 3.2.0 195 | 196 | 197 | 198 | com.vaadin.componentfactory 199 | autocomplete 200 | 2.3.2 201 | 202 | 203 | 204 | com.github.Bowtie8904 205 | BtUserInterface 206 | 964ac8de 207 | 208 | 209 | 210 | 211 | org.apache.commons 212 | commons-imaging 213 | 1.0-alpha3 214 | 215 | 216 | 217 | io.github.fvarrui 218 | javapackager 219 | 1.6.7 220 | 221 | 222 | 223 | 224 | spring-boot:run 225 | 226 | 227 | org.springframework.boot 228 | spring-boot-maven-plugin 229 | 231 | 232 | -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5558 233 | 500 234 | 240 235 | 236 | 237 | 238 | 243 | 244 | com.vaadin 245 | vaadin-maven-plugin 246 | ${vaadin.version} 247 | 248 | 249 | 250 | prepare-frontend 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | production 262 | 263 | true 264 | 265 | 266 | 267 | 268 | com.vaadin 269 | vaadin-maven-plugin 270 | ${vaadin.version} 271 | 272 | 273 | 274 | build-frontend 275 | 276 | compile 277 | 278 | 279 | 280 | true 281 | 282 | 283 | 284 | 285 | io.github.fvarrui 286 | javapackager 287 | 1.6.7 288 | 289 | true 290 | bt.assetmanager.Application 291 | false 292 | ${project.basedir}\packageAssets 293 | 294 | 295 | 296 | bundling-for-windows 297 | package 298 | 299 | package 300 | 301 | 302 | windows 303 | ${project.basedir}\jre\windows\jdk-17.0.4.1+1-jre 304 | true 305 | 306 | 307 | 308 | bundling-for-linux 309 | package 310 | 311 | package 312 | 313 | 314 | linux 315 | true 316 | ${project.basedir}\jdk\linux\jdk-17.0.4.1+1 317 | ${project.basedir}\jre\linux\jdk-17.0.4.1+1-jre 318 | 319 | 320 | 321 | bundling-for-mac 322 | package 323 | 324 | package 325 | 326 | 327 | mac 328 | true 329 | ${project.basedir}\jdk\mac\jdk-17.0.4.1+1 330 | ${project.basedir}\jre\mac\jdk-17.0.4.1+1-jre 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | it 341 | 342 | 343 | 344 | org.springframework.boot 345 | spring-boot-maven-plugin 346 | 347 | 348 | start-spring-boot 349 | pre-integration-test 350 | 351 | start 352 | 353 | 354 | 355 | stop-spring-boot 356 | post-integration-test 357 | 358 | stop 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | org.apache.maven.plugins 367 | maven-failsafe-plugin 368 | 369 | 370 | 371 | integration-test 372 | verify 373 | 374 | 375 | 376 | 377 | false 378 | true 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | --------------------------------------------------------------------------------