-
-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved clipart config to JSON files (#2541)
- Loading branch information
Showing
63 changed files
with
8,997 additions
and
3,453 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...gner/src/main/java/com/willwinder/ugs/nbp/designer/gui/clipart/AbstractClipartSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.ugs.nbp.designer.gui.clipart; | ||
|
||
import java.util.List; | ||
|
||
public abstract class AbstractClipartSource implements ClipartSource { | ||
public abstract List<? extends Clipart> getCliparts(); | ||
|
||
@Override | ||
public List<? extends Clipart> getCliparts(Category category) { | ||
return getCliparts() | ||
.stream() | ||
.filter(clipart -> clipart.getCategory() == category || category == Category.ALL) | ||
.toList(); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/clipart/FontClipartSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright 2022-2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.ugs.nbp.designer.gui.clipart; | ||
|
||
import com.google.gson.Gson; | ||
import com.willwinder.ugs.nbp.designer.gui.clipart.model.FontMapping; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.awt.Font; | ||
import java.awt.FontFormatException; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author Joacim Breiler | ||
*/ | ||
public class FontClipartSource extends AbstractClipartSource { | ||
private final List<FontClipart> cliparts = new ArrayList<>(); | ||
private final FontMapping fontMapping; | ||
|
||
public FontClipartSource(String mappingFile) { | ||
fontMapping = loadFontMapping(mappingFile); | ||
Font font = loadFont(); | ||
fontMapping.getCliparts() | ||
.forEach(clipart -> clipart.getCategories().forEach(category -> | ||
cliparts.add(new FontClipart(clipart.getName(), category, font, clipart.getText(), this)))); | ||
} | ||
|
||
private FontMapping loadFontMapping(String mappingFile) { | ||
Gson gson = new Gson(); | ||
try { | ||
return gson.fromJson(IOUtils.toString(Objects.requireNonNull(FontClipartSource.class.getResourceAsStream(mappingFile)), StandardCharsets.UTF_8), FontMapping.class); | ||
} catch (IOException e) { | ||
throw new ClipartSourceException("Could not load clipart font mapping file", e); | ||
} | ||
} | ||
|
||
private Font loadFont() { | ||
try { | ||
return Font.createFont(Font.TRUETYPE_FONT, Objects.requireNonNull(FontClipartSource.class.getResourceAsStream(fontMapping.getFont()))).deriveFont(FONT_SIZE); | ||
} catch (IOException | FontFormatException e) { | ||
throw new ClipartSourceException("Could not load font", e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return fontMapping.getName(); | ||
} | ||
|
||
@Override | ||
public String getCredits() { | ||
return fontMapping.getCredits(); | ||
} | ||
|
||
@Override | ||
public String getUrl() { | ||
return fontMapping.getUrl(); | ||
} | ||
|
||
@Override | ||
public List<? extends Clipart> getCliparts() { | ||
return cliparts; | ||
} | ||
|
||
@Override | ||
public String getLicense() { | ||
return fontMapping.getLicense(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/clipart/model/FontMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.ugs.nbp.designer.gui.clipart.model; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* A model for deserialize font configuration JSON | ||
* | ||
* @author Joacim Breiler | ||
*/ | ||
public class FontMapping { | ||
private String font; | ||
private String name; | ||
private String credits; | ||
private String url; | ||
private String license; | ||
private List<FontMappingClipart> cliparts; | ||
|
||
public List<FontMappingClipart> getCliparts() { | ||
if (cliparts == null) { | ||
return Collections.emptyList(); | ||
} | ||
return cliparts; | ||
} | ||
|
||
public String getFont() { | ||
return font; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getCredits() { | ||
return credits; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getLicense() { | ||
return license; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...r/src/main/java/com/willwinder/ugs/nbp/designer/gui/clipart/model/FontMappingClipart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.ugs.nbp.designer.gui.clipart.model; | ||
|
||
import com.willwinder.ugs.nbp.designer.gui.clipart.Category; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A model for deserialize font configuration JSON | ||
* | ||
* @author Joacim Breiler | ||
*/ | ||
public class FontMappingClipart { | ||
private String name; | ||
private List<Category> categories; | ||
private String text; | ||
|
||
public String getName() { | ||
return StringUtils.defaultString(name, "Unknown"); | ||
} | ||
|
||
public List<Category> getCategories() { | ||
if (categories == null || categories.isEmpty()) { | ||
return List.of(Category.UNSORTED); | ||
} | ||
return categories; | ||
} | ||
|
||
public String getText() { | ||
return StringUtils.defaultString(text, "?"); | ||
} | ||
} |
Oops, something went wrong.