mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
resource optimization
This commit is contained in:
@@ -17,10 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.diylc.presenter;
|
package org.diylc.presenter;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.*;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -55,16 +52,15 @@ public class DatasheetService {
|
|||||||
private DatasheetService() {}
|
private DatasheetService() {}
|
||||||
|
|
||||||
public List<String[]> loadDatasheet(Class<?> clazz) {
|
public List<String[]> loadDatasheet(Class<?> clazz) {
|
||||||
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
|
||||||
return datasheetCache.computeIfAbsent(clazz.getCanonicalName(), key -> {
|
return datasheetCache.computeIfAbsent(clazz.getCanonicalName(), key -> {
|
||||||
String fileName = clazz.getSimpleName() + ".datasheet";
|
String fileName = clazz.getSimpleName() + ".datasheet";
|
||||||
LOG.info("Loading datasheet file for " + fileName);
|
LOG.info("Loading datasheet file for " + fileName);
|
||||||
URL resource = classloader.getResource(fileName);
|
InputStream inputStream = clazz.getResourceAsStream("/datasheets/" + fileName);
|
||||||
if (resource == null) {
|
if (inputStream == null) {
|
||||||
LOG.warn("Datasheet file not found: " + fileName);
|
LOG.warn("Datasheet file not found: " + fileName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try (BufferedInputStream in = new BufferedInputStream(resource.openStream())) {
|
try (BufferedInputStream in = new BufferedInputStream(inputStream)) {
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
|
||||||
|
|
||||||
List<String[]> types =
|
List<String[]> types =
|
||||||
|
|||||||
@@ -285,7 +285,8 @@ public class Freeway3x3_03 extends AbstractTransparentComponent<Void> implements
|
|||||||
if (svgDiagram == null) {
|
if (svgDiagram == null) {
|
||||||
try {
|
try {
|
||||||
byte[] data =
|
byte[] data =
|
||||||
IOUtils.toByteArray(Freeway3x3_03.class.getResourceAsStream("/freeway_3x3-03.svg"));
|
IOUtils.toByteArray(Freeway3x3_03.class.getResourceAsStream(
|
||||||
|
"/component-drawings/freeway_3x3-03.svg"));
|
||||||
ByteArrayInputStream bis = new ByteArrayInputStream(data);
|
ByteArrayInputStream bis = new ByteArrayInputStream(data);
|
||||||
SVGUniverse universe = new SVGUniverse();
|
SVGUniverse universe = new SVGUniverse();
|
||||||
URI url = universe.loadSVG(bis,
|
URI url = universe.loadSVG(bis,
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import org.diylc.awt.ImageUtils;
|
|||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
import org.diylc.common.Orientation;
|
import org.diylc.common.Orientation;
|
||||||
import org.diylc.components.AbstractTransparentComponent;
|
import org.diylc.components.AbstractTransparentComponent;
|
||||||
import org.diylc.components.boards.AbstractBoard;
|
|
||||||
import org.diylc.components.transform.ImageTransformer;
|
import org.diylc.components.transform.ImageTransformer;
|
||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
@@ -72,7 +71,7 @@ public class Image extends AbstractTransparentComponent<Void> {
|
|||||||
private Orientation orientation;
|
private Orientation orientation;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String name = "/image.png";
|
String name = "/diylc-library-images/image.png";
|
||||||
try (InputStream inputStream = Image.class.getResourceAsStream(name)) {
|
try (InputStream inputStream = Image.class.getResourceAsStream(name)) {
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
ICON = new ImageIcon(inputStream.readAllBytes(), name);
|
ICON = new ImageIcon(inputStream.readAllBytes(), name);
|
||||||
@@ -99,7 +98,7 @@ public class Image extends AbstractTransparentComponent<Void> {
|
|||||||
|
|
||||||
public Image() {
|
public Image() {
|
||||||
try {
|
try {
|
||||||
data = IOUtils.toByteArray(Image.class.getResourceAsStream("/image.png"));
|
data = IOUtils.toByteArray(Image.class.getResourceAsStream("/diylc-library-images/image.png"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ public class SVGImage extends AbstractTransparentComponent<Void> {
|
|||||||
|
|
||||||
public SVGImage() {
|
public SVGImage() {
|
||||||
try {
|
try {
|
||||||
data = IOUtils.toByteArray(SVGImage.class.getResourceAsStream("/diylc.svg"));
|
data = IOUtils.toByteArray(SVGImage.class.getResourceAsStream(
|
||||||
|
"/diylc-library-images/diylc.svg"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Reference in New Issue
Block a user